flow-execution-e2e.test.mjs
107 lines 3.4 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 1 day ago
1 /**
2 * Tier 3 — E2E: start → consent → execute → submit review; grant ≠ consent.
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 handleFlowRunSubmitReviewRequest,
15 } from '../lib/flow/flow-execution.mjs';
16 import { createProposal } from '../hub/proposals-store.mjs';
17 import { writeExecutionPolicy, seedAutomatableFlow } from './fixtures/flow/execution-helpers.mjs';
18
19 const __dirname = path.dirname(fileURLToPath(import.meta.url));
20 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-execution-e2e');
21
22 describe('Flow execution — e2e', () => {
23 const dataDir = path.join(tmpRoot, 'data');
24 const vaultId = 'default';
25
26 beforeEach(() => {
27 fs.rmSync(tmpRoot, { recursive: true, force: true });
28 fs.mkdirSync(dataDir, { recursive: true });
29 process.env.FLOW_RUN_WRITES_ENABLED = '1';
30 process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED = '1';
31 writeExecutionPolicy(dataDir);
32 seedAutomatableFlow(dataDir, vaultId);
33 });
34
35 afterEach(() => {
36 fs.rmSync(tmpRoot, { recursive: true, force: true });
37 delete process.env.FLOW_RUN_WRITES_ENABLED;
38 delete process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED;
39 });
40
41 it('start → consent → execute automatable → submit review', () => {
42 const start = handleFlowRunStartRequest({
43 dataDir,
44 vaultId,
45 cliScopes: ['personal', 'project', 'org'],
46 flowId: 'flow_automatable_test',
47 flowVersion: '1.0.0',
48 });
49 assert.equal(start.ok, true);
50 const runId = start.payload.run.run_id;
51 const stepId = 'flow_automatable_test#1';
52
53 const consent = handleFlowExecutionConsentMintRequest({
54 dataDir,
55 vaultId,
56 cliScopes: ['personal', 'project', 'org'],
57 runId,
58 allowedLanes: ['local_default'],
59 costCapUnits: 10,
60 });
61 assert.equal(consent.ok, true);
62
63 const execute = handleFlowRunExecuteAutomatableRequest({
64 dataDir,
65 vaultId,
66 cliScopes: ['personal', 'project', 'org'],
67 runId,
68 stepId,
69 consentId: consent.payload.consent.consent_id,
70 });
71 assert.equal(execute.ok, true);
72 assert.equal(execute.payload.execution.status, 'completed');
73 assert.ok(execute.payload.execution.evidence_ref);
74
75 const submit = handleFlowRunSubmitReviewRequest({
76 dataDir,
77 vaultId,
78 cliScopes: ['personal', 'project', 'org'],
79 runId,
80 intent: 'Run outcome for review',
81 createProposal,
82 });
83 assert.equal(submit.ok, true);
84 assert.ok(submit.payload.proposal_id);
85 });
86
87 it('external grant id does not satisfy execute consent (SD-5/SD-6)', () => {
88 const start = handleFlowRunStartRequest({
89 dataDir,
90 vaultId,
91 cliScopes: ['personal', 'project', 'org'],
92 flowId: 'flow_automatable_test',
93 flowVersion: '1.0.0',
94 });
95 assert.equal(start.ok, true);
96 const execute = handleFlowRunExecuteAutomatableRequest({
97 dataDir,
98 vaultId,
99 cliScopes: ['personal', 'project', 'org'],
100 runId: start.payload.run.run_id,
101 stepId: 'flow_automatable_test#1',
102 consentId: 'fgrnt_bearer_not_consent',
103 });
104 assert.equal(execute.ok, false);
105 assert.equal(execute.code, 'FLOW_EXECUTION_CONSENT_REQUIRED');
106 });
107 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 1 day ago