Skip to content

fix(test): seed TestGuardOwedAbsoluteMeasuredCommand with CheckContext (#3008) - #3017

Merged
AbirAbbas merged 2 commits into
Agent-Field:devfrom
Gaoshou101:fix/guard-owed-absolute-context-3008
Dec 2, 2026
Merged

AbirAbbas merged 2 commits into
Agent-Field:devfrom
Gaoshou101:fix/guard-owed-absolute-context-3008

Conversation

@Gaoshou101

@Gaoshou101 Gaoshou101 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3008

What changed

  • TestGuardOwedAbsoluteMeasuredCommand previously seeded the inherited synthetic check (old) with Context: make([]string, 8) (all empty strings), while running the subsequent go test ./... through the live bash observer (_codeaf_check), which populates next.Context from checkContextNames (GOOS, GOARCH, GOFLAGS, CGO_ENABLED, GOWORK, GORACE, NODE_ENV, PYTEST_ADDOPTS). Whenever any of those variables was exported in the runner environment, next.identity != old.identity kept the saved absolute failure owed even after a matching portable rerun.
  • Exported verification.CheckContext() in internal/factory/verification/receipts.go (and reused it in CoversUnrun in internal/factory/verification/go_requirements.go to avoid duplicating the checkContextNames loop), and seeded old.Context in TestGuardOwedAbsoluteMeasuredCommand with verification.CheckContext().
  • Added TestGuardOwedAbsoluteMeasuredCommandContext in cmd/codeaf/factory_guard_stale_test.go to pin both sides of the contract with t.Setenv: a rerun under a different GOOS keeps the saved failure owed, while a portable rerun under the matching non-empty GOOS + GOWORK context clears it.

How it was checked

  • Reproduced failure before fix on dev (a5499811) with GOOS=linux and GOWORK=off:
    • GOOS=linux go test -v -count=1 -run '^TestGuardOwedAbsoluteMeasuredCommand$' ./cmd/codeaf -> FAIL at factory_guard_stale_test.go:270: portable rerun did not clear saved absolute failure: repair is incomplete; owed: 'go' 'test' './...' ...
    • GOWORK=off go test -v -count=1 -run '^TestGuardOwedAbsoluteMeasuredCommand$' ./cmd/codeaf -> FAIL at factory_guard_stale_test.go:270
  • Verified after fix:
    • go test -v -count=1 -run '^TestGuard' ./cmd/codeaf -> PASS (1.144s, all 10 TestGuard* tests)
    • GOOS=linux go test -v -count=1 -run '^TestGuardOwedAbsoluteMeasuredCommand' ./cmd/codeaf -> PASS (0.252s)
    • GOWORK=off go test -v -count=1 -run '^TestGuardOwedAbsoluteMeasuredCommand' ./cmd/codeaf -> PASS (0.191s)
    • CGO_ENABLED=0 GOFLAGS=-v go test -v -count=1 -run '^TestGuardOwedAbsoluteMeasuredCommand' ./cmd/codeaf -> PASS (0.195s)
    • go test -race -count=1 ./internal/factory/verification -> PASS (4.930s)
    • go test -count=1 ./internal/namelaw ./cmd/codeaf-changes ./internal/factory/verification -> PASS
    • go vet ./internal/factory/verification ./cmd/codeaf -> clean (exit 0)
    • gofmt -l and git diff --check -> clean
    • Scope limit: did not run the full-repo suite or -race on cmd/codeaf due to container link time; added docs/changes/unreleased/3017-guard-owed-absolute-context.md and validated via make changelog-check.

Checklist

  • Only my own paths are staged — no git add -A.
  • A change entry — docs/changes/unreleased/3017-guard-owed-absolute-context.md added and validated with make changelog-check.
  • No slash command, key, tool, default, limit, or refusal moved (internal/manual/chat/ unaffected).

Fixes Agent-Field#3008

TestGuardOwedAbsoluteMeasuredCommand hardcoded Context: make([]string, 8)
on the inherited synthetic check while executing the portable rerun through
the live bash check observer, which records the runner's checkContextNames
(GOOS, GOARCH, GOFLAGS, CGO_ENABLED, GOWORK, GORACE, NODE_ENV, PYTEST_ADDOPTS).
When any of those variables was set in the environment, the context mismatch
kept the saved absolute failure owed even after a matching portable rerun.

Export verification.CheckContext() (also reused by CoversUnrun), use it to
seed the inherited check, and add TestGuardOwedAbsoluteMeasuredCommandContext
to verify both matching non-empty context clearing and cross-context holding.
@CLAassistant

CLAassistant commented Dec 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@santoshkumarradha

Copy link
Copy Markdown
Member

Hey, thanks for the PR. Could you sign the CLA when you get a chance so we can review it?

@Gaoshou101

Copy link
Copy Markdown
Contributor Author

I have signed the CLA.

Hey, thanks for the PR. Could you sign the CLA when you get a chance so we can review it?

@AbirAbbas AbirAbbas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, nice catch. I ran it against the base commit: with GOFLAGS (or GOOS/GOWORK) exported the old test fails exactly as in #3008, and with your change the TestGuard tests pass with GOFLAGS set, GOOS=linux, GOWORK=off, CGO_ENABLED=0 and a clean environment (several runs each). The assertion that a portable rerun clears the saved failure is untouched; only the seeded context now matches the run it is compared against, and the new test pins the other side (a different GOOS keeps the failure owed), so this tightens the check rather than loosening it. CLA is signed. Looks good to me from this side, I'll leave the merge to the maintainers.

@AbirAbbas AbirAbbas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is the right fix. The test now takes its context from the same helper the product uses, so an exported GOFLAGS on the host no longer trips it, and nothing about what it checks got weaker. Re-ran it here with GOFLAGS set and it passes.

@AbirAbbas
AbirAbbas merged commit 049bea1 into Agent-Field:dev Dec 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestGuardOwedAbsoluteMeasuredCommand fails on a clean dev tree

4 participants