flow-external-agent-data-integrity.test.mjs
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
23 hours ago
| 1 | /** |
| 2 | * Tier 5 — DATA INTEGRITY: bundle round-trip; grant list/revoke metadata stable. |
| 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 { handleFlowProjectRequest } from '../lib/flow/flow-handlers.mjs'; |
| 11 | import { |
| 12 | handleFlowExternalGrantMintRequest, |
| 13 | handleFlowExternalGrantListRequest, |
| 14 | grantForClient, |
| 15 | } from '../lib/flow/external-agent.mjs'; |
| 16 | import { upsertFlowVersion } from '../lib/flow/flow-store.mjs'; |
| 17 | import { |
| 18 | writeExternalAgentPolicy, |
| 19 | makeExternalToolFlowBundle, |
| 20 | } from './fixtures/flow/external-agent-helpers.mjs'; |
| 21 | |
| 22 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 23 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-external-agent-integrity'); |
| 24 | |
| 25 | describe('Flow external-agent — data integrity', () => { |
| 26 | const dataDir = path.join(tmpRoot, 'data'); |
| 27 | const vaultId = 'default'; |
| 28 | |
| 29 | beforeEach(() => { |
| 30 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 31 | fs.mkdirSync(dataDir, { recursive: true }); |
| 32 | writeExternalAgentPolicy(dataDir); |
| 33 | process.env.FLOW_EXTERNAL_AGENT_ENABLED = '1'; |
| 34 | const bundle = makeExternalToolFlowBundle(); |
| 35 | upsertFlowVersion(dataDir, vaultId, bundle.flow, bundle.steps); |
| 36 | }); |
| 37 | |
| 38 | afterEach(() => { |
| 39 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 40 | delete process.env.FLOW_EXTERNAL_AGENT_ENABLED; |
| 41 | }); |
| 42 | |
| 43 | it('agent_bundle preserves steps and skill_refs', () => { |
| 44 | const result = handleFlowProjectRequest({ |
| 45 | dataDir, |
| 46 | vaultId, |
| 47 | flowId: 'flow_ext_agent_test', |
| 48 | harness: 'agent_bundle', |
| 49 | cliScopes: ['personal'], |
| 50 | }); |
| 51 | assert.equal(result.ok, true); |
| 52 | const inner = JSON.parse(result.payload.projection.rendered); |
| 53 | assert.equal(inner.steps[0].skill_refs[0].id, 'web_search'); |
| 54 | assert.equal(inner.flow_id, 'flow_ext_agent_test'); |
| 55 | assert.equal(inner.flow_version, '1.0.0'); |
| 56 | }); |
| 57 | |
| 58 | it('grant metadata survives list with no bearer field', () => { |
| 59 | const mint = handleFlowExternalGrantMintRequest({ |
| 60 | dataDir, |
| 61 | vaultId, |
| 62 | flowId: 'flow_ext_agent_test', |
| 63 | flowVersion: '1.0.0', |
| 64 | requestedTools: ['web_search'], |
| 65 | }); |
| 66 | assert.equal(mint.ok, true); |
| 67 | const list = handleFlowExternalGrantListRequest({ dataDir, vaultId }); |
| 68 | const listed = list.payload.grants[0]; |
| 69 | assert.deepEqual(grantForClient(listed), mint.payload.grant); |
| 70 | assert.equal('bearer' in listed, false); |
| 71 | }); |
| 72 | }); |
File History
1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
23 hours ago