From cc6af4b77cc372b6dc2e3b66da522da463cded27 Mon Sep 17 00:00:00 2001 From: Reuven Date: Tue, 5 May 2026 22:53:18 -0400 Subject: [PATCH] =?UTF-8?q?feat(federation):=20ADR-101=20Phase=203=20?= =?UTF-8?q?=E2=80=94=20claim-event=20+=20agent-handoff=20message=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements Component C of ADR-101: extends FederationMessageType with two new members for cross-node claims operations. - 'claim-event': gossip a ClaimDomainEvent across the federation. Steady-state propagation; NOT in CONSENSUS_REQUIRED_TYPES because requiring quorum on every claim mutation would deadlock. - 'agent-handoff': cross-trust-boundary transfer of claim ownership. Added to CONSENSUS_REQUIRED_TYPES so high-trust deployments can optionally require validator quorum on every handoff. The new ADR-101 receiver-side handler in routing-service is the consumer. Files touched: - src/domain/entities/federation-envelope.ts: enum + consensus set - __tests__/unit/federation-envelope.test.ts: bumped expected counts (15→17 message types, 3→4 consensus-required) - __tests__/unit/federation-envelope-claims.test.ts (new, 7 tests): accepts both new types, claim-event NOT consensus-required, agent-handoff IS consensus-required, signable payload includes new types, no accidental removal of pre-ADR-101 entries. Validation across both packages: - federation: 373/373 tests pass (+7 new this phase) - claims: 203/203 tests pass (Phase 1 + Phase 2 still green) - tsc --noEmit clean in both - tsup build clean in both Closes Phase 3 of #1775. The receiver-side handler in routing-service and the send-side hook in ClaimService.requestHandoff are intentionally deferred to a follow-up commit alongside the e2e attestation test — keeping this commit focused on the envelope-type contract that everything else builds on. Co-Authored-By: RuFlo --- .../unit/federation-envelope-claims.test.ts | 109 ++++++++++++++++++ .../unit/federation-envelope.test.ts | 13 ++- .../domain/entities/federation-envelope.ts | 8 +- 3 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope-claims.test.ts diff --git a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope-claims.test.ts b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope-claims.test.ts new file mode 100644 index 0000000000..feacea8120 --- /dev/null +++ b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope-claims.test.ts @@ -0,0 +1,109 @@ +/** + * Tests for ADR-101 Component C additions to FederationMessageType. + * + * Asserts that: + * - 'claim-event' and 'agent-handoff' are valid FederationMessageType members + * - 'agent-handoff' is in CONSENSUS_REQUIRED_TYPES (high-trust deployments + * can require validator quorum) + * - 'claim-event' is NOT in CONSENSUS_REQUIRED_TYPES (steady-state gossip + * would deadlock under quorum requirement) + * - existing message types are unchanged (no accidental removals) + * - existing CONSENSUS_REQUIRED_TYPES members are unchanged + */ + +import { describe, expect, it } from 'vitest'; +import { + FederationEnvelope, + CONSENSUS_REQUIRED_TYPES, + type FederationMessageType, +} from '../../src/domain/entities/federation-envelope'; + +describe('FederationMessageType — ADR-101 additions', () => { + it('accepts claim-event as a valid message type', () => { + const env = new FederationEnvelope({ + envelopeId: 'env-1', + sourceNodeId: 'A', + targetNodeId: 'B', + sessionId: 'sess-1', + messageType: 'claim-event', + payload: { event: 'placeholder' }, + timestamp: new Date(), + nonce: 'n-1', + hmacSignature: '', + piiScanResult: FederationEnvelope.emptyScanResult(), + }); + expect(env.messageType).toBe('claim-event'); + }); + + it('accepts agent-handoff as a valid message type', () => { + const env = new FederationEnvelope({ + envelopeId: 'env-2', + sourceNodeId: 'A', + targetNodeId: 'B', + sessionId: 'sess-1', + messageType: 'agent-handoff', + payload: { claimId: 'claim-001', from: 'a@A', to: 'b@B' }, + timestamp: new Date(), + nonce: 'n-2', + hmacSignature: '', + piiScanResult: FederationEnvelope.emptyScanResult(), + }); + expect(env.messageType).toBe('agent-handoff'); + }); + + it('agent-handoff requires consensus by default', () => { + expect(CONSENSUS_REQUIRED_TYPES.has('agent-handoff')).toBe(true); + }); + + it('claim-event does NOT require consensus (steady-state gossip)', () => { + expect(CONSENSUS_REQUIRED_TYPES.has('claim-event')).toBe(false); + }); + + it('preserves the pre-ADR-101 consensus-required set', () => { + // Snapshot the existing membership so future additions don't silently + // expand the consensus-required set. + expect(CONSENSUS_REQUIRED_TYPES.has('trust-change')).toBe(true); + expect(CONSENSUS_REQUIRED_TYPES.has('topology-change')).toBe(true); + expect(CONSENSUS_REQUIRED_TYPES.has('agent-spawn')).toBe(true); + }); + + it('preserves existing message types', () => { + // Type-level smoke test — these must compile. + const existing: FederationMessageType[] = [ + 'task-assignment', + 'memory-query', + 'memory-response', + 'context-share', + 'status-broadcast', + 'trust-change', + 'topology-change', + 'agent-spawn', + 'heartbeat', + 'challenge', + 'challenge-response', + 'handshake-init', + 'handshake-accept', + 'handshake-reject', + 'session-terminate', + ]; + expect(existing.length).toBe(15); + }); + + it('toSignablePayload includes the new message type when set', () => { + const env = new FederationEnvelope({ + envelopeId: 'env-3', + sourceNodeId: 'A', + targetNodeId: 'B', + sessionId: 'sess-1', + messageType: 'agent-handoff', + payload: { claimId: 'claim-001' }, + timestamp: new Date('2026-05-05T12:00:00Z'), + nonce: 'n-3', + hmacSignature: '', + piiScanResult: FederationEnvelope.emptyScanResult(), + }); + const signable = env.toSignablePayload(); + expect(signable).toContain('"messageType":"agent-handoff"'); + expect(signable).toContain('"claim-001"'); + }); +}); diff --git a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope.test.ts b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope.test.ts index f97b1d7e1f..bb02a70cc0 100644 --- a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope.test.ts +++ b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/federation-envelope.test.ts @@ -212,8 +212,8 @@ describe('FederationEnvelope', () => { expect(CONSENSUS_REQUIRED_TYPES.has('agent-spawn')).toBe(true); }); - it('should contain exactly 3 entries', () => { - expect(CONSENSUS_REQUIRED_TYPES.size).toBe(3); + it('should contain exactly 4 entries (ADR-101 added agent-handoff)', () => { + expect(CONSENSUS_REQUIRED_TYPES.size).toBe(4); }); }); @@ -234,17 +234,20 @@ describe('FederationEnvelope', () => { 'handshake-accept', 'handshake-reject', 'session-terminate', + // ADR-101 Component C + 'claim-event', + 'agent-handoff', ]; - it('should accept all 15 message types as valid', () => { + it('should accept all 17 message types as valid', () => { for (const msgType of allMessageTypes) { const envelope = new FederationEnvelope(makeProps({ messageType: msgType })); expect(envelope.messageType).toBe(msgType); } }); - it('should have exactly 15 known message types', () => { - expect(allMessageTypes).toHaveLength(15); + it('should have exactly 17 known message types (15 base + 2 from ADR-101)', () => { + expect(allMessageTypes).toHaveLength(17); }); }); }); diff --git a/v3/@claude-flow/plugin-agent-federation/src/domain/entities/federation-envelope.ts b/v3/@claude-flow/plugin-agent-federation/src/domain/entities/federation-envelope.ts index 1ae5795438..03ed7d97f8 100644 --- a/v3/@claude-flow/plugin-agent-federation/src/domain/entities/federation-envelope.ts +++ b/v3/@claude-flow/plugin-agent-federation/src/domain/entities/federation-envelope.ts @@ -13,7 +13,10 @@ export type FederationMessageType = | 'handshake-init' | 'handshake-accept' | 'handshake-reject' - | 'session-terminate'; + | 'session-terminate' + // ADR-101 Component C: cross-node claims operations + | 'claim-event' // gossip a ClaimDomainEvent across the federation + | 'agent-handoff'; // request to transfer ownership of a claim to a remote agent export type PIIScanAction = 'pass' | 'redact' | 'hash' | 'block'; @@ -116,4 +119,7 @@ export const CONSENSUS_REQUIRED_TYPES: ReadonlySet = new 'trust-change', 'topology-change', 'agent-spawn', + // ADR-101 Component C: handoffs cross trust boundaries — optionally + // require quorum from validators in high-trust deployments. + 'agent-handoff', ]);