hosted-write-eval-hints-budget-performance.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
13 days ago
| 1 | /** |
| 2 | * HOSTED-WRITE-EVAL hints budget — Tier 6 performance: skip + budget race wall times. |
| 3 | */ |
| 4 | import { describe, it, mock } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import { SCOOLING_REVIEW_TRAY_INTENT } from '../lib/hub-proposal-personal-self-apply.mjs'; |
| 7 | import { |
| 8 | HOSTED_PROPOSAL_REVIEW_HINTS_INLINE_BUDGET_MS, |
| 9 | maybeScheduleHostedProposalReviewHints, |
| 10 | } from '../hub/gateway/proposal-review-hints-async.mjs'; |
| 11 | |
| 12 | describe('hosted review-hints budget (performance)', () => { |
| 13 | it('self-apply skip completes in under 50ms', async () => { |
| 14 | const t0 = performance.now(); |
| 15 | await maybeScheduleHostedProposalReviewHints({ |
| 16 | method: 'POST', |
| 17 | pathOnly: '/api/v1/proposals', |
| 18 | upstreamStatus: 200, |
| 19 | responseText: JSON.stringify({ proposal_id: 'prop-perf-1' }), |
| 20 | canisterUrl: 'https://example.invalid', |
| 21 | effectiveUserId: 'u', |
| 22 | actorUserId: 'u', |
| 23 | vaultId: 'default', |
| 24 | hintsEnabled: true, |
| 25 | createBody: { intent: SCOOLING_REVIEW_TRAY_INTENT }, |
| 26 | }); |
| 27 | assert.ok(performance.now() - t0 < 50); |
| 28 | }); |
| 29 | |
| 30 | it('default budget constant is 2000', () => { |
| 31 | assert.equal(HOSTED_PROPOSAL_REVIEW_HINTS_INLINE_BUDGET_MS, 2000); |
| 32 | }); |
| 33 | |
| 34 | it('budget race returns within budget + small slack', async () => { |
| 35 | const originalFetch = globalThis.fetch; |
| 36 | globalThis.fetch = mock.fn(async () => { |
| 37 | await new Promise((r) => setTimeout(r, 2000)); |
| 38 | return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } }); |
| 39 | }); |
| 40 | try { |
| 41 | const t0 = performance.now(); |
| 42 | await maybeScheduleHostedProposalReviewHints( |
| 43 | { |
| 44 | method: 'POST', |
| 45 | pathOnly: '/api/v1/proposals', |
| 46 | upstreamStatus: 200, |
| 47 | responseText: JSON.stringify({ proposal_id: 'prop-perf-2' }), |
| 48 | canisterUrl: 'https://example.invalid', |
| 49 | effectiveUserId: 'u', |
| 50 | actorUserId: 'u', |
| 51 | vaultId: 'default', |
| 52 | hintsEnabled: true, |
| 53 | createBody: { intent: 'other' }, |
| 54 | }, |
| 55 | 100, |
| 56 | ); |
| 57 | const elapsed = performance.now() - t0; |
| 58 | assert.ok(elapsed < 350, `expected ~100ms race, got ${elapsed}`); |
| 59 | } finally { |
| 60 | globalThis.fetch = originalFetch; |
| 61 | } |
| 62 | }); |
| 63 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
13 days ago