hub-proposal-review-triggers.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | import test from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import fs from 'node:fs'; |
| 4 | import os from 'node:os'; |
| 5 | import path from 'node:path'; |
| 6 | import { loadReviewTriggers, applyReviewTriggers } from '../lib/hub-proposal-review-triggers.mjs'; |
| 7 | import { getProposalEvaluationRequired } from '../lib/hub-proposal-policy.mjs'; |
| 8 | import { augmentProposalCreateRequestBody } from '../lib/hub-proposal-create-augment.mjs'; |
| 9 | |
| 10 | test('applyReviewTriggers: phrase and path prefix', () => { |
| 11 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kt-tr-')); |
| 12 | fs.writeFileSync( |
| 13 | path.join(dir, 'hub_proposal_review_triggers.json'), |
| 14 | JSON.stringify({ |
| 15 | literal_phrases: [{ match: 'api_key', review_queue: 'sec', review_severity: 'elevated' }], |
| 16 | path_prefixes: [{ prefix: 'legal/', review_queue: 'legal', review_severity: 'standard' }], |
| 17 | label_any: [{ labels: ['pii'], review_queue: 'privacy' }], |
| 18 | }), |
| 19 | ); |
| 20 | const triggers = loadReviewTriggers(dir); |
| 21 | const byPath = applyReviewTriggers(triggers, { path: 'legal/contract.md', body: 'ok', intent: '', labels: [] }); |
| 22 | assert.equal(byPath.forcePending, true); |
| 23 | assert.equal(byPath.review_queue, 'legal'); |
| 24 | assert.equal(byPath.review_severity, 'standard'); |
| 25 | |
| 26 | const byPhrase = applyReviewTriggers(triggers, { path: 'inbox/x.md', body: 'contains api_key value', intent: '', labels: [] }); |
| 27 | assert.equal(byPhrase.forcePending, true); |
| 28 | assert.equal(byPhrase.review_queue, 'sec'); |
| 29 | assert.equal(byPhrase.review_severity, 'elevated'); |
| 30 | |
| 31 | const byLabel = applyReviewTriggers(triggers, { path: 'a.md', body: '', intent: '', labels: ['PII'] }); |
| 32 | assert.equal(byLabel.forcePending, true); |
| 33 | assert.equal(byLabel.review_queue, 'privacy'); |
| 34 | }); |
| 35 | |
| 36 | test('getProposalEvaluationRequired: policy file when env unset', async (t) => { |
| 37 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kt-pol-')); |
| 38 | const prev = process.env.HUB_PROPOSAL_EVALUATION_REQUIRED; |
| 39 | t.after(() => { |
| 40 | if (prev === undefined) delete process.env.HUB_PROPOSAL_EVALUATION_REQUIRED; |
| 41 | else process.env.HUB_PROPOSAL_EVALUATION_REQUIRED = prev; |
| 42 | }); |
| 43 | delete process.env.HUB_PROPOSAL_EVALUATION_REQUIRED; |
| 44 | assert.equal(getProposalEvaluationRequired(dir), false); |
| 45 | fs.writeFileSync(path.join(dir, 'hub_proposal_policy.json'), JSON.stringify({ proposal_evaluation_required: true })); |
| 46 | assert.equal(getProposalEvaluationRequired(dir), true); |
| 47 | }); |
| 48 | |
| 49 | test('augmentProposalCreateRequestBody: policy pending + triggers', async (t) => { |
| 50 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kt-aug-')); |
| 51 | const prev = process.env.HUB_PROPOSAL_EVALUATION_REQUIRED; |
| 52 | t.after(() => { |
| 53 | if (prev === undefined) delete process.env.HUB_PROPOSAL_EVALUATION_REQUIRED; |
| 54 | else process.env.HUB_PROPOSAL_EVALUATION_REQUIRED = prev; |
| 55 | }); |
| 56 | process.env.HUB_PROPOSAL_EVALUATION_REQUIRED = '0'; |
| 57 | fs.writeFileSync( |
| 58 | path.join(dir, 'hub_proposal_review_triggers.json'), |
| 59 | JSON.stringify({ |
| 60 | literal_phrases: [{ match: 'password' }], |
| 61 | path_prefixes: [], |
| 62 | label_any: [], |
| 63 | }), |
| 64 | ); |
| 65 | const body = augmentProposalCreateRequestBody({ path: 'n.md', body: 'reset password', labels: [] }, dir); |
| 66 | assert.equal(body.evaluation_status, 'pending'); |
| 67 | assert.ok(Array.isArray(JSON.parse(body.auto_flag_reasons_json))); |
| 68 | }); |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
1 day ago