|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// FLOW NODE execution proof (ADR-0054 Phase 2), exercised end-to-end through the |
| 4 | +// real HTTP + automation stack. |
| 5 | +// |
| 6 | +// @proof: flow-node-execution |
| 7 | +// ADR-0054 runtime proof for the flow-node high-risk class (node execution + |
| 8 | +// variable wiring). Referenced by the liveness ledger entry `flow.nodes.type` |
| 9 | +// (packages/spec/liveness/flow.json); the spec liveness gate fails if this tag |
| 10 | +// is removed. See proof-registry.mts. |
| 11 | +// |
| 12 | +// A flow being `live` means the engine reads its nodes — necessary but not |
| 13 | +// sufficient. This authors a flow, triggers it over HTTP, and asserts the |
| 14 | +// observable runtime outcome: the `update_record` node ran AND the `noteId` |
| 15 | +// input variable wired into its filter, so EXACTLY the targeted record changed. |
| 16 | + |
| 17 | +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
| 18 | +import { bootStack, type VerifyStack } from '@objectstack/verify'; |
| 19 | +import { flowFixtureStack } from './fixtures/flow-touch-fixture.js'; |
| 20 | + |
| 21 | +describe('objectstack verify FLOW: node execution + variable wiring (#flow-node)', () => { |
| 22 | + let stack: VerifyStack; |
| 23 | + let token: string; |
| 24 | + |
| 25 | + beforeAll(async () => { |
| 26 | + // `automation: true` registers @objectstack/service-automation so the app's |
| 27 | + // flows are pulled from the registry and the trigger route runs them. |
| 28 | + stack = await bootStack(flowFixtureStack, { automation: true }); |
| 29 | + token = await stack.signIn(); |
| 30 | + }, 60_000); |
| 31 | + |
| 32 | + afterAll(async () => { |
| 33 | + await stack?.stop(); |
| 34 | + }); |
| 35 | + |
| 36 | + async function createNote(name: string): Promise<string> { |
| 37 | + const res = await stack.apiAs(token, 'POST', '/data/flow_note', { name, status: 'new' }); |
| 38 | + expect(res.status, `create ${name} failed: ${res.status} ${await res.clone().text()}`).toBeLessThan(300); |
| 39 | + const j = (await res.json()) as { id?: string; record?: { id?: string } }; |
| 40 | + const id = j.id ?? j.record?.id; |
| 41 | + expect(id, 'no id returned from create').toBeTruthy(); |
| 42 | + return id as string; |
| 43 | + } |
| 44 | + |
| 45 | + async function statusOf(id: string): Promise<unknown> { |
| 46 | + const res = await stack.apiAs(token, 'GET', `/data/flow_note/${id}`); |
| 47 | + expect(res.status).toBe(200); |
| 48 | + const j = (await res.json()) as { record?: Record<string, unknown> } & Record<string, unknown>; |
| 49 | + return (j.record ?? j).status; |
| 50 | + } |
| 51 | + |
| 52 | + it('precondition: the automation service is wired and the flow is registered', async () => { |
| 53 | + // The flow-list route is served by the same dispatcher; if automation were |
| 54 | + // unregistered this would not return the flow (the whole proof would be moot). |
| 55 | + const res = await stack.apiAs(token, 'GET', '/automation/flow_touch'); |
| 56 | + expect(res.status, `automation service not wired: ${res.status}`).toBe(200); |
| 57 | + }); |
| 58 | + |
| 59 | + it('runs the update_record node and wires the input variable into the filter', async () => { |
| 60 | + const target = await createNote('target'); |
| 61 | + const bystander = await createNote('bystander'); |
| 62 | + expect(await statusOf(target)).toBe('new'); |
| 63 | + expect(await statusOf(bystander)).toBe('new'); |
| 64 | + |
| 65 | + const res = await stack.apiAs(token, 'POST', '/automation/flow_touch/trigger', { |
| 66 | + params: { noteId: target }, |
| 67 | + }); |
| 68 | + expect(res.status, `trigger failed: ${res.status} ${await res.clone().text()}`).toBeLessThan(300); |
| 69 | + const body = (await res.json()) as { success?: boolean; data?: { success?: boolean; error?: string } }; |
| 70 | + expect(body.success).toBe(true); |
| 71 | + expect(body.data?.success, `flow run not successful: ${JSON.stringify(body.data)}`).toBe(true); |
| 72 | + |
| 73 | + // The node executed → the targeted record was stamped. |
| 74 | + expect(await statusOf(target)).toBe('processed'); |
| 75 | + // Variable wiring is REAL → the filter used noteId, so the bystander is |
| 76 | + // untouched. (A flow that dropped the variable would touch nothing or, with a |
| 77 | + // filterless update, touch every row — both caught here.) |
| 78 | + expect(await statusOf(bystander)).toBe('new'); |
| 79 | + }); |
| 80 | +}); |
0 commit comments