Skip to content

fix: filter phantom package paths from ResolvePackagePaths#190

Merged
em-redhat merged 3 commits into
unbound-force:mainfrom
em-redhat:opsx/fix-phantom-package-paths
Jul 14, 2026
Merged

fix: filter phantom package paths from ResolvePackagePaths#190
em-redhat merged 3 commits into
unbound-force:mainfrom
em-redhat:opsx/fix-phantom-package-paths

Conversation

@em-redhat

Copy link
Copy Markdown
Contributor

Summary

Fixes #104 -- loader.ResolvePackagePaths did not check pkg.Errors on
packages returned by go/packages.Load. When a pattern doesn't resolve to a
real package, go/packages returns a synthetic *packages.Package with
PkgPath set to the input pattern and Errors populated. The filter only
rejected empty/duplicate/_test paths, so phantom paths were returned as valid.

This fix adds pkg.Errors filtering and an io.Writer parameter for warning
output, following the project's established stderr injection pattern.

How to Test

# Run the new regression test (requires go/packages.Load -- no -short flag):
go test -race -count=1 -run TestResolvePackagePaths_InvalidPattern ./internal/loader/...

# Run the integration-level regression test that was previously failing:
go test -race -count=1 -run TestBuildContractCoverageFunc_InvalidPattern ./internal/crap/...

# Full short test suite:
go test -race -count=1 -short ./...

How to Demo

This is an internal bug fix. The observable change is that gaze analyze,
gaze quality, gaze crap, and gaze report now emit warnings to stderr
when a package pattern fails to resolve, instead of silently passing phantom
paths downstream.

# Before: nonexistent pattern silently returned phantom path
# After: nonexistent pattern is filtered with warning
gaze analyze github.com/nonexistent/pkg 2>&1
# Expected: "warning: skipping github.com/nonexistent/pkg: ..."

Key Files Changed

  • internal/loader/loader.go -- Core fix: ResolvePackagePaths gains io.Writer param and pkg.Errors filtering with nil-safe warning output
  • internal/loader/loader_test.go -- New TestResolvePackagePaths_InvalidPattern + 3 existing test signature updates
  • cmd/gaze/main.go -- 2 callers updated (runAnalyze, runQuality) to pass p.stderr
  • internal/aireport/runner_steps.go -- 2 callers updated (runQualityStep passes stderr, runClassifyStep passes nil per D4)
  • internal/crap/contract.go -- 1 caller updated (BuildContractCoverageFunc passes stderr)
  • openspec/changes/fix-phantom-package-paths/ -- Proposal, design, spec, and task artifacts

This PR was generated by /finale (AI-assisted).

loader.ResolvePackagePaths did not check pkg.Errors on packages
returned by go/packages.Load. Nonexistent patterns produced
synthetic packages with populated Errors slices that passed
through the filter, returning phantom paths as valid.

- Add io.Writer parameter for warning output on skipped packages
- Skip packages with load errors, emit per-error warning to stderr
- Update all callers (cmd/gaze, goprovider, aireport DI wrapper)
- Add TestResolvePackagePaths_InvalidPattern regression test

Closes unbound-force#104

Assisted-by: claude-opus
Generated with AI assistance (claude-opus)
@em-redhat
em-redhat force-pushed the opsx/fix-phantom-package-paths branch from 84e3277 to 0456aa5 Compare July 7, 2026 11:28
@em-redhat em-redhat moved this to In Review 👀 in Unbound Force Planning Jul 7, 2026
Comment thread internal/aireport/runner_steps.go
Comment thread internal/loader/loader_test.go
Adds TestResolvePackagePaths_MixedValidAndInvalid which verifies that
when both valid and invalid patterns are provided, only the valid
package path is returned while a warning is emitted for the invalid
pattern. Addresses PR review feedback requesting mixed-pattern
coverage.

Assisted-by: claude-opus
Generated with AI assistance (claude-opus)
@em-redhat
em-redhat requested a review from trevor-vaughan July 14, 2026 10:35
@em-redhat
em-redhat merged commit 5889569 into unbound-force:main Jul 14, 2026
5 checks passed
@em-redhat
em-redhat deleted the opsx/fix-phantom-package-paths branch July 14, 2026 16:24
@em-redhat em-redhat moved this from In Review 👀 to Done ✔️ in Unbound Force Planning Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

Bug: resolvePackagePaths ignores pkg.Errors, returning phantom paths for nonexistent patterns

2 participants