hosted-write-eval-hints-budget-security.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 7 security: no elevation via forged fields; disabled stays off. |
| 3 | */ |
| 4 | import { describe, it } 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 | maybeScheduleHostedProposalReviewHints, |
| 9 | shouldSkipInlineReviewHintsOnCreate, |
| 10 | } from '../hub/gateway/proposal-review-hints-async.mjs'; |
| 11 | |
| 12 | describe('hosted review-hints budget (security)', () => { |
| 13 | it('hintsEnabled false never schedules even for non-self-apply', async () => { |
| 14 | const t0 = Date.now(); |
| 15 | await maybeScheduleHostedProposalReviewHints({ |
| 16 | method: 'POST', |
| 17 | pathOnly: '/api/v1/proposals', |
| 18 | upstreamStatus: 200, |
| 19 | responseText: JSON.stringify({ proposal_id: 'prop-sec-1' }), |
| 20 | canisterUrl: 'https://example.invalid', |
| 21 | effectiveUserId: 'u', |
| 22 | actorUserId: 'u', |
| 23 | vaultId: 'default', |
| 24 | hintsEnabled: false, |
| 25 | createBody: { intent: 'note.update' }, |
| 26 | }); |
| 27 | assert.ok(Date.now() - t0 < 100); |
| 28 | }); |
| 29 | |
| 30 | it('Buffer createBody does not throw and does not skip as self-apply', () => { |
| 31 | assert.equal(shouldSkipInlineReviewHintsOnCreate(Buffer.from(SCOOLING_REVIEW_TRAY_INTENT)), false); |
| 32 | }); |
| 33 | |
| 34 | it('non-create methods are ignored', async () => { |
| 35 | await maybeScheduleHostedProposalReviewHints({ |
| 36 | method: 'GET', |
| 37 | pathOnly: '/api/v1/proposals', |
| 38 | upstreamStatus: 200, |
| 39 | responseText: JSON.stringify({ proposal_id: 'prop-sec-2' }), |
| 40 | canisterUrl: 'https://example.invalid', |
| 41 | effectiveUserId: 'u', |
| 42 | actorUserId: 'u', |
| 43 | vaultId: 'default', |
| 44 | hintsEnabled: true, |
| 45 | createBody: { intent: 'note.update' }, |
| 46 | }); |
| 47 | }); |
| 48 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago