Skip to content

[testify-expert] Improve Test Quality: pkg/lifecycle/lifecycle_test.go #78799

Done

Description

@github-actions

Current state

Item Value
File pkg/lifecycle/lifecycle_test.go
Source pair pkg/lifecycle/lifecycle.go (+ rules.go)
Test functions 6 (plus helper testDelivery)
Lines 153
Assertions require only; no assert
Parallelism no t.Parallel()

Strengths

  • TestDeliveryAdoptionRules is table-driven and covers the rule matrix.
  • TestLifecycleIdentitySeparatesEffectsAndAttempts checks that identity changes split records.
  • TestLifecycleDecisionAndReversal and the replay-conflict test cover the main lifecycle transitions.

Prioritized improvements

1. Missing high-value tests

Each example below was verified against a stdlib-only copy of lifecycle.go and rules.go.

  • IsHuman has no test. It is public API (see pkg/lifecycle/README.md:31) and is called from pkg/cli/logs_lifecycle_adoption.go:145. Suggested table:
func TestIsHuman(t *testing.T) {
	publishers := []string{"gh-aw-bot"}
	tests := []struct {
		name, actorType, login string
		want                   bool
	}{
		{"user", "User", "alice", true},
		{"dependabot bot", "User", "dependabot[bot]", false},
		{"renovate bot upper case", "User", "Renovate[BOT]", false},
		{"bot actor type", "Bot", "alice", false},
		{"empty login", "User", "", false},
		{"publisher, case-insensitive", "User", "GH-AW-BOT", false},
		{"organization", "Organization", "acme", false},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equal(t, tt.want, IsHuman(tt.actorType, tt.login, publishers))
		})
	}
}
  • Delivered target-URL validation is untested. These are rejected: (redacted) scheme, a foreign host, userinfo, and a query string. Also untested: RunID == 0` rejection.
  • Observe error paths are untested. These are: invalid state, zero ObservedAt, and a decision earlier than delivery.
  • Merge Delivery.At conflict is untested. With identity held fixed, a different Delivery.At returns conflicting lifecycle identity or delivery evidence.
  • Merge with empty previous and an invalid incoming record returns an error, but nothing asserts it.
  • Adoption.Equal UTC normalization is not asserted. The same instant in a different zone compares Equal == true while == is false, and Merge accepts it.

2. Fix the weak fallback loop

In TestLifecycleValidatesRetainedDecisionsAndAcceptanceKinds (lines 139–146), both loop iterations set At = Delivery.At + 1s. The time clause therefore fails on every iteration, and the human flag is never isolated. The loop name suggests it tests the human-flag predicate, but it does not.

Verified behavior: At == Delivery.At with HumanVerified=false succeeds. Both At+1s and HumanVerified=true return the same message, delivery fallback is not permitted, because Observe combines both checks in one condition. Assert the success control first, then check each violated clause:

// Before
for _, human := range []bool{false, true} {
	_, err = Observe(fallback, Observation{
		State: "accepted", Signal: "delivered", At: fallback.Delivery.At.Add(time.Second),
		ObservedAt: at, HumanVerified: human, AcceptanceKind: "fallback_delivery",
	})
	require.ErrorContains(t, err, "fallback is not permitted")
}

// After
_, err = Observe(fallback, Observation{
	State: "accepted", Signal: "delivered", At: fallback.Delivery.At,
	ObservedAt: at, AcceptanceKind: "fallback_delivery",
})
require.NoError(t, err)
_, err = Observe(fallback, Observation{
	State: "accepted", Signal: "delivered", At: fallback.Delivery.At.Add(time.Second),
	ObservedAt: at, AcceptanceKind: "fallback_delivery",
})
require.ErrorContains(t, err, "fallback is not permitted")
_, err = Observe(fallback, Observation{
	State: "accepted", Signal: "delivered", At: fallback.Delivery.At,
	ObservedAt: at, HumanVerified: true, AcceptanceKind: "fallback_delivery",
})
require.ErrorContains(t, err, "fallback is not permitted")

3. Assertion upgrades

  • Use assert for behavior checks and keep require for setup, following scratchpad/testing.md. Setup calls such as Delivered and the first Observe should stay on require.
  • Prefer assert.Equal over require.Equal for field comparisons in TestLifecycleIdentitySeparatesEffectsAndAttempts, so one failing field does not hide the rest.

4. Table-driven refactor

TestLifecycleIdentitySeparatesEffectsAndAttempts checks identity changes one by one. Move the Host, Workflow, Type, and TargetURL changes into a table so each field gets its own subtest.

5. Optional: t.Parallel()

The repo uses t.Parallel() in about 754 of 2,695 test files. These tests are pure functions with no shared state, so adding it is low risk.

Acceptance checklist
  • IsHuman table test added, covering user, bot, case-insensitive publisher, and organization cases
  • Delivered rejects `(redacted) foreign host, userinfo, and query string
  • Observe error paths covered: invalid state, zero ObservedAt, decision before delivery
  • Merge Delivery.At conflict covered
  • Fallback loop split into separate assertions that isolate HumanVerified and time
  • make test-unit passes (or go test ./pkg/lifecycle/)
Environment limitation

go test ./pkg/lifecycle/ could not run in the analysis sandbox. github.com/stretchr/[email protected] could not be downloaded from proxy.golang.org because of a TLS certificate error. The probe results above come from a stdlib-only copy of lifecycle.go and rules.go. Confirm them by running the suite in CI before merging test changes.

Generated by 🧪 Daily Testify Uber Super Expert · copilot · routed: haiku55 xhigh · ~9 AIC · ⌖ ~2 AIC · ⊞ 3.9K · ◷

  • expires on Nov 19, 2026, 10:13 AM UTC-08:00

Activity

  1. github-actions commented on Nov 18, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 11.4K · ◷

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions