stemedb/sdk/go/steme/assertion_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

131 lines
3.2 KiB
Go

package steme
import (
"testing"
)
// TestAssertionBuilder tests the fluent assertion builder API.
func TestAssertionBuilder(t *testing.T) {
lifecycle := LifecycleApproved
sourceClass := SourceClassClinical
assertion := NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithConfidence(0.95).
WithLifecycle(lifecycle).
WithSourceClass(sourceClass).
WithSourceHash("0000000000000000000000000000000000000000000000000000000000000000").
Build()
if assertion.Subject != "Tesla_Inc" {
t.Errorf("Subject = %s, want Tesla_Inc", assertion.Subject)
}
if assertion.Predicate != "has_revenue" {
t.Errorf("Predicate = %s, want has_revenue", assertion.Predicate)
}
if assertion.Object.Type != "Number" {
t.Errorf("Object.Type = %s, want Number", assertion.Object.Type)
}
if assertion.Object.Value != 96.7 {
t.Errorf("Object.Value = %v, want 96.7", assertion.Object.Value)
}
if assertion.Confidence != 0.95 {
t.Errorf("Confidence = %f, want 0.95", assertion.Confidence)
}
if assertion.Lifecycle == nil || *assertion.Lifecycle != LifecycleApproved {
t.Errorf("Lifecycle = %v, want Approved", assertion.Lifecycle)
}
if assertion.SourceClass == nil || *assertion.SourceClass != SourceClassClinical {
t.Errorf("SourceClass = %v, want Clinical", assertion.SourceClass)
}
}
// TestAssertionValidation tests assertion validation.
func TestAssertionValidation(t *testing.T) {
tests := []struct {
name string
build func() Assertion
wantErr bool
}{
{
name: "valid assertion",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithConfidence(0.95).
WithSourceHash("0000000000000000000000000000000000000000000000000000000000000000").
Build()
},
wantErr: false,
},
{
name: "confidence too high",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithConfidence(1.5).
WithSourceHash("0000000000000000000000000000000000000000000000000000000000000000").
Build()
},
wantErr: true,
},
{
name: "confidence negative",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithConfidence(-0.1).
WithSourceHash("0000000000000000000000000000000000000000000000000000000000000000").
Build()
},
wantErr: true,
},
{
name: "missing source_hash",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
Build()
},
wantErr: true,
},
{
name: "invalid source_hash length",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithSourceHash("00").
Build()
},
wantErr: true,
},
{
name: "invalid source_hash hex",
build: func() Assertion {
return NewAssertion("Tesla_Inc", "has_revenue").
WithNumber(96.7).
WithSourceHash("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz").
Build()
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assertion := tt.build()
err := assertion.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}