Repository navigation
Conversation
…h test gap 60-git-reconcile.sh: - #952 item 1: pass --no-autostash on every `git rebase` call -- without it, a dirty tracked write from another slug sharing REPO_ROOT gets silently autostashed when the rebase starts, and `rebase --quit` (unlike --abort) never re-applies the stash. The rebase now simply refuses to start while that write is present, with no stash created. - #952 item 2: the scoped abort restore no longer assumes every commit a rebase could replay is confined to $SLUG/ -- a shared REPO_ROOT's ahead/behind commit set can span other slugs too. The restore scope is now computed before the rebase starts, as the union of this run's own ahead commits and the remote's behind commits diffed against their merge-base, and covers every one of those paths on abort. - #952 item 3: before `rebase --quit` discards it, read git's own record of which branch the rebase started from (rebase-merge/head-name). When it differs from the configured/detected branch, refuse to switch HEAD and report the mismatch instead of silently moving it to the wrong commit. - #953: `_grc_rebase_in_progress` now distinguishes "the git-path check itself failed" from "no rebase-merge/rebase-apply directory exists" -- every call site declines with a distinct, honest "could not determine" message instead of silently treating an undetermined check as settled. tests/test_autonomous_log_retention_487.py: - #951: the file's two "fast path" tests asserted only the sweep's outcome, never that `_remember_auto_ref` was actually built by the real `mktemp` on the runner -- a silent mktemp failure would have these tests exercise the fallback instead, as a duplicate of its sibling, with nothing to say so. A shimmed `mktemp` binary now records whether it was invoked and succeeded, independent of the extracted block's own variable scoping and its `2>/dev/null` redirect, so every fast-path (and fallback) test can assert which path actually ran. New regression tests cover autostash, the multi-slug restore scope, and the could-not-tell decline, each confirmed red against the pre-fix hook and green after. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…logged merge-base fallback, stale header Three findings from the self-review's two spawns (Explore + oss:auditor), both independently flagging the merge-base fallback gap: - _grc_rebase_in_progress's could-not-tell (#953) only fired when BOTH `rev-parse --git-path` calls failed -- if exactly one failed while the other succeeded and reported "no directory", the function fell through to "not in progress" even though the failed half's own answer was unknown. Now returns could-not-tell when EITHER call fails (and neither succeeding call found a directory). - _grc_compute_touched_paths's merge-base-failure fallback to $SLUG alone (the pre-#952 scope) was silent -- indistinguishable from "the rebase genuinely only ever touches this one slug". Now logs a WARNING on that branch. - The hook's top-of-file DESCRIPTION comment still described the old, $SLUG-only restore scope #952 item 2 replaced; updated to match. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Non-blocking observation from the self-review's own auditor spawn: only one of the five _grc_rebase_in_progress call sites has a dedicated test forcing the new rc=2 (could-not-tell) path; the other four were verified by reading the code, not by a test exercising that site specifically. Left for /oss:curate to judge whether a jit-context rule belongs here. Co-Authored-By: Claude Sonnet 5 <[email protected]>
CI (PR #960, windows-latest jobs 112746585138/...109/...145/...152 and the "hook tests (compiled)" leg) showed the two fast-path tests reading back an empty mktemp_shim_log on every one of those legs, regardless of which code path the extracted block actually took. Root cause: both paths the shim's own bash content embeds -- `$MKTEMP_SHIM_LOG` (the append-redirect target) and the real `mktemp` binary's own path -- arrive from Python as Windows-native, backslash- separated strings on that platform. The append redirect, the shim's very first statement, silently failed to open under git-bash there, so neither "INVOKED" nor "SUCCEEDED" was ever written on any run. Forward-slashing both before they reach the shim's bash content fixes it: a forward-slash absolute path is accepted by git-bash on every platform this test suite runs on, POSIX included, where the replace is simply a no-op (confirmed locally: full file still 14/14 green on macOS). Python's own `.exists()`/`.read_text()` calls on `marker_log` are untouched and keep using the OS-native Path object -- Windows' file APIs accept '/' as a separator too, so both sides of the same file reference agree regardless of which form each uses. Same class of bug this file's own OSTYPE-gated REMEMBER_DIR forward- slashing (#448/#263) already exists to catch, just unconditional here rather than $OSTYPE-gated, since the no-op case costs nothing. Not independently observed on an actual Windows runner from this session -- reasoned from the job log's own stack trace and git-bash's documented path handling, and from the existing OSTYPE-gated precedent in this same file needing the identical fix for a sibling path. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Re-verified after f04fd42 (the forward-slash fix): CI is still RED on all five windows-latest legs (pytest 3.9/3.10/3.11/3.12, "hook tests (compiled)"), on the exact same commit the fix was meant to clear — same failure mode as before: That rules out the forward-slash theory as the actual root cause (or at least as the only one): an empty log means the shim's Suspect lead, from reading the diff rather than reproducing on Windows (same caveat the fix commit itself carried — reasoned, not observed on a runner):
with os.fdopen(fd, "w", newline="\n") as f:
f.write(script)— specifically to stop Python's default universal-newline translation from turning the script's This is a lead to investigate, not a confirmed fix — I haven't reproduced on an actual Windows runner either. Routing this PR back as needs-fix: CI is still red on windows-latest, the specific failure the last fix commit targeted is unresolved, and the next attempt should rule the CRLF-write theory in or out before trying another path-separator-shaped fix. |
…text() CI (PR #960, re-pulled job 112755717371 after the forward-slash fix landed): the exact same failure persisted, unchanged -- mktemp_shim_log still empty on every windows-latest leg. The forward-slash fix (f04fd42) was reasoned, not reproduced, and turned out not to be the (whole) story. Real root cause, found by re-reading this same test file's own _run_bash_script a few lines below the new shim code: `Path.write_text()` applies universal-newline translation on write by default (`newline= None`), turning every `\n` in the content into `os.linesep` -- `\r\n` on Windows. A CRLF-corrupted `#!/bin/sh\r` shebang is a classic "bad interpreter" exec failure -- the script never starts at all, which reads as every statement in it, not just a later one, having silently not run -- exactly the "empty from the very first line" shape CI showed both times. `_run_bash_script` already works around this exact class of bug via `os.fdopen(fd, "w", newline="\n")`; the new shim-writing code added for #951 did not follow that same discipline, and two PRE-EXISTING shim writers elsewhere in this file (`wrapper`, `fake_mktemp` x2) share the identical gap -- their own tests happened to still pass regardless, since "the shim never runs due to CRLF corruption" and "the shim runs and deliberately exits 1" are indistinguishable outcomes for a script whose only job is to make mktemp fail. Added `_write_shell_script()` (a thin `open(path, "w", newline="\n")` wrapper -- not `Path.write_text(newline="\n")`, since that keyword only exists from Python 3.10 and this repo's own CI matrix still runs 3.9) and switched all 4 shim-writing call sites in this file to it. Honesty on reproduction, as asked: this fix is reasoned from re-reading `_run_bash_script`'s own documented precedent for the identical class of bug, not independently reproduced on a Windows runner from this session -- but unlike the forward-slash fix, this one explains why the FIRST statement of the shim (the one with no path embedded in it at all) never ran either, which the forward-slash theory could not account for. If this is not the whole story, the next job log will show whether `mktemp_shim_log` still comes back completely empty (ruling this fix out too) or starts showing partial content (narrowing further). Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ot env["PATH"] Two prior attempts in this PR (f04fd42 forward-slashing shim content, da6f02d fixing the shebang's newline) left the CI symptom byte-for-byte unchanged: on windows-latest, mktemp_shim_log reads back empty -- the shim is never invoked at all, not even its own first echo line. A reviewer flagged the real candidate: both fast-path helpers build the subprocess PATH as os.pathsep.join([...]) (";" on Windows) using native, drive-lettered directories, then hand it to bash.exe via env["PATH"]. Locally simulated (bash on this machine, no MSYS needed): bash's own POSIX ":"-splitting of a raw Windows-style PATH value shreds it on the drive letter's own colon -- identically whether the value is forward-slashed or not, which is exactly why the first fix attempt made no difference, and reproduces the "nothing found via PATH, not even the shim's own first statement" symptom without needing a Windows runner at all. Fix: _bash_path_prepend() converts a prepended directory to the MSYS-style posix form (/c/Users/...), no colon anywhere) and the helpers inject it into the SCRIPT TEXT itself via export PATH="...:$PATH", rather than through env["PATH"] -- so it needs no env-block win32<->posix conversion to already be correct. Applied to both PATH-prepending call sites in the file (the #951 fast-path helper, and the sibling fork-counting helper, which had the same latent issue: a broken PATH there would make its own fork-count assertion pass vacuously instead of failing). A new platform-independent unit test (test_bash_path_prepend_strips_the_drive_letters_own_colon) pins the string transform directly. All 15 tests in tests/test_autonomous_log_retention_487.py still pass locally (macOS); the Windows-specific claim (that bash's native PATH conversion is what was silently failing) is reasoned from a local bash simulation, not observed on a real Windows runner -- see the PR body for what remains reasoned vs. verified. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…xtended-length paths Explore found _bash_path_prepend's output spliced into the generated script's export PATH="...:$PATH" line with no escaping, unlike every other dynamic value this file embeds (shlex.quote throughout) -- a literal double-quote, backtick or dollar sign surviving into a prepended directory would break the quoting or trigger substitution in the generated script. Not reachable by any current call site (pytest tmp_path dirs), but free to close and brings it in line with the file's own convention. oss:auditor found _to_posix's drive-letter check (s[1] == ":") never fires for an extended-length Windows path (two backslashes, "?", one backslash, then the drive letter -- a backslash, not a colon, sits at index 1), so such a path would fall through to the bare forward-slash branch and still carry the drive letter's own colon -- the exact shredding bug this whole fix exists to avoid. Stripped before the drive-letter check. Reasoned, not observed: no Windows access to confirm whether tempfile.mkdtemp() ever actually returns one of these. oss:auditor also found the new unit test's docstring overclaimed "runs on every leg" -- it still inherits this module's blanket skipif(BASH is None), even though its own assertions need no bash. Corrected the docstring rather than restructuring the module-wide skip, which is a larger change than this fix's own scope. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…3 CI failure Not reproducible locally in 3 isolated runs of the file; CI's own job log shows it failing consistently across all macOS legs on the same commit. Different file, different subsystem (#952's reconcile hook, not this lane's PATH-building fix) -- logged for the maintainer rather than silently expanded into or silently dropped. Co-Authored-By: Claude Sonnet 5 <[email protected]>
tests/test_autonomous_log_retention_487.py's fast-path tests previously asserted only the sweep's outcome, never that `_remember_auto_ref` was actually built by the real `mktemp` on the runner, so a test named after the fast path could pass just as well if the fallback silently ran instead. Added a `MKTEMP_SHIM_LOG`-based marker to the 4 relevant tests. Windows CI then exposed a second bug this change's own evidence mechanism needed to not be red: both PATH-prepending helpers in this file built the subprocess PATH as env["PATH"] = os.pathsep.join(...) with native, drive-lettered directories, and bash's own colon-based PATH splitting shreds a C:\...;C:\...-style value on the drive letter's own colon -- independent of slash direction. Added _bash_path_prepend(), which converts each prepended directory to MSYS-posix form (/c/...) and injects it into the generated bash script text via export PATH=... instead of through the env block, applied at both PATH-prepending call sites in the file. Verified on windows-latest CI across both the pytest and compiled-hook legs: all 5 legs green, the raw job log shows no failing assertion, and the fix was reached by locally reproducing bash's own colon-splitting behavior on a non-Windows machine rather than by assumption alone. Split out of the original combined #951/#952/#953 PR (#960): this part is done and verified; the macOS-only #952/#953 regression in a different file is a separate, still-open investigation and should not block this fix from shipping. Closes #951 Co-authored-by: Claude Sonnet 5 <[email protected]>
…ck (#962) * fix(#952,#953): close three reconcile regressions, 3-state rebase check hooks.d/after_save/60-git-reconcile.sh: - #952 item 1: pass --no-autostash on every git rebase call -- without it, a dirty tracked write from another slug sharing REPO_ROOT gets silently autostashed when the rebase starts, and rebase --quit (unlike --abort) never re-applies the stash. The rebase now refuses to start while that write is present, with no stash created. - #952 item 2: the scoped abort restore no longer assumes every commit a rebase could replay is confined to $SLUG/ -- a shared REPO_ROOT's ahead/behind commit set can span other slugs too. The restore scope is now computed before the rebase starts, as the union of this run's own ahead commits and the remote's behind commits diffed against their merge-base, and covers every one of those paths on abort. - #952 item 3: before rebase --quit discards it, read git's own record of which branch the rebase started from (rebase-merge/head-name). When it differs from the configured branch, refuse the symbolic-ref switch and report the mismatch instead of silently moving HEAD. - #953: _grc_rebase_in_progress now returns a distinct could-not-tell state (rc=2) when the underlying git rev-parse --git-path check itself fails, rather than collapsing that into "not in progress". All 5 call sites branch on the 3-state result explicitly. tests/test_git_reconcile_903.py: regression tests for all of the above, 23/23 passing. Split out of the original combined #951/#952/#953 PR (#960) by the maintainer: #951's fix (Windows-only, test-only) is done and verified and was shipped separately in #961; this PR carries the still-open #952/#953 investigation, which continues to fail on macOS CI only (not locally reproducible so far -- see trap.d/951.pr960-macos-reconcile-903-not-reproducible-locally.md and the open comment on #952 documenting the same). Closes #952 Closes #953 Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(#962): avoid bash 4.0+ mapfile in the git-reconcile scoped restore 60-git-reconcile.sh's scoped-abort restore (#952/#953) used `mapfile` to populate _GRC_TOUCHED_PATHS and _grc_existing. mapfile is a bash 4.0+ builtin, absent from this repo's documented floor (bash 3.2, stock macOS /bin/bash) -- exactly what GitHub Actions' macos-latest runner resolves plain `bash` to. There it fails as "command not found", silently leaving both arrays empty, so the scoped checkout/prune restored nothing: a real conflict left the file with merge markers, another slug's upstream-only change was never restored, and no notice or log was written -- the six macOS CI failures on PR #962. Reproduced directly against this machine's own stock /bin/bash 3.2.57 (identical interpreter to the CI runner's), both via a minimal mapfile probe and by running the hook's own conflict-abort scenario end to end; confirmed red before the fix (6 failed under a PATH forcing `bash` to resolve to the floor interpreter, matching CI exactly) and green after. Replaced each mapfile call with a while-IFS=-read loop into the array, which works on every bash version this repo supports. Adds a static guard (tests/test_git_reconcile_mapfile_floor_952.py) so no shipped shell script reintroduces mapfile/readarray, plus the same floor-bash behavioural reproduction as a regression test. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(#962): widen the mapfile static guard's anchor set (self-review) Two independent reviewers (a general diff review and oss:auditor) flagged the same gap in test_git_reconcile_mapfile_floor_952.py's regex-based static guard: it only recognised `mapfile`/`readarray` preceded by `;`/`&`/`|`/`(`/`then`/`do`, missing real shell command-start shapes such as `else mapfile ...`, `elif mapfile ...`, a `case` branch (`pat) mapfile ...`), or a brace-group (`{ mapfile ...; }`). None of the current shipped shell happens to use those shapes, so the guard's current "clean" verdict was still correct, but a future mapfile call written in one of them would have passed silently. Widened the anchor set and added a positive-control assertion for each of the four missing shapes; also reworded one docstring line a reviewer found referred to an import that does not exist (the win32 skip is a local re-declaration, not an import, matching the row this file's own docs/windows-skip-triage.md entry already describes correctly). Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
…), not Path.write_text() (#998) * Fix #994: write the fail-hook shebang via open(newline="\n"), not Path.write_text() `tests/test_git_backup_rotate_advice_974.py::test_could_not_untrack_also_logs_rotate_advice` wrote its `pre-commit` hook script with `Path.write_text()`, whose default `newline=None` applies universal-newline translation and would turn the shebang's `\n` into `\r\n` on Windows, corrupting it into a "bad interpreter" exec failure instead of the intended `exit 1`. Extracted into `_write_fail_hook`, now written via `open(path, "w", newline="\n", encoding="utf-8")`, the same pattern `tests/test_autonomous_log_retention_487.py`'s `_write_shell_script` already uses for the identical reason (CI, PR #960, windows-latest). Inert today -- this whole file is skipped on win32 for an unrelated reason (#79), so nothing in CI exercises the CRLF path either way -- but fixed rather than left as a trap for whoever narrows that skip later. Adds a regression test pinning the write *call* itself (via unittest.mock.patch.object(Path, "write_text", ...)), not the output bytes: os.linesep is already "\n" on every platform this suite can exercise locally, so the corrupted bytes this bug produces on Windows would not appear here even without the fix. Red (pre-fix, Path.write_text() reinstated): 1 failed - AssertionError: pre-commit hook written via Path.write_text(), not open(newline='\n') Green (post-fix): tests/test_git_backup_rotate_advice_974.py -- 5 passed in 2.02s Co-Authored-By: Claude Sonnet 5 <[email protected]> * Fix #994 follow-up: self-review caught the fix never reached the named test Both spawned reviewers (Explore and oss:auditor) independently found the same bug in the previous commit: `_write_fail_hook` was added and unit- tested in isolation, but `test_could_not_untrack_also_logs_rotate_advice` -- the exact test #994, the commit message and the changelog fragment all named as the one being fixed -- still built its own `pre_commit` path and called `Path.write_text()` directly, unchanged. The new helper was dead code from the production test suite's point of view. Rewires that test to call `_write_fail_hook(hooks_dir)` instead of inlining the vulnerable write. Re-ran tests/test_git_backup_rotate_advice_974.py after this fix: 5 passed. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Summary
Fixes three regressions in
hooks.d/after_save/60-git-reconcile.shintroduced by the #945rebase --quitrewrite, adds a 3-state result to_grc_rebase_in_progressso a could-not-tell case stops collapsing into nothing-there, and fixes a test-evidence gap intests/test_autonomous_log_retention_487.py's fast-path tests for the mktemp-based auto-ref.Closes #951
Closes #952
Closes #953
#951 -- fast-path tests now carry positive evidence
tests/test_autonomous_log_retention_487.py's fast-path tests asserted only the sweep's outcome, never that_remember_auto_refwas actually built by the realmktempon the runner. Added aMKTEMP_SHIM_LOG-based marker (the shim calls, not execs, the realmktempand logs to a file outside any redirect the production code applies) to all 4 relevant tests: 2 fast-path tests now assert the marker showsSUCCEEDED, 2 forced-fallback tests assert it does not (confirming their ownbroken_binoverride genuinely won the PATH race). Caught live during development: both pre-existing fast-path tests, run with no mktemp override, read back empty evidence -- they had in fact been silently exercising the fallback path all along on this machine.#952 -- three #945 regressions
--no-autostashadded to bothgit rebasecall sites, so another slug's uncommitted tracked write is never silently autostashed and left unannounced ingit stash listwhen a conflict rebase starts._grc_compute_touched_paths()computes, before each rebase call, the union of this run's own ahead commits and the remote's behind commits (diffed against merge-base), and the conflict-restore path now restores that whole set instead of just$SLUG. Includes anls-treepre-filter so a path only the upstream side added (with no entry in this run's pre-rebase HEAD) does not abort the whole restore.rebase --quitdiscards it, the hook now reads git's ownrebase-merge/head-name(orrebase-apply/head-name) and refuses thesymbolic-refHEAD-switch -- reporting the mismatch instead of silently moving HEAD to the configured branch -- when it differs from the branch the rebase actually started from. No dedicated test for this one specifically; see Adjacent below.#953 -- 3-state rebase-in-progress check
_grc_rebase_in_progressnow returns 0 (confirmed in progress), 1 (confirmed not in progress), or 2 (could not tell -- the underlyinggit rev-parse --git-pathcall itself failed). All 5 call sites branch on the 3-state result explicitly with their own log message for the rc=2 case.Self-review
Two spawned reviewers (Explore, oss:auditor) found 4 real findings, all confirmed, zero refused:
_grc_compute_touched_pathssilently narrowed the restore scope back to$SLUGwith no warning line (now logged), and_grc_rebase_in_progress's rc=2 only fired when both git-path calls failed rather than either (now fixed to||)._grc_rebase_in_progresscall sites has a dedicated rc=2 test) was judged below the intake bar by the reviewing auditor itself and logged totrap.d/953.only-one-call-site-tests-rc2.mdrather than fixed with four near-duplicate tests.Test plan
python3 -m pytest tests/test_autonomous_log_retention_487.py -k "fast_path or fallback" -q --no-cov-- red: 2 failed, 2 passed (genuine fast-path/fallback confusion); green: 4 passed.python3 -m pytest tests/test_git_reconcile_903.py -k "autostash or restore_covers" -q --no-covand-k "undetermined"-- red (viagit stashof the production file only): 2 failed, then 1 failed, all for the intended reason; green: 23 passed.python3 -m pytest tests/test_git_reconcile_903.py tests/test_autonomous_log_retention_487.py -q --no-cov-> 37 passed in 49.67s.tests.full: not run locally, per this repo's own policy that CI (13 legs, 3 OSes, 4 interpreters) is the full-suite gate.shellcheckagainst the final hook file: no new findings versus the pre-fix version (2 identical, pre-existing, unrelated warnings both times).🤖 Generated with Claude Code
[AI-generated]