fix(harness): explain when a winget package is missing from the catalog (#8823)

* fix: explain when a winget package is missing from the catalog

* fix(harness): suggest winget source update before installing another way
This commit is contained in:
iamsiddhesh-dev authored and GitHub committed 2026-11-22 23:02:38 +05:30
1 parent 20595bca93
commit 7c65ce3cfc
2 files changed
+77

No files matched your search

@@ -1501,6 +1501,12 @@ func (s *Service) runAgentOperation(parent context.Context, plan Plan, operation
if plan.Target == TargetCursor && strings.Contains(out.String(), "[unauthenticated]") {
message = fmt.Sprintf("Cursor's update service rejected the CLI's saved login. Log out of Cursor, update, then log in again. (%v)", runErr)
}
// winget reports "no package found" for an ID its catalog dropped, and
// also when its local source data is stale. Suggest refreshing the
// sources first; if it still fails, the package is gone from the catalog.
if plan.Method == "winget" && wingetPackageNotFound(runErr) {
message = fmt.Sprintf("winget could not find package %s. Run `winget source update` and retry. If it still fails, the package is no longer in the winget catalog, so install it another way, then choose Verify again. (%v)", plan.Package, runErr)
}
s.finishAgentJob(job, StatusFailed, out.String(), message, "")
return
}
@@ -1519,6 +1525,18 @@ func (s *Service) runAgentOperation(parent context.Context, plan Plan, operation
s.runAgentVerification(s.backgroundContext, job, baseline, updaterReport)
}
// wingetNoApplicationsFound is APPINSTALLER_CLI_ERROR_NO_APPLICATIONS_FOUND,
// winget's exit code for an ID its catalog does not have. Matching the code,
// not winget's "No package found" text, keeps this working in every locale.
const wingetNoApplicationsFound uint32 = 0x8A150014
func wingetPackageNotFound(err error) bool {
var exited interface{ ExitCode() int }
// Go reports Windows exit codes unsigned; compare the low 32 bits so a
// signed report of the same code matches too.
return errors.As(err, &exited) && uint32(exited.ExitCode()) == wingetNoApplicationsFound //nolint:gosec // exit codes are 32-bit
}
// maxUpdaterReportRunes keeps the updater line quoted in a failed update
// short enough for the update notice.
const maxUpdaterReportRunes = 80
@@ -801,6 +801,65 @@ func TestCursorRejectedLoginUpdateExplainsRecovery(t *testing.T) {
}
}
// exitCodeError is an *exec.ExitError stand-in: the install runner returns
// the command's exit code through ExitCode().
type exitCodeError struct {
code int
message string
}
func (e exitCodeError) Error() string { return e.message }
func (e exitCodeError) ExitCode() int { return e.code }
func TestWingetPackageNotFoundExplainsRecovery(t *testing.T) {
// winget exits APPINSTALLER_CLI_ERROR_NO_APPLICATIONS_FOUND (0x8A150014)
// for an ID the catalog no longer has, e.g. SST.opencode since November 2026,
// and also when its local source data is stale, so the message suggests
// refreshing the sources before installing another way.
// Go reports the code unsigned; PowerShell's $LASTEXITCODE shows it signed.
const notFound = "No package found matching input criteria.\n"
for _, tc := range []struct {
name string
method string
err error
wantHint bool
}{
{name: "missing package", method: "winget", err: exitCodeError{code: 0x8A150014, message: "exit status 0x8a150014"}, wantHint: true},
{name: "missing package, signed code", method: "winget", err: exitCodeError{code: -1978335212, message: "exit status 0x8a150014"}, wantHint: true},
{name: "other winget failure", method: "winget", err: exitCodeError{code: 1, message: "exit status 1"}},
{name: "same code from another method", method: "npm", err: exitCodeError{code: 0x8A150014, message: "exit status 0x8a150014"}},
} {
t.Run(tc.name, func(t *testing.T) {
s := newTestService("windows", "winget")
t.Cleanup(s.stop)
s.commands = commandRunnerFunc(func(_ context.Context, _ []string, stdout, _ io.Writer) error {
_, _ = io.WriteString(stdout, notFound)
return tc.err
})
s.verifier = harnessVerifierFunc(func(context.Context, Target) (VerifyResult, error) {
t.Fatal("a failed install must not be verified")
return VerifyResult{}, nil
})
plan := Plan{Target: TargetOpencode, Method: tc.method, Package: "SST.opencode", Command: []string{"winget", "install", "-e", "--id", "SST.opencode"}}
job := &Job{Target: TargetOpencode, Status: StatusInstalling}
s.jobs[TargetOpencode] = job
s.runAgentOperation(t.Context(), plan, AgentOperationInstall, job, nil)
if job.Status != StatusFailed || job.Output != notFound {
t.Fatalf("job = %+v, want failure with original diagnostics", job)
}
if tc.wantHint {
for _, want := range []string{"SST.opencode", "winget source update", "retry", "no longer in the winget catalog", "install it another way", "Verify again", "exit status 0x8a150014"} {
if !strings.Contains(job.Error, want) {
t.Fatalf("error = %q, want %q", job.Error, want)
}
}
} else if job.Error != tc.err.Error() {
t.Fatalf("unrelated error was rewritten: %q", job.Error)
}
})
}
}
func TestAgentVendorScriptInstallPreservesPlanEnvironment(t *testing.T) {
s := newTestService("windows", "pwsh.exe")
captured := make(chan ports.InstallScriptCommand, 1)