Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(doctor): our own implementation of the #5379 fix (#5379)

time-attack379f20a002ef
diff --git a/src/commands/doctor/checks/graph-health.ts b/src/commands/doctor/checks/graph-health.ts
index e5cfa2ee9c..89d34080d2 100644
--- a/src/commands/doctor/checks/graph-health.ts
+++ b/src/commands/doctor/checks/graph-health.ts
@@ -87,7 +87,14 @@ async function runGraphCoverage(ctx: DoctorContext): Promise<Check[]> {
message: `Only code/test fixture entity pages found (${entityCount}); graph_coverage not applicable`,
});
} else if (eligibleEntityCount < MIN_ENTITY_PAGES_FOR_COVERAGE) {
- checks.push({ name: 'graph_coverage', status: 'ok', message: `Only ${eligibleEntityCount} eligible entity page${eligibleEntityCount === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale` });
+ // Same small-N floor BrainHealth grades from: a 1-4 page ratio is noise,
+ // and warning on it leaves a WARN that `extract all` cannot clear.
+ const pages = eligibleEntityCount === 1 ? 'page' : 'pages';
+ checks.push({
+ name: 'graph_coverage',
+ status: 'ok',
+ message: `Only ${eligibleEntityCount} eligible entity ${pages} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
+ });
} else if (linkCoverage >= 0.7 && timelineCoverage >= 0.5) {
checks.push({ name: 'graph_coverage', status: 'ok', message: `Entity connected coverage (in/out) ${linkPct}%, entity timeline coverage ${timelinePct}%` });
} else {
diff --git a/src/core/onboard/checks.ts b/src/core/onboard/checks.ts
index 2d5a3f0604..8ed0a490b8 100644
--- a/src/core/onboard/checks.ts
+++ b/src/core/onboard/checks.ts
@@ -63,6 +63,21 @@ export const VISIBLE_ENTITY_PREDICATE = `p.type IN ('person', 'company', 'organi
AND p.deleted_at IS NULL
AND ${QUARANTINE_FILTER_FRAGMENT}`;
+/**
+ * Coverage is a ratio over the visible entity population, and below
+ * MIN_ENTITY_PAGES_FOR_COVERAGE that ratio is noise: BrainHealth reports
+ * null there, so a warn from these checks would contradict it and could never
+ * be cleared by extraction. Returns the not-applicable `ok` result for an
+ * ungraded population, or null when the caller should compute coverage.
+ */
+function ungradedCoverageResult(name: string, entityPages: number): OnboardCheckResult | null {
+ if (entityPages >= MIN_ENTITY_PAGES_FOR_COVERAGE) return null;
+ const message = entityPages === 0
+ ? 'No entity pages — coverage check vacuous'
+ : `Only ${entityPages} entity ${entityPages === 1 ? 'page' : 'pages'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`;
+ return { check: { name, status: 'ok', message }, remediations: [] };
+}
+
type CoverageFeature =
| { table: 'links'; pageIdColumn: 'to_page_id' }
| { table: 'timeline_entries'; pageIdColumn: 'page_id' };
@@ -269,22 +284,8 @@ export async function checkEntityLinkCoverage(
WHERE ${VISIBLE_ENTITY_PREDICATE}`,
);
- if (totalEntities === 0) {
- return {
- check: { name: 'entity_link_coverage', status: 'ok', message: 'No entity pages — coverage check vacuous' },
- remediations: [],
- };
- }
- if (totalEntities < MIN_ENTITY_PAGES_FOR_COVERAGE) {
- return {
- check: {
- name: 'entity_link_coverage',
- status: 'ok',
- message: `Only ${totalEntities} entity page${totalEntities === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
- },
- remediations: [],
- };
- }
+ const ungraded = ungradedCoverageResult('entity_link_coverage', totalEntities);
+ if (ungraded) return ungraded;
// Decide TABLESAMPLE policy (PG only, when >50K entities)
const useSample = engine.kind === 'postgres' && totalEntities > 50_000;
@@ -366,22 +367,8 @@ export async function checkTimelineCoverage(
WHERE ${VISIBLE_ENTITY_PREDICATE}`,
);
- if (totalEntities === 0) {
- return {
- check: { name: 'timeline_coverage', status: 'ok', message: 'No entity pages — coverage check vacuous' },
- remediations: [],
- };
- }
- if (totalEntities < MIN_ENTITY_PAGES_FOR_COVERAGE) {
- return {
- check: {
- name: 'timeline_coverage',
- status: 'ok',
- message: `Only ${totalEntities} entity page${totalEntities === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
- },
- remediations: [],
- };
- }
+ const ungraded = ungradedCoverageResult('timeline_coverage', totalEntities);
+ if (ungraded) return ungraded;
const useSample = engine.kind === 'postgres' && totalEntities > 50_000;
const samplePct = useSample
diff --git a/test/doctor-graph-coverage-inbound.test.ts b/test/doctor-graph-coverage-inbound.test.ts
index 0a3549745a..cea47bcb45 100644
--- a/test/doctor-graph-coverage-inbound.test.ts
+++ b/test/doctor-graph-coverage-inbound.test.ts
@@ -16,6 +16,7 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { sqlQueryForEngine } from '../src/core/sql-query.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
import { buildChecks } from '../src/commands/doctor.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../src/core/types.ts';
let engine: PGLiteEngine;
@@ -33,33 +34,39 @@ beforeEach(async () => {
await resetPgliteState(engine);
});
+/** Insert `count` synthetic person pages `<prefix>-1` .. `<prefix>-<count>`. */
+async function insertPeople(eng: PGLiteEngine, prefix: string, count: number): Promise<void> {
+ const sql = sqlQueryForEngine(eng);
+ await sql`
+ INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
+ SELECT ${prefix}::text || '-' || g, 'default', 'person', 'Person ' || g, '', '{}', ${prefix}::text || '-h' || g, now(), now()
+ FROM generate_series(1, ${count}::int) AS g
+ `;
+}
+
/**
- * Five entity pages that are LINKED TO (inbound only) from note pages, each
- * with a timeline entry so the timeline half of the check stays green and
- * the assertion isolates the link-direction predicate.
+ * Enough person pages to clear the small-N coverage floor, each LINKED TO
+ * (inbound only) from one note page and each with a timeline entry, so the
+ * timeline half of the check stays green and the assertion isolates the
+ * link-direction predicate.
*/
async function seedInboundOnlyEntities(eng: PGLiteEngine): Promise<void> {
const sql = sqlQueryForEngine(eng);
+ await insertPeople(eng, 'inbound-example', MIN_ENTITY_PAGES_FOR_COVERAGE);
await sql`
INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
- VALUES
- ('alice-example', 'default', 'person', 'Alice', '', '{}', 'in1', now(), now()),
- ('acme-example', 'default', 'company', 'Acme', '', '{}', 'in2', now(), now()),
- ('bob-example', 'default', 'person', 'Bob', '', '{}', 'in4', now(), now()),
- ('carol-example', 'default', 'person', 'Carol', '', '{}', 'in5', now(), now()),
- ('dave-example', 'default', 'person', 'Dave', '', '{}', 'in6', now(), now()),
- ('meetings/2026-04-03', 'default', 'note', 'Standup', '', '{}', 'in3', now(), now())
+ VALUES ('meetings/2026-04-03', 'default', 'note', 'Standup', '', '{}', 'in-note', now(), now())
`;
- // Inbound-only: the note links TO both entities; the entities link to nothing.
+ // Inbound-only: the note links TO every person; the people link to nothing.
await sql`
INSERT INTO links (from_page_id, to_page_id, link_type)
SELECT n.id, e.id, 'mentions'
FROM pages n, pages e
- WHERE n.slug = 'meetings/2026-04-03' AND e.slug IN ('alice-example', 'acme-example', 'bob-example', 'carol-example', 'dave-example')
+ WHERE n.slug = 'meetings/2026-04-03' AND e.type = 'person'
`;
await sql`
INSERT INTO timeline_entries (page_id, date, summary)
- SELECT id, '2026-04-03', 'met at standup' FROM pages WHERE slug IN ('alice-example', 'acme-example', 'bob-example', 'carol-example', 'dave-example')
+ SELECT id, '2026-04-03', 'met at standup' FROM pages WHERE type = 'person'
`;
}
@@ -69,40 +76,18 @@ describe('graph_coverage counts inbound-connected entities (#4191)', () => {
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
expect(graph, 'graph_coverage check must be present').toBeDefined();
- // All five entities have inbound links → 100% connected coverage, ok.
+ // Every person has an inbound link → 100% connected coverage, ok.
expect(graph!.status).toBe('ok');
expect(graph!.message).toContain('connected coverage (in/out)');
expect(graph!.message).toContain('100%');
});
test('unlinked entities still warn, with the 70% target named', async () => {
- const sql = sqlQueryForEngine(engine);
- await sql`
- INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
- VALUES
- ('bob-example', 'default', 'person', 'Bob', '', '{}', 'un1', now(), now()),
- ('widget-co', 'default', 'company', 'Widget Co', '', '{}', 'un2', now(), now()),
- ('carol-example', 'default', 'person', 'Carol', '', '{}', 'un3', now(), now()),
- ('dave-example', 'default', 'person', 'Dave', '', '{}', 'un4', now(), now()),
- ('erin-example', 'default', 'person', 'Erin', '', '{}', 'un5', now(), now())
- `;
+ await insertPeople(engine, 'unlinked-example', MIN_ENTITY_PAGES_FOR_COVERAGE);
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
expect(graph!.status).toBe('warn');
expect(graph!.message).toContain('connected coverage (in/out) 0%');
expect(graph!.message).toContain('target 70%');
});
-
- test('one eligible entity page is not applicable without a coverage warning', async () => {
- const sql = sqlQueryForEngine(engine);
- await sql`
- INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
- VALUES ('one-example', 'default', 'person', 'One', '', '{}', 'one', now(), now())
- `;
- const checks = await buildChecks(engine, [], null);
- const graph = checks.find((c) => c.name === 'graph_coverage');
- expect(graph!.status).toBe('ok');
- expect(graph!.message).toContain('Only 1 eligible entity page (< 5)');
- expect(graph!.message).not.toContain('target 70%');
- });
});
diff --git a/test/doctor-graph-coverage-soft-deleted.test.ts b/test/doctor-graph-coverage-soft-deleted.test.ts
index e079684baf..38bc69c20e 100644
--- a/test/doctor-graph-coverage-soft-deleted.test.ts
+++ b/test/doctor-graph-coverage-soft-deleted.test.ts
@@ -20,6 +20,7 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { sqlQueryForEngine } from '../src/core/sql-query.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
import { buildChecks } from '../src/commands/doctor.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../src/core/types.ts';
let engine: PGLiteEngine;
@@ -37,37 +38,29 @@ beforeEach(async () => {
await resetPgliteState(engine);
});
-/** Five eligible entity pages plus a plain note; the entities are then soft-deleted. */
-async function seedSoftDeletedEntities(eng: PGLiteEngine): Promise<void> {
+/**
+ * A plain note plus enough live entity pages to clear the small-N coverage
+ * floor, so the control cases reach the real coverage report.
+ */
+async function seedLiveEntities(eng: PGLiteEngine): Promise<void> {
const sql = sqlQueryForEngine(eng);
await sql`
INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
- VALUES
- ('acme-example', 'default', 'company', 'Acme', '', '{}', 'sd1', now(), now()),
- ('alice-example', 'default', 'person', 'Alice', '', '{}', 'sd2', now(), now()),
- ('people/filler-example-1', 'default', 'person', 'Filler 1', '', '{}', 'sd4', now(), now()),
- ('people/filler-example-2', 'default', 'person', 'Filler 2', '', '{}', 'sd5', now(), now()),
- ('people/filler-example-3', 'default', 'person', 'Filler 3', '', '{}', 'sd6', now(), now()),
- ('technical-a', 'default', 'note', 'Tech A', '', '{}', 'sd3', now(), now())
+ SELECT 'people/live-example-' || g, 'default', 'person', 'Live ' || g, '', '{}', 'lv' || g, now(), now()
+ FROM generate_series(1, ${MIN_ENTITY_PAGES_FOR_COVERAGE}::int) AS g
`;
- await sql`UPDATE pages SET deleted_at = now() WHERE slug IN ('acme-example', 'alice-example', 'people/filler-example-1', 'people/filler-example-2', 'people/filler-example-3')`;
-}
-
-/** Same shape, but the entity pages stay live — the control. */
-async function seedLiveEntities(eng: PGLiteEngine): Promise<void> {
- const sql = sqlQueryForEngine(eng);
await sql`
INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
- VALUES
- ('acme-example', 'default', 'company', 'Acme', '', '{}', 'lv1', now(), now()),
- ('alice-example', 'default', 'person', 'Alice', '', '{}', 'lv2', now(), now()),
- ('people/filler-example-1', 'default', 'person', 'Filler 1', '', '{}', 'lv4', now(), now()),
- ('people/filler-example-2', 'default', 'person', 'Filler 2', '', '{}', 'lv5', now(), now()),
- ('people/filler-example-3', 'default', 'person', 'Filler 3', '', '{}', 'lv6', now(), now()),
- ('technical-a', 'default', 'note', 'Tech A', '', '{}', 'lv3', now(), now())
+ VALUES ('technical-a', 'default', 'note', 'Tech A', '', '{}', 'lv-note', now(), now())
`;
}
+/** Same shape, then every entity page is soft-deleted. */
+async function seedSoftDeletedEntities(eng: PGLiteEngine): Promise<void> {
+ await seedLiveEntities(eng);
+ await sqlQueryForEngine(eng)`UPDATE pages SET deleted_at = now() WHERE type = 'person'`;
+}
+
describe('graph_coverage counts live entity pages only (#3754, doctor surface)', () => {
test('all entity pages soft-deleted -> takes the not-applicable short-circuit', async () => {
await seedSoftDeletedEntities(engine);
@@ -100,8 +93,9 @@ describe('graph_coverage counts live entity pages only (#3754, doctor surface)',
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
expect(graph, 'graph_coverage check must be present').toBeDefined();
- // 5 live entity pages + 1 soft-deleted. The reported denominator excludes it.
- expect(graph!.message).toContain('(5 entity pages)');
- expect(graph!.message).not.toContain('(6 entity pages)');
+ // The live floor-sized set + 1 soft-deleted. The count doctor reports —
+ // and divides its percentages by — must be the live count only.
+ expect(graph!.message).toContain(`(${MIN_ENTITY_PAGES_FOR_COVERAGE} entity pages)`);
+ expect(graph!.message).not.toContain(`(${MIN_ENTITY_PAGES_FOR_COVERAGE + 1} entity pages)`);
});
});
diff --git a/test/entity-coverage-small-n-floor.test.ts b/test/entity-coverage-small-n-floor.test.ts
new file mode 100644
index 0000000000..e00126ef6c
--- /dev/null
+++ b/test/entity-coverage-small-n-floor.test.ts
@@ -0,0 +1,145 @@
+/**
+ * Entity coverage checks below the small-N floor (#5379).
+ *
+ * BrainHealth grades link/timeline coverage only once a brain has
+ * MIN_ENTITY_PAGES_FOR_COVERAGE entity pages; below that it reports null.
+ * doctor's graph_coverage and onboard's entity_link_coverage /
+ * timeline_coverage must agree: a brain with 1-4 entity pages gets an `ok`
+ * "not applicable" result with no remediation, never a 0% WARN that
+ * `gbrain extract all` cannot clear.
+ *
+ * Protects: the status, message and remediation list each check returns at
+ * the floor boundary. Fails if any of the three checks grades a ratio below
+ * the floor, or counts pages its own population excludes (test fixtures for
+ * doctor, quarantined pages for onboard) toward the floor. The at-floor and
+ * zero-page cases are controls that pass with or without the fix.
+ */
+
+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { sqlQueryForEngine } from '../src/core/sql-query.ts';
+import { buildChecks } from '../src/commands/doctor.ts';
+import { checkEntityLinkCoverage, checkTimelineCoverage } from '../src/core/onboard/checks.ts';
+import { buildQuarantineMarker } from '../src/core/quarantine.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../src/core/types.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+import { emptyHome, withEnv } from './helpers/with-env.ts';
+
+let engine: PGLiteEngine;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+});
+
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+beforeEach(async () => {
+ await resetPgliteState(engine);
+});
+
+const BELOW_FLOOR = [1, MIN_ENTITY_PAGES_FOR_COVERAGE - 1];
+
+async function insertPeople(slugPrefix: string, count: number): Promise<void> {
+ await sqlQueryForEngine(engine)`
+ INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
+ SELECT ${slugPrefix}::text || g, 'default', 'person', 'Person ' || g, '', '{}', ${slugPrefix}::text || 'h' || g, now(), now()
+ FROM generate_series(1, ${count}::int) AS g
+ `;
+}
+
+async function graphCoverage() {
+ const checks = await buildChecks(engine, [], null);
+ const graph = checks.find((c) => c.name === 'graph_coverage');
+ expect(graph, 'graph_coverage check must be present').toBeDefined();
+ return graph!;
+}
+
+describe('doctor graph_coverage below the entity floor', () => {
+ for (const n of BELOW_FLOOR) {
+ test(`${n} unlinked entity page(s) → ok, not applicable`, async () => {
+ await insertPeople('people/floor-example-', n);
+ const graph = await graphCoverage();
+ expect(graph.status).toBe('ok');
+ expect(graph.message).toContain(`Only ${n} eligible entity ${n === 1 ? 'page' : 'pages'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE})`);
+ expect(graph.message).not.toMatch(/\d+%/);
+ });
+ }
+
+ test('test-fixture entity pages do not lift a brain over the floor', async () => {
+ await insertPeople('people/floor-example-', MIN_ENTITY_PAGES_FOR_COVERAGE - 1);
+ await insertPeople('tools/gbrain/test/fixture-', 3);
+ const graph = await graphCoverage();
+ expect(graph.status).toBe('ok');
+ expect(graph.message).toContain(`Only ${MIN_ENTITY_PAGES_FOR_COVERAGE - 1} eligible entity pages`);
+ });
+
+ test('control: at the floor, unlinked entities warn with the target', async () => {
+ await insertPeople('people/floor-example-', MIN_ENTITY_PAGES_FOR_COVERAGE);
+ const graph = await graphCoverage();
+ expect(graph.status).toBe('warn');
+ expect(graph.message).toContain('connected coverage (in/out) 0% (target 70%)');
+ expect(graph.message).toContain(`(${MIN_ENTITY_PAGES_FOR_COVERAGE} entity pages)`);
+ });
+});
+
+const ONBOARD_CHECKS = [
+ ['entity_link_coverage', checkEntityLinkCoverage],
+ ['timeline_coverage', checkTimelineCoverage],
+] as const;
+
+async function putPeople(count: number, frontmatter: Record<string, unknown> = {}, tag = 'visible'): Promise<void> {
+ for (let i = 1; i <= count; i++) {
+ await engine.putPage(`people/${tag}-example-${i}`, {
+ type: 'person',
+ title: `${tag} ${i}`,
+ compiled_truth: 'A synthetic entity.',
+ timeline: '',
+ frontmatter,
+ });
+ }
+}
+
+describe('onboard coverage checks below the entity floor', () => {
+ for (const [name, check] of ONBOARD_CHECKS) {
+ // Pin an empty home so the warn path's pack lookup never reads the operator's config.
+ const run = () => withEnv({ GBRAIN_HOME: emptyHome() }, () => check(engine));
+
+ for (const n of BELOW_FLOOR) {
+ test(`${name}: ${n} entity page(s) → ok, not applicable, no remediation`, async () => {
+ await putPeople(n);
+ const result = await run();
+ expect(result.check).toEqual({
+ name,
+ status: 'ok',
+ message: `Only ${n} entity ${n === 1 ? 'page' : 'pages'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
+ });
+ expect(result.remediations).toEqual([]);
+ });
+ }
+
+ test(`${name}: quarantined pages do not count toward the floor`, async () => {
+ await putPeople(MIN_ENTITY_PAGES_FOR_COVERAGE - 1);
+ await putPeople(2, { quarantine: buildQuarantineMarker('junk_pattern', 'synthetic fixture') }, 'quarantined');
+ const result = await run();
+ expect(result.check.status).toBe('ok');
+ expect(result.check.message).toStartWith(`Only ${MIN_ENTITY_PAGES_FOR_COVERAGE - 1} entity pages`);
+ });
+
+ test(`${name}: control — at the floor, zero coverage warns`, async () => {
+ await putPeople(MIN_ENTITY_PAGES_FOR_COVERAGE);
+ const result = await run();
+ expect(result.check.status).toBe('warn');
+ expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0% \(target \d+%\)/);
+ });
+
+ test(`${name}: control — no entity pages keeps the vacuous message`, async () => {
+ const result = await run();
+ expect(result.check).toEqual({ name, status: 'ok', message: 'No entity pages — coverage check vacuous' });
+ expect(result.remediations).toEqual([]);
+ });
+ }
+});
diff --git a/test/onboard-coverage-invariants.test.ts b/test/onboard-coverage-invariants.test.ts
index f7754fbde8..6bb4628b62 100644
--- a/test/onboard-coverage-invariants.test.ts
+++ b/test/onboard-coverage-invariants.test.ts
@@ -14,6 +14,7 @@ import {
checkTimelineCoverage,
} from '../src/core/onboard/checks.ts';
import { buildQuarantineMarker } from '../src/core/quarantine.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../src/core/types.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
let engine: PGLiteEngine;
@@ -32,10 +33,16 @@ beforeEach(async () => {
await resetPgliteState(engine);
});
+// Enough visible entities to clear the small-N floor, so the checks compute a
+// ratio instead of reporting "not applicable". Counting the quarantined page
+// as well would make it 1 of 6, i.e. 17%.
async function seedVisibleAndQuarantinedEntities(): Promise<void> {
- for (let i = 0; i < 5; i++) {
- await engine.putPage(`people/visible-example-${i}`, {
- type: 'person', title: `Visible Example ${i}`, compiled_truth: 'A visible synthetic entity.', timeline: '',
+ for (let n = 1; n <= MIN_ENTITY_PAGES_FOR_COVERAGE; n++) {
+ await engine.putPage(`people/visible-example-${n}`, {
+ type: 'person',
+ title: `Visible Example ${n}`,
+ compiled_truth: 'A visible synthetic entity.',
+ timeline: '',
});
}
await engine.putPage('people/quarantined-example', {
@@ -110,29 +117,7 @@ describe('onboard entity coverage invariants', () => {
const result = await checkEntityLinkCoverage(engine);
expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
- expect(result.check.message).not.toContain('50%');
- });
-
- test('one entity page is not applicable for link coverage', async () => {
- await engine.putPage('people/one-example', {
- type: 'person', title: 'One Example', compiled_truth: 'A synthetic entity.', timeline: '',
- });
- const result = await checkEntityLinkCoverage(engine);
- expect(result.check.status).toBe('ok');
- expect(result.check.message).toContain('Only 1 entity page (< 5)');
- expect(result.check.message).not.toContain('Coverage 0%');
- expect(result.remediations).toHaveLength(0);
- });
-
- test('five entities with zero inbound links still warn', async () => {
- for (let i = 0; i < 5; i++) {
- await engine.putPage(`people/unlinked-${i}`, {
- type: 'person', title: `Unlinked ${i}`, compiled_truth: 'A synthetic entity.', timeline: '',
- });
- }
- const result = await checkEntityLinkCoverage(engine);
- expect(result.check.status).toBe('warn');
- expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
+ expect(result.check.message).not.toContain('17%');
});
test('timeline coverage applies the same visible-sample invariant', async () => {
@@ -146,28 +131,6 @@ describe('onboard entity coverage invariants', () => {
const result = await checkTimelineCoverage(engine);
expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
- expect(result.check.message).not.toContain('50%');
- });
-
- test('one entity page is not applicable for timeline coverage', async () => {
- await engine.putPage('people/one-example', {
- type: 'person', title: 'One Example', compiled_truth: 'A synthetic entity.', timeline: '',
- });
- const result = await checkTimelineCoverage(engine);
- expect(result.check.status).toBe('ok');
- expect(result.check.message).toContain('Only 1 entity page (< 5)');
- expect(result.check.message).not.toContain('Coverage 0%');
- expect(result.remediations).toHaveLength(0);
- });
-
- test('five entities with zero timeline entries still warn', async () => {
- for (let i = 0; i < 5; i++) {
- await engine.putPage(`people/no-timeline-${i}`, {
- type: 'person', title: `No Timeline ${i}`, compiled_truth: 'A synthetic entity.', timeline: '',
- });
- }
- const result = await checkTimelineCoverage(engine);
- expect(result.check.status).toBe('warn');
- expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
+ expect(result.check.message).not.toContain('17%');
});
});
diff --git a/test/onboard-phantom-rec-gates.test.ts b/test/onboard-phantom-rec-gates.test.ts
index 52e3e633ac..e78eacd643 100644
--- a/test/onboard-phantom-rec-gates.test.ts
+++ b/test/onboard-phantom-rec-gates.test.ts
@@ -44,6 +44,7 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
import { emptyHome, withEnv } from './helpers/with-env.ts';
import { checkEntityLinkCoverage, checkTimelineCoverage } from '../src/core/onboard/checks.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../src/core/types.ts';
import { packSupportsNerInference } from '../src/core/schema-pack/best-effort.ts';
import type { ResolvedPack } from '../src/core/schema-pack/registry.ts';
import { _resetPackCacheForTests } from '../src/core/schema-pack/registry.ts';
@@ -186,7 +187,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
});
it('low coverage + pack WITHOUT NER rules → WARN but NO extract-ner rec, with a reason', async () => {
- await seedEntities(5); // eligible entity pages, zero inbound links → coverage 0%
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE); // entity pages, zero inbound links → coverage 0%
await withPack(REGEXLESS_PACK, async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -199,7 +200,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
it('low coverage + pack WITH NER rules → recommends extract-ner', async () => {
// The positive direction. Without this case, "no rec emitted" passes for
// any reason at all — including a pack that never resolved.
- await seedEntities(5);
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE);
await withPack('gbrain-base', async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -212,7 +213,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
it('unresolvable pack → rec withheld, but the message says so distinctly', async () => {
// Fail-closed must stay VISIBLE. A pack that cannot be resolved is an
// operator problem, and must not read as "your pack declares no NER rules".
- await seedEntities(5);
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE);
await withPack('no-such-pack-e2e-fixture', async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -233,7 +234,7 @@ describe('recommender / handler parity (the anti-drift invariant)', () => {
// either side that breaks the pairing fails here.
for (const [pack, expectRec] of [['gbrain-base', true], [REGEXLESS_PACK, false]] as const) {
it(`agree on ${pack}: rec emitted=${expectRec} ⇔ handler can run`, async () => {
- await seedEntities(5);
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE);
await withPack(pack, async () => {
const { extractNerLinks } = await import('../src/core/extract-ner.ts');
const { remediations } = await checkEntityLinkCoverage(engine);
@@ -257,7 +258,7 @@ describe('recommender / handler parity (the anti-drift invariant)', () => {
// handler resolves the tier-7 default gbrain-base and would happily run —
// a MISSED recommendation, the phantom bug's mirror image. (The home must
// be regexlessHome so the DB-named pack resolves from disk at all.)
- await seedEntities(5);
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE);
await engine.setConfig('schema_pack', REGEXLESS_PACK);
await withEnv({ GBRAIN_HOME: regexlessHome, GBRAIN_SCHEMA_PACK: undefined }, async () => {
const { extractNerLinks } = await import('../src/core/extract-ner.ts');
@@ -274,7 +275,7 @@ describe('checkTimelineCoverage — datable-meetings gate', () => {
// Pack-independent: this gate counts dated meeting pages, it never loads a
// pack. Pinned anyway so the whole file is hermetic by construction.
it('low coverage + zero dated meetings → WARN but NO rec, with a reason', async () => {
- await seedEntities(5); // eligible entity pages with no timeline entries → coverage 0%
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE); // entity pages with no timeline entries → coverage 0%
await withPack('gbrain-base-v2', async () => {
const { check, remediations } = await checkTimelineCoverage(engine);
expect(check.status).toBe('warn');
@@ -285,7 +286,7 @@ describe('checkTimelineCoverage — datable-meetings gate', () => {
});
it('low coverage + a dated meeting present → recommends extract-timeline-from-meetings', async () => {
- await seedEntities(5);
+ await seedEntities(MIN_ENTITY_PAGES_FOR_COVERAGE);
await engine.putPage('m0', {
title: 'Standup', type: 'meeting' as never,
compiled_truth: 'body that is long enough to pass any minimum-length guards in the codebase',