agent-delegation-data-integrity.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 5 — DATA-INTEGRITY: consent→grant field copy, audit pins, schema round-trip. |
| 3 | */ |
| 4 | import { describe, it, beforeEach, afterEach } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import fs from 'node:fs'; |
| 7 | import path from 'node:path'; |
| 8 | import { fileURLToPath } from 'node:url'; |
| 9 | |
| 10 | import { |
| 11 | handleDelegationGrantMintRequest, |
| 12 | handleDelegationAuditAppendRequest, |
| 13 | validateGrantRecord, |
| 14 | validateAuditRecord, |
| 15 | seedDelegationFixtures, |
| 16 | } from '../lib/agent/delegation.mjs'; |
| 17 | import { |
| 18 | writeDelegationPolicy, |
| 19 | makeAgentIdentity, |
| 20 | makeDelegationConsent, |
| 21 | TEST_PRINCIPAL_REF, |
| 22 | } from './fixtures/agent/delegation-helpers.mjs'; |
| 23 | |
| 24 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 25 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-agent-delegation-data-integrity'); |
| 26 | |
| 27 | describe('Agent delegation — data integrity', () => { |
| 28 | const dataDir = path.join(tmpRoot, 'data'); |
| 29 | const vaultId = 'default'; |
| 30 | |
| 31 | beforeEach(() => { |
| 32 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 33 | fs.mkdirSync(dataDir, { recursive: true }); |
| 34 | writeDelegationPolicy(dataDir); |
| 35 | process.env.DELEGATION_ENABLED = '1'; |
| 36 | const identity = makeAgentIdentity(); |
| 37 | const consent = makeDelegationConsent(); |
| 38 | seedDelegationFixtures(dataDir, vaultId, identity, consent); |
| 39 | }); |
| 40 | |
| 41 | afterEach(() => { |
| 42 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 43 | delete process.env.DELEGATION_ENABLED; |
| 44 | }); |
| 45 | |
| 46 | it('grant copies principal/scope from consent; audit preserves pins', () => { |
| 47 | const consent = makeDelegationConsent(); |
| 48 | const identity = makeAgentIdentity(); |
| 49 | const mint = handleDelegationGrantMintRequest({ |
| 50 | dataDir, |
| 51 | vaultId, |
| 52 | consentId: consent.consent_id, |
| 53 | actorAgentId: identity.agent_id, |
| 54 | taskRef: 'task_hw_week3', |
| 55 | runRef: 'run_2026w25', |
| 56 | flowId: 'flow_weekly_review', |
| 57 | flowVersion: '1.4.0', |
| 58 | }); |
| 59 | assert.equal(mint.ok, true); |
| 60 | assert.equal(mint.payload.grant.principal_ref, consent.principal_ref); |
| 61 | assert.equal(mint.payload.grant.scope, consent.scope); |
| 62 | assert.equal(validateGrantRecord(mint.payload.grant).ok, true); |
| 63 | |
| 64 | const audit = handleDelegationAuditAppendRequest({ |
| 65 | dataDir, |
| 66 | vaultId, |
| 67 | grantId: mint.payload.grant.grant_id, |
| 68 | actorAgentId: identity.agent_id, |
| 69 | principalRef: TEST_PRINCIPAL_REF, |
| 70 | action: 'advance_step', |
| 71 | evidenceRefs: ['proposal:integrity'], |
| 72 | taskRef: 'task_hw_week3', |
| 73 | runRef: 'run_2026w25', |
| 74 | flowId: 'flow_weekly_review', |
| 75 | flowVersion: '1.4.0', |
| 76 | stepId: 'flow_weekly_review#1', |
| 77 | }); |
| 78 | assert.equal(audit.ok, true); |
| 79 | assert.equal(validateAuditRecord(audit.payload).ok, true); |
| 80 | const roundTrip = JSON.parse(JSON.stringify(audit.payload)); |
| 81 | assert.equal(roundTrip.schema, 'knowtation.delegation_audit/v0'); |
| 82 | assert.deepEqual(roundTrip.evidence_refs, ['proposal:integrity']); |
| 83 | }); |
| 84 | }); |
File History
2 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago