Skip to content

test(doctor): pin the half-built-index diagnostic, which nothing asserted - #195

Merged
kevintseng merged 1 commit into
mainfrom
test/pin-half-built-index-diagnostic
Aug 23, 2026
Merged

test(doctor): pin the half-built-index diagnostic, which nothing asserted#195
kevintseng merged 1 commit into
mainfrom
test/pin-half-built-index-diagnostic

Conversation

@kevintseng

Copy link
Copy Markdown
Contributor

Summary

vector-generation.open — the memesh doctor row that tells a user an interrupted rebuild is holding a second, full-size copy of their vectors on disk — shipped with the generation-swap work and had no test asserting it. The three test files that mention vector_generation seed that metadata key as a fixture for other behaviour, and cli-reindex-vectors-guard.test.ts covers reindex --discard-generation: the action, not the diagnostic that names it. This adds the missing read-side pin. No production code changes.

Type of change

  • Feature (feat)
  • Bug fix (fix)
  • Refactor (refactor)
  • Docs only (docs)
  • Test only (test)
  • Build / CI / chore
  • Release (release)

Docs synced (project doc-sync rule — CLAUDE.md)

  • CHANGELOG.md updated — deliberately not: no user-visible behaviour changes. CONTRIBUTING.md ties doc updates to behaviour / API / architecture changes; this is none of them.
  • docs/ARCHITECTURE.md — no module structure change
  • docs/api/API_REFERENCE.md — no MCP / HTTP / CLI surface change
  • README.md — no user-facing change
  • README locales — README.md unchanged
  • Version files — no version bump
  • dist/skills-manifest.json — nothing under .claude-plugin/, scripts/hooks/, skills/ or version files was touched
  • memesh doctor Overall — not run; nothing in this PR can move it, and reporting a check I did not run is what this repository's rules forbid

Verification

Run in this checkout, this session:

npm run typecheck                     exit=0
node scripts/run-tests-isolated.mjs   158 files, 2314 tests passed, exit=0
npm run verify:release                exit=0
npx vitest run tests/cli/doctor-half-built-index.test.ts   5 passed, exit=0
  • npx tsc --noEmit clean (via npm run typecheck, which covers src/, tests/ and the root configs)
  • npm run build — not run; no source file changed, so dist/ is unchanged
  • npm test -- --run passing — run as scripts/run-tests-isolated.mjs (throwaway HOME): 158 files, 2314 tests, 0 failed. The five new cases are this file's; I did not re-run the suite on main to state a delta, so none is claimed.
  • Hooks untouched
  • LLM flows untouched

Break-test. A green suite is not evidence a guard is protected, so the check was mutated in a copy of the tree, rebuilding dist each time — the tests spawn the built CLI, so a mutation left in src alone grades a binary that never changed:

mutant result
readVectorGeneration() short-circuited to { state: 'none' } KILLED (4 cases red)
const staged = generationRowIds().size= 0 KILLED (1 case red)
severity 'warn''pass' KILLED (2 cases red)
state === 'open' inverted INVALID, not counted — stops type-checking, so it was never executed

Restored copy green again (exit=0). Restoration is by writing the original file back, never git checkout.

Test plan

  • npx vitest run tests/cli/doctor-half-built-index.test.ts — 5 passed
  • Delete the vector_generation branch in src/core/doctor.ts (or set staged to a constant), npx tsc, re-run the file — it must go red
  • npm run verify:release — exit=0, C1: new=0

Known limitations / follow-ups

  • The fixture writes the staging table directly instead of killing a real rebuild mid-flight. A real rebuild needs an embedding provider, and what doctor reads is the state, not the route to it.
  • This closes the last of the four items the PR feat: reindex builds the new vector index beside the old one (generation swap) #185 review deferred. The other three were already implemented and pinned — already_staged / stale-hash resume (reindex-reports-what-happened.test.ts:403,438), the reindex circuit breaker (:464), and the body-phase timeout (embedder-provider-fetch.test.ts:152). Verified by reading the assertions, not by the presence of a file name.

…rted

`vector-generation.open` is the doctor row that tells a user an interrupted
rebuild is holding a second, full-size copy of their vectors on disk. It
shipped with the generation-swap work and no test asserted it. The three test
files that mention `vector_generation` seed that metadata key as a fixture for
other behaviour, and the CLI test covers `reindex --discard-generation` — the
action, not the diagnostic that names it. Write side pinned, read side not:
exactly the shape where both halves are correct and the chain between them was
never walked.

Five cases against the built CLI in a throwaway HOME, because the staged count
comes from counting rows in a vec0 virtual table and a stub cannot execute
that:

  - silence on a database with no half-built index (the half that gives the
    warning meaning — without it a hard-wired row passes every other case)
  - the row's width, provider and start time, emitted exactly once
  - the staged count, seeded with two rows so a count and a boolean differ
  - the unreadable-marker branch, which must NOT offer to resume a generation
    whose embedding space is unknown
  - the row clearing after the fix it names is actually run

Break-tested in a copy of the tree, rebuilding dist each time — the test spawns
the binary, so a mutation left in src alone grades one that never changed.
Short-circuiting the read, hard-wiring the staged count to 0, and downgrading
the severity to pass: 3/3 KILLED, restored copy green again. A fourth mutant
(inverting `state === 'open'`) was rejected as INVALID rather than counted: it
stops type-checking, and a mutant that does not compile was never executed.

No CHANGELOG entry: no user-visible behaviour changes here.

Verification, this checkout, this session:
  npm run typecheck                       exit=0
  node scripts/run-tests-isolated.mjs     158 files, 2314 tests passed, exit=0
  npm run verify:release                  exit=0 (C1 clean after the
                                          exactly-once assertion was added)
@kevintseng
kevintseng merged commit 3b921a2 into main Aug 23, 2026
13 checks passed
@kevintseng
kevintseng deleted the test/pin-half-built-index-diagnostic branch August 23, 2026 14:58
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.

1 participant