Prepare coalesced resolution replay
This commit is contained in:
@@ -520,3 +520,49 @@ func TestExplanationReplaysResolutionAdditionsAndOverlappingIntent(t *testing.T)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplanationReplayDescriptorsRemainDetachedAcrossQueries(t *testing.T) {
|
||||
type config struct {
|
||||
Count int `yaml:"count"`
|
||||
}
|
||||
result, err := testLoad(Bytes("resolution-explanation.yml", []byte("count: 1\n")), Options[config]{
|
||||
Definition: Definition[config]{Resolve: func(value *config, resolution *Resolution) error {
|
||||
value.Count = 2
|
||||
resolution.Record(Keys("count"), ChangeNormalization, "normalized", Keys("count"))
|
||||
return nil
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, ok := result.Explain(Keys("count"))
|
||||
if !ok {
|
||||
t.Fatal("missing explanation")
|
||||
}
|
||||
var firstResolution *ValueChange
|
||||
for index := range first.History {
|
||||
if first.History[index].Origin.Layer == LayerResolution {
|
||||
firstResolution = &first.History[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
if firstResolution == nil || len(firstResolution.Reasons) != 1 || len(firstResolution.Dependencies) != 1 {
|
||||
t.Fatalf("resolution history = %#v", first.History)
|
||||
}
|
||||
firstResolution.Reasons[0] = "mutated"
|
||||
firstResolution.Dependencies[0].segments[0].key = "mutated"
|
||||
|
||||
second, ok := result.Explain(Keys("count"))
|
||||
if !ok {
|
||||
t.Fatal("missing repeated explanation")
|
||||
}
|
||||
for _, change := range second.History {
|
||||
if change.Origin.Layer == LayerResolution {
|
||||
if !reflect.DeepEqual(change.Reasons, []string{"normalized"}) || len(change.Dependencies) != 1 || change.Dependencies[0].String() != "/count" {
|
||||
t.Fatalf("repeated explanation observed caller mutation: %#v", change)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("resolution change missing from repeated explanation: %#v", second.History)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user