Skip to content

test: make "missing path" assertions hermetic - #34

Merged
ronak-create merged 1 commit into
masterfrom
fix/hermetic-missing-path-tests
Aug 18, 2026
Merged

test: make "missing path" assertions hermetic#34
ronak-create merged 1 commit into
masterfrom
fix/hermetic-missing-path-tests

Conversation

@ronak-create

Copy link
Copy Markdown
Member

Problem

Fifteen tool test suites hardcode an absolute path to assert not-found behaviour:

result, err := runWC([]string{"/nonexistent/file.txt"}, ...)

This assumes the path is absent from whatever machine runs the tests. That holds on no platform by guarantee, and on Windows it is actively wrong: /nonexistent/file.txt resolves to C:\nonexistent\file.txt, an ordinary creatable location.

When the path does exist, the assertion silently inverts — the test stops exercising the missing-file branch and starts exercising a real file.

This is not hypothetical. On a machine carrying a stray C:\nonexistent\path (a bare git repo, unrelated to this project), TestDu_NonExistent fails on master:

--- FAIL: TestDu_NonExistent (0.00s)
    du_test.go:173: expected error for non-existent path
FAIL    github.com/synseqack/aict/tools/du

du is correct here — it walked a directory that genuinely exists and correctly reported no errors. The test is what's broken. The other fourteen sites carry the identical latent fault and fail the same way given the right filesystem state.

Fix

Add internal/testutil.MissingPath, which anchors the path to t.TempDir() — a directory the test framework creates empty and removes on cleanup, so the leaf name is reliably absent on every platform:

func MissingPath(t *testing.T, name string) string {
	t.Helper()
	return filepath.Join(t.TempDir(), name)
}

Then swap all fifteen call sites (awk, cat, checksums, diff, du, file, find, head, ls, realpath, sed, stat, tail, tar, wc). Leaf names are preserved so extension-sensitive tools (file, tar) keep testing what they tested before.

Verification

  • go test ./... — full suite green, with the stray C:\nonexistent\path still present on disk, which is what demonstrates the hermeticity rather than a cleanup.
  • go vet ./... clean.
  • gofmt -l reports no new entries (pre-existing formatting drift in non-test sources is untouched and out of scope here).

Test-only change: no tool behaviour is modified.

Fifteen tool test suites hardcoded absolute paths such as
"/nonexistent/file.txt" to assert not-found behaviour. That assumes the
path is absent from whatever machine runs the tests -- guaranteed on no
platform, and actively wrong on Windows, where "/nonexistent/file.txt"
resolves to C:\nonexistent\file.txt, an ordinary and creatable location.

When such a path does exist the assertion silently inverts. On a machine
with a stray C:\nonexistent\path, TestDu_NonExistent walked a real
directory tree, collected zero errors, and failed -- while du itself was
behaving correctly. The other fourteen sites carry the same latent fault.

Add internal/testutil.MissingPath, which anchors the path to t.TempDir():
a directory the test framework creates empty and removes on cleanup, so
the leaf name is reliably absent everywhere. Use it at all fifteen sites.

Co-authored-by: u84u <u84u@aol.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ronak-create
ronak-create merged commit 4050549 into master Aug 18, 2026
11 checks passed
@ronak-create
ronak-create deleted the fix/hermetic-missing-path-tests branch August 18, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant