Skip to content

followup: close 8 pre-existing test failures (pdf fixtures + UI build wiring) - #2

Merged
zaynram merged 10 commits into
mainfrom
followup-pdf-fixtures-and-ui-bundle
May 29, 2026
Merged

zaynram merged 10 commits into
mainfrom
followup-pdf-fixtures-and-ui-bundle

Conversation

@zaynram

@zaynram zaynram commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Followup to #1 (audit-driven hardening, merged at d544ea7). Scopes the 8 unchanged pre-existing test failures called out in that PR's verification section into two atomic chores. Currently chore-only — no implementation yet — so the user can direct execution per chore.

Scope (two chores)

1. pdf-test-fakectx-pdfviews-fixture

Blast radius: src/server/tools/pdf.test.ts only.
Closes: 5 refresh-extraction tests failing with TypeError: undefined is not an object (evaluating 'ctx.pdfViews.get').
Root cause: S1's §13 v1.1 amendment added ctx.pdfViews: Map<paper_id, viewUUID> as the viewUUID resolution surface; fakeCtx (pdf.test.ts:63-92) wasn't updated to populate it. Production path (real scholar.pdf.open) works fine.
Fix: extend fakeCtx to accept pdfViews arg; pre-populate per test.
Estimate: ≤30 LOC, single commit.

2. fix-build-ui-script-cwd-paths

Blast radius: package.json (+ optionally scripts/build-ui.ts, scripts/measure-bundle.ts).
Closes: 3 bundle.test.ts tests failing on missing build/ui/app.html and build/ui/bundle-budget.json.
Root cause: bun --cwd=scripts build-ui shifts cwd to scripts/ before running build-ui.ts, but the script passes repo-root-relative paths ("src/ui/index.html", "build/ui") that no longer resolve. bundle.test.ts beforeAll swallows the build error silently.
Fix: drop --cwd=scripts from both scripts (preferred), OR anchor paths to import.meta.dir in the script files.
Estimate: ≤5 LOC, single commit.

Why two chores instead of one bundle

reject-monolithic-scopes discipline: these are independent concerns with different blast radii (test fixture vs build pipeline). Splitting lets each land + verify independently and keeps each commit focused.

State

  • Branch off main (post-merge, d544ea7)
  • Both chores added to .claude/context/chores.xml with file:line refs, failure modes, fix options, acceptance criteria
  • Execute chore 1: pdf-test-fakectx-pdfviews-fixture (single commit, ~30 LOC)
  • Execute chore 2: fix-build-ui-script-cwd-paths (single commit, ~5 LOC)
  • Verify full suite reaches 297 pass / 8 skip / 0 fail
  • Verify bunx tsc --noEmit clean
  • Convert from draft to ready-for-merge

Test plan

  • Each chore landed as Red→Green TDD (fixture chore: confirm 5 tests go red→green; build chore: confirm 3 bundle tests go red→green via bun run build:ui succeeding)
  • Final suite: 297 pass / 8 skip / 0 fail (vs. PR1's 289 / 8 / 8)
  • Typecheck clean
  • No regressions on the 289 tests PR1 left green

🤖 Generated with Claude Code

…d chores

Followup PR scoping for the 8 unchanged pre-existing test failures called
out in the audit PR (S1-S3 + H1-H5 + M1-M9 sweep, merged at d544ea7).
Both chores are single-concern, single-commit-shaped, and small (≤30 LOC
each). Synopses include exact file:line refs, failure modes, fix options,
and acceptance criteria so each can be executed independently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zaynram
zaynram marked this pull request as ready for review May 29, 2026 16:58
Copilot AI review requested due to automatic review settings May 29, 2026 16:58
Closes chore pdf-test-fakectx-pdfviews-fixture. S1's §13 v1.1 amendment
introduced ctx.pdfViews: Map<paper_id, viewUUID> as the viewUUID
resolution surface (refreshExtraction at pdf.ts:141 does
`ctx.pdfViews.get(args.paper_id)`). fakeCtx never populated it, leaving
the 5 refresh-extraction tests failing at TypeError. Production code path
is unchanged; the gap was test-only.

Extend fakeCtx with an optional `paperId` opt that seeds
`<paperId> -> view-<paperId>`. Each failing test now passes its paper_id
via the same fakeCtx call. Suite: 6/6 pdf.test.ts pass.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Followup to PR #1 that resolves the 8 pre-existing test failures via two small, isolated fixes: seeding ctx.pdfViews in the pdf.test.ts fakeCtx helper, and fixing the build:ui/measure-bundle package scripts that were running with the wrong cwd.

Changes:

  • Extend fakeCtx in pdf.test.ts to accept a paperId opt and pre-populate pdfViews with view-<paperId>, updating all 5 refresh-extraction tests accordingly.
  • Drop --cwd=scripts from the build:ui and measure-bundle scripts in package.json so repo-root-relative paths inside the scripts resolve correctly.
  • Document both chores in .claude/context/chores.xml with status closed and fulfillment SHAs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/server/tools/pdf.test.ts Seeds ctx.pdfViews via new paperId opt on fakeCtx; updates 5 callers.
package.json Switches build:ui and measure-bundle from bun --cwd=scripts <name> to bun scripts/<name>.ts.
.claude/context/chores.xml Records both chores as closed with fulfillment commit refs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zaynram and others added 8 commits May 29, 2026 11:59
Closes chore fix-build-ui-script-cwd-paths. `bun --cwd=scripts X` shifted
cwd to scripts/ before running the script, but build-ui.ts and
measure-bundle.ts both pass repo-root-relative paths internally
("src/ui/index.html", "build/ui") that no longer resolve from scripts/.
Result: bun run build:ui exited with FileNotFound for src/ui; bundle.test.ts
beforeAll silently swallowed the build error and the 3 bundle-budget
assertions failed on missing artifacts.

Fix is option A from the chore: drop --cwd=scripts and call the script
file directly. Other --cwd=scripts entries (build:pdf, build:vec,
build:plugin) left untouched — out of chore scope; their bodies may
genuinely depend on cwd=scripts and no failing test exercises them.

Suite reaches 297 pass / 8 skip / 0 fail (was 289 / 8 / 8 on PR1).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- pdf-test-fakectx-pdfviews-fixture → 24309eb
- fix-build-ui-script-cwd-paths     → 609749d

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test fixtures resolve vec0 via runtime/vendor/sqlite-vec/vec0.so
(tests/util/vec0.ts). runtime/ is gitignored per CLAUDE.md (per-user
state), so CI must materialize vec0 before bun test runs — otherwise
loadExtension fails and 23+ tests cascade-fail through the chunk_vec
virtual table.

The Smoke step that previously ran AFTER test compiled vec0 to /tmp/
which the test fixtures don't look for. Replace that flow by calling
bun run build:vec before bun test; build-vec0 emits to the canonical
runtime/vendor location and caches by file existence.

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

When invoked as a script via \`bun run build:vec\`, the if-main block
passed util.subpath("build/vendor/sqlite-vec") — a DIRECTORY — to
compileVec0FromSource, which then handed it to gcc as the -o output.
ld errored "cannot open output file ...: No such file or directory"
because the parent dir wasn't created either.

Fix: append the platform-specific filename (vec0.{so,dylib,dll}) when
calling compileVec0FromSource at script entry, and mkdirSync the parent
of destPath inside the compile function before invoking the compiler.

Verified locally by deleting build/vendor/sqlite-vec + runtime/vendor/
sqlite-vec and running bun run build:vec — both locations now populated
with the compiled vec0.so. Suite remains at 297 pass / 0 fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bun:test mock.module() is process-global; the unscoped mock.module at
ingest.test.ts module-load time persisted into later test files
(roots.test.ts), making allPdfRoots return ["/tmp"] for tests that needed
the real DB-backed lookup. Local bun 1.3.14 happens to isolate this; CI's
1.3.11 surfaces it as roots.add seeing setRoots called with ["/tmp"]
instead of the test's tmpdir-rooted paths.

Snapshot the real default-pdf-root exports at module load, install the
mock in beforeAll, and re-mock with the real exports in afterAll. The
hygiene is bun-version-agnostic and the right pattern regardless.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zaynram
zaynram merged commit db68e80 into main May 29, 2026
1 check passed
@zaynram
zaynram deleted the followup-pdf-fixtures-and-ui-bundle branch May 29, 2026 17:31
zaynram added a commit that referenced this pull request Jun 6, 2026
…inels (#2)

Cowork field test (2026-06-05): refresh-extraction reported chunks_written:1 on a
failed extraction and silently poisoned the corpus with the child's error text.

Root cause: the vendored pdf child returns failures as the standard MCP error
envelope `{ content:[{type:"text",text:<msg>}], isError:true }`, and the SDK's
`callTool` does NOT throw on `isError` (it's an in-band tool error for the model
to read). `getText` flattened that error text and returned it as if it were
document text, so refreshExtraction chunked + embedded the one-line sentinel.

Fix: extract a pure `parseGetTextResult` that throws `PDF_GET_TEXT_FAILED` on the
isError envelope and flattens the success content otherwise; `getText` routes
through it. The failure now propagates out of refreshExtraction instead of
writing a bogus single chunk. The child responded (it's alive), so the liveness
stamp is kept. Pure helper ⇒ unit-tested directly (isError throws / success
flattens / bare-string passthrough / labelled error when isError has no message),
mirroring sanitizeRoots + buildClientCapabilities.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
zaynram added a commit that referenced this pull request Jun 6, 2026
…pagates get_text errors, writes zero chunks

The parseGetTextResult unit tests (lifecycle.test.ts) prove the seam throws on
the vendor isError envelope, and getText routes through it (lifecycle.ts:320).
This adds the caller-layer proof the advisor required: the field report's #2 is
about refreshExtraction, which must propagate the failure instead of chunking
the error sentinel and reporting chunks_written:1.

Highest fidelity short of a real spawn: the stubbed getText runs the REAL
parseGetTextResult on an isError envelope (exactly what the production handle
does), so the test exercises the wired path child-error → getText throws →
caller propagates — not a hand-rolled stand-in. Asserts refreshExtraction
rejects with PDF_GET_TEXT_FAILED AND that zero paper_chunks / chunk_vec rows
were written (the "not chunks_written:1" claim in concrete form). A swallowing
try/catch in the caller would flip the rejection assertion red, so this also
guards the no-downgrade property by construction.

Verified clean across all three layers: seam (helper unit tests), wiring
(getText returns parseGetTextResult at lifecycle.ts:320), caller (this test).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants