flow-run-store-data-integrity.test.mjs
75 lines 2.4 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 5 — DATA-INTEGRITY: run_ref ↔ run_id linkage, step state invariants (P-FLOW).
3 */
4 import { describe, it, beforeEach, afterEach } from 'node:test';
5 import assert from 'node:assert/strict';
6 import fs from 'node:fs';
7 import path from 'node:path';
8 import { fileURLToPath } from 'node:url';
9
10 import {
11 getFlowRun,
12 seedOverseerAnchorRun,
13 OVERSEER_FIXTURE_RUN_REF,
14 runForClient,
15 } from '../lib/flow/flow-store.mjs';
16
17 const __dirname = path.dirname(fileURLToPath(import.meta.url));
18 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-run-store-integrity');
19
20 describe('Flow run store — data integrity', () => {
21 beforeEach(() => {
22 fs.rmSync(tmpRoot, { recursive: true, force: true });
23 fs.mkdirSync(tmpRoot, { recursive: true });
24 });
25
26 afterEach(() => {
27 fs.rmSync(tmpRoot, { recursive: true, force: true });
28 });
29
30 it('seed → get round-trip preserves SD-2 fields and run_ref linkage', () => {
31 const dataDir = path.join(tmpRoot, 'rt');
32 fs.mkdirSync(dataDir);
33 seedOverseerAnchorRun(dataDir, 'default');
34 const scopes = new Set(['project', 'org']);
35 const got = getFlowRun(dataDir, 'default', OVERSEER_FIXTURE_RUN_REF, {
36 visibleScopes: scopes,
37 });
38 assert.ok(got);
39 assert.equal(got.run.task_ref, 'task_2g_handover_001');
40 assert.equal(got.run.external_ref, 'musehub:commit:abc123def456');
41 assert.equal(got.run.run_ref, OVERSEER_FIXTURE_RUN_REF);
42 assert.equal(got.run.flow_version, '0.1.0');
43 });
44
45 it('done + evidence_required step states never appear with verified:false', () => {
46 const dataDir = path.join(tmpRoot, 'inv');
47 fs.mkdirSync(dataDir);
48 const scopes = new Set(['project', 'org']);
49 const got = getFlowRun(dataDir, 'default', 'run_overseer_in_progress', {
50 visibleScopes: scopes,
51 });
52 assert.ok(got);
53 for (const state of got.run.step_states) {
54 if (state.status === 'done') {
55 assert.equal(state.verified, true);
56 assert.ok(state.evidence_ref);
57 }
58 }
59 });
60
61 it('runForClient is deterministic for the same stored row', () => {
62 const row = {
63 run_id: 'run_det',
64 run_ref: 'flow_run:run_det',
65 flow_id: 'flow_x',
66 flow_version: '1.0.0',
67 scope: 'personal',
68 status: 'pending',
69 step_states: [],
70 started: '2026-01-01T00:00:00Z',
71 provenance: { actor: 'c'.repeat(64), harness: 'test' },
72 };
73 assert.deepEqual(runForClient(row), runForClient(row));
74 });
75 });
File History 1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago