fix(purge): preserve transitive live dependents (#7041)
Propagate sweep protection through closed candidates so an open descendant keeps every candidate ancestor in its protecting dependency chain. Cover the shared helper, dry-run, real sweep, and all storage contract wirings. Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Rongjun GENG
This commit is contained in:
parent
4524f4a428
commit
5db60f42ac
7 changed files with 102 additions and 6 deletions
|
|
@ -667,6 +667,7 @@ var roleContractCases = []roleContract{
|
|||
RunSweeperWispsPlaneClearsTheWholeWispsTable,
|
||||
RunSweeperWispsPlaneRequiresAFilter,
|
||||
RunSweeperProtectsLiveDependents,
|
||||
RunSweeperProtectsTransitiveLiveDependents,
|
||||
RunSweeperProtectsLiveDependentsAcrossPlanes,
|
||||
RunSweeperLimitTakesTheOldestClosedFirst,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -747,6 +747,49 @@ func RunSweeperProtectsLiveDependents(t *testing.T, ctx context.Context, fixture
|
|||
sweeperAssertWispRows(t, ctx, fixture, 4, openChild, convoy, hooked, relater)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsTransitiveLiveDependents pins that protection propagates
|
||||
// through closed candidates: an open grandchild keeps both its closed parent
|
||||
// and closed grandparent. Otherwise sweeping the grandparent orphans a live
|
||||
// hierarchy even though the direct parent was correctly retained.
|
||||
func RunSweeperProtectsTransitiveLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
if fixture.AddDependencies == nil {
|
||||
t.Skip("fixture has no AddDependencies hook; cannot wire the hierarchy this case needs")
|
||||
}
|
||||
root := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "root", true), nil)
|
||||
middle := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "middle", true), nil)
|
||||
leafIssue := sweeperIssue(fixture, "transitive", "leaf", true)
|
||||
leafIssue.Status = types.StatusOpen
|
||||
leafIssue.ClosedAt = nil
|
||||
leaf := sweeperSeed(t, ctx, fixture, leafIssue, nil)
|
||||
|
||||
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
|
||||
Actor: "sweeper-seed",
|
||||
Edges: []publicops.DependencyEdge{
|
||||
{IssueID: middle, DependsOnID: root, Type: publicops.DepParentChild},
|
||||
{IssueID: leaf, DependsOnID: middle, Type: publicops.DepParentChild},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("wiring transitive hierarchy: %v", err)
|
||||
}
|
||||
|
||||
request := publicops.SweepRequest{
|
||||
Tier: publicops.SweepWispsPlane,
|
||||
IDPattern: sweeperPattern(fixture, "transitive"),
|
||||
ClosedBefore: &sweeperCutoff,
|
||||
ProtectLiveDependents: true,
|
||||
}
|
||||
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if preview.Swept != 0 || preview.Skipped.LiveDependent != 2 {
|
||||
t.Fatalf("dry run: Swept = %d, LiveDependent = %d; want 0 and 2", preview.Swept, preview.Skipped.LiveDependent)
|
||||
}
|
||||
result := sweeperSweep(t, ctx, fixture, request)
|
||||
if result.Swept != 0 || result.Skipped.LiveDependent != 2 {
|
||||
t.Fatalf("sweep: Swept = %d, LiveDependent = %d; want 0 and 2", result.Swept, result.Skipped.LiveDependent)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 3, root, middle, leaf)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsLiveDependentsAcrossPlanes pins that the live-dependent
|
||||
// protection reads BOTH dependency tables: a closed wisp that a live DURABLE
|
||||
// (issues-table) bead depends on through parent-child, tracks or blocks is
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ func TestSweeperContract(t *testing.T) {
|
|||
t.Run("ProtectsLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsTransitiveLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsTransitiveLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsLiveDependentsAcrossPlanes", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependentsAcrossPlanes(t, ctx, fixture)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ func TestSweeperContract(t *testing.T) {
|
|||
t.Run("ProtectsLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsTransitiveLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsTransitiveLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsLiveDependentsAcrossPlanes", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependentsAcrossPlanes(t, ctx, fixture)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ func TestSweeperContract(t *testing.T) {
|
|||
t.Run("ProtectsLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsTransitiveLiveDependents", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsTransitiveLiveDependents(t, ctx, fixture)
|
||||
})
|
||||
t.Run("ProtectsLiveDependentsAcrossPlanes", func(t *testing.T) {
|
||||
conformance.RunSweeperProtectsLiveDependentsAcrossPlanes(t, ctx, fixture)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -332,18 +332,37 @@ func SweepLiveDependentSources(incoming map[string][]*types.Dependency) []string
|
|||
return ids
|
||||
}
|
||||
|
||||
// SweepLiveDependentTargets returns the candidates a live row depends on: the
|
||||
// targets of protecting edges whose source is in live.
|
||||
// SweepLiveDependentTargets returns the candidates a live row depends on,
|
||||
// directly or through other candidates. A protected closed candidate must act
|
||||
// as live for the next edge up the chain; otherwise an open grandchild keeps
|
||||
// its closed parent while the same sweep deletes the closed grandparent.
|
||||
func SweepLiveDependentTargets(incoming map[string][]*types.Dependency, live map[string]bool) map[string]bool {
|
||||
protected := make(map[string]bool)
|
||||
targetsBySource := make(map[string][]string)
|
||||
for target, deps := range incoming {
|
||||
for _, dep := range deps {
|
||||
if dep != nil && isSweepProtectingEdge(dep.Type) && live[dep.IssueID] {
|
||||
protected[target] = true
|
||||
break
|
||||
if dep != nil && isSweepProtectingEdge(dep.Type) {
|
||||
targetsBySource[dep.IssueID] = append(targetsBySource[dep.IssueID], target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected := make(map[string]bool)
|
||||
queue := make([]string, 0, len(live))
|
||||
for id, isLive := range live {
|
||||
if isLive {
|
||||
queue = append(queue, id)
|
||||
}
|
||||
}
|
||||
for next := 0; next < len(queue); next++ {
|
||||
source := queue[next]
|
||||
for _, target := range targetsBySource[source] {
|
||||
if protected[target] {
|
||||
continue
|
||||
}
|
||||
protected[target] = true
|
||||
queue = append(queue, target)
|
||||
}
|
||||
}
|
||||
return protected
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -430,6 +430,30 @@ func TestSweepLiveDependentsCountOnlyProtectingEdgesFromLiveSources(t *testing.T
|
|||
}
|
||||
}
|
||||
|
||||
func TestSweepLiveDependentTargetsPropagatesThroughProtectedCandidates(t *testing.T) {
|
||||
dep := func(source, target string) *types.Dependency {
|
||||
return &types.Dependency{IssueID: source, DependsOnID: target, Type: types.DepParentChild}
|
||||
}
|
||||
incoming := map[string][]*types.Dependency{
|
||||
"root": {dep("middle", "root")},
|
||||
"middle": {dep("leaf", "middle")},
|
||||
"cycle-a": {dep("cycle-b", "cycle-a")},
|
||||
"cycle-b": {dep("cycle-a", "cycle-b")},
|
||||
}
|
||||
|
||||
protected := SweepLiveDependentTargets(incoming, map[string]bool{"leaf": true})
|
||||
for _, id := range []string{"middle", "root"} {
|
||||
if !protected[id] {
|
||||
t.Errorf("%s not protected; it is transitively depended on by a live source", id)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"cycle-a", "cycle-b"} {
|
||||
if protected[id] {
|
||||
t.Errorf("%s protected without a live path into its closed cycle", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSweepRequestRefusesANegativeLimit(t *testing.T) {
|
||||
err := ValidateSweepRequest(issueops.SweepRequest{Tier: issueops.SweepEphemeral, Limit: -1})
|
||||
if !errors.Is(err, issueops.ErrValidation) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue