Keep required local inputs separate from committed source
This commit is contained in:
@@ -116,6 +116,11 @@ access-observation assertions use a complete rehearsal configuration.
|
||||
|
||||
## 2. Committed readiness turns local required files into committed inputs
|
||||
|
||||
**Completed:** Required local files use filesystem checks in both readers.
|
||||
Regression coverage verifies ignored relative/absolute keys, missing local
|
||||
copies despite committed blobs, and captured module/main-package inputs.
|
||||
Readiness and rehearsal suites pass.
|
||||
|
||||
**Priority:** P2. **Stages:** 7, 12.
|
||||
|
||||
**Relevant code:** [`Run`](../../internal/readiness/readiness.go), required-file
|
||||
|
||||
@@ -26,6 +26,9 @@ func TestCommittedReadinessUsesCapturedModuleAndMainPackage(t *testing.T) {
|
||||
run("init", "--initial-branch=main")
|
||||
run("config", "user.name", "ReleaseKit Test")
|
||||
run("config", "user.email", "releasekit@example.test")
|
||||
if err := os.WriteFile(filepath.Join(repo, ".gitignore"), []byte(".releasekit/\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(repo, "go.mod"), []byte("module example.com/fixture\n\ngo 1.25.0\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -38,16 +41,39 @@ func TestCommittedReadinessUsesCapturedModuleAndMainPackage(t *testing.T) {
|
||||
run("add", "--all")
|
||||
run("commit", "-m", "capture inputs")
|
||||
commit := run("rev-parse", "HEAD")
|
||||
if err := os.Mkdir(filepath.Join(repo, ".releasekit"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := filepath.Join(repo, ".releasekit", "ssh-key")
|
||||
if err := os.WriteFile(key, []byte("local fixture key"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.Remove(filepath.Join(repo, "main.go"))
|
||||
os.Remove(filepath.Join(repo, "required.txt"))
|
||||
os.WriteFile(filepath.Join(repo, "go.mod"), []byte("invalid working module"), 0600)
|
||||
request := Request{RepositoryDir: repo, Commit: commit, Product: "Example", Context: "local", Source: &releaseidentity.SourceSpec{GoEnabled: true}, Operations: []string{"build"}, Build: &artifact.Settings{MainPackage: ".", BinaryName: "fixture", Targets: []artifact.Target{{OS: "linux", Arch: "amd64"}}}, RequiredFiles: []string{"required.txt", filepath.Join(repo, "required.txt")}}
|
||||
request.RequiredFiles = append(request.RequiredFiles, ".releasekit/ssh-key", key)
|
||||
report := Run(t.Context(), request)
|
||||
for _, check := range report.Checks {
|
||||
if check.Status == "failed" {
|
||||
t.Fatalf("captured readiness failed: %+v", check)
|
||||
}
|
||||
}
|
||||
if err := os.Remove(filepath.Join(repo, "required.txt")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
report = Run(t.Context(), request)
|
||||
missing := 0
|
||||
for _, check := range report.Checks {
|
||||
if check.ID == "required-file" && check.Status == "failed" {
|
||||
missing++
|
||||
}
|
||||
if check.ID == "build-inputs" && check.Status != "passed" {
|
||||
t.Fatalf("captured build inputs changed: %+v", check)
|
||||
}
|
||||
}
|
||||
if missing != 2 {
|
||||
t.Fatalf("missing local inputs were supplied by Git: %+v", report.Checks)
|
||||
}
|
||||
request.Commit = ""
|
||||
report = Run(t.Context(), request)
|
||||
failed := false
|
||||
|
||||
@@ -137,13 +137,6 @@ func Run(ctx context.Context, request Request) Report {
|
||||
}
|
||||
for _, name := range request.RequiredFiles {
|
||||
path := name
|
||||
committedName := name
|
||||
committedInput := request.Commit != "" && !filepath.IsAbs(name)
|
||||
if request.Commit != "" && filepath.IsAbs(name) && repoErr == nil {
|
||||
if relative, relErr := filepath.Rel(repository, filepath.Clean(name)); relErr == nil && relative != ".." && !strings.HasPrefix(relative, ".."+string(filepath.Separator)) {
|
||||
committedName, committedInput = relative, true
|
||||
}
|
||||
}
|
||||
if !filepath.IsAbs(path) {
|
||||
path = filepath.Join(repository, path)
|
||||
}
|
||||
@@ -154,8 +147,6 @@ func Run(ctx context.Context, request Request) Report {
|
||||
err = errors.New("relative required file path escapes the repository")
|
||||
} else if repoErr != nil && !filepath.IsAbs(name) {
|
||||
err = errors.New("repository unavailable for relative required file")
|
||||
} else if committedInput {
|
||||
_, err = committedFile(ctx, repository, request.Commit, filepath.ToSlash(committedName))
|
||||
} else {
|
||||
var info os.FileInfo
|
||||
info, err = os.Stat(path)
|
||||
|
||||
Reference in New Issue
Block a user