agent-delegation-data-integrity.test.mjs
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0
feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes…
Human
minor
⚠ breaking
11 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
1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882
fix(test): align Band B landing assertion with desktop MCP …
Human
11 days ago