Repository navigation
fix(jsonlstore): assert the store root's real normalization contract - #744
Merged
Merged
Conversation
The hole: two jsonlstore tests expected the store root to be symlink-resolved. `normalizeStoreRoot` has only ever called `filepath.Abs` — absolute plus lexical Clean, no symlink resolution — and #673 changed no production line in this package; it edited test files only, running `filepath.EvalSymlinks` over the *expectations*. On Linux `t.TempDir()` is already canonical so the two agree and CI stays green. On macOS `/var` is a symlink to `/private/var`, so `TestStoreNormalizesRootAndConfinesInventoryNames` and `TestSessionStorageContinuity_Scenario1_AtomicCrashRecovery/temporary _replacement_shares_destination_directory` both fail on `main`. The fix: revert both expectations to the un-resolved path, which is what the store actually produces, and document the invariant on `normalizeStoreRoot` so a future macOS flake is not "fixed" by swapping in EvalSymlinks on the production side. The invariant preserved: the store root is the path the operator configured, normalized lexically. Every resolver-derived path, flock identity and diagnostic hangs off it, so resolving symlinks there would silently rewrite all of them. Proof: the two tests above now pass on macOS and remain unchanged in meaning on Linux — they assert `filepath.Abs` semantics directly. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Two tests in
internal/adapter/store/jsonlstorefail on macOS, onmainitself. They pass on Linux, which is why CI is green.TestStoreNormalizesRootAndConfinesInventoryNamesTestSessionStorageContinuity_Scenario1_AtomicCrashRecovery/temporary_replacement_shares_destination_directoryOn macOS
/varis a symlink to/private/var, sot.TempDir()hands back a non-canonical path. Both tests run their expectation throughfilepath.EvalSymlinksand compare it against a value the store derives withfilepath.Abs.Failure 2 looks at first glance like production rejecting a directory, but it is not: the string
"temporary replacement is not in the snapshot directory"lives only in the test file — it is the error returned by the test's own injectedops.createTempstub. Production just wraps it asprobe atomic replacement: %w.Which side was wrong: (b), test over-specification
normalizeStoreRootcallsfilepath.Abs— absolute plus lexicalClean, no symlink resolution. Evidence it was never meant to do more:git log -S normalizeStoreRootreturns exactly one commit, 433ae87 (feat(storage): preserve session continuity at scale #645), which introduced it withfilepath.Abs. It has never calledEvalSymlinks.EvalSymlinksexpectations, 68bf0e6 (feat(authority): enforce delegated capability sets #673), touched no production line in this package —git show 68bf0e6 --stat -- internal/adapter/store/jsonlstore/lists four test files, +11/−4. It was a test-only edit asserting behaviour the store never had.cmd/mecatui/state.go("Workspaces are realpath-keyed (filepath.Abs + EvalSymlinks)"),internal/app/escapeclassifier.go,internal/app/driverstore.go.jsonlstoreis deliberately not one of them.So this is (b), not a production regression. Nothing in the store is broken; the assertions describe a contract it does not have.
The fix
Revert both expectations to the un-resolved path and document the invariant on
normalizeStoreRoot, so the next person hitting this on macOS doesn't "fix" it by addingEvalSymlinksto the production side.Invariant preserved: the store root is the path the operator configured, normalized lexically. Every resolver-derived path, flock identity and diagnostic hangs off
resolver.dir, so resolving symlinks there would silently rewrite all of them — for every store on macOS, and for any deployment pointing at a symlinked volume.Proof: both tests now pass on macOS and are unchanged in meaning on Linux — they assert
filepath.Abssemantics directly.Gates
task lint— clean (0 issues across all modules).go test ./internal/adapter/store/jsonlstore/— green on macOS (was 2 failures).go test -race ./internal/app/— green.