Skip to content

fix(jsonlstore): assert the store root's real normalization contract - #744

Merged
jhrozek merged 1 commit into
mainfrom
fix/jsonlstore-store-root-symlink-expectation
Aug 24, 2026
Merged

jhrozek merged 1 commit into
mainfrom
fix/jsonlstore-store-root-symlink-expectation

Conversation

@jhrozek

@jhrozek jhrozek commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

The bug

Two tests in internal/adapter/store/jsonlstore fail on macOS, on main itself. They pass on Linux, which is why CI is green.

  1. TestStoreNormalizesRootAndConfinesInventoryNames
    storage_path_test.go:20: normalized store root = "/var/folders/.../001/store",
                              want "/private/var/folders/.../001/store"
    
  2. TestSessionStorageContinuity_Scenario1_AtomicCrashRecovery/temporary_replacement_shares_destination_directory
    session_storage_durability_internal_test.go:40: newStoreWithSnapshotOps:
      jsonlstore: probe atomic replacement: temporary replacement is not in the snapshot directory
    

On macOS /var is a symlink to /private/var, so t.TempDir() hands back a non-canonical path. Both tests run their expectation through filepath.EvalSymlinks and compare it against a value the store derives with filepath.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 injected ops.createTemp stub. Production just wraps it as probe atomic replacement: %w.

Which side was wrong: (b), test over-specification

normalizeStoreRoot calls filepath.Abs — absolute plus lexical Clean, no symlink resolution. Evidence it was never meant to do more:

  • git log -S normalizeStoreRoot returns exactly one commit, 433ae87 (feat(storage): preserve session continuity at scale #645), which introduced it with filepath.Abs. It has never called EvalSymlinks.
  • The commit that introduced the EvalSymlinks expectations, 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.
  • Elsewhere in the repo, where canonicalization is intended, production does it and says so — cmd/mecatui/state.go ("Workspaces are realpath-keyed (filepath.Abs + EvalSymlinks)"), internal/app/escapeclassifier.go, internal/app/driverstore.go. jsonlstore is 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 adding EvalSymlinks to 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.Abs semantics 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.

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]>
@jhrozek
jhrozek merged commit de8df36 into main Aug 24, 2026
18 checks passed
@jhrozek
jhrozek deleted the fix/jsonlstore-store-root-symlink-expectation branch August 24, 2026 11:05
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