Skip to content

fix(#972,#975,#982): anchor v1 cache substitution, harden reconcile touched-path scope, fix stale reconcile doc wording - #985

Merged
fdaviddpt merged 4 commits into
mainfrom
fix/982
Oct 8, 2026
Merged

fdaviddpt merged 4 commits into
mainfrom
fix/982

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #972. Closes #975. Closes #982.

#972 -- scripts/log.sh

_remember_cfg_flatten_cache_path_v1() and the inline _f_v1 derivation in _remember_cfg_flatten_cache_publish() used a bare ${var/-v2-/-} substring substitution over the FULL path (including ${TMPDIR:-/tmp}), so a TMPDIR containing the literal substring -v2- (e.g. /mnt/build-v2-staging/tmp) diverted the substitution away from the real pre-#864 orphan-cache filename segment. Fixed by anchoring the substitution to the basename only at both call sites (split path into dir/base via %/* and ##*/, substitute only on the base).

New test file tests/test_tmpdir_v2_substring_collision_972.py, two tests -- the actual collision case and a positive control. Red confirmed against the pre-fix code (git stash the changed script, run, git stash pop): 1 failed as expected, positive control passed. Green: 5 passed combined with the pre-existing tests/test_v1_cache_orphan_cleanup_888.py.

#975 -- hooks.d/after_save/60-git-reconcile.sh pre-re-enable checklist

The whole file is unreachable in production (kill switch, unconditional exit 0) and its own test suite is entirely skip-disabled for the same reason, confirmed unchanged before and after this diff (6 passed, 21 skipped both times). Issue named 4 known defects:

  1. Fixed. _grc_compute_touched_paths swallowed git diff --name-only errors to 2>/dev/null with nobody checking rc, silently emptying the touched-path list while the consumer's _checkout_ok stayed 1. Now checks both calls' rc and falls back to $SLUG-only scope with a logged WARNING, mirroring the existing merge-base-failure fallback immediately above it.
  2. Fixed (two commits). core.quotePath left on for that diff output, so a touched path with non-ASCII/special bytes silently dropped out of the restore. A shared helper _grc_unquote_porcelain_path was factored out and applied at both the original call site and a new one. Self-review (see below) found the first version only stripped outer quote characters without decoding git's C-style interior escaping; fixed in a follow-up commit.
  3. Not code-changed, re-verified still present. Two residual TOCTOU windows, explicitly named and justified as deliberately deferred in the file's own comments and trap.d/966.residual-race.md -- out of scope for a same-diff fix (fix: scoped conflict-abort restore in 60-git-reconcile.sh can destroy another slug's concurrent write (regression in #952/#962) #966's own stated boundary).
  4. Not code-changed, re-verified still present. Only 1 of 5 _grc_rebase_in_progress call sites has a dedicated test, and that one test is itself skipped under the kill switch too. Adding dedicated tests for the other 4 sites was judged not worth doing: they would also be skipped and provide zero real verification until fix: 60-git-reconcile.sh conflict-abort restore can still destroy a concurrent write before the rebase --quit snapshot window (residual after #966) #969's real fix lands.

Verification for items 1 and 2's actual fix is reasoned/verified-by-direct-bash-repro, not observed-via-pytest -- the whole file's test harness cannot reach these functions while the kill switch holds: bash -n syntax-checks clean, and the active (non-skipped) test classes across the affected test files pass with no change in pass/skip counts.

Self-review correction

A reviewer found that the first version of _grc_unquote_porcelain_path only stripped outer " characters and did not decode git's C-style interior escaping (\", \\, \t, \n, \NNN octal for non-ASCII/control bytes) -- so the exact non-ASCII case item 2 claims to fix would still silently drop out of the restore. Reproduced directly: git's porcelain token for an accented filename renders as "caf\303\251.txt", and the first-version helper produced the literal 17-byte escape text, not the real UTF-8 filename. Fixed via a sentinel-protected printf '%b' pass, verified against 4 cases directly in bash (non-ASCII octal, embedded quote, plain unquoted, and the pathological literal-backslash-before-literal-quote case). No pytest regression test added for this helper specifically, for the same unreachability reason as the rest of the file.

#982 -- docs/configuration.md

docs/configuration.md line 31's git_reconcile.enabled row said the hook "exits immediately, before even reading this flag" -- false since PR #979, which made the hook read the flag first before deciding whether to log a hook-errors.log notice via report_error, prior to its still-unconditional exit 0. Fixed the doc row to describe the actual read-then-notify behavior, naming the hook-errors.log / /remember:doctor Recent-errors-WARN consequence for users who opted in.

Adjacent finding (same stale-wording class, found while verifying #979's "eight test copies" claim): tests/test_git_backup_push_rejected_253.py and tests/test_git_restore_hook_253.py still carried the identical false "exits before it ever reads git_reconcile.enabled" phrase in their own docstrings and assertion messages (not test logic) -- two of the test files #979 apparently did not cover. Fixed in this same diff: mechanical same-subsystem prose correction, one-sentence blast radius each, re-verified by re-running both files afterward (62 passed, no change in test logic, only message text changed).

Bookkeeping: trap.d/969.stale-reconcile-prose-not-updated.md removed per the issue's own note that it is now stale -- verified clean (0 matches) against all three files the fragment names before deleting.

New test file tests/test_reconcile_flag_doc_wording_982.py, three tests. Red confirmed against the pre-fix doc (git stash docs/configuration.md, run, git stash pop): 1 failed as expected. Green: 29 passed combined with tests/test_host_neutral_wording_562.py and tests/test_config_contract.py.

Docs

README.md: no change needed -- grepped for the stale phrases this diff touches ("exits immediately, before even reading", "v1 orphan") and confirmed both absent; README never described either of these internals.

Platform

Observed (macOS/darwin, bash 5): all pytest runs above, bash -n syntax checks, the direct bash reproductions of the quoting fix. Reasoned (not run on this machine): Linux/Windows legs of CI -- confirmed via reading .github/workflows/tests.yml that the matrix is ubuntu-latest/macos-latest/windows-latest x python 3.9-3.12, and that macos-latest resolves plain bash to the stock 3.2 binary this repo's own CLAUDE.md pins as the floor; all new/changed shell and the new Python test files were written against that floor.

[AI-generated]

fdaviddpt and others added 4 commits October 8, 2026 04:21
…ouched-path scope, fix stale reconcile doc wording

#972: scripts/log.sh's pre-#864 orphan-cache-path derivation used a bare
`${var/-v2-/-}` substring substitution over the full path instead of the
filename's own -v2- segment, so a TMPDIR containing the literal substring
-v2- diverted the substitution away from the real orphan. Anchored to the
basename at both call sites.

#975: two of the four known defects in the hard-disabled
60-git-reconcile.sh are fixed ahead of its eventual re-enable -- a
git diff --name-only failure while computing the touched-paths restore
scope is now logged and falls back to the pre-#952 scope instead of
silently narrowing to nothing, and that diff output is now unquoted the
same way the conflict-reporting path already was. The two residual TOCTOU
windows and the partial _grc_rebase_in_progress test coverage are
re-verified still present and still out of scope for a same-diff fix (the
code is entirely unreachable while #969's kill switch holds, and the
existing test suite for this file is fully skipped for the same reason).

#982: docs/configuration.md's git_reconcile.enabled row said the hook
"exits immediately, before even reading this flag" -- false since #979,
which made the hook read the flag first (only to decide whether to log a
hook-errors.log notice) before its unconditional exit. Same stale wording
corrected in two test files' own prose (#979 missed those, not just the
doc); the now-stale trap.d/969 bookkeeping fragment is removed since #979
did fix all three files it names.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Second half of the combined #972/#975/#982 fix -- the trap.d bookkeeping
removal landed in the previous commit; this one carries the actual code
fixes (scripts/log.sh, hooks.d/after_save/60-git-reconcile.sh,
docs/configuration.md), the two stale-wording corrections in test prose,
the two new regression test files, and the three changelog fragments.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ter quotes

Self-review finding (Explore spawn): the shared _grc_unquote_porcelain_path
helper added in the previous commit stripped only the leading/trailing
double-quote characters git's porcelain output wraps a path in -- it left
git's own C-style escaping of the path's interior untouched (an escaped
quote, an escaped backslash, a tab/newline, or octal for a non-ASCII/
control byte), so the exact case #975 item 2 names (a touched path with
non-ASCII bytes) still would not match the real file on disk after
"unquoting". Verified directly: the pre-fix helper turned the porcelain
token for cafe-with-accent.txt into the literal escape text, not the
real UTF-8 bytes.

Fixed by decoding the escapes properly: a literal escaped backslash is
protected behind a sentinel before printf %b decodes the rest (the
escaped quote and the octal/control escapes bash's own %b already
understands), then the sentinel is restored to a literal backslash.
Verified against four cases directly in bash: the non-ASCII octal case,
an embedded quote, a plain unquoted path, and the pathological case of a
literal backslash immediately followed by a literal quote in the real
filename (which a naive single-pass substitution gets wrong).

No new pytest regression test for this helper specifically -- the whole
hook (and its own test suite) is unreachable while #969's kill switch
holds, same constraint noted in the prior commit; bash -n syntax-checks
clean and the active (non-skipped) test classes in
tests/test_git_reconcile_903.py, tests/test_git_backup_push_rejected_253.py
and tests/test_git_restore_hook_253.py still pass (68 passed, 21 skipped,
no change in skip count).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ash-quote shape

CI on PR #985 failed 10 legs (pytest ubuntu/windows x python 3.9-3.12, plus
"hook tests (compiled)" on ubuntu/windows). Root cause: this repo's own
built-tree shape checker (tests/test_scanner_shapes_source_898.py,
.github/scripts/check_release_tree.py's BACKSLASH_QUOTE/ESCAPED_QUOTE,
#898 round 7/8) forbids a literal backslash-then-quote shape in a shipped
.sh file -- a sed/awk-style escape-replacement pattern the real Anthropic
directory portal scanner holds submissions on. The previous commit's
_grc_unquote_porcelain_path wrote exactly that shape twice
(${_grc_up_path//\\\"/\"}).

Rewrote the same two escape-replacement steps using variables built from
single characters (_grc_up_bs, _grc_up_bsbs, _grc_up_bsq) instead of a
literal backslash-quote sequence in the source -- the same convention
this file's own _grc_foreign_changes already uses for its outer-quote
strip (a `_grc_dq='"'` variable rather than an inline `\"`). Verified:

- All 5 decode cases (non-ASCII octal, embedded quote, plain path,
  pathological backslash-before-quote, tab control char) re-run directly
  in bash -- unchanged output, confirming the rewrite is behavior-
  preserving.
- bash -n syntax-checks clean.
- tests/test_scanner_shapes_source_898.py: 389 passed, both against the
  worktree directly and against a disposable local clone compiled with
  .github/scripts/compile_hooks.py --apply (the exact step the failing
  "hook tests (compiled)" CI job runs) -- zero BACKSLASH_QUOTE/
  ESCAPED_QUOTE hits either way.
- Full previously-targeted test set re-run: 465 passed, 21 skipped (no
  change in skip count -- the kill-switch-disabled reconcile suite is
  unaffected).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit ee82161 into main Oct 8, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the fix/982 branch October 8, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant