mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
feat(federation): ADR-101 Phase 3 — claim-event + agent-handoff message types
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 <ruv@ruv.net>
This commit is contained in:
1 parent
edc39f7da6
commit
cc6af4b77c
3 files changed
+124
-6
No files matched your search
+109
@@ -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"');
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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<FederationMessageType> = 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',
|
||||
]);
|
||||
Reference in new issue
Block a user