flow-store-versioned-step-keying-unit.test.mjs
69 lines 2.4 KB
Raw
sha256:cfe8c8cf68336f6d46318bd40610c18d9ff7df231df2fb190af1f5a9c4f4f93b fix(flow-store): versioned step keying for multi-version fl… Human minor ⚠ breaking 7 hours ago
1 /**
2 * Tier 1 — UNIT: versioned step keying helpers (7A-10c).
3 *
4 * @see lib/flow/flow-store.mjs
5 */
6 import { describe, it } from 'node:test';
7 import assert from 'node:assert/strict';
8 import {
9 stampStepsForStore,
10 normalizeVaultSteps,
11 stepsForFlowVersion,
12 buildFlowStepId,
13 } from '../lib/flow/flow-store.mjs';
14
15 describe('Flow store — versioned step keying (unit)', () => {
16 it('stampStepsForStore stamps flow_version on every step', () => {
17 const steps = [{
18 schema: 'knowtation.flow_step/v0',
19 step_id: 'flow_x#1',
20 flow_id: 'flow_x',
21 ordinal: 1,
22 }];
23 const stamped = stampStepsForStore(steps, '1.2.3');
24 assert.equal(stamped[0].flow_version, '1.2.3');
25 assert.equal(stamped[0].step_id, 'flow_x#1');
26 });
27
28 it('stepsForFlowVersion returns only steps for the requested version', () => {
29 const vault = {
30 flows: [
31 { flow_id: 'flow_x', version: '1.0.0', steps: [buildFlowStepId('flow_x', 1)] },
32 { flow_id: 'flow_x', version: '2.0.0', steps: [buildFlowStepId('flow_x', 1)] },
33 ],
34 steps: [
35 { flow_id: 'flow_x', flow_version: '1.0.0', step_id: 'flow_x#1', ordinal: 1, instruction: 'v1' },
36 { flow_id: 'flow_x', flow_version: '2.0.0', step_id: 'flow_x#1', ordinal: 1, instruction: 'v2' },
37 ],
38 runs: [],
39 candidates: [],
40 projections: [],
41 };
42 const v1 = stepsForFlowVersion(vault, 'flow_x', '1.0.0');
43 const v2 = stepsForFlowVersion(vault, 'flow_x', '2.0.0');
44 assert.equal(v1.length, 1);
45 assert.equal(v2.length, 1);
46 assert.equal(v1[0].instruction, 'v1');
47 assert.equal(v2[0].instruction, 'v2');
48 });
49
50 it('normalizeVaultSteps expands legacy rows without flow_version per flow version', () => {
51 const vault = {
52 flows: [
53 { flow_id: 'flow_x', version: '1.0.0', steps: ['flow_x#1'] },
54 { flow_id: 'flow_x', version: '2.0.0', steps: ['flow_x#1'] },
55 ],
56 steps: [{ flow_id: 'flow_x', step_id: 'flow_x#1', ordinal: 1, instruction: 'legacy' }],
57 runs: [],
58 candidates: [],
59 projections: [],
60 };
61 normalizeVaultSteps(vault);
62 assert.equal(vault.steps.length, 2);
63 assert.ok(vault.steps.every((s) => s.flow_version));
64 const v1 = stepsForFlowVersion(vault, 'flow_x', '1.0.0');
65 const v2 = stepsForFlowVersion(vault, 'flow_x', '2.0.0');
66 assert.equal(v1[0].instruction, 'legacy');
67 assert.equal(v2[0].instruction, 'legacy');
68 });
69 });
File History 1 commit
sha256:cfe8c8cf68336f6d46318bd40610c18d9ff7df231df2fb190af1f5a9c4f4f93b fix(flow-store): versioned step keying for multi-version fl… Human minor 7 hours ago