fix: honor GH_AW_WORKFLOWS_DIR in GetWorkflowDir() and eliminate 27 hardcoded literals#32100
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…e 27 hardcoded literals
- Add os.Getenv("GH_AW_WORKFLOWS_DIR") override to constants.GetWorkflowDir()
- Add regression tests for env-var override and empty-env fallback
- Replace getWorkflowsDir() shim in pkg/cli/workflows.go with constants.GetWorkflowDir()
- Replace all 27 hardcoded ".github/workflows" literals across pkg/cli/ and pkg/parser/
with constants.GetWorkflowDir() calls
- Add constants import to files that lacked it (compile_orchestrator, compile_validation,
mcp_safe_update_cache, mcp_list, compile_watch, update_container_pins, import_bfs)
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot merge main and recompile |
…owdir-env-var-drift Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done — merged main and ran |
There was a problem hiding this comment.
Pull request overview
Fixes constants.GetWorkflowDir() to honor GH_AW_WORKFLOWS_DIR at runtime and propagates the helper across the CLI/parser so the workflow directory override works consistently (instead of being bypassed by hardcoded ".github/workflows" literals). Adds regression tests for the env-var override behavior, and includes regenerated workflow lockfiles.
Changes:
- Implement env-var override in
pkg/constants.GetWorkflowDir()and add unit tests covering override + empty behavior. - Replace hardcoded
".github/workflows"usage across CLI/parser call sites withconstants.GetWorkflowDir(). - Regenerate multiple
.github/workflows/*.lock.ymlfiles (notably updating theclaude_harnessinvocation argument ordering/placement).
Show a summary per file
| File | Description |
|---|---|
| pkg/constants/constants.go | Implement runtime GH_AW_WORKFLOWS_DIR override in GetWorkflowDir(). |
| pkg/constants/constants_test.go | Add regression tests for env override + empty env behavior. |
| pkg/parser/import_bfs.go | Use constants.GetWorkflowDir() as default base path for remote nested imports. |
| pkg/cli/workflows.go | Route workflow-dir resolution through constants.GetWorkflowDir(). |
| pkg/cli/upgrade_command.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/update_container_pins.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/trial_helpers.go | Use constants.GetWorkflowDir() when building workflow description path. |
| pkg/cli/run_workflow_execution.go | Use constants.GetWorkflowDir() for lock-file path resolution. |
| pkg/cli/resolver.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/remove_command.go | Default workflows directory now uses constants.GetWorkflowDir(). |
| pkg/cli/mcp_safe_update_cache.go | Default workflows directory now uses constants.GetWorkflowDir(). |
| pkg/cli/mcp_list.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/logs_utils.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/list_workflows_command.go | Default --path now uses constants.GetWorkflowDir(). |
| pkg/cli/lint_command.go | Default --dir now uses constants.GetWorkflowDir(). |
| pkg/cli/fix_command.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/enable.go | Default workflows directory now uses constants.GetWorkflowDir(). |
| pkg/cli/compile_watch.go | Watch mode now targets constants.GetWorkflowDir() under git root. |
| pkg/cli/compile_validation.go | Dependabot validation compares against constants.GetWorkflowDir(). |
| pkg/cli/compile_orchestrator.go | Default workflow directory now uses constants.GetWorkflowDir(). |
| pkg/cli/add_command.go | Default workflows directory now uses constants.GetWorkflowDir() under git root. |
| .github/workflows/test-create-pr-error-handling.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/static-analysis-report.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/smoke-agent-scoped-approved.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/smoke-agent-public-none.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/smoke-agent-public-approved.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/smoke-agent-all-none.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/smoke-agent-all-merged.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/sergo.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/schema-consistency-checker.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/safe-output-health.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/prompt-clustering-analysis.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/lockfile-stats.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/hourly-ci-cleaner.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/go-pattern-detector.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/github-mcp-tools-report.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/github-mcp-structural-analysis.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/example-workflow-analyzer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/design-decision-gate.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/deep-report.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-token-consumption-report.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-team-evolution-insights.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-subagent-optimizer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-security-red-team.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-safe-outputs-conformance.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-safe-output-optimizer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-otel-instrumentation-advisor.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-grafana-otel-instrumentation-advisor.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-function-namer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-code-metrics.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-choice-test.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-caveman-optimizer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-aw-cross-repo-compile-check.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-astrostylelite-markdown-spellcheck.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/daily-agentrx-trace-optimizer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/copilot-session-insights.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/copilot-agent-analysis.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/commit-changes-analyzer.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/cloclo.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/cli-version-checker.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/claude-code-user-docs-review.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/ci-doctor.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/aw-failure-investigator.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/audit-workflows.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/approach-validator.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
| .github/workflows/api-consumption-report.lock.yml | Regenerated lockfile (updates claude_harness invocation arg ordering/placement). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
pkg/cli/logs_utils.go:38
- The verbose warning message is hardcoded to "No .github/workflows directory found" even though workflowsDir is now dynamic via constants.GetWorkflowDir(). Update the message (and ideally the preceding comment) to reference the actual workflowsDir so GH_AW_WORKFLOWS_DIR users get accurate output.
pkg/cli/enable.go:287 - When GH_AW_WORKFLOWS_DIR is set, this verbose message still says "No .github/workflows directory found" even though workflowsDir is now derived from constants.GetWorkflowDir(). Consider including the actual workflowsDir in the message to avoid confusing output under overrides.
- Files reviewed: 22/22 changed files
- Comments generated: 7
| func GetWorkflowDir() string { | ||
| if dir := os.Getenv("GH_AW_WORKFLOWS_DIR"); dir != "" { | ||
| return dir | ||
| } | ||
| return filepath.Join(".github", "workflows") | ||
| } |
| workflowsDir := filepath.Join(gitRoot, constants.GetWorkflowDir()) | ||
| if _, err := os.Stat(workflowsDir); os.IsNotExist(err) { | ||
| return fmt.Errorf("the .github/workflows directory does not exist in git root (%s)", gitRoot) | ||
| } |
| workflowsDir := getWorkflowsDir() | ||
|
|
||
| _, _, err := readWorkflowFile(normalizedID+".md", workflowsDir) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to find workflow in local .github/workflows: %w", err) | ||
| } |
| // Find all include files in .github/workflows | ||
| // Only consider files in subdirectories (like shared/) as potential include files | ||
| // Root-level .md files are workflow files, not include files | ||
| workflowsDir := ".github/workflows" | ||
| workflowsDir := constants.GetWorkflowDir() | ||
| var allIncludes []string |
| cmd.Flags().String("path", constants.GetWorkflowDir(), "Path to workflows directory in the remote repository (used with --repo)") | ||
| cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows; ignored when --repo is set)") | ||
|
|
| // Check if the lock file exists in .github/workflows | ||
| lockFilePath = filepath.Join(".github/workflows", lockFileName) | ||
| lockFilePath = filepath.Join(constants.GetWorkflowDir(), lockFileName) | ||
| if _, err := os.Stat(lockFilePath); os.IsNotExist(err) { | ||
| executionLog.Printf("Lock file not found: %s (workflow must be compiled first)", lockFilePath) |
|
@copilot review all comments |
…ators Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
All review comments addressed in the latest commits:
The lockfile changes in |
Bug Fix
What was the bug?
GetWorkflowDir()was documented to readGH_AW_WORKFLOWS_DIRat call time but always returned the hardcoded string. Additionally, 27 production sites bypassed the helper entirely by inlining".github/workflows", making the env-var override non-functional throughout the codebase.How did you fix it?
pkg/constants/constants.go— implement the documented contract:Call-site consolidation — replaced all 27 hardcoded
".github/workflows"literals withconstants.GetWorkflowDir()across 20 files:pkg/cli/:workflows.go(shim),enable.go,logs_utils.go,compile_orchestrator.go,compile_validation.go,mcp_safe_update_cache.go,upgrade_command.go,list_workflows_command.go,lint_command.go,mcp_list.go,trial_helpers.go,fix_command.go,remove_command.go(×3),resolver.go,add_command.go,compile_watch.go,run_workflow_execution.go,update_container_pins.gopkg/parser/import_bfs.goconstantsimport to 7 files that lacked itFlag defaults in
lint_command.goandlist_workflows_command.gonow callconstants.GetWorkflowDir()at command-construction time so they also respect the env var.Testing
Added
TestGetWorkflowDirEnvOverrideandTestGetWorkflowDirEnvEmptytopkg/constants/constants_test.goto pin the env-var override behaviour as a regression guard.