Skip to content

test(ledger): a project fold outlives a branch switch and a new commit - #754

Merged
fajarhide merged 3 commits into
mainfrom
test/739-ledger-folds-across-branch-switch
Sep 3, 2026
Merged

test(ledger): a project fold outlives a branch switch and a new commit#754
fajarhide merged 3 commits into
mainfrom
test/739-ledger-folds-across-branch-switch

Conversation

@fajarhide

@fajarhide fajarhide commented Sep 3, 2026

Copy link
Copy Markdown
Owner

The host's prompt cache is pinned to the git snapshot it started on, so a checkout or a
new commit means the next session shares no prefix and starts cold, even where the bytes
are identical. The ledger's project scope is keyed on the repository root and never reads
a ref, so it folds across both. That is the one saving in this lane the cache
structurally cannot make, and nothing asserted it: grep -n branch src/ledger/mod.rs
returned a doc comment about something else.

The test primes a project scope from a real repository's project_key, switches branch
and lands a commit under it, then asks a new session id for the same block and requires
the fold.

Real git rather than a hand-built .git directory, because the property is that a real
snapshot change does not move the scope, and a fabricated .git would still pass if
someone made the key shell out to git rev-parse. It runs hermetically:
GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM point at files that do not exist and the
identity is set per process, so the machine's own git config decides nothing.

Verification: make ci green, including smoke_test.sh 70/70. Driven red twice, once
per direction it can be wrong.

Making project_key read .git/HEAD, which is the refactor this exists to catch:

assertion `left == right` failed: the project scope moved with the branch, so every
session after a checkout would open a fresh history
  left: "/var/folders/.../.tmpmnkzui#ref: refs/heads/feature"
 right: "/var/folders/.../.tmpmnkzui#ref: refs/heads/main"

Pointing the second session at another project scope, which proves the fold assertion
carries its own weight:

panicked at src/ledger/mod.rs:1800:14:
the project history has to outlive the snapshot it was recorded on

Closes #739

Greptile Summary

The PR adds a regression test proving that project-scoped ledger folding survives a real Git branch switch and subsequent commit.

  • Adds a helper that invokes Git without inherited Git-specific environment configuration.
  • Creates a real temporary repository, records project history, changes its snapshot, and verifies a new session still receives the fold.
  • Documents the regression fix in the changelog.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/ledger/mod.rs Adds hermetic Git test infrastructure and branch-switch regression coverage; both previously reported environment-isolation issues are fixed.
changelog.d/739.fixed.md Accurately documents the newly covered project-ledger behavior.

Reviews (3): Last reviewed commit: "test(ledger): uppercase the GIT_ prefix ..." | Re-trigger Greptile

The host's prompt cache is pinned to the git snapshot it started on, so a
checkout or a new commit starts the next session cold even where the bytes are
identical. The ledger's project scope is keyed on the repository root and never
reads a ref, so it folds across both. That is the one saving in this lane the
cache structurally cannot make, and nothing asserted it.

Real git rather than a hand-built .git directory: the property is that a real
snapshot change does not move the scope, and a fabricated .git would still pass
if someone made the key shell out to git rev-parse. Run hermetically, with
GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM pointed at files that do not exist, so
the machine's own git config decides nothing.

Closes #739
Comment thread src/ledger/mod.rs Outdated
Greptile on #754: the helper called itself hermetic while only pinning the
config files. GIT_DIR alone points the whole test at another repository, and
it surfaces as 'fatal: this operation must be run in a work tree' from a test
that never mentions one. Reproduced with GIT_DIR set, rc=101 on 'git add'.

Removing every inherited GIT_* rather than a list of the ones that bite: the
list would need maintaining, and the loop is shorter than the list.
Comment thread src/ledger/mod.rs Outdated
Windows treats environment names case-insensitively and git honours them that
way, so a git_dir would have survived the case-sensitive prefix check and kept
the hole the previous commit closed.
@fajarhide
fajarhide merged commit 8d39e60 into main Sep 3, 2026
14 checks passed
@fajarhide
fajarhide deleted the test/739-ledger-folds-across-branch-switch branch September 3, 2026 05:06
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.

No test asserts the ledger folds across a branch switch, which is the one saving the host cache structurally cannot make

1 participant