Add focused unit coverage for pre-activation job compiler helpers - #48506
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
|
❌ Design Decision Gate 🏗️ failed during design decision gate check. |
|
✅ PR Code Quality Reviewer completed the code quality review. |
|
✅ Test Quality Sentinel completed test quality analysis. |
There was a problem hiding this comment.
Pull request overview
Adds focused unit tests for pre-activation job assembly and guard behavior.
Changes:
- Tests permissions, condition guards, needs deduplication, and outputs.
- Updates generated model-cost metadata in an unrelated workflow lock file.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/compiler_pre_activation_job_test.go |
Adds focused pre-activation compiler tests. |
.github/workflows/smoke-copilot-auto.lock.yml |
Adds unrelated model-cost metadata. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
🧪 Test Quality Sentinel Report✅ Test Quality Score: 85/100 — Excellent
📊 Metrics (6 tests)
Advisory (not a violation)Several Verdict
|
There was a problem hiding this comment.
The new test file is well-structured and targets high-value paths in compiler_pre_activation_job.go. All assertions are accurate against the production code. No issues found.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 23.7 AIC · ⌖ 5.16 AIC · ⊞ 5K
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd — two minor suggestions, no blocking issues.
📋 Key Themes & Highlights
Key Themes
TestBuildPreActivationJobis monolithic: multiple independent behaviours are asserted in one flat function. When any assertion fails, the test output doesn't pinpoint which specification broke. Splitting intot.Runblocks is the standard Go idiom and aligns with red-green-refactor.- Dev-mode permissions gap:
buildPreActivationPermissionshas explicit release and script mode sub-tests but theIsDev()branch ofneedsContentsReadis never directly asserted. It's exercised indirectly byTestBuildPreActivationJobbut without a permissions assertion, so a regression there would go undetected.
Positive Highlights
- ✅ Excellent coverage of the three helpers that were previously completely untested.
- ✅ Guard-composition tests (label, expression-bot, skip-author-associations) cleanly exercise the branching logic in
applyPreActivationIfConditionGuards. - ✅
needsdeduplication andmatched_commanddefault-output assertions are exactly the kind of assembly seam that prevents silent regressions. - ✅ Good use of
require.NoError/require.NotNilto fail fast before downstream assertions.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 33.2 AIC · ⌖ 4.87 AIC · ⊞ 6.7K
Comment /matt to run again
|
|
||
| result := c.applyPreActivationIfConditionGuards(data, false, "") | ||
|
|
||
| assert.Contains(t, result, "github.event_name") |
There was a problem hiding this comment.
[/tdd] TestBuildPreActivationJob is a single flat function testing multiple independent behaviours — when one assertion fails it's unclear which behaviour broke.
💡 Split into focused sub-tests
Each t.Run block names exactly one behaviour and can go red independently:
func TestBuildPreActivationJob(t *testing.T) {
t.Run("composes if from base-if + label guard + author guard", func(t *testing.T) { ... })
t.Run("deduplicates on.needs", func(t *testing.T) { ... })
t.Run("wires on.steps outputs as <id>_result", func(t *testing.T) { ... })
t.Run("always declares matched_command output", func(t *testing.T) { ... })
}This follows the red-green-refactor loop: each sub-test is a specification.
@copilot please address this.
| stepsStr := strings.Join(steps, "\n") | ||
|
|
||
| require.NotEmpty(t, steps) | ||
| assert.Contains(t, stepsStr, "Checkout actions folder") |
There was a problem hiding this comment.
[/tdd] Missing boundary case: buildPreActivationPermissions in dev mode is never tested directly — the TestBuildPreActivationJob uses ActionModeDev but doesn't assert permission content, so the needsContentsRead branch for dev mode has no explicit coverage.
💡 Add a dev-mode sub-test
t.Run("dev mode infers contents:read", func(t *testing.T) {
c := NewCompiler()
c.SetActionMode(ActionModeDev)
_, permissions := c.buildPreActivationPermissions(&WorkflowData{Name: "wf"}, "./actions/setup")
assert.Contains(t, permissions, "contents: read")
})Without this, the needsContentsRead branch for IsDev() is only exercised by TestBuildPreActivationJob which doesn't check permissions at all.
@copilot please address this.
There was a problem hiding this comment.
Verdict: COMMENT
Solid, well-targeted test coverage for previously untested pre-activation compiler helpers -- no blocking correctness or security issues found, but a few test-quality nits should be tightened.
💡 Themes
- Duplicate assertion in
TestBuildPreActivationJob:assert.Equal(t, []string{"prepare"}, job.Needs)appears twice back-to-back -- likely copy-paste, adds no coverage. - Weak substring assertions on permissions: both permission tests use
assert.Containsagainst rendered YAML rather than validating the exact permission set. Since these helpers directly control the workflow's GitHub token scopes, tests should pin the full expected permission set (exact match) rather than allow silent scope creep to pass unnoticed. - Unrelated lock file drift:
.github/workflows/smoke-copilot-auto.lock.ymlpicks up aGH_AW_INFO_MODEL_COSTSline that traces to unrelated model-pricing work in a separate recent commit (#48482), not to this PR's test-only scope. Not a functional problem, but worth separating out for cleaner history. - Test coverage itself is well-scoped (release vs script mode permissions, guard composition, expression-based bot list edge case, full job assembly) and follows existing repo test conventions.
🔎 Code quality review by PR Code Quality Reviewer · sonnet50 · 67.8 AIC · ⌖ 4.58 AIC · ⊞ 7.4K
Comment /review to run again
Comments that could not be inline-anchored
pkg/workflow/compiler_pre_activation_job_test.go:145
Duplicate assertion: assert.Equal(t, []string{"prepare"}, job.Needs) is asserted twice back-to-back.
<details><summary>💡 Details</summary>
Lines 144-145 both assert job.Needs equals []string{"prepare"}. The second call is dead weight -- likely a copy-paste leftover -- and provides zero additional coverage. If the intent was to also verify dedup behavior more thoroughly (e.g. ordering when duplicates appear at different positions), that intent was lost; as written it just repeats the sa…
pkg/workflow/compiler_pre_activation_job_test.go:39
Permission assertions use loose substring Contains on rendered YAML instead of validating the exact permission set, which is risky since job permissions are a security-relevant surface.
<details><summary>💡 Details</summary>
The test only checks that the rendered permissions string contains "actions: read", "contents: read", "issues: write", "pull-requests: read" via assert.Contains. This does not assert there are exactly these four scopes and no more -- a regression that accident…
.github/workflows/smoke-copilot-auto.lock.yml:152
This lock file change is unrelated recompile drift from a prior commit and doesn't belong in a test-only PR.
<details><summary>💡 Details</summary>
The added GH_AW_INFO_MODEL_COSTS line traces back to model-pricing logic (compiler_model_pricing.go / compiler_yaml_step_lifecycle.go) unrelated to pre-activation job test coverage, and matches drift from a separate recent commit ("Fix imported engine.model silently dropped when max-ai-credits is set", #48482). Bundling incidental `make reco…
…unit tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@copilot run pr-finisher skill |
…lot-auto.lock.yml Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done — reverted the unrelated |
compiler_pre_activation_job.gowas the only large compiler module without a dedicated test file, leaving core pre-activation assembly logic under-covered. This PR adds focused unit tests for the highest-value helper paths used to build job structure, guards, and permissions.New dedicated test file
pkg/workflow/compiler_pre_activation_job_test.goto isolate pre-activation helper coverage from broader integration-heavy compiler tests.buildPreActivationPermissionscoveragecontents: read,actions: read,pull-requests: read) plus expliciton.permissionsmerge behavior.applyPreActivationIfConditionGuardscoverageauthor_associationguard when eligibleskip-author-associationsguard clauses.buildPreActivationJobcoverageifcondition (baseif+ label guard + author guard)on.needson.steps(<id>_result)matched_commandoutput defaulting to empty for non-command workflows.