[Testing 17] test(backend): document-integrity unit tests + ratchet raise

✅ merged · #253 · open-legal-products/mike ← amal66/mike · opened 3mo ago by amal66 · merged 3mo ago by willchen96 · +602-24 across 6 files · ↗ on GitHub

From the PR description

This lands the "document integrity" tier of the backlog in docs/testing-coverage.md: four new unit suites, 46 tests, no new dependencies, no production code changes.

Why these four: docxTrackedChanges.ts is the code that rewrites a client's .docx to show edits as tracked changes - if it corrupts a document or drops the wrong run, that's a real problem for a legal product. chat/prompts.ts carries the citation contract the response parser depends on. documentTypes.ts decides how uploads are handled and served. systemWorkflows.ts is the built-in workflow catalog the UI trusts to be well-formed.

What the tests do:

  • docxTrackedChanges (19): builds tiny real .docx files in memory with JSZip (already a dependency) and checks the whole life cycle - a replacement comes out as a proper w:del/w:ins pair, only the changed span is tracked, accepting a change yields exactly the edited text and rejecting it restores the original. Also locks in the safe failure modes: unmatched or ambiguous edits are reported as errors (never guessed), and garbage input throws instead of producing a broken file.
  • chat/prompts (8): the citation rules, doc-label hygiene, and safety instructions are present in every prompt variant, and the CourtListener research block appears only when research tools are actually available.
  • documentTypes (12): known types resolve (case-insensitively), unknown/missing input falls back sanely, and spreadsheets are deliberately excluded from PDF conversion.
  • systemWorkflows (7): unique ids, complete metadata, non-empty skill markdown, well-formed tabular columns, and the assistant shortlist stays in sync with the full definitions.

Ratchet: global coverage moves from 11.18/10.98/14.43/10.91 to 23.88/17.98/23.06/23.79 (stmts/branches/funcs/lines), so the floors in backend/vitest.config.mts go up from 11/10/14/10 to 23/17/23/23. Backlog doc updated to match.

Verified: npm ci && npm run test:coverage green with the new floors; npm run build green.

🤖 Generated with Claude Code

Our analysis

Add document integrity test coverage — read the full analysis →

Think the analysis missed something the PR description covers?

Commits in this PR (1)

SHA Subject Author Date
7f09e475 test(backend): document-integrity tier - docxTrackedChanges, prompts, documentTypes, systemWorkflows Amalanand Muthukumaran 2026-07-25 ↗ GitHub
commit body
Four new unit suites (46 tests) for the document-integrity tier of the
coverage backlog:

- docxTrackedChanges: in-memory docx fixtures via JSZip; insert/delete
  runs, minimal tracked spans, accept/reject round-trips, id numbering,
  ambiguous/not-found/malformed-input paths (19 tests)
- chat/prompts: base prompt invariants, citation contract markers, and
  CourtListener splice on/off (8 tests)
- documentTypes: type predicates, pdf-conversion policy, MIME fallbacks
  (12 tests)
- systemWorkflows: unique builtin ids, well-formed metadata/columns,
  non-empty skill markdown, assistant-list sync (7 tests)

Coverage ratchet raised from 11/10/14/10 to 23/17/23/23 (measured
23.88% stmts / 17.98% branches / 23.06% funcs / 23.79% lines); backlog
doc updated to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-253.md from inside the repo you want the changes in.

⬇ Download capture-pull-253.md