Skip to content

Bring mcp/cas to 100% line/branch/function coverage: 85.71% → 100% branch - #1583

Merged
sergey-shandar merged 2 commits into
mainfrom
claude/mcp-cas-coverage-improvement
Aug 15, 2026
Merged

Bring mcp/cas to 100% line/branch/function coverage: 85.71% → 100% branch#1583
sergey-shandar merged 2 commits into
mainfrom
claude/mcp-cas-coverage-improvement

Conversation

@sergey-shandar

Copy link
Copy Markdown
Contributor

Summary

fjs/mcp/cas/module.f.mjs was at 85.71% branch coverage (5 uncovered branches, no proof.f.mjs existed yet). This brings it to 100% line/branch/function coverage:

  • Two provably unreachable defensive guards, restructured away. cas_get's content: true path re-derives type/mimeType via the dialect-aware detector, then checked fromVec/base64Encode for null before encoding the payload. media/type's own finish() only ever classifies a blob as 'text' when its bit length is byte-aligned — the same condition fromVec checks — and every byte ever written through cas_add/the CAS store is whole chunks, so base64Encode's only failure mode (non-byte-aligned input) can't occur either. Both null-checks are replaced with assertNotNullish, mirroring the identical pattern media/module.f.mjs's own detect() already uses for the same invariant (down to the comment).
  • Three genuinely-reachable race branches, covered by a new proof.f.mjs: a writeBytes failure during cas_add, and cas_get's "hash vanished between reads" race on both the metadata-refine path (falls back to the streaming verdict) and the content-fetch path (returns an error — no fallback once inline content was promised). Each is real only under an actual race (a failing disk, a concurrent writer, a GC sweep) between two of the tool's own steps. proof.f.mjs reaches them the same way fjs/cas/proof.f.mjs does (from PR Bring cas (top-level) to 100% line/branch/function coverage: 96.59% → 100% branch #1576): a synthetic effect driver that succeeds by default except for the one call under test.

Test plan

  • npx tsc --noEmit
  • node --test --experimental-test-coverage --test-coverage-include='fjs/mcp/cas/module.f.mjs' fjs/emergent_testing/all.test.mjs → 100.00% line/branch/func
  • node ./fjs/module.mjs t → 2800 pass, 0 fail

🤖 Generated with Claude Code


Generated by Claude Code

85.71% branch coverage (5 uncovered branches), the lowest of the
remaining modules:

- Two were provably unreachable defensive guards: cas_get's content:true
  path re-derives type/mimeType via the dialect-aware detector, then
  checks fromVec/base64Encode for null before encoding the payload.
  media/type's own finish() only ever classifies a blob as 'text' when
  its bit length is byte-aligned (the same condition fromVec checks),
  and every byte ever written through cas_add/the CAS store is whole
  chunks, so base64Encode's only failure mode (non-byte-aligned input)
  can't occur either. Replaced both with assertNotNullish, mirroring
  the identical assertNotNullish media/module.f.mjs's own detect()
  already uses for the same invariant.
- The other three (a writeBytes failure during cas_add, and cas_get's
  hash-vanished-between-reads races on both the metadata-refine and
  content-fetch paths) are real only under an actual race or failing
  disk, so proof.f.mjs (new file) reaches them the same way
  fjs/cas/proof.f.mjs does: a synthetic effect driver that succeeds by
  default except for the one call under test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BmWCv5YGRXToq26xPoSXjX
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BmWCv5YGRXToq26xPoSXjX
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
functionalscript 54749c3 Commit Preview URL

Branch Preview URL
Aug 15 2026, 07:39 AM

@o2alexanderfedin o2alexanderfedin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked both guard removals independently rather than taking the comments' word for it — the unreachability arguments hold.

fromVec (module.f.mjs:280): the guard sits behind refined.type === 'text', and the dialect layer in fjs/media only ever rewrites mime_type, so type can only come from detectVec. finish emits 'text' only under utf8Text(s.utf8) && (s.length & 0b111n) === 0n, and push short-circuits only once the verdict is already base64 — so a 'text' verdict implies a complete byte fold, which is exactly what fromVec re-checks with the same decoder. No dialect branch or other caller reaches the encode path with an unclassified blob.

base64Encode (module.f.mjs:289): value is only ever collectRead(c.read(key)), built from Buffer chunks in the Node handler, so bit length is always a multiple of 8 and encode's sole null condition (len % 8n !== 0n) can't fire. cas_add likewise only stores byte-aligned Vecs.

Measured, not assumed: npx tsc clean, fjs test 2800/2800, and a scoped coverage run over fjs/mcp/cas/module.f.mjs reports 100.00 line / 100.00 branch / 100.00 funcs — matching the claim. New proof.f.mjs follows the co-located convention and reuses the drive technique from fjs/cas/proof.f.mjs.

@sergey-shandar
sergey-shandar added this pull request to the merge queue Aug 15, 2026
Merged via the queue into main with commit 41d051c Aug 15, 2026
19 checks passed
@sergey-shandar
sergey-shandar deleted the claude/mcp-cas-coverage-improvement branch August 15, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants