Skip to content

test(parsers): property-based and metamorphic tests with fast-check on ac-parser, parseQaSummary, and the marker parsers #1095

Closed

Description

@admarble

Blocked by: — Tier: mechanical Doc: guard plan 2026-09-18 (16-bug classification; research: OSS-Fuzz, Ravi & Coblenz OOPSLA'25 on PBT mutation power)

Why

Two of the recent bugs were parsers tested on one shape. parseQaSummary (src/lib/workflow/phase-executor.ts:595) counts only | AC-N | table rows, so a checklist-shaped report produced 0/1 met under an AC_MET verdict (#1073). isIssueMergedIntoMain's (#N) grep matched any commit title mentioning the number (#1044). Example-based tests pin the shapes the author imagined; properties pin the invariants that must hold for every shape.

Change

Add fast-check as a dev dependency and one property file per parser:

  • src/lib/ac-parser.property.test.ts — never throws or hangs on arbitrary strings; metamorphic: re-indenting, reordering unrelated lines, or changing - [ ] to - [x] does not change the set of AC ids parsed; every parsed AC's text is a substring of the input.
  • src/lib/workflow/phase-executor.property.test.ts — parseQaSummary never throws; for a generated report containing N AC lines in any supported shape (table row, checklist, bold-prefixed) with M marked MET, it returns acTotal === N and acMet === M; consistency: an AC_MET* verdict with acMet === 0 and acTotal > 0 is never emitted (the bug(qa): the posted verdict comment publishes a miscounted AC coverage — "0/1 met" on an 8-AC issue under an AC_MET verdict #1073 hardening).
  • src/lib/workflow/mutation-marker.property.test.ts and qa-gaps-marker.property.test.ts — round-trip: parse(format(x)) deep-equals x for generated payloads; parse never throws on arbitrary text.

Each property must kill at least one seeded mutant that the existing example tests miss, recorded in the PR body.

Closes #1073 when this lands: AC-2 is the checklist-shape fix and AC-3 is the consistency hardening #1073 asks for. The parseQaSummary change lives in phase-executor.ts; the only batch-executor.ts edit is the presence guard inside buildQaVerdictComment so the count line is omitted when the parser returned no counts (PLAN D-10).

Release-graph plan — guard-2026-09 (2026-09-20)

Graph: guard-2026-09 Tier: mechanical Wave: 1
May touch: package.json, package-lock.json (fast-check only), src/lib/ac-parser.property.test.ts, src/lib/workflow/phase-executor.property.test.ts, src/lib/workflow/mutation-marker.property.test.ts, src/lib/workflow/qa-gaps-marker.property.test.ts, src/lib/workflow/phase-executor.ts (parseQaSummary), src/lib/workflow/batch-executor.ts (buildQaVerdictComment only — #1070 edits the postQaVerdictComment gate in the same wave), CHANGELOG.md; not vitest.config.ts (#1086 owns it this wave — seeds live in the test files)

The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). Close #1073 from the PR body (Closes #1073).

Acceptance criteria

  • AC-1: fast-check is in devDependencies and npx vitest run --project unit -t "property" runs at least 8 properties — Verify: the run's summary shows ≥ 8 passed.
  • AC-2: parseQaSummary counts checklist-form ACs (- [x] **AC-1**: …) — Verify: npx vitest run src/lib/workflow/phase-executor.property.test.ts -t "checklist" → green. Mutation-verified per CLAUDE.md §Testing: restore the table-only regex → the property fails; restore.
  • AC-3: parseQaSummary never returns acMet === 0 with acTotal > 0 for an AC_MET* verdict; the count line is omitted instead — Verify: -t "consistency" → green.
  • AC-4: the ac-parser metamorphic property holds — Verify: npx vitest run src/lib/ac-parser.property.test.ts → green. Mutation-verified: make the parser drop the last AC when the line is indented → the property fails; restore.
  • AC-5: marker round-trips hold — Verify: npx vitest run src/lib/workflow/mutation-marker.property.test.ts src/lib/workflow/qa-gaps-marker.property.test.ts → green.
  • AC-6: every property is deterministic in CI: each fc.assert passes { seed } from process.env.FC_SEED when set and prints the failing seed on failure — Verify: FC_SEED=42 npx vitest run -t "property" → same result as unseeded.
  • AC-7: npm run build && npm test green.
  • AC-8: the fast-check integration targets the vitest major on main at execution time (^4.1.11 on 2026-09-20) and the PR does not bump vitest; dependabot chore(deps-dev): bump vitest from 4.1.11 to 5.0.1 #1082 (vitest 5) stays open and unmerged — Verify: git show origin/main:package.json | grep '"vitest"' and the PR's package.json agree on the major.

Not in scope

Fuzzing pre-tool.sh (see the hook golden-corpus issue) and any change to the AC line format.

Activity

  1. added
    enhancement
    qa
    on Sep 19, 2026
  2. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Runner context — guard-2026-09 launch, 2026-09-20. Base: origin/main at da9ed6e8 (2.16.0 plus the plan docs). These rules override the exec skill's defaults for this run:

    • No full npm test in the worktree. Run only the test files this issue's ACs name. The runner runs the full suite once per PR from a clean shell. Under sequant run the suite is not hermetic against SEQUANT_* (bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086), so a full run shows red files you did not cause.
    • A named test file red before your change: re-run it as env -u SEQUANT_ORCHESTRATOR -u SEQUANT_WORKTREE -u SEQUANT_PHASE -u SEQUANT_ISSUE -u SEQUANT_RELAY -u SEQUANT_RELAY_FRAME npx vitest run <file>. If it is still red, the PR body names the issue number and the base-vs-head result for that test.
    • Mutation marker (gate-test ACs): <!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} --> in the PR body. failedTest MUST start with the test file path, or the qa classifier reports it Failed. Commit before mutating.
    • 30-minute no-progress wall per phase. Commit a WIP checkpoint before any long command; every command foreground, with timeout.
    • Commits: single-line git commit -m "...", no Co-Authored-By. Never rebase or force-push after pushing. One AC per line in the PR body, ids AC-N only.
    • Stop at the PR. Do not merge.

    Issue-specific: Do not bump vitest; dependabot #1082 (vitest 5) stays unmerged, so fast-check must work with ^4.1.11. In src/lib/workflow/batch-executor.ts edit buildQaVerdictComment only; #1070 edits the postQaVerdictComment call-site gate in the same file concurrently. PR body: Closes #1073.

  3. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (8 ACs, 3 directories)

    AC Quality Check

    • AC-1: "at least 8 properties" is measurable. The plan below yields 10 (ac-parser 3, parseQaSummary 3, mutation-marker 2, qa-gaps-marker 2). Every property name must contain the word property, because -t "property" is a name filter.
    • AC-3: ⚠️ Untestable as written. parseQaSummary(output) never sees the verdict, so it cannot return a verdict-dependent count. See Open Question 2.
    • AC-4: ⚠️ The named mutation is vacuous. See Open Question 1.
    • AC-6: ⚠️ Unset FC_SEED means a random seed each run. See Open Question 4.

    Scope Assessment

    Non-Goals: present ("Not in scope": fuzzing pre-tool.sh, any change to the AC line format).

    Metric Value Status
    Feature count 1 (+ the #1073 fix) ✅
    AC items 8 ✅
    Directory spread 3 (root, src/lib, src/lib/workflow) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC Verification Scenario
    AC-1 Integration Test Given fast-check in devDependencies → When npx vitest run --project unit -t "property" → Then ≥ 8 passed
    AC-2 Unit Test (property) Given a generated report with N AC lines in table, checklist or bold-prefixed shape and M marked MET → When parseQaSummary runs → Then acTotal===N && acMet===M
    AC-3 Unit Test (property) Given any AC_MET* verdict and a summary with acMet===0 → When buildQaVerdictComment runs → Then there is no AC coverage: line
    AC-4 Unit Test (property) Given a generated body with unique AC ids → When filler lines are re-indented or reordered, or [ ] becomes [x] → Then the parsed id set is unchanged
    AC-5 Unit Test (property) Given payloads generated within the marker contract → Then parse(format(x)) deep-equals x. Parse never throws on arbitrary text
    AC-6 Integration Test Given FC_SEED=42 → Then the result equals the unseeded run, and a failure prints the seed
    AC-7 Integration Test npm run build && npm test. Run by the runner after the PR opens, not by the agent
    AC-8 Manual Test git show origin/main:package.json and the PR's package.json agree on the vitest major

    Implementation Plan

    Facts checked against origin/main (da9ed6e8):

    • fast-check is not installed. 4.10.2 is current, has no vitest peer dependency, and supports Node ≥ 12.
    • *.property.test.ts matches the unit project glob, so the 5 s timeout applies. Keep the default numRuns (100) and use bounded string generators.
    • No format function exists for either marker. The emitters live in skill prose. The round-trip tests need a test-local format that mirrors the documented shape: <!-- SEQUANT_X: ${JSON.stringify(x)} -->.

    Phase 1: dependency and fix (sequential)

    1. npm i -D fast-check (package.json, lockfile). Do not touch vitest.
    2. phase-executor.ts parseQaSummary: also count checklist lines (- [x|X| ] **AC-N**[:] …). Count each AC id once, with the table row winning on a duplicate. The checkbox is the MET signal. Table-shape logic is unchanged.
    3. batch-executor.ts buildQaVerdictComment only: omit the AC coverage: line when acTotal===0, or when the verdict is AC_MET* and acMet===0. bug(qa): a failing qa verdict (AC_NOT_MET) is never posted to the issue — posting is gated on phase success #1070 edits the postQaVerdictComment call site in the same file, so keep the diff to that one function.

    Phase 2: property files (independent, parallelizable)

    1. ac-parser.property.test.ts:
      • never throws or hangs on fc.string();
      • metamorphic id-set invariance over a structured generator (typed lines: AC lines with unique ids, and filler lines with no leading -, # or fence);
      • a description-containment property (see Open Question 3).
    2. phase-executor.property.test.ts: never throws; the "checklist" property (-t "checklist"); the "consistency" property (-t "consistency", imports buildQaVerdictComment).
    3. mutation-marker.property.test.ts and qa-gaps-marker.property.test.ts: round-trip plus a never-throws property. Use fc.record generators, with GapFindingSchema-shaped findings for qa-gaps.
    4. Each fc.assert takes { ...(process.env.FC_SEED ? { seed: Number(process.env.FC_SEED) } : {}) }. fast-check prints the seed on failure by default. Inline this in each file: a shared helper is outside the "May touch" list.
    5. Mutation-verify AC-2 and AC-4 (commit first, one marker each). Add the CHANGELOG.md entry.

    Design Review

    1. Where does the logic belong? The parseQaSummary fix stays in phase-executor.ts. The verdict-consistency guard goes in buildQaVerdictComment, the only place where verdict and summary meet.
    2. Simplest correct approach? Checklist counting is one more line matcher feeding the existing loop. Rejected alternative: take counts from SEQUANT_QA_GAPS. That marker carries findings, not per-AC status.
    3. Existing pattern? Table-driven line matchers, as in AC_PATTERNS. The marker round-trip follows the flat-JSON HTML-comment idiom.
    4. Reviewer pushback? "Why not @fast-check/vitest?" It adds a second dependency and no capability the plain fc.assert calls lack.

    Feature Quality Planning

    Notable items (three of these are defects fast-check will find on the current code):

    • Indented AC lines are dropped. AC_PATTERNS anchor on ^-, and - [ ] **AC-1**: x parses to nothing (verified). A "re-indent" metamorphic property over AC lines fails on the base branch.
    • } inside a SEQUANT_MUTATION string value drops the marker. The {[^}]+} regex truncates mid-JSON (verified: mutation:"removed } brace" gives 0 markers). A backtick in a value survives, and only ``` fences and inline-code spans are stripped. SEQUANT_QA_GAPS has the same weakness on the sequence `} -->` inside a value.
    • The description is not always a substring of the input. - [ ] **AC-1: foo** bar parses to foo bar (verified). The ** is dropped and the two capture groups are joined with a space. The ids are also upper-cased.

    Derived ACs

    Source Derived AC Priority
    Robustness AC-9: generators are documented as encoding the marker contract (no } in flat-marker values, no --> in qa-gaps values); a boundary example test pins each known-lossy input Medium

    Open Questions

    1. AC-4 mutation and re-indent scope. The base parser already drops indented AC lines, so the AC's mutation ("drop the last AC when the line is indented") changes nothing and no property could kill it. Recommendation: re-indent only filler lines, and use a real mutant such as "skip the last input line" or "dedupe case-insensitively". Changing AC-line indentation would change the AC format, which is out of scope. Impact if wrong: the property is red on base, or the mutation record is vacuous.
    2. AC-3 wording. parseQaSummary has no verdict input. Recommendation: test the guard in buildQaVerdictComment (per D-10), covering AC_MET, AC_MET_BUT_NOT_A_PLUS and READY_FOR_MERGE. Impact if wrong: the AC cannot be met literally.
    3. Substring property. Recommendation: assert every whitespace-separated description token appears in the input, rather than the whole description. Impact if wrong: the property is red on base for the pattern-3 form.
    4. Seed policy. Recommendation: leave the seed random when FC_SEED is unset. That is how new counterexamples get found, and failures print the seed. Impact if wrong: a newly found counterexample turns CI red until fixed.
    5. Closes #1073. bug(qa): the posted verdict comment publishes a miscounted AC coverage — "0/1 met" on an 8-AC issue under an AC_MET verdict #1073 also reports duplicated gaps (one-line and full-paragraph forms of the same finding). This plan does not fix that. Recommendation: write Closes #1073 as the owner instructed, but note the gaps duplication in the PR body and file a follow-up. Impact if wrong: a defect closes unfixed.
    6. Marker format. No production formatter exists, so a test-local one only proves parser consistency with a mirror of the docs. Recommendation: accept this, and name it in the test.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: the deliverable is tests, so testgen would only stub the deliverable. There is no UI. Mutation markers are needed for AC-2 and AC-4, with failedTest starting with the test file path.


    Label Review

    Current: enhancement, qa
    Recommended: enhancement, qa, planned
    Reason: planning is complete.
    Quality Loop: won't auto-enable (SCOPE_OK).

  4. added
    planned
    on Sep 20, 2026
  5. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 0/3 met

    Gaps:

    Suggestions:

    • File the duplicated-gaps follow-up before merge, and reference it in the PR body next to Closes #1073.
    • Consider making \*\* optional in the checklist regex in a follow-up (see gap 2 below).
  6. added 4 commits that reference this issue on Sep 20, 2026
  7. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Merged as PR #1114 (squash 08afa29) on 2026-09-20; #1073 closed from the same PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplannedqa

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions