hosted-write-eval-kn-b-unit.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago
| 1 | /** |
| 2 | * HOSTED-WRITE-EVAL-KN-b — Tier 1 unit: personal self-apply predicate. |
| 3 | */ |
| 4 | import { describe, it } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import { |
| 7 | SCOOLING_REVIEW_TRAY_INTENT, |
| 8 | matchesScoolingReviewTrayFingerprint, |
| 9 | isElevatedOrAutoFlagged, |
| 10 | isPersonalSelfApplyClass, |
| 11 | applyPersonalSelfApplyEvaluationE1, |
| 12 | parseAutoFlagReasons, |
| 13 | personalSelfApplyAllowsApprove, |
| 14 | } from '../lib/hub-proposal-personal-self-apply.mjs'; |
| 15 | |
| 16 | function matchingProposal(overrides = {}) { |
| 17 | return { |
| 18 | status: 'proposed', |
| 19 | intent: SCOOLING_REVIEW_TRAY_INTENT, |
| 20 | external_ref: 'scooling.review:fixture-001', |
| 21 | path: 'reviewed/fixture-001.md', |
| 22 | review_severity: 'standard', |
| 23 | ...overrides, |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | describe('HOSTED-WRITE-EVAL-KN-b unit — predicate', () => { |
| 28 | it('matches fingerprint when intent, external_ref, and path hold', () => { |
| 29 | assert.equal(matchesScoolingReviewTrayFingerprint(matchingProposal()), true); |
| 30 | }); |
| 31 | |
| 32 | it('rejects mismatched intent', () => { |
| 33 | assert.equal( |
| 34 | matchesScoolingReviewTrayFingerprint(matchingProposal({ intent: 'other.intent' })), |
| 35 | false, |
| 36 | ); |
| 37 | }); |
| 38 | |
| 39 | it('rejects bad external_ref and path', () => { |
| 40 | assert.equal( |
| 41 | matchesScoolingReviewTrayFingerprint(matchingProposal({ external_ref: 'muse:abc' })), |
| 42 | false, |
| 43 | ); |
| 44 | assert.equal( |
| 45 | matchesScoolingReviewTrayFingerprint(matchingProposal({ path: 'inbox/x.md' })), |
| 46 | false, |
| 47 | ); |
| 48 | }); |
| 49 | |
| 50 | it('detects elevated and auto-flag reasons (array + json)', () => { |
| 51 | assert.equal(isElevatedOrAutoFlagged(matchingProposal({ review_severity: 'elevated' })), true); |
| 52 | assert.equal( |
| 53 | isElevatedOrAutoFlagged(matchingProposal({ auto_flag_reasons: ['phrase:secret'] })), |
| 54 | true, |
| 55 | ); |
| 56 | assert.equal( |
| 57 | isElevatedOrAutoFlagged( |
| 58 | matchingProposal({ auto_flag_reasons_json: JSON.stringify(['path_prefix:legal/']) }), |
| 59 | ), |
| 60 | true, |
| 61 | ); |
| 62 | assert.equal(parseAutoFlagReasons(matchingProposal()).length, 0); |
| 63 | assert.equal(isElevatedOrAutoFlagged(matchingProposal()), false); |
| 64 | }); |
| 65 | |
| 66 | it('full class requires vault:write, partition, proposed, fingerprint, not elevated', () => { |
| 67 | assert.equal( |
| 68 | isPersonalSelfApplyClass({ |
| 69 | proposal: matchingProposal(), |
| 70 | hasVaultWrite: true, |
| 71 | partitionOwned: true, |
| 72 | role: 'member', |
| 73 | }), |
| 74 | true, |
| 75 | ); |
| 76 | assert.equal( |
| 77 | isPersonalSelfApplyClass({ |
| 78 | proposal: matchingProposal(), |
| 79 | hasVaultWrite: false, |
| 80 | partitionOwned: true, |
| 81 | role: 'member', |
| 82 | }), |
| 83 | false, |
| 84 | ); |
| 85 | assert.equal( |
| 86 | isPersonalSelfApplyClass({ |
| 87 | proposal: matchingProposal({ status: 'approved' }), |
| 88 | hasVaultWrite: true, |
| 89 | partitionOwned: true, |
| 90 | role: 'member', |
| 91 | }), |
| 92 | false, |
| 93 | ); |
| 94 | assert.equal( |
| 95 | isPersonalSelfApplyClass({ |
| 96 | proposal: matchingProposal({ review_severity: 'elevated' }), |
| 97 | hasVaultWrite: true, |
| 98 | partitionOwned: true, |
| 99 | role: 'member', |
| 100 | }), |
| 101 | false, |
| 102 | ); |
| 103 | }); |
| 104 | |
| 105 | it('E1 sets passed only when fingerprint matches and not elevated; clears forged passed on elevated', () => { |
| 106 | const passed = applyPersonalSelfApplyEvaluationE1( |
| 107 | { ...matchingProposal(), evaluation_status: 'pending' }, |
| 108 | { evaluatedBy: 'google:learner', evaluatedAt: '2026-07-22T00:00:00.000Z' }, |
| 109 | ); |
| 110 | assert.equal(passed.evaluation_status, 'passed'); |
| 111 | assert.equal(passed.evaluated_by, 'google:learner'); |
| 112 | assert.equal(passed.evaluated_at, '2026-07-22T00:00:00.000Z'); |
| 113 | |
| 114 | const elevated = applyPersonalSelfApplyEvaluationE1( |
| 115 | { |
| 116 | ...matchingProposal({ review_severity: 'elevated' }), |
| 117 | evaluation_status: 'passed', |
| 118 | auto_flag_reasons: ['phrase:x'], |
| 119 | evaluated_by: 'forged', |
| 120 | }, |
| 121 | { evaluatedBy: 'google:learner' }, |
| 122 | ); |
| 123 | assert.equal(elevated.evaluation_status, 'pending'); |
| 124 | assert.equal(elevated.evaluated_by, undefined); |
| 125 | |
| 126 | const mismatch = applyPersonalSelfApplyEvaluationE1( |
| 127 | { intent: 'other', path: 'reviewed/a.md', external_ref: 'scooling.review:a', evaluation_status: 'pending' }, |
| 128 | { evaluatedBy: 'u' }, |
| 129 | ); |
| 130 | assert.equal(mismatch.evaluation_status, 'pending'); |
| 131 | }); |
| 132 | |
| 133 | it('approve helper mirrors class check', () => { |
| 134 | assert.equal( |
| 135 | personalSelfApplyAllowsApprove({ |
| 136 | proposal: matchingProposal(), |
| 137 | hasVaultWrite: true, |
| 138 | partitionOwned: true, |
| 139 | role: 'member', |
| 140 | }), |
| 141 | true, |
| 142 | ); |
| 143 | }); |
| 144 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
10 days ago