Repository navigation
test(hooks): regression coverage for sdd-cache and simplify-ignore round-trip (#295) - #501
Conversation
There was a problem hiding this comment.
Welcome. The hooks have seen a lot of churn lately (SSRF guard, perl removal, cache changes) and had thin coverage, so regression tests for sdd-cache and simplify-ignore are exactly what they needed. Test-merged clean, the suites pass. Approving in spirit. Going to review this one a little more.
addyosmani
left a comment
There was a problem hiding this comment.
I went back through this line by line. The tests themselves are genuinely good: isolated temp project dirs, curl stubbed so there is no real network, byte-exact assertions on shell-hostile content (backticks,
The gap that stops me landing it as-is: neither hook test is wired into CI. I checked the workflows and nothing runs simplify-ignore-test.sh or the new sdd-cache-test.sh, and this PR doesn't add them, so they'd sit in the repo and never run. Coverage that doesn't run doesn't guard anything, which is the whole point of adding it.
Can you add both to .github/workflows/test-plugin-install.yml (a step each, and since the hooks no-op without jq, make sure a missing-jq run skips rather than fails)? With that wired in I'm glad to take it. One small thing too: the script names its temp var TMPDIR, which shadows the standard env var, worth renaming to avoid surprises.
ccdbf6d to
e605e5a
Compare
|
CI gap closed in e605e5a (plus a rebase onto current main): a new test-hooks job in One deliberate exclusion, found while wiring: |
|
Direction's settled: #574 landed and the hook area is stable now. I merged #578 first since its data-loss fix is user-facing and going into this release, which means this one now overlaps it on simplify-ignore-test.sh. Can you rebase on latest main? Your test-hooks CI job and the round-trip tests will land on top and give #578's fix its CI coverage. Approval stands. |
Wire the two regression suites into the workflow as a test-hooks job so the coverage actually guards the hooks, per review. Deliberately excludes session-start-test.sh: it currently asserts the pre-addyosmani#474 payload shape and fails against the envelope the hook now emits; PR addyosmani#510 updates that test and can wire it in when it lands.
|
Rebased onto current main ( How the overlap with #578 was resolved. Both PRs appended a "Tests 11–13" block at the same point in The round-trip tests now exercise #578's fix. Tests 14–16 run Read → [Edit] → Stop against the real hook, and Stop now goes down the expand-placeholders-on-disk path rather than the backup restore. All three assert byte-identical recovery — including the shell-hostile content in test 14 (backslashes, Verified locally on the rebased head: The |
e605e5a to
4b9395b
Compare
The round-trip test added in this PR failed on ubuntu-latest while passing
on macOS: after Read → Stop, a protected block containing a backslash came
back altered (byte 109, line 3 of the fixture).
expand_file rebuilds each line with `${line//$placeholder/$block_content}`.
Bash 5.2 enables patsub_replacement by default, which makes the replacement
side of that expansion special: an unquoted `&` expands to the matched text
and backslashes are consumed. Block content is raw code and routinely
contains `&&` and backslashes, so on any bash 5.2 host every protected block
with either character was corrupted when it was expanded back. Bash 3.2 on
macOS has no such option, which is why local runs never showed it.
Turn the option off at the top of the hook; older bashes reject the shopt,
so the error is ignored there. Extend the byte-fidelity fixture with `&&`
and `&` so the ampersand case is guarded alongside the backslash one.
|
Follow-up: the first CI run on the rebased head went red on exactly one assertion, and it turned out to be a real Linux-only bug rather than a flaky test. Head is now What failed. Test 14 (Read → Stop, byte fidelity) reported Root cause. Fix (commit
On scope. I know the approval was for pure test coverage with no product change, and I'd normally keep it that way. But leaving the PR red with a known data-corruption bug felt worse than a one-line guard that the new job verifies on the platform that exhibits it. If you'd rather sequence it separately, say so and I'll split |
addyosmani
left a comment
There was a problem hiding this comment.
Rebased cleanly over #578, and this is more than tests: the patsub_replacement guard in simplify-ignore.sh is a real bash 5.2 fix that would otherwise corrupt restored blocks on Linux. The test-hooks CI job wires both suites (sdd-cache 29, simplify-ignore 49). Merging, this gives #578's fix its CI coverage too.
Adds the test coverage called out in #295: the two sdd-cache hooks had no tests, and the data-loss-critical expand/restore half of simplify-ignore was untested (the issue's "highest-value missing test: round-trip fidelity").
What's included
hooks/sdd-cache-test.sh(new): 29 assertions covering both cache hooks — the 304 revalidation contract, validator-less entries never being served, byte-exact serving of shell-hostile content (backticks,$vars, backslashes), stale-entry removal when the origin stops sending validators, final-response header parsing, and a full post→pre round-trip. No real network traffic: a deterministiccurlstub onPATHsimulates the origin, so the suite is fast and runs offline.hooks/simplify-ignore-test.sh(extended): 3 new full-lifecycle tests exercising the expand/restore path the existing function-extraction tests cannot reach — Read→Stop restores original bytes exactly (cmp), no-trailing-newline fidelity, and Read→edit→Edit-event→Stop preserving both the protected block and the model's edit.Version-agnostic by design
The suite is deliberately written to pass on current
mainand on #294's hardened scripts — verified against both (test URLs are publichttps://, seeded cache entries use fresh timestamps, and no test asserts behavior #294 changes). It can merge first and then serve as the regression check for evaluating #294.Complements #294 — no file overlap, not a competing fix.
Verification
Both runs repeated against the #294 branch with the same result.