mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-30 19:49:14 +00:00
Static documentation of each cycle phase's scope: 'source' (safe to parallelize per source), 'global' (must serialize brain-wide), or 'mixed' (per-phase decomposition needed before parallelizing). The PHASE_SCOPE record is the load-bearing input for any future autopilot fan-out wave. It surfaces what codex round-1 P0-1 was warning about: not all 14 cycle phases are source-scoped today. embed/orphans/purge/resolve_symbol_edges/grade_takes/calibration_profile walk brain-wide regardless of sourceId. Per-source cycle LOCKS (this PR) let two cycles RUN concurrently, but global-scoped phases inside each will still touch the same rows. The taxonomy is documentation, not runtime enforcement (runtime enforcement deferred per plan; filed as TODO). New doctor check cycle_phase_scope renders the taxonomy as an operator-facing message AND surfaces phase_scope_map under Check.details for JSON consumers. Added optional Check.details field to the doctor types — mirrors PhaseResult.details. Additive; no schema_version bump. 11 unit tests across phase-scope-coverage + doctor-cycle-phase-scope. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
/**
|
|
* v0.38 PHASE_SCOPE coverage regression.
|
|
*
|
|
* The phase-scope taxonomy in `src/core/cycle.ts` is documentation, not
|
|
* runtime enforcement (deferred TODO per plan). This test guards the
|
|
* static contract:
|
|
*
|
|
* 1. Every `ALL_PHASES` entry has a `PHASE_SCOPE` entry. New phases
|
|
* added without taxonomy declaration fail this test.
|
|
* 2. No extra `PHASE_SCOPE` entries beyond `ALL_PHASES`. Stale entries
|
|
* from removed phases fail this test.
|
|
* 3. Every value is one of 'source' | 'global' | 'mixed' (type check).
|
|
*
|
|
* Future fan-out wave consumes PHASE_SCOPE directly; this test makes
|
|
* the contract enforceable at the unit-test layer.
|
|
*/
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { ALL_PHASES, PHASE_SCOPE, type PhaseScope } from '../src/core/cycle.ts';
|
|
|
|
const VALID_SCOPES: ReadonlyArray<PhaseScope> = ['source', 'global', 'mixed'];
|
|
|
|
describe('PHASE_SCOPE coverage', () => {
|
|
test('every ALL_PHASES entry has a PHASE_SCOPE entry', () => {
|
|
const missing = ALL_PHASES.filter(p => !(p in PHASE_SCOPE));
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
test('no extra PHASE_SCOPE entries beyond ALL_PHASES', () => {
|
|
const all = new Set<string>(ALL_PHASES);
|
|
const extra = Object.keys(PHASE_SCOPE).filter(p => !all.has(p));
|
|
expect(extra).toEqual([]);
|
|
});
|
|
|
|
test('every PHASE_SCOPE value is source | global | mixed', () => {
|
|
const invalid: string[] = [];
|
|
for (const [phase, scope] of Object.entries(PHASE_SCOPE)) {
|
|
if (!VALID_SCOPES.includes(scope)) {
|
|
invalid.push(`${phase}: ${scope}`);
|
|
}
|
|
}
|
|
expect(invalid).toEqual([]);
|
|
});
|
|
|
|
test('all 16 phases covered (regression on accidental omission)', () => {
|
|
// Pin the count so a future PR that adds a phase to ALL_PHASES
|
|
// without updating PHASE_SCOPE notices here too.
|
|
expect(ALL_PHASES.length).toBe(16);
|
|
expect(Object.keys(PHASE_SCOPE).length).toBe(16);
|
|
});
|
|
|
|
test('embed remains global (the headline brain-wide phase)', () => {
|
|
// Pin embed specifically — codex r1 P0-1 called this out as the
|
|
// canonical reason per-source locks aren't sufficient for true
|
|
// fan-out. If future code makes embed source-scopable, this fails
|
|
// and forces a corresponding lift in the fan-out wave.
|
|
expect(PHASE_SCOPE.embed).toBe('global');
|
|
});
|
|
|
|
test('sync remains source-scoped (the headline per-source phase)', () => {
|
|
expect(PHASE_SCOPE.sync).toBe('source');
|
|
});
|
|
});
|