flow-run-store-unit.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 1 — UNIT: flow_run store helpers (P-FLOW / 7A-10). |
| 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 | FLOW_RUN_ID_RE, |
| 12 | FLOW_RUN_REF_RE, |
| 13 | OVERSEER_FIXTURE_RUN_REF, |
| 14 | buildDefaultRunRef, |
| 15 | isValidRunLookupKey, |
| 16 | findRunInVault, |
| 17 | runForClient, |
| 18 | seedOverseerAnchorRun, |
| 19 | getFlowRun, |
| 20 | listFlowRuns, |
| 21 | } from '../lib/flow/flow-store.mjs'; |
| 22 | |
| 23 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 24 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-run-store-unit'); |
| 25 | |
| 26 | describe('Flow run store — unit', () => { |
| 27 | beforeEach(() => { |
| 28 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 29 | fs.mkdirSync(tmpRoot, { recursive: true }); |
| 30 | }); |
| 31 | |
| 32 | afterEach(() => { |
| 33 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 34 | }); |
| 35 | |
| 36 | it('regexes accept canonical ids and portable run_ref pointers', () => { |
| 37 | assert.match('run_overseer_in_progress', FLOW_RUN_ID_RE); |
| 38 | assert.match(OVERSEER_FIXTURE_RUN_REF, FLOW_RUN_REF_RE); |
| 39 | assert.doesNotMatch('flow_run:', FLOW_RUN_REF_RE); |
| 40 | assert.doesNotMatch('not_a_run', FLOW_RUN_ID_RE); |
| 41 | }); |
| 42 | |
| 43 | it('buildDefaultRunRef prefixes flow_run:', () => { |
| 44 | assert.equal(buildDefaultRunRef('run_abc123'), 'flow_run:run_abc123'); |
| 45 | }); |
| 46 | |
| 47 | it('isValidRunLookupKey accepts run_id or run_ref', () => { |
| 48 | assert.equal(isValidRunLookupKey('run_test'), true); |
| 49 | assert.equal(isValidRunLookupKey(OVERSEER_FIXTURE_RUN_REF), true); |
| 50 | assert.equal(isValidRunLookupKey(''), false); |
| 51 | assert.equal(isValidRunLookupKey('bad'), false); |
| 52 | }); |
| 53 | |
| 54 | it('findRunInVault resolves by run_id or run_ref', () => { |
| 55 | const vault = { |
| 56 | runs: [ |
| 57 | { run_id: 'run_a', run_ref: 'flow_run:ptr-a', scope: 'project' }, |
| 58 | { run_id: 'run_b', run_ref: OVERSEER_FIXTURE_RUN_REF, scope: 'project' }, |
| 59 | ], |
| 60 | }; |
| 61 | assert.equal(findRunInVault(vault, 'run_a')?.run_ref, 'flow_run:ptr-a'); |
| 62 | assert.equal(findRunInVault(vault, OVERSEER_FIXTURE_RUN_REF)?.run_id, 'run_b'); |
| 63 | assert.equal(findRunInVault(vault, 'missing'), null); |
| 64 | }); |
| 65 | |
| 66 | it('runForClient emits run_ref and pointer-only fields', () => { |
| 67 | const client = runForClient({ |
| 68 | run_id: 'run_x', |
| 69 | flow_id: 'flow_overseer_handover', |
| 70 | flow_version: '0.1.0', |
| 71 | scope: 'project', |
| 72 | status: 'in_progress', |
| 73 | step_states: [], |
| 74 | started: '2026-06-19T10:00:00Z', |
| 75 | provenance: { actor: 'a'.repeat(64), harness: 'seed' }, |
| 76 | task_ref: 'task_2g_handover_001', |
| 77 | external_ref: 'musehub:commit:abc', |
| 78 | }); |
| 79 | assert.equal(client.schema, 'knowtation.flow_run/v0'); |
| 80 | assert.equal(client.run_ref, 'flow_run:run_x'); |
| 81 | assert.equal(client.task_ref, 'task_2g_handover_001'); |
| 82 | assert.equal(client.external_ref, 'musehub:commit:abc'); |
| 83 | }); |
| 84 | |
| 85 | it('seedOverseerAnchorRun is idempotent', () => { |
| 86 | const dataDir = path.join(tmpRoot, 'seed'); |
| 87 | fs.mkdirSync(dataDir); |
| 88 | const first = seedOverseerAnchorRun(dataDir, 'default'); |
| 89 | const second = seedOverseerAnchorRun(dataDir, 'default'); |
| 90 | assert.equal(first.seeded, true); |
| 91 | assert.equal(second.seeded, false); |
| 92 | }); |
| 93 | |
| 94 | it('getFlowRun resolves overseer fixture by portable run_ref', () => { |
| 95 | const dataDir = path.join(tmpRoot, 'get-ref'); |
| 96 | fs.mkdirSync(dataDir); |
| 97 | const visible = new Set(['personal', 'project', 'org']); |
| 98 | const byRef = getFlowRun(dataDir, 'default', OVERSEER_FIXTURE_RUN_REF, { |
| 99 | visibleScopes: visible, |
| 100 | }); |
| 101 | assert.ok(byRef); |
| 102 | assert.equal(byRef.schema, 'knowtation.flow_run_get/v0'); |
| 103 | assert.equal(byRef.run.run_id, 'run_overseer_in_progress'); |
| 104 | assert.equal(byRef.run.run_ref, OVERSEER_FIXTURE_RUN_REF); |
| 105 | }); |
| 106 | |
| 107 | it('listFlowRuns stamps flow_run_list schema discriminator', () => { |
| 108 | const dataDir = path.join(tmpRoot, 'list'); |
| 109 | fs.mkdirSync(dataDir); |
| 110 | const result = listFlowRuns(dataDir, 'default', { |
| 111 | visibleScopes: new Set(['project', 'org']), |
| 112 | filterScopes: new Set(['project', 'org']), |
| 113 | effectiveScope: 'project', |
| 114 | }); |
| 115 | assert.equal(result.schema, 'knowtation.flow_run_list/v0'); |
| 116 | assert.ok(result.runs.length >= 1); |
| 117 | }); |
| 118 | }); |
File History
1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago