Resolve selected lazy modules by exact native cache identity
Private module tooling / contract (pull_request) Failing after 5s

Authored-By: Codex (GPT-6) <noreply@openai.com>
This commit is contained in:
Evelyn Chen
2026-09-07 14:55:37 +00:00
parent e75412e6d4
commit 52c9456208
2 changed files with 33 additions and 7 deletions
+19 -7
View File
@@ -99,13 +99,9 @@ func generate() error {
return errors.New("private module must have exact unreplaced version")
}
mod := module{Path: src.Path, Version: src.Version, Files: []artifact{}}
rel, err := filepath.Rel(cacheRoot, src.GoMod)
if err != nil || !safePath(rel) || !strings.HasSuffix(rel, ".mod") || !strings.HasSuffix(filepath.Dir(rel), "/@v") {
return errors.New("unexpected native module cache layout")
}
stem, err := moduleStem(src.Path, src.Version)
if err != nil || filepath.ToSlash(rel) != stem+".mod" {
return errors.New("native artifact path differs from module identity")
stem, err := cacheStem(cacheRoot, src.Path, src.Version, src.GoMod)
if err != nil {
return err
}
for _, ext := range []string{".info", ".mod", ".zip"} {
name := stem + ext
@@ -185,6 +181,22 @@ func moduleStem(path, version string) (string, error) {
return escape(path) + "/@v/" + escape(version), nil
}
func cacheStem(cacheRoot, path, version, goMod string) (string, error) {
stem, err := moduleStem(path, version)
if err != nil {
return "", err
}
// Lazy module graphs omit GoMod for selected but unexpanded modules.
// Their canonical cache path is still determined by exact identity.
if goMod != "" {
rel, err := filepath.Rel(cacheRoot, goMod)
if err != nil || filepath.ToSlash(rel) != stem+".mod" {
return "", errors.New("native artifact path differs from module identity")
}
}
return stem, nil
}
func safePath(p string) bool {
return p != "" && filepath.Clean(p) == p && !filepath.IsAbs(p) && p != ".." && !strings.HasPrefix(p, "../") && !strings.ContainsAny(p, "\\\x00")
}