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

+12 -2
View File
@@ -76,9 +76,18 @@ export async function getRevision(
};
}
/** Restore a revision: write its body+metadata back into the live `documents` row. */
/**
* Restore a revision: write its body+metadata back into the live `documents` row.
*
* @param id revision UUID
* @param opts optional seam for testing — override the chunk-rebuild step so
* tests can assert it's invoked without touching embeddings.
*/
export async function restoreRevision(
id: string,
opts?: {
reindex?: (slug: string) => Promise<number>;
},
): Promise<{ slug: string; documentId: string } | null> {
const [rev] = await db
.select({
@@ -118,7 +127,8 @@ export async function restoreRevision(
// Rebuild semantic chunks + embeddings from the restored body so semantic
// and hybrid search stay consistent (otherwise document_chunks would hold
// the NEW body's chunks while documents.body holds the OLD/restore body).
await reindexChunks(rev.slug);
const reindex = opts?.reindex ?? reindexChunks;
await reindex(rev.slug);
return { slug: rev.slug, documentId: rev.documentId };
}