model-runtime-lane-performance.test.mjs
106 lines 3.7 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 2 days ago
1 /**
2 * Tier 6 — PERFORMANCE: model-runtime-lane timing bounds
3 *
4 * Verifies that the pure selection and policy functions complete within
5 * acceptable wall-clock bounds for high-frequency call sites (adapter hot path).
6 *
7 * Because the functions are pure/synchronous, the bounds are deliberately generous
8 * to avoid flakiness on loaded CI runners while still catching pathological regressions
9 * (e.g. inadvertent I/O or O(n²) internal logic).
10 *
11 * Reference: docs/COMPANION-APP-PHASE-1-ADAPTER-SEAM.md §1 (no I/O constraint)
12 */
13 import { describe, it } from 'node:test';
14 import assert from 'node:assert/strict';
15 import {
16 selectLane,
17 isManagedLane,
18 enforceConsentPolicy,
19 } from '../lib/model-runtime-lane.mjs';
20
21 const RUNS = 10_000;
22 /** Maximum allowed milliseconds per batch of RUNS calls (very generous). */
23 const MAX_MS_BATCH = 200;
24 /** Maximum allowed average microseconds per single call. */
25 const MAX_US_PER_CALL = 10;
26
27 describe('Performance — selectLane', () => {
28 it(`${RUNS} calls complete in < ${MAX_MS_BATCH}ms`, () => {
29 const caps = { inBrowserAvailable: true, managedKeyAvailable: true };
30 const prefs = {};
31 const start = performance.now();
32 for (let i = 0; i < RUNS; i++) selectLane(caps, prefs);
33 const elapsed = performance.now() - start;
34 assert.ok(
35 elapsed < MAX_MS_BATCH,
36 `selectLane: ${RUNS} calls took ${elapsed.toFixed(1)}ms — exceeded ${MAX_MS_BATCH}ms`,
37 );
38 });
39
40 it(`average per-call time is below ${MAX_US_PER_CALL}µs`, () => {
41 const caps = { managedKeyAvailable: true };
42 const prefs = { orgPrivacyMode: false };
43 const start = performance.now();
44 for (let i = 0; i < RUNS; i++) selectLane(caps, prefs);
45 const avgUs = ((performance.now() - start) / RUNS) * 1000;
46 assert.ok(
47 avgUs < MAX_US_PER_CALL,
48 `selectLane avg ${avgUs.toFixed(2)}µs/call — exceeded ${MAX_US_PER_CALL}µs`,
49 );
50 });
51 });
52
53 describe('Performance — isManagedLane', () => {
54 it(`${RUNS} calls to isManagedLane complete in < ${MAX_MS_BATCH}ms`, () => {
55 const start = performance.now();
56 for (let i = 0; i < RUNS; i++) isManagedLane(i % 2 === 0 ? 'direct_provider' : 'local');
57 const elapsed = performance.now() - start;
58 assert.ok(
59 elapsed < MAX_MS_BATCH,
60 `isManagedLane: ${RUNS} calls took ${elapsed.toFixed(1)}ms`,
61 );
62 });
63 });
64
65 describe('Performance — enforceConsentPolicy', () => {
66 it(`${RUNS} calls to enforceConsentPolicy complete in < ${MAX_MS_BATCH}ms`, () => {
67 const params = {
68 lane: 'direct_provider',
69 containsPrivateData: true,
70 consentId: undefined,
71 isDelegate: false,
72 delegatedManagedAllowed: false,
73 };
74 const start = performance.now();
75 for (let i = 0; i < RUNS; i++) enforceConsentPolicy(params);
76 const elapsed = performance.now() - start;
77 assert.ok(
78 elapsed < MAX_MS_BATCH,
79 `enforceConsentPolicy: ${RUNS} calls took ${elapsed.toFixed(1)}ms`,
80 );
81 });
82 });
83
84 describe('Performance — full pipeline (selectLane → isManagedLane → enforceConsentPolicy)', () => {
85 it(`${RUNS} full pipeline invocations complete in < ${MAX_MS_BATCH * 2}ms`, () => {
86 const caps = { managedKeyAvailable: true };
87 const prefs = {};
88 const start = performance.now();
89 for (let i = 0; i < RUNS; i++) {
90 const lane = selectLane(caps, prefs);
91 isManagedLane(lane);
92 enforceConsentPolicy({
93 lane,
94 containsPrivateData: true,
95 consentId: undefined,
96 isDelegate: false,
97 delegatedManagedAllowed: false,
98 });
99 }
100 const elapsed = performance.now() - start;
101 assert.ok(
102 elapsed < MAX_MS_BATCH * 2,
103 `full pipeline: ${RUNS} calls took ${elapsed.toFixed(1)}ms`,
104 );
105 });
106 });
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