feat(work): schedule task evaluation through work graph
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
)
|
||||
|
||||
func evaluationGraphRequest(stage capability.TaskEvaluationProfileStage) work.TaskEvaluationGraphRequest {
|
||||
profile := capability.TaskEvaluationProfile{ID: "profile-1", Revision: 1, CapabilityID: "capability-1", Stage: stage, BenchmarkVersion: "general-v1", RequiredCaseIDs: []string{"case-a", "case-b"}, QualityWeightMillis: 600, ReliabilityWeightMillis: 300, LatencyWeightMillis: 100}
|
||||
request := work.TaskEvaluationGraphRequest{GraphID: "graph-1", Profile: profile, BindingIDs: []capability.CapabilityBindingID{"binding-a", "binding-b"}, DispatchIDs: []string{"dispatch-a", "dispatch-b"}, IdempotencyPrefix: "task-eval", Budget: work.GraphBudget{MaxParallel: 2, MaxAttempts: 2}}
|
||||
if stage == capability.TaskEvaluationAdditional {
|
||||
request.Profile.ParentProfileID = "profile-general"
|
||||
request.Profile.TriggerEvidenceRef = "artifact:unresolved-1"
|
||||
request.Profile.Stage = capability.TaskEvaluationAdditional
|
||||
request.ParentGraphID, request.ParentGraphRevision, request.ParentGraphState, request.TriggerEvidenceRef = "graph-general", 2, work.GraphPartial, "artifact:unresolved-1"
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
func TestBuildTaskEvaluationGraphFansOutOneNodePerBinding(t *testing.T) {
|
||||
graph, err := BuildTaskEvaluationGraph(evaluationGraphRequest(capability.TaskEvaluationGeneral))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(graph.Nodes) != 2 || graph.Nodes[0].Purpose != work.GraphNodePurposeTaskEvaluation || graph.Nodes[0].TaskProfileID != "profile-1" || len(graph.Nodes[0].CaseIDs) != 2 {
|
||||
t.Fatalf("unexpected task graph nodes: %+v", graph.Nodes)
|
||||
}
|
||||
if graph.ParentGraphID != "" || graph.TriggerEvidenceRef != "" {
|
||||
t.Fatalf("general graph unexpectedly has expansion lineage: %+v", graph)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTaskEvaluationGraphRequiresCompletedOrPartialGeneralParent(t *testing.T) {
|
||||
request := evaluationGraphRequest(capability.TaskEvaluationAdditional)
|
||||
request.ParentGraphState = work.GraphRunning
|
||||
if _, err := BuildTaskEvaluationGraph(request); err == nil {
|
||||
t.Fatal("expected additional graph to require a finished parent graph")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTaskEvaluationGraphRejectsGeneralReplacement(t *testing.T) {
|
||||
request := evaluationGraphRequest(capability.TaskEvaluationGeneral)
|
||||
request.ParentGraphID = "old-graph"
|
||||
request.ParentGraphRevision = 2
|
||||
request.ParentGraphState = work.GraphPartial
|
||||
request.TriggerEvidenceRef = "artifact:unresolved"
|
||||
if _, err := BuildTaskEvaluationGraph(request); err == nil {
|
||||
t.Fatal("expected general graph replacement to be rejected")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user