flow-execution-stress.test.mjs
85 lines 2.9 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 13 hours ago
1 /**
2 * Tier 4 — STRESS: concurrent starts and idempotent execute.
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 handleFlowRunStartRequest,
12 handleFlowExecutionConsentMintRequest,
13 handleFlowRunExecuteAutomatableRequest,
14 } from '../lib/flow/flow-execution.mjs';
15 import { writeExecutionPolicy, seedAutomatableFlow } from './fixtures/flow/execution-helpers.mjs';
16
17 const __dirname = path.dirname(fileURLToPath(import.meta.url));
18 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-execution-stress');
19
20 describe('Flow execution — stress', () => {
21 beforeEach(() => {
22 fs.rmSync(tmpRoot, { recursive: true, force: true });
23 fs.mkdirSync(tmpRoot, { recursive: true });
24 process.env.FLOW_RUN_WRITES_ENABLED = '1';
25 process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED = '1';
26 });
27
28 afterEach(() => {
29 fs.rmSync(tmpRoot, { recursive: true, force: true });
30 delete process.env.FLOW_RUN_WRITES_ENABLED;
31 delete process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED;
32 });
33
34 it('many concurrent run starts remain bounded', () => {
35 const dataDir = path.join(tmpRoot, 'starts');
36 fs.mkdirSync(dataDir);
37 writeExecutionPolicy(dataDir);
38 seedAutomatableFlow(dataDir, 'default');
39 for (let i = 0; i < 50; i += 1) {
40 const r = handleFlowRunStartRequest({
41 dataDir,
42 vaultId: 'default',
43 cliScopes: ['personal', 'project', 'org'],
44 flowId: 'flow_automatable_test',
45 flowVersion: '1.0.0',
46 });
47 assert.equal(r.ok, true);
48 }
49 });
50
51 it('duplicate execute posts return same execution_id', () => {
52 const dataDir = path.join(tmpRoot, 'idem');
53 fs.mkdirSync(dataDir);
54 writeExecutionPolicy(dataDir);
55 seedAutomatableFlow(dataDir, 'default');
56 const start = handleFlowRunStartRequest({
57 dataDir,
58 vaultId: 'default',
59 cliScopes: ['personal', 'project', 'org'],
60 flowId: 'flow_automatable_test',
61 flowVersion: '1.0.0',
62 });
63 const consent = handleFlowExecutionConsentMintRequest({
64 dataDir,
65 vaultId: 'default',
66 cliScopes: ['personal', 'project', 'org'],
67 runId: start.payload.run.run_id,
68 allowedLanes: ['local_default'],
69 costCapUnits: 5,
70 });
71 const input = {
72 dataDir,
73 vaultId: 'default',
74 cliScopes: ['personal', 'project', 'org'],
75 runId: start.payload.run.run_id,
76 stepId: 'flow_automatable_test#1',
77 consentId: consent.payload.consent.consent_id,
78 };
79 const first = handleFlowRunExecuteAutomatableRequest(input);
80 const second = handleFlowRunExecuteAutomatableRequest(input);
81 assert.equal(first.ok, true);
82 assert.equal(second.ok, true);
83 assert.equal(first.payload.execution.execution_id, second.payload.execution.execution_id);
84 });
85 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 13 hours ago