flow-store-versioned-step-keying-integration.test.mjs
sha256:cfe8c8cf68336f6d46318bd40610c18d9ff7df231df2fb190af1f5a9c4f4f93b
fix(flow-store): versioned step keying for multi-version fl…
Human
minor
⚠ breaking
7 hours ago
| 1 | /** |
| 2 | * Tier 2 — INTEGRATION: authoring reconcile + pinned getFlow (7A-10c). |
| 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 | import { |
| 10 | handleFlowProposeRequest, |
| 11 | precheckApprovedFlowProposal, |
| 12 | applyFlowProposalToIndex, |
| 13 | flowStateId, |
| 14 | } from '../lib/flow/flow-authoring.mjs'; |
| 15 | import { getFlow, flowDefinitionForClient, latestStoredFlow, loadFlowStore } from '../lib/flow/flow-store.mjs'; |
| 16 | import { createProposal, getProposal } from '../hub/proposals-store.mjs'; |
| 17 | import { makeFlowBundle, emptyStarterDir } from './fixtures/flow/authoring-helpers.mjs'; |
| 18 | |
| 19 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 20 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-versioned-step-keying-int'); |
| 21 | const visible = new Set(['personal', 'project', 'org']); |
| 22 | |
| 23 | function approve(dataDir, id) { |
| 24 | const pre = precheckApprovedFlowProposal(dataDir, getProposal(dataDir, id)); |
| 25 | if (pre.ok) applyFlowProposalToIndex(dataDir, pre.vaultId, pre.flow, pre.steps); |
| 26 | return pre; |
| 27 | } |
| 28 | |
| 29 | describe('Flow store — versioned step keying (integration)', () => { |
| 30 | const dataDir = path.join(tmpRoot, 'data'); |
| 31 | const vaultId = 'default'; |
| 32 | let starterDir; |
| 33 | |
| 34 | beforeEach(() => { |
| 35 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 36 | fs.mkdirSync(dataDir, { recursive: true }); |
| 37 | starterDir = emptyStarterDir(dataDir); |
| 38 | process.env.FLOW_AUTHORING_WRITES = '1'; |
| 39 | }); |
| 40 | afterEach(() => { |
| 41 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 42 | delete process.env.FLOW_AUTHORING_WRITES; |
| 43 | }); |
| 44 | |
| 45 | it('propose-edit with reworded step preserves v1 step text when pinned', () => { |
| 46 | const bundle = makeFlowBundle({ flowId: 'flow_10c_int', version: '1.0.0', steps: 2 }); |
| 47 | approve( |
| 48 | dataDir, |
| 49 | handleFlowProposeRequest({ |
| 50 | dataDir, vaultId, visibleScopes: visible, kind: 'new', |
| 51 | flow: bundle.flow, steps: bundle.steps, intent: 'add', createProposal, |
| 52 | }).payload.proposal_id, |
| 53 | ); |
| 54 | |
| 55 | const store = loadFlowStore(dataDir); |
| 56 | const cur = latestStoredFlow(store.vaults[vaultId], 'flow_10c_int'); |
| 57 | const canonical = flowDefinitionForClient(cur.flow, cur.steps); |
| 58 | const edited = structuredClone(canonical); |
| 59 | edited.flow.version = '2.0.0'; |
| 60 | edited.steps[0].instruction = 'Integration reword for step 1.'; |
| 61 | |
| 62 | approve( |
| 63 | dataDir, |
| 64 | handleFlowProposeRequest({ |
| 65 | dataDir, vaultId, visibleScopes: visible, kind: 'edit', |
| 66 | flow: edited.flow, steps: edited.steps, intent: 'reword', |
| 67 | flowId: 'flow_10c_int', baseVersion: '1.0.0', |
| 68 | baseStateId: flowStateId(canonical.flow, canonical.steps), createProposal, |
| 69 | }).payload.proposal_id, |
| 70 | ); |
| 71 | |
| 72 | const v1 = getFlow(dataDir, vaultId, 'flow_10c_int', { |
| 73 | filterScopes: visible, version: '1.0.0', starterDir, |
| 74 | }); |
| 75 | const v2 = getFlow(dataDir, vaultId, 'flow_10c_int', { |
| 76 | filterScopes: visible, version: '2.0.0', starterDir, |
| 77 | }); |
| 78 | assert.equal(v1.steps[0].instruction, bundle.steps[0].instruction); |
| 79 | assert.equal(v2.steps[0].instruction, 'Integration reword for step 1.'); |
| 80 | }); |
| 81 | }); |
File History
1 commit
sha256:cfe8c8cf68336f6d46318bd40610c18d9ff7df231df2fb190af1f5a9c4f4f93b
fix(flow-store): versioned step keying for multi-version fl…
Human
minor
⚠
7 hours ago