forked from longtao.wu/droboticflow
74 lines
3.9 KiB
Go
74 lines
3.9 KiB
Go
package workforcestats
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"testing"
|
|
)
|
|
|
|
func TestOutputProblemsKeepOriginalReviewerAndLatestRevocation(t *testing.T) {
|
|
d := OutputSnapshot{
|
|
Items: []domain.HumanItemRecord{{ID: "item", LegacyTaskID: "task"}},
|
|
Operations: []domain.ReviewOperation{
|
|
{ID: "qc1", StageID: "quality_review", Status: "completed", Decision: "rejected", UserID: "A", ReviewerSupplierID: "original"},
|
|
{ID: "qc2", StageID: "quality_review", Status: "completed", Decision: "rejected", UserID: "B"},
|
|
{ID: "accept", StageID: "prepackage_acceptance", Status: "completed", Decision: "rejected", UserID: "C", Draft: domain.ReviewDraft{Problems: []domain.ReviewProblem{{ID: "ap", SourceItemID: "item", Scope: "slice"}, {ID: "foreign", SourceItemID: "other", Scope: "slice"}}}},
|
|
},
|
|
Baselines: []domain.ReworkBaselineRecord{
|
|
{ItemID: "item", Round: 1, ReviewOperationID: "qc1", CreatedAt: "2026-10-01T00:00:00Z", Problems: []domain.ReviewProblem{{ID: "p", Scope: "slice"}}},
|
|
{ItemID: "item", Round: 2, ReviewOperationID: "qc2", CreatedAt: "2026-10-02T00:00:00Z", Problems: []domain.ReviewProblem{{ID: "p", Scope: "slice"}, {ID: "p2", Scope: "slice"}, {ID: "task", Scope: "task"}}},
|
|
},
|
|
Handlings: []domain.ReworkHandlingRecord{
|
|
{ID: "item:handling:1", SkippedOpinionIDs: []string{"p"}, UpdatedAt: "2026-10-01T01:00:00Z"},
|
|
{ID: "item:handling:2", SkippedOpinionIDs: []string{}, UpdatedAt: "2026-10-02T01:00:00Z"},
|
|
{ID: "item:acceptance-handling:accept", SkippedOpinionIDs: []string{"ap"}},
|
|
},
|
|
}
|
|
facts := buildOutputProblems(d, []OutputWorkFact{{Part: 0, TaskID: "task"}})
|
|
if len(facts) != 3 {
|
|
t.Fatalf("duplicate/carried/foreign opinions: %+v", facts)
|
|
}
|
|
owners := map[string]OutputProblemFact{}
|
|
for _, f := range facts {
|
|
owners[f.User] = f
|
|
}
|
|
if owners["A"].Misreported || owners["A"].Supplier != "original" || !owners["C"].Misreported {
|
|
t.Fatalf("attribution/revocation: %+v", facts)
|
|
}
|
|
d.Handlings[1].SkippedOpinionIDs = []string{"p"}
|
|
facts = buildOutputProblems(d, []OutputWorkFact{{Part: 0, TaskID: "task"}})
|
|
for _, f := range facts {
|
|
if f.User == "A" && !f.Misreported {
|
|
t.Fatal("mark was not restored")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMissingLegacyOpinionEvidenceDoesNotProduceFalseRate(t *testing.T) {
|
|
d := OutputSnapshot{Reviews: []domain.AnnotationReviewRecord{{ID: "legacy", TaskID: "t", ReviewerUserID: "qc", Decision: domain.AnnotationReviewRejected}}}
|
|
facts := buildOutputProblems(d, []OutputWorkFact{{TaskID: "t", Part: 0}})
|
|
facts = append(facts, OutputProblemFact{Part: 0, Role: OutputRoleQuality, User: "qc", Misreported: true})
|
|
rows := CohortQuality(OutputDataset{Parts: []OutputPartFact{{ID: "p"}}, Problems: facts}, OutputQuery{})
|
|
if len(rows) != 1 || rows[0].Misreport.Value != nil || rows[0].Misreport.Unknown != 1 {
|
|
t.Fatalf("partial evidence fabricated ratio %+v", rows)
|
|
}
|
|
}
|
|
|
|
func TestAcceptanceForwardedOpinionsDoNotBecomeQualityPoints(t *testing.T) {
|
|
origin := &domain.ReviewProblemOrigin{StageID: "prepackage_acceptance", OperationID: "accept", ProblemID: "a", UserID: "acceptor"}
|
|
d := OutputSnapshot{Items: []domain.HumanItemRecord{{ID: "item", LegacyTaskID: "task"}}, Operations: []domain.ReviewOperation{
|
|
{ID: "accept", StageID: "prepackage_acceptance", Status: "completed", Decision: "rejected", UserID: "acceptor", Draft: domain.ReviewDraft{Problems: []domain.ReviewProblem{{ID: "a", SourceItemID: "item", Scope: "slice"}}}},
|
|
{ID: "qc", StageID: "quality_review", Status: "completed", Decision: "rejected", UserID: "reviewer"},
|
|
}, Baselines: []domain.ReworkBaselineRecord{{ItemID: "item", ReviewOperationID: "qc", Problems: []domain.ReviewProblem{{ID: "forward", Scope: "slice", Origin: origin}, {ID: "qc-new", Scope: "slice"}}}}}
|
|
facts := buildOutputProblems(d, []OutputWorkFact{{Part: 0, TaskID: "task"}})
|
|
if len(facts) != 2 {
|
|
t.Fatalf("forwarded opinion counted twice: %+v", facts)
|
|
}
|
|
counts := map[string]int{}
|
|
for _, f := range facts {
|
|
counts[f.User]++
|
|
}
|
|
if counts["acceptor"] != 1 || counts["reviewer"] != 1 {
|
|
t.Fatal(counts)
|
|
}
|
|
}
|