hosted-write-eval-hints-budget-integration.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago
| 1 | /** |
| 2 | * HOSTED-WRITE-EVAL hints budget — Tier 2 integration: schedule respects skip + budget race. |
| 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 { maybeScheduleHostedProposalReviewHints } from '../hub/gateway/proposal-review-hints-async.mjs'; |
| 8 | |
| 9 | describe('hosted review-hints inline schedule (integration)', () => { |
| 10 | it('returns immediately for Scooling self-apply create without waiting on LLM', async () => { |
| 11 | const started = Date.now(); |
| 12 | await maybeScheduleHostedProposalReviewHints({ |
| 13 | method: 'POST', |
| 14 | pathOnly: '/api/v1/proposals', |
| 15 | upstreamStatus: 200, |
| 16 | responseText: JSON.stringify({ proposal_id: 'prop-skip-1' }), |
| 17 | canisterUrl: 'https://example.invalid', |
| 18 | effectiveUserId: 'user-a', |
| 19 | actorUserId: 'user-a', |
| 20 | vaultId: 'default', |
| 21 | hintsEnabled: true, |
| 22 | createBody: { intent: SCOOLING_REVIEW_TRAY_INTENT, path: 'reviewed/x.md', body: 'n' }, |
| 23 | }); |
| 24 | assert.ok(Date.now() - started < 200, 'self-apply skip must not await hints job'); |
| 25 | }); |
| 26 | |
| 27 | it('honors short budget when hintsEnabled and non-self-apply', async () => { |
| 28 | const originalFetch = globalThis.fetch; |
| 29 | globalThis.fetch = mock.fn(async () => { |
| 30 | await new Promise((r) => setTimeout(r, 500)); |
| 31 | return new Response(JSON.stringify({ status: 'proposed', path: 'a.md', body: 'x' }), { |
| 32 | status: 200, |
| 33 | headers: { 'content-type': 'application/json' }, |
| 34 | }); |
| 35 | }); |
| 36 | try { |
| 37 | const started = Date.now(); |
| 38 | await maybeScheduleHostedProposalReviewHints( |
| 39 | { |
| 40 | method: 'POST', |
| 41 | pathOnly: '/api/v1/proposals', |
| 42 | upstreamStatus: 200, |
| 43 | responseText: JSON.stringify({ proposal_id: 'prop-budget-1' }), |
| 44 | canisterUrl: 'https://example.invalid', |
| 45 | effectiveUserId: 'user-a', |
| 46 | actorUserId: 'user-a', |
| 47 | vaultId: 'default', |
| 48 | hintsEnabled: true, |
| 49 | createBody: { intent: 'note.update', path: 'a.md', body: 'x' }, |
| 50 | }, |
| 51 | 80, |
| 52 | ); |
| 53 | const elapsed = Date.now() - started; |
| 54 | assert.ok(elapsed < 400, `budget race should finish quickly, got ${elapsed}ms`); |
| 55 | } finally { |
| 56 | globalThis.fetch = originalFetch; |
| 57 | } |
| 58 | }); |
| 59 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago