-
Notifications
You must be signed in to change notification settings - Fork 298
Description
Overview
The file pkg/workflow/compiler_activation_jobs.go has grown to 1052 lines, exceeding the 800-line healthy threshold. It contains three distinct job-building domains — pre-activation, activation, and main/agent — that are large enough to warrant separation into focused, independently testable files.
Current State
- File:
pkg/workflow/compiler_activation_jobs.go - Size: 1052 lines
- Test file:
compiler_activation_jobs_test.go— 464 lines - Test-to-source ratio: ~44%
- Complexity: 6 functions spanning 3 logical domains;
buildPreActivationJobalone is ~340 lines with deeply nested conditional step generation
Full File Analysis
Function Inventory
| Function | Lines | Domain |
|---|---|---|
buildPreActivationJob |
22–357 (~335 lines) | Pre-activation job |
extractPreActivationCustomFields |
363–445 (~83 lines) | Pre-activation job |
buildActivationJob |
449–762 (~313 lines) | Activation job |
buildMainJob |
766–991 (~225 lines) | Main/agent job |
generatePromptInActivationJob |
998–1012 (~14 lines) | Activation job |
generateCheckoutGitHubFolderForActivation |
1019–1052 (~33 lines) | Activation job |
Complexity Hotspots
buildPreActivationJob(lines 22–357): Complex multi-stage step builder — reaction setup, membership check, rate limiting, stop-time, skip-if-match, skip-if-no-match, skip-roles, skip-bots, command position, then condition expression assembly. Each conditional block appends YAML strings, making the function hard to follow.buildActivationJob(lines 449–762): Similarly deep nesting — timestamp check, sanitized text, status comment, lock-for-agent, secret validation, prompt generation, artifact upload, permissions assembly.buildMainJob(lines 766–991): Cleaner but still 225 lines with complex dependency resolution (custom job deps, prompt-referenced jobs, safe outputs env vars).
Coupling Notes
All three top-level builders are methods on *Compiler and share only the WorkflowData struct. They do not call each other, making clean file separation straightforward without interface changes.
Refactoring Strategy
Proposed File Splits
Split into three focused files under the same workflow package (same package = no import changes needed):
-
compiler_pre_activation_job.go- Functions:
buildPreActivationJob,extractPreActivationCustomFields - Responsibility: Builds the pre-activation guard job — membership, rate-limit, stop-time, skip checks, command position
- Estimated LOC: ~420
- Functions:
-
compiler_activation_job.go- Functions:
buildActivationJob,generatePromptInActivationJob,generateCheckoutGitHubFolderForActivation - Responsibility: Builds the activation job — timestamp check, sanitised outputs, status comment, lock, prompt upload
- Estimated LOC: ~370
- Functions:
-
compiler_main_job.go- Functions:
buildMainJob - Responsibility: Builds the agent job — step generation, dependency resolution, safe-outputs env, permissions
- Estimated LOC: ~230
- Functions:
The original compiler_activation_jobs.go is deleted after moving all functions; the package-level var compilerActivationJobsLog logger is moved to whichever file uses it most (pre-activation) and each new file declares its own logger if needed.
Shared Utilities
No new shared utilities are needed — all helpers (generateGitHubScriptWithRequire, GetActionPin, expression builders) already live in separate files.
Interface Abstractions
No new interfaces are required. The split is purely structural; all three new files are in the same workflow package and continue to be methods on *Compiler.
Test Coverage Plan
The existing compiler_activation_jobs_test.go (464 lines) should be split in parallel:
-
compiler_pre_activation_job_test.go- Test cases: membership check generation, rate-limit step, stop-time step, skip-if-match/no-match, skip-roles, skip-bots, command position, custom steps/outputs merge, activated output expression assembly
- Target coverage: ≥80%
-
compiler_activation_job_test.go- Test cases: timestamp step, sanitised text outputs, status comment step, lock-for-agent step, secret validation, prompt generation delegation, artifact upload step, permissions map assembly,
generateCheckoutGitHubFolderForActivation(action-tag skip, always-add path) - Target coverage: ≥80%
- Test cases: timestamp step, sanitised text outputs, status comment step, lock-for-agent step, secret validation, prompt generation delegation, artifact upload step, permissions map assembly,
-
compiler_main_job_test.go- Test cases: setup step inclusion, job condition handling when activation job exists/absent, custom job dependency resolution, prompt-referenced job deps, safe-outputs env vars, permissions augmentation in dev mode, outputs map
- Target coverage: ≥80%
Implementation Guidelines
- Preserve Behaviour: All existing functionality must work identically — run
make test-unitafter each file is split - Move logger: Keep the
compilerActivationJobsLoglogger incompiler_pre_activation_job.go; addcompilerActivationJobLogandcompilerMainJobLogin the other two files - Same package: All files stay in
package workflow— no import path changes - Add build tags: New
*_test.gofiles must start with//go:build !integration - Incremental: Split one file at a time, run
make test-unitbetween each - Delete original: Remove
compiler_activation_jobs.goonly after all three replacement files compile and tests pass - Run full validation:
make agent-finishbefore committing
Acceptance Criteria
-
compiler_activation_jobs.gois removed and replaced by 3 focused files - Each new file is under 500 lines
- All tests pass (
make test-unit) - Test coverage ≥80% for all new test files
- No breaking changes to public API
- Code passes linting (
make lint) - Build succeeds (
make build) -
make recompilesucceeds (lock files regenerate cleanly)
Additional Context
- Repository Guidelines: Follow patterns in
AGENTS.mdandscratchpad/cli-command-patterns.md - Validation Complexity Guidelines: Target 100–200 lines per file; hard limit 300 lines (see AGENTS.md)
- Testing: Match existing test patterns in
pkg/workflow/*_test.go - Workflow run: §22578126726
Priority: Medium
Effort: Small (structural move only — no logic changes)
Expected Impact: Improved maintainability, easier code navigation, clearer test boundaries per job type
Generated by Daily File Diet
- expires on Mar 4, 2026, 1:33 PM UTC