flow-execution-data-integrity.test.mjs
64 lines 2.4 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 15 hours ago
1 /**
2 * Tier 5 — DATA INTEGRITY: version pin, ordinal order, task_ref round-trip.
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 { handleFlowRunStartRequest, handleFlowRunExecuteAutomatableRequest } from '../lib/flow/flow-execution.mjs';
11 import { writeExecutionPolicy, seedAutomatableFlow } from './fixtures/flow/execution-helpers.mjs';
12
13 const __dirname = path.dirname(fileURLToPath(import.meta.url));
14 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-execution-integrity');
15
16 describe('Flow execution — data integrity', () => {
17 beforeEach(() => {
18 fs.rmSync(tmpRoot, { recursive: true, force: true });
19 fs.mkdirSync(tmpRoot, { recursive: true });
20 process.env.FLOW_RUN_WRITES_ENABLED = '1';
21 process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED = '1';
22 });
23
24 afterEach(() => {
25 fs.rmSync(tmpRoot, { recursive: true, force: true });
26 delete process.env.FLOW_RUN_WRITES_ENABLED;
27 delete process.env.FLOW_AUTOMATABLE_EXECUTION_ENABLED;
28 });
29
30 it('flow_version pin survives execute', () => {
31 const dataDir = path.join(tmpRoot, 'pin');
32 fs.mkdirSync(dataDir);
33 writeExecutionPolicy(dataDir);
34 const bundle = seedAutomatableFlow(dataDir, 'default');
35 const start = handleFlowRunStartRequest({
36 dataDir,
37 vaultId: 'default',
38 cliScopes: ['personal', 'project', 'org'],
39 flowId: bundle.flow.flow_id,
40 flowVersion: bundle.flow.version,
41 taskRef: 'task_sd2_001',
42 externalRef: 'muse:sha:abc',
43 });
44 assert.equal(start.payload.run.flow_version, '1.0.0');
45 assert.equal(start.payload.run.task_ref, 'task_sd2_001');
46 assert.equal(start.payload.run.external_ref, 'muse:sha:abc');
47 });
48
49 it('step_states preserve ordinal order after mutations', () => {
50 const dataDir = path.join(tmpRoot, 'ordinal');
51 fs.mkdirSync(dataDir);
52 writeExecutionPolicy(dataDir);
53 seedAutomatableFlow(dataDir, 'default');
54 const start = handleFlowRunStartRequest({
55 dataDir,
56 vaultId: 'default',
57 cliScopes: ['personal', 'project', 'org'],
58 flowId: 'flow_automatable_test',
59 flowVersion: '1.0.0',
60 });
61 const ids = start.payload.run.step_states.map((s) => s.step_id);
62 assert.deepEqual(ids, ['flow_automatable_test#1']);
63 });
64 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 15 hours ago