fix(assessment): require the leak to agree with a statement before its landmark

This commit is contained in:
shira committed 2026-10-11 15:03:14 +03:00
1 parent 754c745fba
commit 3de226b16c
3 files changed
+95 -6

No files matched your search

@@ -331,6 +331,37 @@ func TestTheLeakOfADeletedAttemptIsNotAttributedToAnotherVariantOfItsFamily(t *t
}
}
// A family whose first phrase follows the size of the task: the text before the
// phrase differs between variants, and only the closing sentence is shared.
func dependencyOrderStatement(jobs int, dependencies string) string {
return fmt.Sprintf("A worker runs %[1]d jobs numbered from 1 to %[1]d, one at a time. A dependency A->B means job A must finish before job B starts. "+
"The dependencies are: %[2]s. The dependencies contain no cycle, so at least one valid order exists. "+
"Among all execution orders that respect every dependency, choose the one that is smallest when compared number by number from the first position. "+
"Write that order as job numbers separated by single spaces.", jobs, dependencies)
}
func TestTheLeakOfADeletedAttemptIsNotAttributedToAVariantThatSharesOnlyTheClosingSentence(t *testing.T) {
repository := &leakRepositoryFake{}
deleted, left := domain.AssessmentAttemptID(uuid.New()), domain.AssessmentAttemptID(uuid.New())
// The attempt that is left was served the same family with other numbers, so
// the closing sentence of the leak is the only text that its statement shares.
repository.serve(left, dependencyOrderStatement(5, "3->4 2->5 2->4 2->1 1->4"))
repository.serve(left, dependencyOrderStatement(8, "6->2 4->6 2->7 8->4"))
tracer := newLeakTracer(t, repository)
leak := domain.VisibleAssessmentText(leakWatermark(t, deleted).Mark(dependencyOrderStatement(9, "7->2 9->4 2->9 6->2")))
result := traceAs(t, tracer, leak, "")
if result.Status != domain.AssessmentLeakTraceNotFound || !result.AttemptID.IsZero() {
t.Fatalf("result = %+v, want not found: the statements that are left differ from the leak before their shared closing sentence", result)
}
// The attempt that holds the leaked variant is still found among the others.
repository.serve(deleted, dependencyOrderStatement(9, "7->2 9->4 2->9 6->2"))
found := traceAs(t, tracer, leak, "")
if found.Status != domain.AssessmentLeakTraceFound || found.AttemptID != deleted || found.Candidates != 1 {
t.Fatalf("result = %+v, want the attempt that holds the leaked variant and none of the others", found)
}
}
func TestACutLeakIsFoundButOtherWordsInsideTheStatementAreNot(t *testing.T) {
repository := &leakRepositoryFake{}
ids := attemptsThatWriteTheStatementDifferently(t, 1)