chore(testing): Phase 9 — bun:test suite + CI gating with no-DB fakes
CI / typecheck + build (turbo) (push) Canceled after 0s

Added a real test suite (32 tests, 0 external services) using bun:test with
in-process module mocking for @mcpedia/db, @mcpedia/queue, @mcpedia/core.

Enablers:
- apps/api: extracted createApp(deps?) factory + dashboard.ts module from
  index.ts so the HTTP surface is unit-testable (real queue is lazy-imported).
- packages/core: exported shouldCreateRevision pure predicate; restoreRevision
  gained an opts.reindex seam for the chunk-rebuild contract.
- apps/mcp: renamed smoke.test.ts -> smoke.ts (bun test now owns .test.ts),
  updated stale assertions (10 tools, 4 docs in docs section).
- infra: turbo test task (cache:false), test scripts across packages,
  @types/bun + tsconfig base types, CI 'Test' step after Build.

Packages with tests: embeddings(5), parser(5), search(8), core(4),
mcp(6 auth-gates), api(8 contracts).

All green: typecheck(4/4), test(6/6 pkgs), build(web). Live API verified
/health, /metrics, /dashboard, /hooks/* auth gate on temp port.
This commit is contained in:
asepharyana committed 2026-08-20 11:12:32 +07:00
1 parent 0cdf261d40
commit 76f778c10d
25 files changed
+1055 -193

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import { test, expect } from "bun:test";
import { shouldCreateRevision } from "../src/index.service";
/**
* Phase 9: unit tests for the revision-dedup decision rule.
*
* `shouldCreateRevision` is the pure predicate that `indexContentFile` consults
* before writing a new row to `document_revisions`. It's extracted because the
* dedup correctness is the single most important guarantee of the revision
* system ("metadata-only edits don't bloat history"), and it must hold without
* a database.
*
* The DB-backed paths (`snapshotRevision`, `restoreRevision`) are exercised
* end-to-end by the existing manual e2e (`bun run index` + restore via the web
* /api/revisions/restore route, see PHASES.md Phase 4 verification). Here we
* lock the decision invariant in CI.
*/
test("shouldCreateRevision: first snapshot when no prior revision exists", () => {
// No prior revision row → always snapshot the first version.
expect(shouldCreateRevision(null, "body text")).toBe(true);
expect(shouldCreateRevision(undefined, "body text")).toBe(true);
});
test("shouldCreateRevision: identical body creates no new revision (dedup)", () => {
// The exact dedup rule that prevents metadata-only edits from bloating
// history: if the body is byte-identical to the latest revision's body,
// skip the snapshot.
expect(shouldCreateRevision("same body", "same body")).toBe(false);
// The dedup rule applies regardless of body length — large identical bodies
// also skip the snapshot.
expect(shouldCreateRevision("a".repeat(5000), "a".repeat(5000))).toBe(false);
});
test("shouldCreateRevision: changed body creates a new revision", () => {
expect(shouldCreateRevision("old body", "new body")).toBe(true);
// Whitespace / trailing newline changes count as a real body change.
expect(shouldCreateRevision("body", "body\n")).toBe(true);
});
test("shouldCreateRevision: empty-string vs non-empty counts as a change", () => {
expect(shouldCreateRevision("", "content")).toBe(true);
expect(shouldCreateRevision("content", "")).toBe(true);
});