Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion cmd/codeaf/factory_guard_stale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestGuardOwedAbsoluteMeasuredCommand(t *testing.T) {
t.Fatal(err)
}
failed := 7
old := verification.Check{Args: []string{"/usr/local/go/bin/go", "test", "./..."}, Command: "/usr/local/go/bin/go test ./...", Cwd: root, Context: make([]string, 8), Exit: &failed, Before: at, After: at, ID: "saved", Source: "old"}
old := verification.Check{Args: []string{"/usr/local/go/bin/go", "test", "./..."}, Command: "/usr/local/go/bin/go test ./...", Cwd: root, Context: verification.CheckContext(), Exit: &failed, Before: at, After: at, ID: "saved", Source: "old"}
if err := verification.Inherit(file, []verification.Check{old}); err != nil {
t.Fatal(err)
}
Expand All @@ -271,6 +271,35 @@ func TestGuardOwedAbsoluteMeasuredCommand(t *testing.T) {
}
}

func TestGuardOwedAbsoluteMeasuredCommandContext(t *testing.T) {
root, file, run := staleGuardFixture(t)
at, err := verification.SnapshotAt(root)
if err != nil {
t.Fatal(err)
}
t.Setenv("GOOS", "linux")
t.Setenv("GOWORK", "off")
failed := 7
old := verification.Check{Args: []string{"/usr/local/go/bin/go", "test", "./..."}, Command: "/usr/local/go/bin/go test ./...", Cwd: root, Context: verification.CheckContext(), Exit: &failed, Before: at, After: at, ID: "saved", Source: "old"}
if err := verification.Inherit(file, []verification.Check{old}); err != nil {
t.Fatal(err)
}
door := &receiptStageDoor{StageDoor: &repairReportDoor{}, file: file, dir: root, requireFresh: true, requireAnyCheck: true}
t.Cleanup(door.closeVerification)
// A rerun under a different target context must keep the saved failure owed.
t.Setenv("GOOS", "darwin")
run("go test ./...")
if err := door.Report(t.Context(), factory.StageResult{Done: true}); err == nil || !strings.Contains(err.Error(), "'go' 'test' './...'") {
t.Fatalf("different GOOS context must keep saved failure owed: %v", err)
}
// A portable rerun in the matching non-empty context clears it.
t.Setenv("GOOS", "linux")
run("go test ./...")
if err := door.Report(t.Context(), factory.StageResult{Done: true}); err != nil {
t.Fatalf("matching context portable rerun did not clear saved absolute failure: %v", err)
}
}

func TestGuardOwedAbsoluteUnmeasuredCommand(t *testing.T) {
root, file, run := staleGuardFixture(t)
guardUnrunJournal(t, file, "/usr/local/go/bin/go test ./...", "refused")
Expand Down
8 changes: 8 additions & 0 deletions docs/changes/unreleased/3017-guard-owed-absolute-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
kind: internal
title: TestGuardOwedAbsoluteMeasuredCommand seeds inherited context from CheckContext
pr: 3017
surface: [factory]
invalidates:
- "Was true: `TestGuardOwedAbsoluteMeasuredCommand` seeded its inherited synthetic check with an all-empty `make([]string, 8)` context, so any runner with `GOOS`, `GOARCH`, `GOFLAGS`, `CGO_ENABLED`, `GOWORK`, `GORACE`, `NODE_ENV`, or `PYTEST_ADDOPTS` exported saw an environment mismatch on dev. Is true now: `verification.CheckContext()` supplies the active execution-scope context so the test passes on any clean checkout regardless of those host variables."
---
7 changes: 1 addition & 6 deletions internal/factory/verification/go_requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package verification

import (
"encoding/json"
"os"
"path"
"slices"
"sort"
Expand Down Expand Up @@ -210,11 +209,7 @@ func CoversUnrun(command, cwd string, pass Check) bool {
if len(args) == 0 || args[0] != "go" {
return false
}
var context []string
for _, name := range checkContextNames {
context = append(context, os.Getenv(name))
}
old, ok := goRequirement(Check{Args: args, Cwd: cwd, Context: context})
old, ok := goRequirement(Check{Args: args, Cwd: cwd, Context: CheckContext()})
if !ok || pass.Cwd != cwd || pass.Diagnostic || pass.Problem != "" || pass.Exit == nil || *pass.Exit != 0 || pass.Before.Head == "" || pass.Before != pass.After {
return false
}
Expand Down
10 changes: 10 additions & 0 deletions internal/factory/verification/receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ const SetupFailurePrefix = "Could not record verification:"

var checkContextNames = [...]string{"GOOS", "GOARCH", "GOFLAGS", "CGO_ENABLED", "GOWORK", "GORACE", "NODE_ENV", "PYTEST_ADDOPTS"}

// CheckContext captures the execution-scope environment values recorded for
// observed checks.
func CheckContext() []string {
ctx := make([]string, len(checkContextNames))
for i, name := range checkContextNames {
ctx[i] = os.Getenv(name)
}
return ctx
}

const originalCommandPrefix = "# codeaf-check-original:"
const observerShellGuard = `if [ -n "${BASH_VERSION-}" ]; then`

Expand Down
Loading