Commit Graph

3 Commits

Author SHA1 Message Date
Tom Boucher
a28dcec981 chore(#597): replace count-based ratchet guards with AST lint + named-set allowlists (#603)
The windows-test-parity ratchet greps test source for fs.rmSync-without-
maxRetries (and six other Windows-portability anti-patterns), failing when an
integer offender COUNT exceeds a frozen baseline (rmSync: 95). A count ratchet
is a Goodhart metric: fixing one offender and adding another keeps the count
constant, so a new defect slips through green. Replace it — and every other
count ratchet in the repo — with a layered, masking-proof design.

Behavioral seam test
- tests/helpers-cleanup.test.cjs proves helpers.cleanup() carries the Windows
  EBUSY retry budget. cleanup() delegates retries to Node's fs.rmSync via
  maxRetries (it owns no loop), so the test asserts the option contract
  (recursive/force/maxRetries>0/retryDelay>0) + real-FS removal + the cwd-guard,
  rather than a loop that does not exist. The EBUSY risk is now tested ONCE at
  the helper, not approximated textually at every call site.

Write-time ESLint rule (AST-accurate, replaces the grep)
- eslint-rules/no-raw-rmsync-in-tests.cjs (error in tests/**/*.test.cjs) bans
  raw fs.rmSync, steering to cleanup(). Catches member, computed (fs['rmSync']),
  destructured and aliased forms; escape hatch is inline
  `// eslint-disable-next-line local/no-raw-rmsync-in-tests -- <reason>` only.
- Migrated 336 raw fs.rmSync teardown calls across ~116 test files to cleanup().
  ~18 genuinely load-bearing sites (mid-test SUT/fault-injection removals,
  error-swallowing or name-colliding local teardown helpers) keep the raw call
  with an inline eslint-disable + reason.

Shared anti-ratchet primitive
- scripts/lib/allowlist-ratchet.cjs:
  - assertWithinAllowlist: fails on NOVEL ids (new offender introduced) AND on
    STALE ids (a known offender was fixed but not pruned) — identity, not count,
    and a ratchet DOWN toward zero.
  - assertTightCeiling: a size/length budget whose ceiling must stay within a
    grace band of the high-water mark, so budgets may only tighten, never creep.

Ratchets converted onto the primitive
- windows-test-parity-guard.test.cjs: rmSync rule deleted (now ESLint-enforced);
  the remaining six patterns moved from integer baselines to named-set
  allowlists with ratchet-down.
- scripts/lint-test-file-count.{cjs,allowlist.json}: per-module integer counts →
  named filename sets (closes the swap-a-file-keep-the-count blind spot); a
  module dropping under cap now FAILS to force pruning its allowlist entry.
- enh-2790 skill-count `<= 63` → named skill allowlist (ratchets toward ~58).

Size budgets hardened (tighten-only)
- agent-size / workflow-size / feat-3039 help-tiered: ceilings lowered to the
  current high-water mark and an assertTightCeiling anti-creep check added per
  tier. Fixed external-contract limits (description ≤100 chars, agent ≤100 KB)
  are intentionally left as-is — they are not grandfathered creeping budgets.

No user-facing behavior change (tests + tooling only); no USER_FACING_PREFIXES
touched, so no changeset fragment is required.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 22:43:49 -04:00
Tom Boucher
420c64da4b test(3646): add routing-block hyphen-form regression tests for workflow templates (#3800)
* test(3646): add routing-block hyphen-form regression tests for workflow templates

Extends bug-3683-workflow-colon-namespace-leak.test.cjs with a new R suite
that asserts the specific user-facing symptom from #3646: ▶-prefixed routing
lines in installed workflow files (validate-phase.md, secure-phase.md) must
use /gsd-<cmd> hyphen form and must not contain the /gsd:<cmd> colon form.

The R suite adds positive-assertion coverage that the prior W suite lacked:
W3 checks absence-of-colon globally; R1/R2/R3 check that routing-position
strings (▶-marker lines) are present AND use the correct hyphen form — the
distinction that makes this a behavioral install-contract test rather than a
source-grep.

Verified the new tests FAIL when normalizeAgentBodyForRuntime is disabled
(the pre-fix state) and PASS with the fix in place.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(3646): fix Windows parity — use /\r?\n/ in routing-line splitters

Replace .split('\n') with .split(/\r?\n/) in the two new R-suite helpers
so Windows CRLF checkouts (autocrlf=true) don't produce trailing \r on
▶-prefixed routing lines, which would break the startsWith('▶') filter.

Caught by tests/windows-test-parity-guard.test.cjs ratchet baseline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: add changeset for PR #3800 (#3646 routing-block regression tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(3646): tighten token-level assertions — check embedded colons in /gsd tokens

Codex adversarial review found that R1/R2/R3 only checked for
/gsd:<cmd> (colon immediately after gsd), leaving a gap where
/gsd-validate:phase would pass all tests.

Add token-level assertion: extract all /gsd[^\s]* tokens from ▶-prefixed
routing lines and assert none contain an embedded colon. This catches any
token where normalisation only partially converted the colon form.

Documentation placeholder lines like /gsd-[command] are not affected
because the placeholder token /gsd-[command] contains no colon.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(3646): consolidate dual Claude install into shared fixture to stop TOCTOU interference

W and R suites both ran runClaudeLocalInstall in separate before() hooks, adding
two concurrent heavy-install operations per test-file run. Under --test-concurrency=4
on Node 22 (ubuntu/windows), this extra disk I/O starved the barrier-based TOCTOU
concurrency test in locking-bugs-1909-1916-1925-1927.test.cjs, causing its timing-
sensitive barrier to release unevenly and let one subprocess complete before the
other, producing a false lost-update failure.

Fix: lift the Claude install to a single shared claudeTmpDir at the outer describe
level so W and R share one install. Gemini suite (G) is unaffected and keeps its
own install. All 11 tests in the file pass; TOCTOU tests unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(3646): address review — fix changeset misclassification, remove false Windows-parity claim, tighten R-suite assertions

- F1: Reword changeset from "Fixed/now emit" (implies behavior change) to "patch" + test-only description (accurate: normalizer already shipped in #3685)
- F4: Tighten R3 comment to document unique value vs W3: ▶-line scope + embedded-colon token check
- F5: Extend R3 sweep to include references/ dir alongside workflows/
- F6: Change R1/R2 assert.ok(length >= N) to assert.strictEqual(length, N) so line removals surface immediately
- F7: Update inline comments in R1/R2 and before() hook to match strictEqual semantics; add sub-suite dependency list to before()

Reviewed-by: gsd-code-reviewer, sonnet-adversarial
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(3800): correct changeset type from invalid 'patch' to 'Fixed'

docs-lint rejects the fragment because 'patch' is not an ALLOWED_TYPES
value; 'Fixed' is the correct label for a regression-test addition with
no user-visible behavior change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 23:19:52 -04:00
Tom Boucher
09ab16f9e5 fix(3683): normalize /gsd:<cmd> → /gsd-<cmd> in command, workflow, and reference bodies (#3685)
* fix(3683): normalize /gsd:<cmd> → /gsd-<cmd> in command, workflow, and reference bodies

Extends #3677's agent-body normalizer to all body text staged through
copyWithPathReplacement (commands, workflows, references). The initial
isCommand guard was structurally redundant — normalizeAgentBodyForRuntime
already self-gates on shouldNormalizeHyphenNamespaceInAgentBody(runtime),
so dropping it covers all hyphen-name runtimes (Claude / Qwen / Hermes)
without affecting colon-canonical runtimes (Gemini).

Addresses the user-visible symptom in #3683: workflows like
get-shit-done/workflows/discuss-phase.md (7 colon refs) leaked /gsd:<cmd>
markers to the model context, which the model echoed at the end of
/gsd-discuss-phase runs.

Source-prose drift caught by the new cross-reference invariant test:

  - commands/gsd/plan-phase.md: removed a slash-form mention of the
    deleted /gsd-research-phase command (#3042)
  - commands/gsd/profile-user.md: replaced a slash-form artifact
    reference with a backticked bare name (the referenced item is a
    skill config, not a user-callable slash command)

Tests:

  - tests/bug-3683-command-colon-namespace-leak.test.cjs — runtime-form
    regression for commands/gsd/*.md staging
  - tests/bug-3683-command-cross-reference-invariant.test.cjs — locks
    cross-reference coherence: every /gsd-X / /gsd:X reference in a
    command body must resolve to commands/gsd/X.md (so a future rename
    forces every cross-reference to update)
  - tests/bug-3683-workflow-colon-namespace-leak.test.cjs — runtime-form
    regression for workflows + references; negative test for gemini
    asserting the colon form is preserved

Fixes #3683

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(changeset): remove undefined cycle reference

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 00:13:59 -04:00