| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/event" |
| 7 | "reasonix/internal/evidence" |
| 8 | ) |
| 9 | |
| 10 | // Enabling extensions must never sever the audit channels: every capability |
| 11 | // the trajectory recorder implements has to pass through frontendEventSink. |
| 12 | func TestFrontendEventSinkForwardsAuditCapabilities(t *testing.T) { |
| 13 | inner := &capabilityProbeSink{Sink: event.Discard} |
| 14 | s := newFrontendEventSink(inner, nil) |
| 15 | event.RecordOutcomeProgress(s, evidence.OutcomeSample{Round: 1}) |
| 16 | event.RecordAnchorSafetyAudit(s, event.AnchorSafetyAudit{Mode: "shadow"}) |
| 17 | event.RecordMemoryRecall(s, event.MemoryRecallAudit{Suppressed: "probe"}) |
| 18 | event.RecordDelegationAdmission(s, event.DelegationAdmissionAudit{Tool: "probe"}) |
| 19 | event.RecordContractShadow(s, event.ContractShadowAudit{Verdict: "probe"}) |
| 20 | event.RecordCompletionReport(s, event.CompletionReportAudit{Verdict: "probe"}) |
| 21 | event.RecordWorkspaceMutation(s, event.WorkspaceMutation{ToolName: "write_file"}) |
| 22 | event.RecordRunBudget(s, event.RunBudgetSample{Currency: "USD"}) |
| 23 | if inner.outcome != 1 || inner.recall != 1 || inner.delegation != 1 || inner.contract != 1 || inner.completion != 1 || inner.workspace != 1 || inner.runBudget != 1 || inner.anchorSafety != 1 { |
| 24 | t.Fatalf("audits dropped by frontendEventSink: %+v", inner) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestInboxEventSinkForwardsMissingCapabilities(t *testing.T) { |
| 29 | inner := &capabilityProbeSink{Sink: event.Discard} |
| 30 | s := &inboxEventSink{inner: inner} |
| 31 | event.RecordDelegationAudit(s, evidence.DelegationAudit{}) |
| 32 | event.RecordAnchorSafetyAudit(s, event.AnchorSafetyAudit{Mode: "shadow"}) |
| 33 | event.RecordWorkspaceMutation(s, event.WorkspaceMutation{ToolName: "write_file"}) |
| 34 | event.RecordRunBudget(s, event.RunBudgetSample{Currency: "USD"}) |
| 35 | if inner.delegationAudit != 1 || inner.workspace != 1 || inner.runBudget != 1 || inner.anchorSafety != 1 { |
| 36 | t.Fatalf("host capabilities dropped by inboxEventSink: %+v", inner) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | type capabilityProbeSink struct { |
| 41 | event.Sink |
| 42 | outcome, recall, delegation, delegationAudit, contract, completion, workspace, runBudget, anchorSafety int |
| 43 | } |
| 44 | |
| 45 | func (p *capabilityProbeSink) RecordOutcomeProgress(evidence.OutcomeSample) { p.outcome++ } |
| 46 | func (p *capabilityProbeSink) RecordMemoryRecall(event.MemoryRecallAudit) { p.recall++ } |
| 47 | func (p *capabilityProbeSink) RecordDelegationAdmission(event.DelegationAdmissionAudit) { |
| 48 | p.delegation++ |
| 49 | } |
| 50 | func (p *capabilityProbeSink) RecordContractShadow(event.ContractShadowAudit) { p.contract++ } |
| 51 | func (p *capabilityProbeSink) RecordCompletionReport(event.CompletionReportAudit) { |
| 52 | p.completion++ |
| 53 | } |
| 54 | func (p *capabilityProbeSink) RecordDelegationAudit(evidence.DelegationAudit) { |
| 55 | p.delegationAudit++ |
| 56 | } |
| 57 | func (p *capabilityProbeSink) RecordWorkspaceMutation(event.WorkspaceMutation) { p.workspace++ } |
| 58 | func (p *capabilityProbeSink) RecordRunBudget(event.RunBudgetSample) { p.runBudget++ } |
| 59 | func (p *capabilityProbeSink) RecordAnchorSafetyAudit(event.AnchorSafetyAudit) { p.anchorSafety++ } |
| 60 |