runner: Task 16, go.mod-only pins are metadata; new tree pins
A module the base pins only by its go.mod line has its .mod staged and is not reported missing: Go builds no package from a module without its tree line. NewModules reports candidate go.sum tree lines for versions the base pins only by go.mod, or not at all, so the worker can end the step deps_new_module from the pin comparison before any build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+86
−14
docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+18 −0internal/runner/depsbundle/depsbundle_test.go+29 −6internal/runner/depsbundle/gosum.go+27 −0internal/runner/depsbundle/stage.go+12 −8
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index fbf63719..c6c9e3fd 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -1233,3 +1233,21 @@ Mutation checks (same method: exact unique strings replaced by a script, `-count |
| 173 and 174, rerun with the checks moved into the preflight: 173 (no symlink refusal) FAIL `a_symlink`: `depsbundle_test.go:415: ... want ErrUnsafePath`, `:419: Stage wrote .../example.com/dep@v1.0.0/escape.txt`. 174 (no expanded limit) FAIL `TestExpandedLimit/expanded` `:451` and `TestOversizedZipRefusedBeforeHash` `:572`. Both restored. |
| Not covered by a test: a walk error (an `fs.FS` whose directory read fails) is returned, but no test fakes one. |
| + |
| +### Task 16, the go.mod-only ruling (coordinator, after the NEEDS_CONTEXT report) |
| + |
| +I tested the first ruling (stage the .mod, rely on `checks.NeedsNetwork`) with throwaway tests and it did not hold: with the .mod staged, the go command fails on the zip's lock file in the read-only cache, and the stage's `offlineRefusal` does not accept that line. The task report has the table. Final ruling, decided from the pins (`internal/runner/checks` untouched): |
| +1. A base pin with only a `/go.mod` line is metadata. Its .mod (and .info) is staged and it is **not** in `Missing`: Go builds no package from a module without its tree line in go.sum. |
| +2. A candidate go.sum tree (h1 zip) line for a module version the base pins only by its go.mod, or does not pin at all, is a new pin. The new `NewModules(base, candidate)` reports it, from the pin comparison before any build (the worker's `deps_new_module`, Task 17). |
| +3. A candidate that imports such a module without adding the tree line fails as it would on a personal runner. Nothing to do. |
| + |
| +A pinned tree line whose zip the bundle lacks is still `Missing` (`deps_missing`). |
| + |
| +Red (stub `NewModules` returning nil; `stage` still reporting go.mod-only modules missing): `go test ./internal/runner/depsbundle -count=1` FAIL: |
| +- `TestGoModOnlyPinStaged` (renamed from `TestGoModOnlyPinReported`, both subtests): `depsbundle_test.go:748: missing [example.com/dep@v1.0.0], want none: a go.mod-only requirement is metadata`. |
| +- `TestCandidateTreeLineIsNewModule`: `depsbundle_test.go:798: NewModules = [], <nil>; want [example.com/added@v1.0.0 example.com/dep@v1.0.0]: the candidate adds their tree lines`. |
| + |
| +Green: `go test ./internal/runner/depsbundle -count=3`: ok. `make budget build vet`: exit 0. staticcheck v0.7.0, gofmt and `git diff --check`: clean. |
| + |
| +191. New pins limited to versions the base does not pin at all (`pins[l.m].Zip == ""` → `pins[l.m] == (Pin{})`). `-run TestCandidateTreeLineIsNewModule`: FAIL `depsbundle_test.go:798: NewModules = [example.com/added@v1.0.0], <nil>; want [example.com/added@v1.0.0 example.com/dep@v1.0.0]: the candidate adds their tree lines`. Restored. |
| +192. A go.mod-only module reported missing again (`return pin.Zip == "", nil` → `return false, nil`). `-run TestGoModOnlyPinStaged`: FAIL both subtests, `depsbundle_test.go:748: missing [example.com/dep@v1.0.0], want none: a go.mod-only requirement is metadata`. Restored. |
diff --git a/internal/runner/depsbundle/depsbundle_test.go b/internal/runner/depsbundle/depsbundle_test.go| index 01889200..a8c9fc75 100644 |
| --- a/internal/runner/depsbundle/depsbundle_test.go |
| +++ b/internal/runner/depsbundle/depsbundle_test.go |
| @@ -725,10 +725,11 @@ func TestModuleDiscoveryErrors(t *testing.T) { |
| }) |
| } |
| -// TestGoModOnlyPinReported: a module the base pins only by its go.mod has |
| -// its .mod staged and no source, so it is reported missing, whether the |
| -// bundle carries a zip for it or not. |
| -func TestGoModOnlyPinReported(t *testing.T) { |
| +// TestGoModOnlyPinStaged: a module the base pins only by its go.mod is |
| +// metadata only (Go builds no package from a module without its tree |
| +// line in go.sum): its .mod is staged, its source is not, and it is not |
| +// missing, whether the bundle carries a zip for it or not. |
| +func TestGoModOnlyPinStaged(t *testing.T) { |
| for _, withZip := range []bool{true, false} { |
| t.Run(fmt.Sprintf("zip in the bundle %v", withZip), func(t *testing.T) { |
| cache := t.TempDir() |
| @@ -743,8 +744,8 @@ func TestGoModOnlyPinReported(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if !slices.Equal(s.Missing, []Module{dep}) { |
| - t.Errorf("missing %v, want [%v]: its source is not staged", s.Missing, dep) |
| + if len(s.Missing) != 0 { |
| + t.Errorf("missing %v, want none: a go.mod-only requirement is metadata", s.Missing) |
| } |
| if _, err := os.Stat(filepath.Join(s.Dir, "cache/download/example.com/dep/@v/v1.0.0.mod")); err != nil { |
| t.Errorf("its .mod was not staged: %v", err) |
| @@ -781,3 +782,25 @@ func TestZipDirectoryEntries(t *testing.T) { |
| t.Fatalf("sub/s.go = %q, %v", got, err) |
| } |
| } |
| + |
| +// TestCandidateTreeLineIsNewModule: a candidate go.sum tree line for a |
| +// module version the base pins only by its go.mod (or not at all) is a |
| +// new pin, found by comparing the pins before any build. |
| +func TestCandidateTreeLineIsNewModule(t *testing.T) { |
| + cache := t.TempDir() |
| + pin := fixtureModule(t, cache, dep, map[string]string{"go.mod": "module example.com/dep\n", "dep.go": "package dep\n"}) |
| + added := Module{"example.com/added", "v1.0.0"} |
| + addedPin := fixtureModule(t, cache, added, map[string]string{"go.mod": "module example.com/added\n", "a.go": "package added\n"}) |
| + base := fstest.MapFS{"go.mod": {Data: []byte(goModFor("example.com/app", dep))}, "go.sum": {Data: []byte(sumText(dep.Path + " " + dep.Version + "/go.mod " + pin.Mod))}} |
| + cand := fstest.MapFS{"go.mod": {Data: []byte(goModFor("example.com/app", dep, added))}, "go.sum": {Data: []byte(sumText(sumFor(dep, pin), sumFor(added, addedPin)))}} |
| + |
| + if got, err := NewModules(base, cand); err != nil || !slices.Equal(got, []Module{added, dep}) { |
| + t.Fatalf("NewModules = %v, %v; want [%v %v]: the candidate adds their tree lines", got, err, added, dep) |
| + } |
| + if got, err := NewModules(base, base); err != nil || len(got) != 0 { |
| + t.Fatalf("NewModules(base, base) = %v, %v; want none", got, err) |
| + } |
| + if got, err := Conflicts(base, cand); err != nil || len(got) != 0 { |
| + t.Fatalf("Conflicts = %v, %v; want none: no base pin changed", got, err) |
| + } |
| +} |
diff --git a/internal/runner/depsbundle/gosum.go b/internal/runner/depsbundle/gosum.go| index 186d354e..566af643 100644 |
| --- a/internal/runner/depsbundle/gosum.go |
| +++ b/internal/runner/depsbundle/gosum.go |
| @@ -219,6 +219,33 @@ func Conflicts(base, candidate fs.FS) ([]Module, error) { |
| return out, nil |
| } |
| +// NewModules are the modules for which a candidate go.sum adds a tree |
| +// (h1 zip) line the base has none for: a version the base pins only by |
| +// its go.mod, or does not pin at all. Go builds no package from a module |
| +// without its tree line, so that line is a new pin: the step ends |
| +// cannot_run, needs_network, deps_new_module from this comparison, |
| +// before any build. Sorted, each once. |
| +func NewModules(base, candidate fs.FS) ([]Module, error) { |
| + pins, err := Pins(base) |
| + if err != nil { |
| + return nil, err |
| + } |
| + lines, err := sumLines(candidate) |
| + if err != nil { |
| + return nil, err |
| + } |
| + seen := map[Module]bool{} |
| + var out []Module |
| + for _, l := range lines { |
| + if !l.mod && pins[l.m].Zip == "" && !seen[l.m] { |
| + seen[l.m] = true |
| + out = append(out, l.m) |
| + } |
| + } |
| + sortModules(out) |
| + return out, nil |
| +} |
| + |
| type sumLine struct { |
| m Module |
| mod bool // the "/go.mod" line |
diff --git a/internal/runner/depsbundle/stage.go b/internal/runner/depsbundle/stage.go| index 7ad579f6..c2c3c01c 100644 |
| --- a/internal/runner/depsbundle/stage.go |
| +++ b/internal/runner/depsbundle/stage.go |
| @@ -76,10 +76,11 @@ func (s Staged) Remove() error { return removeTree(s.Dir) } |
| // pin has a tree hash), extracts the zip with golang.org/x/mod/zip.Unzip, |
| // writes the cache/download files (and the .ziphash the go command looks |
| // for), and makes the tree read-only, all in a fresh directory under |
| -// dir. A module the base does not pin is never staged. A module without |
| -// staged source (its base pin has no tree line, or the bundle has no |
| -// zip for it) has only its .mod staged and is reported missing. On an |
| -// error nothing is left under dir. |
| +// dir. A module the base does not pin is never staged. A module the |
| +// base pins only by its go.mod has its .mod staged and no source (a |
| +// candidate adding its tree line is NewModules's to report). One whose |
| +// zip the bundle lacks has its .mod staged and is reported missing. On |
| +// an error nothing is left under dir. |
| func Stage(ctx context.Context, bundle io.Reader, pins map[Module]Pin, dir string, limits Limits) (_ Staged, err error) { |
| st := &stager{limits: limits.withDefaults(), parts: map[Module]*received{}} |
| if st.fresh, err = os.MkdirTemp(dir, "deps-"); err != nil { |
| @@ -286,9 +287,9 @@ func parseName(name string) (Module, string, bool) { |
| // stage verifies and writes one wanted module and reports whether it is |
| // complete. Nothing is written when the base does not pin it or the |
| -// bundle lacks its .mod. Its verified .mod is written but it is not |
| -// complete when it has no source to stage: the base pins only its |
| -// go.mod, or the bundle lacks its zip. |
| +// bundle lacks its .mod. A module the base pins only by its go.mod is |
| +// complete with its .mod alone. One whose tree pin names a zip the |
| +// bundle lacks has its .mod written but is not complete. |
| func (st *stager) stage(ctx context.Context, m Module, pins map[Module]Pin) (bool, error) { |
| pin, pinned := pins[m] |
| p := st.parts[m] |
| @@ -331,7 +332,10 @@ func (st *stager) stage(ctx context.Context, m Module, pins map[Module]Pin) (boo |
| } |
| } |
| if !source { |
| - return false, nil |
| + // Complete when the base pins only its go.mod (metadata: Go |
| + // builds no package from it); missing when the bundle lacks the |
| + // zip its tree pin names. |
| + return pin.Zip == "", nil |
| } |
| if err := modzip.Unzip(filepath.Join(st.fresh, filepath.FromSlash(esc)+"@"+ver), module.Version{Path: m.Path, Version: m.Version}, p.zip); err != nil { |
| return false, fmt.Errorf("%w: %v", ErrUnsafePath, err) |