task-write-performance.test.mjs
75 lines 2.5 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 6 — PERFORMANCE: propose + apply p95 budgets.
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 { handleTaskProposeRequest } from '../lib/task/task-write.mjs';
11 import { createProposal } from '../hub/proposals-store.mjs';
12 import { approveTaskProposal, sampleTaskCreatePayload, visibleAll } from './fixtures/task/write-helpers.mjs';
13
14 const __dirname = path.dirname(fileURLToPath(import.meta.url));
15 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-task-write-perf');
16 const PROPOSE_P95_MS = 50;
17 const APPLY_P95_MS = 50;
18 const SAMPLES = 20;
19
20 describe('task write — performance', () => {
21 const dataDir = path.join(tmpRoot, 'data');
22 beforeEach(() => {
23 fs.rmSync(tmpRoot, { recursive: true, force: true });
24 fs.mkdirSync(dataDir, { recursive: true });
25 process.env.TASK_WRITES_ENABLED = '1';
26 });
27 afterEach(() => {
28 delete process.env.TASK_WRITES_ENABLED;
29 });
30
31 it(`propose p95 < ${PROPOSE_P95_MS}ms over ${SAMPLES} samples`, async () => {
32 const times = [];
33 for (let i = 0; i < SAMPLES; i += 1) {
34 const body = sampleTaskCreatePayload();
35 body.task.task_id = `task_perf_${i}`;
36 const t0 = performance.now();
37 await handleTaskProposeRequest({
38 dataDir,
39 vaultId: 'default',
40 visibleScopes: visibleAll,
41 proposalKind: 'task_create',
42 body,
43 intent: 'perf',
44 createProposal,
45 });
46 times.push(performance.now() - t0);
47 }
48 times.sort((a, b) => a - b);
49 const p95 = times[Math.floor(times.length * 0.95)];
50 assert.ok(p95 < PROPOSE_P95_MS, `p95=${p95.toFixed(2)}ms`);
51 });
52
53 it(`approve apply p95 < ${APPLY_P95_MS}ms`, async () => {
54 const times = [];
55 for (let i = 0; i < SAMPLES; i += 1) {
56 const body = sampleTaskCreatePayload();
57 body.task.task_id = `task_perf_apply_${i}`;
58 const proposed = await handleTaskProposeRequest({
59 dataDir,
60 vaultId: 'default',
61 visibleScopes: visibleAll,
62 proposalKind: 'task_create',
63 body,
64 intent: 'perf',
65 createProposal,
66 });
67 const t0 = performance.now();
68 approveTaskProposal(dataDir, proposed.payload.proposal_id);
69 times.push(performance.now() - t0);
70 }
71 times.sort((a, b) => a - b);
72 const p95 = times[Math.floor(times.length * 0.95)];
73 assert.ok(p95 < APPLY_P95_MS, `p95=${p95.toFixed(2)}ms`);
74 });
75 });
File History 1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago