package domain import "testing" // Normalization rules will change. A v2 signature must never match a v1 one, // or changing them silently regroups history and moves the recurrence counts // eligibility was already decided on. func TestSignatureCarriesItsVersion(t *testing.T) { sig := DebtSignature(DebtOperational, "lease_expired", "workpc-opencode", "internal/herdr") if sig != "v1:operational:lease_expired:workpc-opencode:internal/herdr" { t.Fatalf("signature %q", sig) } // Arity never varies, so a missing part cannot shift the fields left. if got := DebtSignature(DebtPolish, "deferred_finding", "", ""); got != "v1:polish:deferred_finding:-:-" { t.Fatalf("empty parts not padded: %q", got) } } func TestComponentIsTwoSegments(t *testing.T) { for path, want := range map[string]string{ "internal/store/store.go": "internal/store", "internal/herdr/adapter.go": "internal/herdr", "cmd/orchestra-worker/main.go": "cmd/orchestra-worker", "BURNIN.md": "BURNIN.md", "": "", } { if got := DebtComponent(path); got != want { t.Fatalf("component(%q) = %q, want %q", path, got, want) } } } // Imported history predates the events that would have justified it. A // fabricated event id would break the provenance rule the ledger enforces. func TestObservationNeedsExactlyOneProvenance(t *testing.T) { sig := DebtSignature(DebtOperational, "x", "", "") both := DebtObservation{EventID: "e1", LegacyRef: "BURNIN.md:F18", Kind: ObservationBlockReason, Signature: sig} neither := DebtObservation{Kind: ObservationBlockReason, Signature: sig} if both.Validate() == nil || neither.Validate() == nil { t.Fatal("exactly one of event_id and legacy_ref must be required") } for _, ok := range []DebtObservation{ {EventID: "e1", Kind: ObservationBlockReason, Signature: sig}, {LegacyRef: "BURNIN.md:F18", Kind: ObservationBlockReason, Signature: sig}, } { if err := ok.Validate(); err != nil { t.Fatalf("valid observation refused: %v", err) } } stale := DebtObservation{EventID: "e1", Kind: ObservationBlockReason, Signature: "v0:operational:x:-:-"} if stale.Validate() == nil { t.Fatal("a signature from another version must be refused") } }