78 lines
3.5 KiB
Go
78 lines
3.5 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"git.cin.su/m/Assistant/contracts/work"
|
|
"git.cin.su/m/Assistant/modules/work/domain"
|
|
"testing"
|
|
)
|
|
|
|
func TestGovernedEvolutionExecutesGatesAndLedgerOutcome(t *testing.T) {
|
|
calls := []string{}
|
|
result, err := domain.RunGovernedEvolution("need-1", work.GovernedEvolutionOps{
|
|
CreateCandidate: func() (work.EvolutionCandidate, error) {
|
|
calls = append(calls, "candidate")
|
|
return work.EvolutionCandidate{ID: "candidate-1", ProposalRef: "proposal-1", CreatorIdentity: "creator", RollbackRef: "rollback-plan"}, nil
|
|
},
|
|
Evaluate: func(c work.EvolutionCandidate) (work.EvolutionEvaluation, error) {
|
|
calls = append(calls, "evaluate")
|
|
return work.EvolutionEvaluation{CandidateRef: c.ID, EvaluatorIdentity: "independent", Approved: true, MustNotWorsenPassed: true, EvidenceRefs: []work.EvidenceRef{"eval"}, RecordedAtUnixMillis: 1}, nil
|
|
},
|
|
SandboxBuild: func(work.EvolutionCandidate) (work.EvidenceRef, error) {
|
|
calls = append(calls, "sandbox-build")
|
|
return "sandbox", nil
|
|
},
|
|
Benchmark: func(work.EvolutionCandidate) (work.EvidenceRef, bool, error) {
|
|
calls = append(calls, "benchmark")
|
|
return "benchmark", true, nil
|
|
},
|
|
Canary: func(work.EvolutionCandidate) (work.EvidenceRef, bool, error) {
|
|
calls = append(calls, "canary")
|
|
return "canary", true, nil
|
|
},
|
|
Promote: func(work.EvolutionCandidate, work.EvolutionEvaluation) (string, error) {
|
|
calls = append(calls, "promote")
|
|
return "promotion", nil
|
|
},
|
|
Rollback: func(work.EvolutionCandidate) (string, error) {
|
|
calls = append(calls, "rollback")
|
|
return "rollback", nil
|
|
},
|
|
LearningLedgerOutcome: func(work.GovernedEvolutionResult) (string, error) {
|
|
calls = append(calls, "ledger")
|
|
return "ledger-outcome", nil
|
|
},
|
|
})
|
|
if err != nil || !result.Promoted || result.LearningLedgerOutcomeRef != "ledger-outcome" {
|
|
t.Fatalf("result=%+v err=%v", result, err)
|
|
}
|
|
want := []string{"candidate", "evaluate", "sandbox-build", "benchmark", "canary", "promote", "ledger"}
|
|
if len(calls) != len(want) {
|
|
t.Fatalf("calls=%v", calls)
|
|
}
|
|
for i := range want {
|
|
if calls[i] != want[i] {
|
|
t.Fatalf("calls=%v", calls)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGovernedEvolutionRollsBackOnMustNotWorsenFailure(t *testing.T) {
|
|
rolledBack := false
|
|
result, err := domain.RunGovernedEvolution("need-1", work.GovernedEvolutionOps{
|
|
CreateCandidate: func() (work.EvolutionCandidate, error) {
|
|
return work.EvolutionCandidate{ID: "candidate-1", ProposalRef: "proposal-1", CreatorIdentity: "creator", RollbackRef: "rollback-plan"}, nil
|
|
},
|
|
Evaluate: func(c work.EvolutionCandidate) (work.EvolutionEvaluation, error) {
|
|
return work.EvolutionEvaluation{CandidateRef: c.ID, EvaluatorIdentity: "independent", Approved: true, MustNotWorsenPassed: true, EvidenceRefs: []work.EvidenceRef{"eval"}, RecordedAtUnixMillis: 1}, nil
|
|
},
|
|
SandboxBuild: func(work.EvolutionCandidate) (work.EvidenceRef, error) { return "sandbox", nil }, Benchmark: func(work.EvolutionCandidate) (work.EvidenceRef, bool, error) { return "benchmark", false, nil },
|
|
Promote: func(work.EvolutionCandidate, work.EvolutionEvaluation) (string, error) {
|
|
t.Fatal("promotion bypassed failed benchmark")
|
|
return "", nil
|
|
}, Rollback: func(work.EvolutionCandidate) (string, error) { rolledBack = true; return "rollback-evidence", nil }, LearningLedgerOutcome: func(r work.GovernedEvolutionResult) (string, error) { return "ledger-rollback", nil },
|
|
})
|
|
if err == nil || !rolledBack || result.RollbackRef != "rollback-evidence" || result.Promoted {
|
|
t.Fatalf("result=%+v err=%v", result, err)
|
|
}
|
|
}
|