flow-external-agent-stress.test.mjs
61 lines 2.0 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 10 hours ago
1 /**
2 * Tier 4 — STRESS: concurrent mints bounded; no bearer in list under load.
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 {
11 handleFlowExternalGrantMintRequest,
12 handleFlowExternalGrantListRequest,
13 } from '../lib/flow/external-agent.mjs';
14 import { upsertFlowVersion } from '../lib/flow/flow-store.mjs';
15 import {
16 writeExternalAgentPolicy,
17 makeExternalToolFlowBundle,
18 } from './fixtures/flow/external-agent-helpers.mjs';
19
20 const __dirname = path.dirname(fileURLToPath(import.meta.url));
21 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-flow-external-agent-stress');
22
23 describe('Flow external-agent — stress', () => {
24 const dataDir = path.join(tmpRoot, 'data');
25 const vaultId = 'default';
26
27 beforeEach(() => {
28 fs.rmSync(tmpRoot, { recursive: true, force: true });
29 fs.mkdirSync(dataDir, { recursive: true });
30 writeExternalAgentPolicy(dataDir);
31 process.env.FLOW_EXTERNAL_AGENT_ENABLED = '1';
32 const bundle = makeExternalToolFlowBundle();
33 upsertFlowVersion(dataDir, vaultId, bundle.flow, bundle.steps);
34 });
35
36 afterEach(() => {
37 fs.rmSync(tmpRoot, { recursive: true, force: true });
38 delete process.env.FLOW_EXTERNAL_AGENT_ENABLED;
39 });
40
41 it('many concurrent mints stay bounded and list has no bearer', async () => {
42 const mints = await Promise.all(
43 Array.from({ length: 32 }, () =>
44 handleFlowExternalGrantMintRequest({
45 dataDir,
46 vaultId,
47 flowId: 'flow_ext_agent_test',
48 flowVersion: '1.0.0',
49 requestedTools: ['web_search'],
50 }),
51 ),
52 );
53 for (const m of mints) {
54 assert.equal(m.ok, true);
55 }
56 const list = handleFlowExternalGrantListRequest({ dataDir, vaultId });
57 assert.equal(list.ok, true);
58 assert.equal(list.payload.grants.length, 32);
59 assert.equal(JSON.stringify(list.payload).includes('fgrnt_bearer_'), false);
60 });
61 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 10 hours ago