Name a stale package index, rather than reporting a failed install
novox/hq 04-ISSUES/002, which was recorded against HAL and is present here: a machine asking the mirrors for a version they have already replaced gets a 404 from every one of them. The package exists and the declaration is correct — it is the machine's view that is old — and reported as a generic install failure it sends somebody to check the manifest, which is the one thing that is right. It is deliberately not fixed by syncing. `pacman -Sy <pkg>` installs a package built against libraries the machine does not have: a partial upgrade, which this distribution does not support and which surfaces much later as something apparently unrelated. The remedy is a full upgrade, which is a decision about the whole machine rather than something a host does silently while applying one resource. So this says which of the two it is looking at, and leaves the decision where it belongs. Every mirror, not one: a single mirror timing out is transient and retrying is the answer. And the package manager's own words were being discarded entirely — the output was read into `_`. Whatever it said is now part of the failure, which is the rule everywhere else here and was not being followed in the one place the reason only exists in the output.
This commit is contained in:
@@ -345,3 +345,72 @@ func TestAPartialHostRefusesUsersAndAllowsArchives(t *testing.T) {
|
||||
t.Error("a partial host created a user")
|
||||
}
|
||||
}
|
||||
|
||||
// A stale index and a wrong declaration fail identically, and are fixed in completely different
|
||||
// places.
|
||||
//
|
||||
// novox/hq 04-ISSUES/002: the package exists, the declaration is correct, and the machine is
|
||||
// asking the mirrors for a version they have already replaced. Reported as a generic install
|
||||
// failure it sends somebody to check the manifest, which is the one thing that is right.
|
||||
func TestAStaleIndexIsNamedRatherThanReportedAsAFailedInstall(t *testing.T) {
|
||||
said := "error: failed retrieving file 'dnsmasq-2.90-1-x86_64.pkg.tar.zst' from mirror.one : " +
|
||||
"The requested URL returned error: 404\n" +
|
||||
"error: failed retrieving file 'dnsmasq-2.90-1-x86_64.pkg.tar.zst' from mirror.two : " +
|
||||
"The requested URL returned error: 404\n" +
|
||||
"error: failed to commit transaction (failed to retrieve some files)"
|
||||
run := func(context.Context, string, ...string) (string, error) {
|
||||
return said, errors.New("exit status 1")
|
||||
}
|
||||
err := (arch{}).InstallPackage(context.Background(), run, "dnsmasq")
|
||||
if err == nil {
|
||||
t.Fatal("an install that failed reported success")
|
||||
}
|
||||
for _, want := range []string{"stale package index", "upgrading the machine", "partial upgrade"} {
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
t.Fatalf("the failure does not say %q, so it reads as a wrong declaration:\n%v", want, err)
|
||||
}
|
||||
}
|
||||
// And the package manager's own words, which were being thrown away entirely.
|
||||
if !strings.Contains(err.Error(), "404") {
|
||||
t.Fatalf("what the package manager said was discarded:\n%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// An ordinary failure is not dressed up as a stale index: saying "upgrade the machine" about a
|
||||
// package that does not exist sends somebody to do something large and useless.
|
||||
func TestAnOrdinaryInstallFailureIsNotCalledAStaleIndex(t *testing.T) {
|
||||
run := func(context.Context, string, ...string) (string, error) {
|
||||
return "error: target not found: nosuchpackage", errors.New("exit status 1")
|
||||
}
|
||||
err := (arch{}).InstallPackage(context.Background(), run, "nosuchpackage")
|
||||
if err == nil {
|
||||
t.Fatal("an install that failed reported success")
|
||||
}
|
||||
if strings.Contains(err.Error(), "stale package index") {
|
||||
t.Fatalf("a package that does not exist was called a stale index:\n%v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "target not found") {
|
||||
t.Fatalf("what the package manager said was discarded:\n%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// One mirror failing is transient and retrying is the answer. Every mirror saying the file is gone
|
||||
// is the index being old.
|
||||
func TestOneMirrorFailingIsNotAStaleIndex(t *testing.T) {
|
||||
run := func(context.Context, string, ...string) (string, error) {
|
||||
return "warning: failed retrieving file 'x.pkg.tar.zst' from mirror.one : timeout",
|
||||
errors.New("exit status 1")
|
||||
}
|
||||
err := (arch{}).InstallPackage(context.Background(), run, "x")
|
||||
if err != nil && strings.Contains(err.Error(), "stale package index") {
|
||||
t.Fatalf("one mirror timing out was called a stale index:\n%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// And an install that works still works.
|
||||
func TestAnInstallThatSucceedsSaysNothing(t *testing.T) {
|
||||
run := func(context.Context, string, ...string) (string, error) { return "installed", nil }
|
||||
if err := (arch{}).InstallPackage(context.Background(), run, "dnsmasq"); err != nil {
|
||||
t.Fatalf("a successful install reported a failure: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user