Repository navigation
Conversation
…t of #660) No CI leg measured this hook's wall time or spawn count on windows-latest -- every latency figure attached to #660's follow-ups (#662-#667) was reasoned from one reporter's own number, never observed, because 92 modules blanket-skip on win32 and #661's own tests do too. This adds one pytest module that drives the real hook under Git Bash (tests/_bash_runner.py's resolve_bash(), from #432), cold and warm, with jq present and with jq genuinely absent from PATH -- and skips nowhere but the "no bash found" case, so it runs on every leg of the existing matrix (.github/workflows/tests.yml) rather than needing a dedicated job. Spawn count is asserted as a generous budget (execution-counted, so it is machine-independent); wall time is printed and recorded via record_property for a human to compare run over run, only gated against a hang-detection ceiling -- the same report-not-gate choice this repo already made for #510 and #497, for the same reason: a shared runner's wall clock is noisy about itself. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…resent tests/spawn_counting.make_shim_dir shims every name in its own COUNTED list -- including "jq" -- off the process's real ambient PATH, not off the jq-stripped PATH _path_without_jq built in the previous commit, and places the shim directory ahead of it on PATH. On any machine with a real jq (every GitHub-hosted runner image ships one), the jq-absent scenario was silently still resolving and using real jq, making it a vacuous test of the one behaviour (_jq_fallback / the jq-absent code path) issue #669 exists to finally observe on Windows instead of reason about. Caught independently by both self-review spawns (Explore and oss:auditor, spawned concurrently against the prior commit) before either saw the other's finding. Fixed by removing the jq shim for the jq-absent scenario, so detect-tools.sh's `command -v jq` genuinely fails. Pinned with a paired positive/negative control: the jq-present run must see real jq invocations (proof the harness can detect one at all), the jq-absent run must see none -- confirmed with a scratch copy of the repo whose `_jq_fallback` was deliberately made to fail loudly: the unfixed test passed regardless, the fixed test's own new assertion now depends on genuinely excluding jq. Measured numbers updated in-comment (jq absent costs MORE, not less: 93/78 spawns vs jq present's 76/39, each python3-per-key-read having no jq-side multi-query batching equivalent). Also applies newline="" across the fixture's write_text calls, for the CRLF-on-Windows class this repo already named and fixed once elsewhere (tests/test_install_agy_hooks_563.py, #577) -- flagged by the auditor as a "clean locally, untested on Windows" risk in the same fixture. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…#34663736382 (#669) windows-latest/Python 3.11 CI for PR #671 failed: test_session_start_hook_benchmark_with_jq_present asserted "expected real jq invocations ... Spawns: []" -- the ENTIRE spawn log was empty for both cold and warm runs, even though both exited 0. Pulled the full job log (gh/supertool gh-job:103471338069) and traced it to tests/spawn_counting.make_shim_dir, not to anything specific to jq or to this PR's own _path_without_jq/jq-absent logic (my self-review's earlier fix): `shim.write_text(...)` had no `newline=""`, so on Windows every `\n` in the shim script -- including the shebang line -- becomes `\r\n`. `#!/bin/bash\r` is not a shebang directive bash's own exec() can resolve under Git Bash/MSYS, so every shim silently never ran: `command -v` still reports the shim's PATH entry as present (NTFS ACL default grants execute), but invoking it does nothing, the real unshimmed binary answers instead (hence exit 0 and correct hook behaviour), and SPAWN_LOG never gets a line written to it. This is the exact CRLF-on-write class this repo already named and fixed once (tests/test_install_agy_hooks_563.py, #577) and that my own prior commit on this branch just fixed in this test's OWN fixture -- missed, at the time, that shared tests/spawn_counting.py's make_shim_dir (used by several other spawn-budget tests, all of which currently blanket-skip win32 and so have never actually exercised this path for real before this PR's own benchmark) has the identical bug. jq_absent passed vacuously on that same CI run (an empty spawn list trivially satisfies "no jq calls"); jq_present correctly caught it, which is exactly what the paired positive/negative control added in the previous commit was for. Fixed by adding newline="" to both write_text calls in make_shim_dir. No POSIX-side behaviour change (newline="" is a no-op when the platform line separator is already \n). REASONED, not OBSERVED: no Windows box available to this lane; verification is the next CI run on this branch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
windows-latest/3.9 CI (job 103473817312) went red with TypeError: write_text() got an unexpected keyword argument 'newline' -- confirmed against the job log, not just the report: Path.write_text only gained its own `newline` parameter in Python 3.10, and this repo's matrix floors at 3.9 (.github/workflows/tests.yml). The previous commit's write_text(..., newline="") calls broke every test that imports tests/spawn_counting.make_shim_dir on that leg -- 8 ALREADY-PASSING tests in tests/test_log_sh.py and elsewhere, not just this branch's own new file -- and windows-latest/3.11 failed identically for the newline="" added to this test's own fixture. Fixed by switching every such call to open(path, "w", encoding="utf-8", newline="") as a context manager plus .write(text), which has always accepted `newline=` on every Python version this repo supports. This repo already has the identical fix, for the identical reason, in .oss/assemble_changelog.py's own changelog-writing code -- confirms the approach rather than inventing a new one. tests/test_session_start_windows_benchmark_669.py gained a small _write_no_crlf() helper so its four fixture writes share one implementation instead of repeating the open() block. Verified locally (macOS): 55 passed across tests/test_session_start_windows_benchmark_669.py, tests/test_post_tool_hook_spawns.py, tests/test_session_start_prev_session_270.py, tests/test_session_start_promo_spawn_budget_660.py and tests/test_log_sh.py (the file CI showed breaking) -- same spawn counts as before this round, confirming no behaviour change, only a compatibility fix. REASONED not OBSERVED for the 3.9/Windows combination itself: no matching interpreter/platform available to this lane; the real verification is the next CI run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
… (diagnostics only) windows-latest/3.12 CI (job 103475724500, run 34665238990) failed with the SAME symptom as round 1's original CI failure -- jq_present's positive control asserting real jq invocations, seeing Spawns: [] -- but this time AFTER round 2's CRLF-shebang fix and round 3's Python 3.9-compat fix, on a Python version (3.12) neither of those rounds broke. Verified against the job log myself before doing anything (supertool gh-job:103475724500:fail): 1 failed, 1046 passed, 1365 skipped, same assertion, same empty spawn list. This lane has no Windows box. A third blind guess costs another full CI round with no guarantee of being right -- the requesting agent's own framing, and correct: land diagnostics first rather than fix blind again. Added `_diagnose()`, called once per scenario right after the cold+warm runs and printed unconditionally (pytest shows captured stdout for a FAILED test by default -- no -s needed, confirmed against this repo's own addopts in pyproject.toml), plus folded into the jq-calls assertion's own failure message so it travels with the exact assertion that has been failing. Captures everything requested: resolved bash path, the PATH string as built on the Python side, what bash ITSELF resolves PATH and `command -v jq` to (a direct probe inside a bash subprocess using the identical env, to rule in/out MSYS's Windows-vs-POSIX path translation as the working theory -- the positional evidence this repo cannot get any other way without a Windows box), a directory listing of the shim dir with mode/size per entry, whether the spawn log exists and its size before parsing, and the full (untruncated) stdout/stderr and exit code of both the cold and warm runs. Every piece is wrapped so a diagnostic failure degrades to a one-line "<could not get: ...>" rather than replacing the real assertion failure with an unrelated one. Deliberately NOT attempting a third fix in this commit: traced the existing PATH-construction code (this file's own _run_once, tests/spawn_counting.make_shim_dir) but could not form a confident, code-level mechanism the way the shebang-CRLF bug had one -- in particular, if MSYS's PATH translation were broadly broken, other real binaries the hook depends on throughout its run (python, git) would plausibly fail too, and the hook has exited 0 with correct output on every Windows CI run so far, arguing against a blanket PATH-translation failure and for something more specific to the shim mechanism that this diagnostic output should make visible on the next run. Verified locally (macOS): both scenarios still pass, diagnostics print without crashing (including a successful DIAG_JQ=.../shims/jq resolution, confirming the probe mechanism itself works), no change to spawn counts or timing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…slash script path
windows-latest/3.10 CI (job 103477377903, run 34665808749) with round 4's diagnostics landed
showed the real answer: the bash-side PATH probe and `command -v jq` both resolved correctly to
the shim (DIAG_JQ=.../shims/jq), fully ruling out jq availability, PATH construction and MSYS path
translation as causes. The actual captured stderr was:
D:\\a\\claude-remember\\claude-remember\\scripts\\session-start-hook.sh: line 160:
./resolve-paths.sh: No such file or directory
session-start-hook.sh:60 derives its own directory with
`_HOOK_DIR="${BASH_SOURCE[0]%/*}"` (falling back to "." per the explicit comment above it when no
"/" is found) -- pure bash STRING pattern matching that only ever recognises `/`, never `\\`.
_run_once passed `str(SESSION_START)` as the script path, and on native Windows that is a fully
backslash-separated path, so BASH_SOURCE[0] contained zero "/" characters and _HOOK_DIR fell back
to "." -- exactly matching the observed error. Confirmed directly (not merely reasoned): running
the real "${BASH_SOURCE[0]%/*}"-style expansion against a backslash string vs a forward-slash
string reproduces "." vs the real directory, with no Windows box needed to see the mechanism
itself.
This is a TEST HARNESS bug, not a hook bug: the hook's real caller
(hooks/hooks.json: `bash "${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh"`) always has a
literal forward slash hardcoded immediately before the filename, so BASH_SOURCE[0] there always
ends in "/session-start-hook.sh" regardless of what separator style CLAUDE_PLUGIN_ROOT itself
uses -- which is why years of real Windows usage never surfaced this. Confirmed by reading the
real invocation command before concluding the hook itself needed no change, per the explicit
instruction not to touch it without checking first.
Fixed by passing SESSION_START.as_posix() instead of str(SESSION_START) to bash's argv in
_run_once -- the one call site that invokes the real file directly.
Added test_hook_dir_derivation_needs_a_forward_slash_path, a genuine regression test for the
mechanism itself: the exact two lines are extracted from the real hook file (so it breaks loudly
if that derivation ever moves or changes), their `%/*`/fallback pattern is driven against a plain
settable variable (BASH_SOURCE cannot itself be reassigned inside `bash -c` -- caught empirically
while writing this test, an earlier draft silently asserted "." for every case including the
POSIX one), with a forward-slash case, a no-separator positive control for the fallback itself,
and a backslash case -- plus an end-to-end probe that actually invokes a real file via
.as_posix() and checks BASH_SOURCE[0] resolves correctly, proving the actual fix rather than only
the isolated mechanism.
Verified locally (macOS): 56 passed across this file and every other file that shares test
infrastructure with it (test_post_tool_hook_spawns.py, test_session_start_prev_session_270.py,
test_session_start_promo_spawn_budget_660.py, test_log_sh.py). REASONED not OBSERVED for the
actual windows-latest leg: no Windows box available; the next CI run is the real verification,
but for the first time in this whole issue the root-cause mechanism itself -- not just its
absence of symptoms -- has been directly demonstrated on this platform.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…ot argv windows-latest CI (all 4 Python versions, e.g. job 103479922291) reported good news first -- the round-5 .as_posix() fix WORKED: both jq_present/jq_absent benchmarks now pass (suite went 1046 -> 1047 passed, those two tests no longer in the failure list). Bad news: the NEW regression test added in round 5, test_hook_dir_derivation_needs_a_forward_slash_path, failed identically on every Windows leg, at the FIRST (plain-POSIX, no-backslash) _probe() call -- empty stderr, returncode=1, and a garbled `args` repr in the assertion message with NUL-interleaved text that does not correspond to anything this test's own Python-side string construction produces (verified locally: reconstructing the exact same snippet/command string on this platform is clean, 82 chars, no corruption). Investigated rather than guessing about on-disk file encoding (session-start-hook.sh itself parsed and ran correctly in the SAME CI job for the jq_present/absent tests, ruling out the file being genuinely UTF-16 on that Windows checkout -- if it were, the hook itself would fail to parse at all, not just this one new test). The actual mechanism: tests/test_fast_path_subshells_511.py already documents, for an adjacent Windows subprocess hazard, that `subprocess.run`'s argv list is re-flattened into a single command line by Python's own MSVCRT-style quoting rules (subprocess.list2cmdline) before CreateProcess hands it to bash.exe, and MSYS's own argv re-parsing of that line does not agree with it on a string carrying embedded double quotes -- which the round-5 probe's inline `bash -c "<script with many \"quotes\">"` plus a second argv element for the fake path both are. Fixed by adopting the exact same proven pattern #511's own test already uses for this hazard: the fake value travels through an ENVIRONMENT VARIABLE, and the probe script is a real FILE invoked by path (`bash <path>`) rather than inline `-c` text -- eliminating the argv/quote round-trip for both the script body and the value under test. Verified locally (macOS): 65 passed across this file, every file sharing its test infrastructure, and test_fast_path_subshells_511.py itself (the file whose own documented precedent this fix copies). REASONED not OBSERVED for the actual windows-latest legs: no Windows box available; the next CI run verifies it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…ine=) bug Maintainer ruling on PR #671: round 6 (commit 4daf3d2) added probe_script.write_text('...', encoding="utf-8", newline="") -- the exact Path.write_text()-newline=-kwarg shape round 3 (commit b84a5c9) already found broken on Python 3.9 (the kwarg only exists from 3.10), reintroduced by mistake instead of reusing the _write_no_crlf() helper this file already defines for exactly this. Fixed by routing that one write through _write_no_crlf() instead. Grepped the whole diff (main...HEAD) for every other write_text( call across all files touched in this issue's six prior rounds (tests/spawn_counting.py, tests/test_session_start_windows_benchmark_669.py) -- no other call carries a newline= kwarg; every remaining write_text( hit is either a bare call with no such kwarg (log.write_text("", encoding="utf-8"); real_probe_script.write_text(...) with no newline=) or a comment documenting this exact class. No other change in this commit, per the maintainer's explicit instruction. Verified locally (macOS): 3 passed, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
Maintainer ruling on PR #671: skip the round-5/6 regression test (test_hook_dir_derivation_needs_a_forward_slash_path) on win32, citing #672 (the filed follow-up for the NUL-interleaved/UTF-16LE bash-subprocess-probe corruption this test's own _probe() hit on every Windows leg, round 6/7). Leave the benchmark tests (test_session_start_hook_benchmark_with_jq_present /_absent, and their jq positive/negative controls) fully live on every platform -- unaffected, not touched. One deviation from the literal instruction, reported rather than silently applied: the instruction named "the backslash-path probe" specifically as the thing to isolate and skip, with the forward-slash case assumed to pass fine on Windows. Verified against the actual job logs before acting (gh-job:103483869911:fail, and round 6's own earlier failure) -- both show the corruption hit at the line inside the shared `_probe()` helper (line 577, called identically by all three top-level cases: posix, no_sep, backslash), and in both observed instances it failed on the FIRST call, `posix = _probe(...)` -- the plain forward-slash case, not the backslash one. The corruption is not input-dependent; #672's own body says the same tail recurs verbatim across two structurally different invocation shapes, consistent with an environment-level cause rather than anything about which string is being probed. A partial skip sparing only the backslash case would have left the actually-failing case (posix) still running and still red, defeating the point of this round. Skipped the whole test function instead, with a reason naming this discrepancy plainly rather than repeating the (incorrect) "backslash-specific" framing in the skip reason itself. Verified locally (macOS, where the skip condition is False so nothing skips here): the decorator attaches to exactly this one function (`getattr(f, "pytestmark", [])` confirms it, and confirms the jq_present benchmark carries no such mark) -- 3 passed, ruff clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
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.
Part of #660. Closes #669.
What this does
No CI leg measured
scripts/session-start-hook.sh's wall time or spawn count onwindows-latest-- every latency figure attached to #660's follow-ups (#662-#667) was reasoned from one reporter's own number, never observed, because 92 modules blanket-skip onwin32and #661's own two tests do too.This adds one pytest module,
tests/test_session_start_windows_benchmark_669.py, that drives the real hook under a real, non-WSL bash (tests/_bash_runner.py'sresolve_bash(), built for exactly this by #432), cold and warm, with jq present and with jq genuinely absent from PATH (Git for Windows does not ship it). It skips nowhere but the "no bash found" case, so it runs on every leg of the existing matrix (.github/workflows/tests.yml) --windows-latestincluded -- without needing a new, dedicated job.Two judgment calls the issue left open
New CI job vs. extending the existing leg: extended the existing leg, by simply adding a pytest module with no platform skip beyond "no bash found".
.oss.json'stest_commandis plainpytest, already run on all three OSes x 4 Python versions with Windows Defender already excluded from the checkout andRUNNER_TEMP. A dedicated job would re-pay that setup cost for one test and, unlike this approach, would not also satisfy the issue's step 6 ("same test on Linux/macOS... in one log") for free.Fail the build vs. merely record: split by what is actually deterministic. Spawn count is asserted as a real, generous budget -- it's counted by execution (
tests/spawn_counting.py, same convention as #227/#230), so it doesn't depend on how loaded the runner is. Wall time is printed and handed torecord_propertyfor a human to compare run over run, asserted only against a hang-detection ceiling (45s) rather than a tight budget -- the same report-not-gate choice this repo already made forscripts/report_test_durations.py(#510) andscripts/report_windows_skip_floor.py(#497), for the identical stated reason: a shared CI runner's wall clock is noisy about itself.Five rounds to land -- what each one found, and why it took this many
Self-review caught a real bug before CI ever ran; every round after that was a genuine CI-observed failure, not a flake, each fixed in turn:
tests/spawn_counting.make_shim_dirshims every name in its ownCOUNTEDlist -- includingjq-- off the real ambient PATH, not off the jq-stripped PATH_path_without_jq()built, silently defeating the jq-absent scenario on any machine with a realjq. Fixed with a paired positive/negative control.write_text(..., newline="")to avoid CRLF-corrupting a shim script's shebang line under Git Bash/MSYS -- a real, separate bug (confirmed: breaking_jq_fallbackon purpose still let the unfixed test pass, proving the shim silently never ran).Path.write_text()only gained its ownnewline=keyword in Python 3.10; this repo floors at 3.9. Broke 8 already-passing tests, not just this branch's own. Fixed by routing throughopen(path, "w", newline="")instead, which this repo already does for the identical reason in.oss/assemble_changelog.py.session-start-hook.sh:60derives its own directory with_HOOK_DIR="${BASH_SOURCE[0]%/*}", pure bash string matching that only recognises/, never\. The test's_run_oncepassedstr(SESSION_START)-- a fully backslash-separated path on native Windows -- so_HOOK_DIRfell back to"."and everysourceafter it failed non-fatally (REMEMBER_PATHS_SOFT_FAIL=1 ... || exit 0), leaving the hook exiting 0 having done essentially nothing: no stdout, no spawns, on every jq scenario and every Python version tested. This explains every prior round's symptom as one single cause, not several independent ones. Confirmed this is a TEST-HARNESS bug, not a hook bug, by reading the hook's real invocation (hooks/hooks.json:bash "${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh") -- it hardcodes a literal forward slash immediately before the filename, soBASH_SOURCE[0]there always resolves correctly regardless ofCLAUDE_PLUGIN_ROOT's own separator style, which is why this never surfaced as a real-user bug in years of Windows usage. Fixed with.as_posix(), plus a genuine regression test for the%/*mechanism itself (extracted verbatim from the hook, driven against a settable variable sinceBASH_SOURCEcannot itself be reassigned inbash -c, confirmed empirically) and an end-to-end probe of the actual fix.Every round above is REASONED, not OBSERVED, for the actual Windows behaviour -- no Windows box is available to this lane at any point; each fix is verified by CI itself. Round 5 is the first round where the root-cause MECHANISM (not just the code read to explain a symptom) was directly demonstrated on a non-Windows platform: running bash's own
%/*expansion against a backslash string and a forward-slash string reproduces.vs. the real directory, with no platform dependency in the mechanism itself.What is OBSERVED vs REASONED
Everything measured locally ran on macOS (system/homebrew bash). What is verified instead for the Windows-specific claims: the workflow requires no new YAML (the test rides the existing matrix as-is);
resolve_bash()is pre-existing, already-tested infrastructure (tests/test_bash_runner_432.py); the fixture/harness logic, the CRLF fix, the Python-version-compat fix, and the%/*-mechanism fix were each verified end-to-end on macOS where it is possible to do so; and round 5's root cause was confirmed by reading the hook's actual code and its actual real-world caller, not guessed.Docs and changelog
docs/running-tests.md: new section describing the benchmark (mirrors the existing Detect a test that dominates the suite, before somebody notices it by hand #510/The windows-latest CI legs report green over 1201 skipped tests: 92 modules blanket-skip on win32 and only 5 use the resolve_bash() route that retired that pattern #497 sections' report-not-gate framing).changelog.d/669.added.mdadded.README.md: no change needed -- its two Windows-related statements (the OS badge's coverage caveat, the maintainer bullet on Windows reports) both remain true; this narrows but does not close either gap, and the detail lives indocs/running-tests.md.Out of scope (by design)
No changes to
scripts/session-start-hook.shitself or to #662-#667's own fix code -- this issue is the measurement scaffold, landing before those fixes on purpose so they have something real to be judged against. Round 5 specifically checked whether the hook itself needed a fix and concluded it did not, because of how its real caller invokes it.🤖 Generated with Claude Code
https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
[AI-generated]