hosted-write-eval-hints-budget-integration.test.mjs
59 lines 2.3 KB
Raw
sha256:4215cecbbabf5591b1ff69053cc938b4b6c800f0d487be40618c1d4254d8b67b security: npm audit fix pre-bridge 2026-09-05 Human 2 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 3 commits
sha256:4215cecbbabf5591b1ff69053cc938b4b6c800f0d487be40618c1d4254d8b67b security: npm audit fix pre-bridge 2026-09-05 Human 2 days ago
sha256:9eaa2a7ec9aaf5866cd03d0deadf843cca97778299d1857b5452f71d92a1880a feat(f24): flip DOCS_NOTION_HUB_KEY_AUTHORIZED=true (Tier 3) Human minor 16 days ago
sha256:e4c529f14a0bb908c1caaaeb3f95f3623a1a82e636e7e3722ca2cd3dc9821263 security: npm audit fix pre-bridge 2026-07-29 Human 40 days ago