feat(repair): repairIndex returns the per-family receipt and narrates its summary
repairIndex() now returns a RepairReport: one row per repair family (orphaned containers, count rollups, VFS containment, metadata corruption, write quarantine, each provider's invariant pass, degraded-read state) with checked / healed counts and an explicit skip reason for anything not run — no silent rows. A summary line narrates families checked and heals applied. This is the receipts half of the graph-trust program's ask: a repair that cannot show its work per store is a repair nobody can audit. Pinned: a healthy store yields a complete zero-heal receipt with every family accounted; a manufactured pre-8.3.1 ghost container appears in the receipt as a counted heal. Additive: void-callers are unaffected.
This commit is contained in:
parent
40e7119b85
commit
8d45f964e9
4 changed files with 168 additions and 7 deletions
71
tests/integration/repair-report.test.ts
Normal file
71
tests/integration/repair-report.test.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* @module tests/integration/repair-report
|
||||
* @description repairIndex() returns the per-family receipt (checked /
|
||||
* healed / skipped-with-reason per family) and narrates a summary — the
|
||||
* "repair that shows its work" half of the graph-trust program's ask. A
|
||||
* repair nobody can audit is a repair nobody can trust.
|
||||
*/
|
||||
import { describe, it, expect, afterEach } from 'vitest'
|
||||
import { mkdtempSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { Brainy } from '../../src/index.js'
|
||||
import { NounType } from '../../src/types/graphTypes.js'
|
||||
|
||||
type RawBox = {
|
||||
storage: { writeNounRaw(id: string, r: { metadata: unknown; vector: unknown }): Promise<void> }
|
||||
}
|
||||
|
||||
const dirs: string[] = []
|
||||
const brains: Brainy[] = []
|
||||
afterEach(async () => {
|
||||
for (const b of brains.splice(0)) await b.close().catch(() => {})
|
||||
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('repairIndex per-family receipt', () => {
|
||||
it('a healthy store gets a complete zero-heal receipt — every family accounted, none silent', async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'brainy-repair-clean-'))
|
||||
dirs.push(dir)
|
||||
const brain = new Brainy({ storage: { type: 'filesystem', path: dir }, requireSubtype: false, silent: true })
|
||||
await brain.init()
|
||||
brains.push(brain)
|
||||
await brain.add({ data: 'healthy row', type: NounType.Document, metadata: { n: 1 } })
|
||||
await brain.flush()
|
||||
|
||||
const report = await brain.repairIndex()
|
||||
expect(report.families.length, 'every family reports a row').toBeGreaterThanOrEqual(5)
|
||||
const names = report.families.map((f) => f.family)
|
||||
for (const expected of ['orphaned-containers', 'count-rollups', 'metadata-corruption']) {
|
||||
expect(names, `family ${expected} accounted`).toContain(expected)
|
||||
}
|
||||
// Every row is either checked or carries its skip reason — no silent rows.
|
||||
for (const f of report.families) {
|
||||
expect(f.checked || !!f.skipped, `${f.family} is checked or explains itself`).toBe(true)
|
||||
}
|
||||
expect(report.healedTotal).toBe(0)
|
||||
expect(report.durationMs).toBeGreaterThanOrEqual(0)
|
||||
}, 120000)
|
||||
|
||||
it('a manufactured ghost container appears in the receipt as a heal', async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'brainy-repair-ghost-'))
|
||||
dirs.push(dir)
|
||||
const brain = new Brainy({ storage: { type: 'filesystem', path: dir }, requireSubtype: false, silent: true })
|
||||
await brain.init()
|
||||
brains.push(brain)
|
||||
await brain.add({ data: 'real row', type: NounType.Document, metadata: { n: 1 } })
|
||||
await brain.flush()
|
||||
// The pre-8.3.1 ghost shape: a vector leg with no content leg.
|
||||
const storage = (brain as unknown as RawBox).storage
|
||||
await storage.writeNounRaw('00000000-0000-7000-8000-00000000dead', {
|
||||
metadata: null,
|
||||
vector: { vector: [0.1, 0.2], noun: 'document' }
|
||||
})
|
||||
|
||||
const report = await brain.repairIndex()
|
||||
const orphans = report.families.find((f) => f.family === 'orphaned-containers')
|
||||
expect(orphans?.checked).toBe(true)
|
||||
expect(orphans!.healed, 'the ghost was pruned and receipted').toBeGreaterThan(0)
|
||||
expect(report.healedTotal).toBeGreaterThan(0)
|
||||
}, 120000)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue