companion-shell-performance.test.mjs
59 lines 1.9 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 2 days ago
1 /**
2 * Tier 6 — PERFORMANCE: Phase 5 cache and admission overhead bounds.
3 */
4
5 import { describe, it } from 'node:test';
6 import assert from 'node:assert/strict';
7
8 import { createCompanionInferenceListener } from '../lib/companion-inference-listener.mjs';
9 import { createCompanionResourceProbe } from '../lib/companion-resource-probe.mjs';
10
11 describe('resource probe cache', () => {
12 it('honors the <=500ms cache bound', async () => {
13 let now = 1000;
14 let reads = 0;
15 const probe = createCompanionResourceProbe({
16 pid: 123,
17 platform: 'linux',
18 now: () => now,
19 readFile: async () => {
20 reads += 1;
21 return '100 25 0 0 0 0 0';
22 },
23 pageSizeBytes: 4096,
24 cacheMs: 500,
25 });
26
27 assert.equal((await probe.statResources()).ramBytes, 25 * 4096);
28 now += 499;
29 assert.equal((await probe.statResources()).ramBytes, 25 * 4096);
30 assert.equal(reads, 1);
31 now += 2;
32 await probe.statResources();
33 assert.equal(reads, 2);
34 });
35 });
36
37 describe('front-door admission overhead', () => {
38 it('handles a small burst of admitted health requests without event-loop starvation', async () => {
39 const listener = createCompanionInferenceListener({
40 expectedToken: 'loopback-token',
41 runtimeRequest(_req, res) {
42 res.statusCode = 200;
43 res.end('ok');
44 },
45 });
46 const bound = await listener.start();
47 try {
48 const start = performance.now();
49 const responses = await Promise.all(Array.from({ length: 25 }, () => fetch(`http://127.0.0.1:${bound.port}/v1/models`, {
50 headers: { Authorization: 'Bearer loopback-token' },
51 })));
52 const elapsed = performance.now() - start;
53 assert.equal(responses.every((res) => res.status === 200), true);
54 assert.ok(elapsed < 2000, `front-door burst took ${elapsed}ms`);
55 } finally {
56 await listener.close();
57 }
58 });
59 });
File History 2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 2 days ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 2 days ago