flow-run-store-stress.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 4 — STRESS: many runs list/get stays bounded (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 | loadFlowStore, |
| 12 | saveFlowStore, |
| 13 | listFlowRuns, |
| 14 | getFlowRun, |
| 15 | runForClient, |
| 16 | MAX_FLOW_RUNS_LIST, |
| 17 | } from '../lib/flow/flow-store.mjs'; |
| 18 | |
| 19 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 20 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-run-store-stress'); |
| 21 | |
| 22 | describe('Flow run store — stress', () => { |
| 23 | beforeEach(() => { |
| 24 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 25 | fs.mkdirSync(tmpRoot, { recursive: true }); |
| 26 | }); |
| 27 | |
| 28 | afterEach(() => { |
| 29 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 30 | }); |
| 31 | |
| 32 | it('list caps at MAX_FLOW_RUNS_LIST with truncated flag', () => { |
| 33 | const dataDir = path.join(tmpRoot, 'many'); |
| 34 | fs.mkdirSync(dataDir); |
| 35 | const vaultId = 'default'; |
| 36 | const store = loadFlowStore(dataDir); |
| 37 | store.vaults[vaultId] = { |
| 38 | flows: [], |
| 39 | steps: [], |
| 40 | runs: [], |
| 41 | candidates: [], |
| 42 | projections: [], |
| 43 | tasks: [], |
| 44 | task_loops: [], |
| 45 | orchestrator_graphs: [], |
| 46 | }; |
| 47 | for (let i = 0; i < MAX_FLOW_RUNS_LIST + 25; i += 1) { |
| 48 | store.vaults[vaultId].runs.push({ |
| 49 | schema: 'knowtation.flow_run/v0', |
| 50 | run_id: `run_stress_${i}`, |
| 51 | run_ref: `flow_run:run_stress_${i}`, |
| 52 | flow_id: 'flow_overseer_handover', |
| 53 | flow_version: '0.1.0', |
| 54 | scope: 'project', |
| 55 | status: 'in_progress', |
| 56 | step_states: [], |
| 57 | started: new Date(Date.UTC(2026, 0, 1, 0, 0, i)).toISOString(), |
| 58 | provenance: { actor: 'b'.repeat(64), harness: 'stress' }, |
| 59 | }); |
| 60 | } |
| 61 | saveFlowStore(dataDir, store); |
| 62 | |
| 63 | const scopes = new Set(['project', 'org']); |
| 64 | const list = listFlowRuns(dataDir, vaultId, { |
| 65 | visibleScopes: scopes, |
| 66 | filterScopes: scopes, |
| 67 | effectiveScope: 'project', |
| 68 | }); |
| 69 | assert.equal(list.runs.length, MAX_FLOW_RUNS_LIST); |
| 70 | assert.equal(list.truncated, true); |
| 71 | |
| 72 | const deepStates = Array.from({ length: 50 }, (_, j) => ({ |
| 73 | step_id: `flow_overseer_handover#${j + 1}`, |
| 74 | status: 'pending', |
| 75 | evidence_ref: null, |
| 76 | verified: false, |
| 77 | })); |
| 78 | const deepRun = store.vaults[vaultId].runs[0]; |
| 79 | deepRun.step_states = deepStates; |
| 80 | saveFlowStore(dataDir, store); |
| 81 | const got = getFlowRun(dataDir, vaultId, deepRun.run_ref, { visibleScopes: scopes }); |
| 82 | assert.ok(got); |
| 83 | assert.equal(got.run.step_states.length, 50); |
| 84 | assert.doesNotThrow(() => JSON.stringify(got.run.step_states.map(runForClient))); |
| 85 | }); |
| 86 | }); |
File History
1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago