fix(releaseupdate): don't treat empty available as deferred
Service.Check matched deferred[component.ID] == component.Available, and a never-deferred recipient's absent entry is the empty string -- equal to an empty Available emitted for a component with no update. Guard on a real (non-empty) available version before applying the deferral, so an up-to-date recipient is not told their update is deferred. No WIRE/DELETE decision applies: this is a correctness fix on a live consumer, not unreachable code.
This commit is contained in:
1 parent
0a73394c23
commit
72d80f1dfc
2 files changed
+25
-1
No files matched your search
@@ -147,7 +147,7 @@ func (s *Service) Check(ctx context.Context, recipient int64) (Snapshot, error)
|
||||
deferred := state[strconv.FormatInt(recipient, 10)]
|
||||
for index := range snapshot.Components {
|
||||
component := &snapshot.Components[index]
|
||||
if deferred[component.ID] == component.Available {
|
||||
if component.Available != "" && deferred[component.ID] == component.Available {
|
||||
component.Available = ""
|
||||
snapshot.Deferred = true
|
||||
}
|
||||
|
||||
@@ -50,6 +50,30 @@ func TestServiceDefersOnlyTheVersionsShownToThatRecipient(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestServiceCheckNeverDeferredEmptyAvailable pins the empty-Available
|
||||
// combination: for a recipient who has never deferred a component (or a
|
||||
// component absent from the deferral map), deferred[component.ID] is the
|
||||
// empty string, and a component with no available update also has an empty
|
||||
// Available. "" == "" must not read as a deferral -- that tells an
|
||||
// up-to-date recipient their update is "deferred".
|
||||
func TestServiceCheckNeverDeferredEmptyAvailable(t *testing.T) {
|
||||
catalog := &catalogStub{snapshot: Snapshot{Components: []Component{
|
||||
{ID: ComponentDaemon, Label: "Gateway", Installed: "1.0.0", Available: ""},
|
||||
}}}
|
||||
service := Service{Catalog: catalog, StatePath: filepath.Join(t.TempDir(), "deferrals.json")}
|
||||
|
||||
snapshot, err := service.Check(context.Background(), 42)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if snapshot.Deferred {
|
||||
t.Error("Deferred = true for a never-deferred recipient with no available update")
|
||||
}
|
||||
if got := snapshot.Components[0].Available; got != "" {
|
||||
t.Errorf("Available = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestServiceCheckEnrichesInstallTypeAndReference is the regression proof
|
||||
// for archie-core-1786751948782-3-837a8fd0 point 4: the external check
|
||||
// command reports what version exists, not how this instance was actually
|
||||
|
||||
Reference in new issue
Block a user