Skip to content

feat(test): forge test flakes --issues --stale-after closes stale flake issues from CI - #2795

Open
reliant-01 wants to merge 2 commits into
mainfrom
w9/flakes-stale
Open

reliant-01 wants to merge 2 commits into
mainfrom
w9/flakes-stale

Conversation

@reliant-01

Copy link
Copy Markdown
Contributor

Problem

forge test flakes --issues closes an open flake:suspected issue only when the local test record (.forge/tests/runs/) shows its test leaving the suspected/flaky states. A CI runner is a fresh machine with an empty record, so on CI nothing is ever closed. reliant keeps a hand-written scripts/flake-report.sh --sweep for this (run daily by its flake-report.yml), and forge's own copy of that script does the same. Any forge project that files flake issues from CI needs it.

Behaviour

New, additive flag: forge test flakes --issues --stale-after <age> (7d, 168h; a whole number of days or a Go duration). Without the flag nothing changes. With it, after the existing record-driven filing/commenting/closing, a sweep reads the evidence from the open issues themselves and closes each open flake:suspected issue forge filed (title flake:suspected: <Test> (<pkg>)) when:

  • the test is gone: its func <Test>( is in no *_test.go of the package directory in this checkout (needs a go.mod at the root; a package path from another module is never taken as gone), or
  • it is stale: its newest evidence is older than <age>. Evidence is the issue's createdAt, or the newest comment starting "Failed then passed on retry again" (the comment forge, and flake-report.sh before it, writes on a repeat flake). Other comments don't keep an issue open.

An issue whose test the local record still calls suspected/flaky is left to the record rule, so a local run never closes an issue and then reopens it. Each close comments Closed by \forge test flakes --issues`: . A new flake of this test reopens it., and that is accurate: the filing path searches issues with --state alland reopens and comments on the closed issue instead of filing a new one.--dry-runprintswould close #N: . The flag works with an empty local record. The clock is injectable (IssueOptions.Now), so the tests never sleep. --stale-afterwithout--issues, or an age it can't parse, exits 2. The createdAt,commentsfields are requested fromgh issue list` only when sweeping.

Docs: the command's --help, and the ci/gate skill (a new paragraph on flake issues from CI).

Tests

  • internal/testflakes: TestSyncIssuesStaleAfter, a table over the empty record: a stale issue is closed with a comment; a fresh one is kept; a forge evidence comment resets the age, an old one doesn't; a non-forge comment doesn't; a gone test is closed even when fresh; an hours duration works; dry-run writes nothing; no flag means no sweep; a hand-filed title is left alone; a test the record still calls a flake is left alone. Also TestSyncIssuesAsksForDatesOnlyToSweep and TestParseStaleAfter.
  • internal/cli: TestRunTestFlakesStaleAfter (usage errors; a sweep from an empty record closes a gone test's issue).
  • Ran: task test:short -- ./internal/testflakes/..., task test -- ./internal/testflakes/... (-race), go test -short -run Flake ./internal/cli/, the new tests with -count=3, go build ./..., go vet, scripts/ci-golangci-changed.sh (0 issues), and go test -short -run Skill ./internal/templates/....

Post-merge check

After this ships in a forge release reliant pins: in reliant, run forge test flakes --issues --stale-after 7d --dry-run from main. Its would close lines should match scripts/flake-report.sh --sweep --dry-run (except for any hand-filed issues, which forge leaves alone). Then reliant's flake-report.yml sweep step can call forge, and --sweep can be deleted from the script.

Rollback

Revert this commit. The flag is new and opt-in, so no existing invocation depends on it. Issues it closed stay closed, and a later flake reopens them as before.

@reliant-labs reliant-labs Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

review:changes

Lane: MEDIUM (one pass on gpt-6-luna@codex).

MEDIUM: agent-instructions (internal/templates/project/skills/forge/ci/gate/SKILL.md); code (internal/cli/test_flakes.go, internal/testflakes/issues.go)

The stale sweep can close valid flake issues when it cannot inspect the test package; this is a data-loss defect.

  • blocker [B1] internal/testflakes/issues.go:237 — The gone-test path converts a failed os.Stat of a package path containing a dotted first segment into “not evidence” (correctly), but for ordinary package paths it reaches TestBody, which returns an empty string both when no test exists and when the package directory is missing or files cannot be read. Thus a typo, removed/missing checkout subtree, or transient filesystem read error closes every matching open issue as if its test were deleted. A sweep run from a partial checkout can therefore close valid issues. The sweep must distinguish a successful scan proving absence from inability to inspect. Fix: Treat stat/read/parse failures as indeterminate and leave the issue open; only close when the package is verifiably present and a successful source scan proves the test absent. Add regression cases for missing package directories and unreadable test files.

Fix the blockers and push: the push is reviewed again. (pr-fix takes over if nobody does.)

Reviewed be1a1c5ef675d65384a658ab4bc6533cf8e9c04f.

Posted by Reliant for PR pipeline · pr-review · opened, an automation of @reliant-01.

@reliant-labs reliant-labs Bot added review:changes Blocking review findings; workflow repairs or fix, push, re-label merge:queue fix:needed and removed review:pending labels Nov 25, 2026
@reliant-labs reliant-labs Bot added review:pending and removed review:changes Blocking review findings; workflow repairs or fix, push, re-label merge:queue labels Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant