flow-run-store-performance.test.mjs
90 lines 2.9 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 6 — PERFORMANCE: list/get p95 budget on large run fixture (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 MAX_FLOW_RUNS_LIST,
16 } from '../lib/flow/flow-store.mjs';
17
18 const __dirname = path.dirname(fileURLToPath(import.meta.url));
19 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-run-store-perf');
20
21 const P95_BUDGET_MS = 250;
22
23 describe('Flow run store — performance', () => {
24 beforeEach(() => {
25 fs.rmSync(tmpRoot, { recursive: true, force: true });
26 fs.mkdirSync(tmpRoot, { recursive: true });
27 });
28
29 afterEach(() => {
30 fs.rmSync(tmpRoot, { recursive: true, force: true });
31 });
32
33 it('listFlowRuns and getFlowRun complete within p95 budget', () => {
34 const dataDir = path.join(tmpRoot, 'perf');
35 fs.mkdirSync(dataDir);
36 const vaultId = 'default';
37 const store = loadFlowStore(dataDir);
38 store.vaults[vaultId] = {
39 flows: [],
40 steps: [],
41 runs: [],
42 candidates: [],
43 projections: [],
44 tasks: [],
45 task_loops: [],
46 orchestrator_graphs: [],
47 };
48 for (let i = 0; i < MAX_FLOW_RUNS_LIST; i += 1) {
49 store.vaults[vaultId].runs.push({
50 schema: 'knowtation.flow_run/v0',
51 run_id: `run_perf_${i}`,
52 run_ref: `flow_run:run_perf_${i}`,
53 flow_id: 'flow_overseer_handover',
54 flow_version: '0.1.0',
55 scope: 'project',
56 status: 'in_progress',
57 step_states: [{ step_id: 'flow_overseer_handover#1', status: 'pending', verified: false }],
58 started: new Date(Date.UTC(2026, 0, 1, 0, 0, i)).toISOString(),
59 provenance: { actor: 'd'.repeat(64), harness: 'perf' },
60 });
61 }
62 saveFlowStore(dataDir, store);
63
64 const scopes = new Set(['project', 'org']);
65 const listSamples = [];
66 for (let i = 0; i < 20; i += 1) {
67 const t0 = performance.now();
68 listFlowRuns(dataDir, vaultId, {
69 visibleScopes: scopes,
70 filterScopes: scopes,
71 effectiveScope: 'project',
72 flowId: 'flow_overseer_handover',
73 });
74 listSamples.push(performance.now() - t0);
75 }
76 listSamples.sort((a, b) => a - b);
77 const listP95 = listSamples[Math.floor(listSamples.length * 0.95)] ?? listSamples.at(-1);
78 assert.ok(listP95 < P95_BUDGET_MS, `list p95 ${listP95}ms exceeds ${P95_BUDGET_MS}ms`);
79
80 const getSamples = [];
81 for (let i = 0; i < 20; i += 1) {
82 const t0 = performance.now();
83 getFlowRun(dataDir, vaultId, 'flow_run:run_perf_42', { visibleScopes: scopes });
84 getSamples.push(performance.now() - t0);
85 }
86 getSamples.sort((a, b) => a - b);
87 const getP95 = getSamples[Math.floor(getSamples.length * 0.95)] ?? getSamples.at(-1);
88 assert.ok(getP95 < P95_BUDGET_MS, `get p95 ${getP95}ms exceeds ${P95_BUDGET_MS}ms`);
89 });
90 });
File History 1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago