stemedb/sdk/go/adk/supersede_test.go
jordan b3e8a9a058 feat: Multi-application expansion with chaos testing and community UI
Major additions:
- Community Next.js app (port 18187) for browsing claims with API docs
- stemedb-chaos crate: Fault injection, chaos testing, CRDT properties
- Latent ingestion system: Reddit/FDA ingesters with ADK-Go agents
- Disputed claims handling: Manual review workflows and validation
- Aphoria security scanner: New extractors (SQL injection, command
  injection, weak crypto, TLS version), policy-based ignores, UAT reports
- Docker infrastructure: Dockerfile, docker-compose.yml for full stack
- VulnBank demo: Intentionally vulnerable multi-language test corpus

SDK & API enhancements:
- Source registry handlers for tracking data provenance
- Metrics endpoint
- Skeptic filtering improvements

Code quality:
- Split 14 large files (>500 lines) into focused modules
- All files now under 500-line limit per project guidelines

Documentation:
- Chaos testing guide, circuit breakers, observability docs
- Phase 7 UAT documentation updates
- Martin Kleppmann technical writer agent

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:24:14 -07:00

105 lines
3.0 KiB
Go

package adk
import (
"context"
"encoding/json"
"testing"
"github.com/orchard9/stemedb-go/steme"
)
func TestSupersedeTool(t *testing.T) {
// Track what supersession was created
var capturedParams steme.SupersedeParams
client := &mockClient{
supersedeFunc: func(ctx context.Context, params steme.SupersedeParams) (*steme.SupersedeResult, error) {
capturedParams = params
return &steme.SupersedeResult{
Status: "superseded",
TargetHash: params.TargetHash,
SupersessionType: params.SupersessionType,
Timestamp: 1704067200,
}, nil
},
}
tool := NewSupersedeTool(client)
input := SupersedeInput{
Hash: "abc123def456",
Type: "Invalidate",
Reason: "Proposal treated as approved. See incident INC-2024-001",
NewHash: "def456abc123",
AgentID: "deadbeef00000000000000000000000000000000000000000000000000000000",
Signature: "0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000",
}
inputBytes, err := json.Marshal(input)
if err != nil {
t.Fatalf("failed to marshal input: %v", err)
}
outputBytes, err := tool.Execute(context.Background(), inputBytes)
if err != nil {
t.Fatalf("supersede failed: %v", err)
}
var output SupersedeOutput
if err := json.Unmarshal(outputBytes, &output); err != nil {
t.Fatalf("failed to unmarshal output: %v", err)
}
// Verify output
if !output.Success {
t.Errorf("expected success, got error: %s", output.Error)
}
if output.TargetHash != "abc123def456" {
t.Errorf("expected target hash abc123def456, got %s", output.TargetHash)
}
if output.SupersessionType != "Invalidate" {
t.Errorf("expected supersession type Invalidate, got %s", output.SupersessionType)
}
// Verify captured params
if capturedParams.TargetHash != "abc123def456" {
t.Errorf("expected target hash abc123def456, got %s", capturedParams.TargetHash)
}
if capturedParams.SupersessionType != steme.SupersessionInvalidate {
t.Errorf("expected supersession type Invalidate, got %s", capturedParams.SupersessionType)
}
if capturedParams.Reason != "Proposal treated as approved. See incident INC-2024-001" {
t.Errorf("expected reason about proposal, got %s", capturedParams.Reason)
}
}
func TestParseSupersessionType(t *testing.T) {
tests := []struct {
input string
expected steme.SupersessionType
}{
{"Invalidate", steme.SupersessionInvalidate},
{"invalidate", steme.SupersessionInvalidate},
{"Temporal", steme.SupersessionTemporal},
{"temporal", steme.SupersessionTemporal},
{"Refinement", steme.SupersessionRefinement},
{"RequiresReview", steme.SupersessionRequiresReview},
{"requires_review", steme.SupersessionRequiresReview},
{"Additive", steme.SupersessionAdditive},
{"additive", steme.SupersessionAdditive},
{"unknown", steme.SupersessionInvalidate}, // Default
}
for _, tt := range tests {
result := parseSupersessionType(tt.input)
if result != tt.expected {
t.Errorf("parseSupersessionType(%s) = %v, expected %v", tt.input, result, tt.expected)
}
}
}