Fix virtual package parsing issue and add test case

Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-30 07:34:11 +00:00
parent 1a07661c6e
commit 60332806e6
6 changed files with 34 additions and 1 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
src/cmd/apt_query/apt_query*
src/cmd/apt_query/apt_query*
apt_query_test*

Binary file not shown.

View file

View file

@ -68,3 +68,10 @@ func TestNormalizedList_VirtualPackagesExists_StdoutsConcretePackage(t *testing.
result := cmdtesting.New(t, createReplayLogs).Run("normalized-list", "libvips")
result.ExpectSuccessfulOut("libvips42=8.9.1-2")
}
func TestNormalizedList_VirtualPackageWithNoProviders_StderrsErrorMessage(t *testing.T) {
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list", "python")
result.ExpectError(`Encountered error resolving some or all package names, see combined std[out,err] below.
virtual package 'python' has no concrete package providers
virtual package 'python' has no concrete package providers`)
}

View file

@ -0,0 +1,18 @@
2025/09/30 07:33:25 Debug log created at /home/runner/work/cache-apt-pkgs-action/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
2025/09/30 07:33:26 EXECUTION-OBJ-START
{
"Cmd": "apt-cache --quiet=0 --no-all-versions show python",
"CombinedOut": "N: Can't select candidate version from package python as it has no candidate\nN: Can't select versions from package 'python' as it is purely virtual\nN: No packages found\n",
"ExitCode": 0
}
EXECUTION-OBJ-END
2025/09/30 07:33:27 EXECUTION-OBJ-START
{
"Cmd": "bash -c apt-cache showpkg python | grep -A 1 \"Reverse Provides\" | tail -1",
"CombinedOut": "Reverse Provides: \n",
"ExitCode": 0
}
EXECUTION-OBJ-END
2025/09/30 07:33:27 Encountered error resolving some or all package names, see combined std[out,err] below.
virtual package 'python' has no concrete package providers
virtual package 'python' has no concrete package providers

View file

@ -42,6 +42,13 @@ func getNonVirtualPackage(executor exec.Executor, name string) (pkg *AptPackage,
if isErrLine(execution.CombinedOut) {
return pkg, execution.Error()
}
// Check if the output is just "Reverse Provides:" with no actual package info
trimmedOutput := strings.TrimSpace(execution.CombinedOut)
if trimmedOutput == "Reverse Provides:" {
return pkg, fmt.Errorf("virtual package '%s' has no concrete package providers", name)
}
splitLine := GetSplitLine(execution.CombinedOut, " ", 3)
if len(splitLine.Words) < 2 {
return pkg, fmt.Errorf("unable to parse space delimited line's package name and version from apt-cache showpkg output below:\n%s", execution.CombinedOut)