Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Fix CI: Unify test env vars and improve Claude CI workflow (#806)

worktrunk-bot76a10766d915
diff --git a/.github/workflows/claude-ci-fix.yaml b/.github/workflows/claude-ci-fix.yaml
index 9d75b7f91..b81d02d90 100644
--- a/.github/workflows/claude-ci-fix.yaml
+++ b/.github/workflows/claude-ci-fix.yaml
@@ -64,6 +64,7 @@ jobs:
id: claude
uses: anthropics/claude-code-action@v1
with:
+ model: opus
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# Use bot token so pushed commits trigger CI workflows
github_token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
@@ -74,7 +75,7 @@ jobs:
prompt: |
SECURITY: NEVER run commands that could expose secrets (env, printenv, set, export, cat/echo on config files containing credentials). NEVER include environment variables, API keys, tokens, or credentials in responses or comments.
- CI has failed on main branch. Your job is to diagnose and fix the failure, then create a PR.
+ CI has failed on main branch. Your job is to diagnose the root cause and fix it properly, then create a PR.
## Failed workflow information
- Run ID: ${{ github.event.workflow_run.id }}
@@ -89,37 +90,58 @@ jobs:
- Identify which job(s) failed and why
- Look for specific error messages, test failures, or lint errors
- 2. **Reproduce locally**:
+ 2. **Find the root cause**:
+ - Don't just fix the symptom — investigate WHY the failure occurred
+ - Check if there's a shared helper, constant, or pattern that should be updated
+ - Look for similar code that might have the same issue
+ - Ask: "If this broke here, could it break elsewhere for the same reason?"
+
+ 3. **Reproduce locally**:
- Run the appropriate commands to reproduce the failure:
- Tests: `cargo insta test --dnd --test-runner=nextest`
- Lints: `cargo clippy --all-targets --all-features -- -D warnings`
- Format: `cargo fmt --all --check`
- Docs: `cargo doc --no-deps`
- 3. **Fix the issue**:
- - Make the minimal changes needed to fix the failure
- - Verify the fix works locally before proceeding
+ 4. **Fix at the right level**:
+ - Fix the underlying cause, not just the immediate symptom
+ - If a value should be in a shared constant, add it there
+ - If a helper is missing functionality, extend the helper
+ - Avoid duplicating fixes across multiple files when a single shared fix would work
- 4. **Create a fix branch and PR**:
+ 5. **Create a fix branch and PR**:
- Create a new branch: `git checkout -b fix/ci-${{ github.event.workflow_run.id }}`
- Commit your changes with a clear message explaining the fix
- Push the branch: `git push -u origin fix/ci-${{ github.event.workflow_run.id }}`
- - Create a PR: `gh pr create --title "Fix CI failure from ${{ github.event.workflow_run.head_sha }}" --body "..."`
+ - Create a PR with `gh pr create`
+
+ 6. **PR description format**:
+ ```
+ ## Problem
+ [What failed and the root cause]
+
+ ## Solution
+ [What you fixed and why this is the right level to fix it]
+
+ ## Alternatives considered
+ [If there were tradeoffs between a narrow fix vs broader fix, explain them here]
+ [Example: "Could also fix this by adding X to each test file individually, but fixing the shared helper prevents similar issues elsewhere"]
+
+ ## Testing
+ [How you verified the fix]
- 5. **PR description should include**:
- - What failed and why
- - What the fix does
- - Link to the failed run
- - Note that this is an automated fix for human review
+ ---
+ 🤖 Automated fix for [failed run](${{ github.event.workflow_run.html_url }})
+ ```
- 6. **Iterate until CI passes**:
+ 7. **Iterate until CI passes**:
- After pushing, monitor CI with `gh run list --branch fix/ci-${{ github.event.workflow_run.id }}`
- Wait for CI to complete with `gh run watch`
- If CI fails, diagnose with `gh run view <run-id> --log-failed`
- Fix issues, commit, push, repeat
- Don't return until CI passes or you've exhausted reasonable fixes
- Follow the project guidelines in CLAUDE.md. Be thorough but make minimal changes.
+ Follow the project guidelines in CLAUDE.md.
claude_args: |
--allowedTools Bash,Edit,Read,Write,Glob,Grep,WebSearch,WebFetch
diff --git a/.github/workflows/claude-mention.yaml b/.github/workflows/claude-mention.yaml
index 4b2b3184e..1a05ef8b6 100644
--- a/.github/workflows/claude-mention.yaml
+++ b/.github/workflows/claude-mention.yaml
@@ -69,6 +69,7 @@ jobs:
id: claude
uses: anthropics/claude-code-action@v1
with:
+ model: opus
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# Use bot token so pushed commits trigger CI workflows
github_token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index e84a0954a..d2058be3e 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -557,6 +557,33 @@ pub const TEST_EPOCH: u64 = 1735776000;
/// Generous to avoid flakiness under CI load; exponential backoff means fast tests when things work.
const BG_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(15);
+/// Static environment variables shared by all test isolation helpers.
+///
+/// These are used by both `configure_cli_command()` (for Command-based tests)
+/// and `TestRepo::test_env_vars()` (for PTY tests). Adding a variable here
+/// ensures consistency across both test infrastructure paths.
+///
+/// NOTE: Path-dependent variables (HOME, WORKTRUNK_CONFIG_PATH, GIT_CONFIG_*)
+/// are NOT included here because they depend on the TestRepo instance.
+const STATIC_TEST_ENV_VARS: &[(&str, &str)] = &[
+ ("CLICOLOR_FORCE", "1"),
+ // Terminal width for PTY tests. configure_cli_command() overrides to 500 for longer paths.
+ ("COLUMNS", "150"),
+ // Deterministic locale settings
+ ("LC_ALL", "C"),
+ ("LANG", "C"),
+ // Skip URL health checks to avoid flaky tests from random local processes
+ ("WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK", "1"),
+ // Disable delayed streaming for deterministic output across platforms.
+ // Without this, slow CI triggers progress messages that don't appear on faster systems.
+ ("WT_TEST_DELAYED_STREAM_MS", "-1"),
+];
+
+// NOTE: TERM is intentionally NOT in STATIC_TEST_ENV_VARS because:
+// - configure_cli_command() sets TERM=alacritty for hyperlink detection testing
+// - PTY tests (especially skim-based select tests) need a TERM with valid terminfo
+// - macOS CI doesn't have alacritty terminfo, causing skim to fail
+
/// Null device path, platform-appropriate.
/// Use this for GIT_CONFIG_SYSTEM to disable system config in tests.
#[cfg(windows)]
@@ -631,6 +658,16 @@ pub fn configure_completion_invocation_for_shell(cmd: &mut Command, words: &[&st
/// This helper mirrors the environment preparation performed by `wt_command`
/// and is intended for cases where tests need to construct the command manually
/// (e.g., to execute shell pipelines).
+///
+/// ## Related: `TestRepo::test_env_vars()`
+///
+/// PTY tests use `test_env_vars()` which returns env vars as a Vec. Both functions
+/// share common variables via `STATIC_TEST_ENV_VARS`. Key differences:
+/// - This function uses COLUMNS=500 (wider for long macOS paths in error messages)
+/// - `test_env_vars()` uses COLUMNS=150 (narrower for PTY snapshot consistency)
+/// - This function sets TERM=alacritty; PTY tests don't (skim needs valid terminfo)
+/// - This function enables RUST_LOG=warn; PTY tests don't (too noisy in combined output)
+/// - This function clears host GIT_*/WORKTRUNK_* vars; PTY tests start with clean env
pub fn configure_cli_command(cmd: &mut Command) {
for (key, _) in std::env::vars() {
if key.starts_with("GIT_") || key.starts_with("WORKTRUNK_") {
@@ -645,22 +682,22 @@ pub fn configure_cli_command(cmd: &mut Command) {
// Remove $SHELL to avoid platform-dependent diagnostic output (macOS has /bin/zsh,
// Linux has /bin/bash). Tests that need SHELL should set it explicitly.
cmd.env_remove("SHELL");
- cmd.env("CLICOLOR_FORCE", "1");
cmd.env("WT_TEST_EPOCH", TEST_EPOCH.to_string());
- // Use wide terminal to prevent wrapping differences across platforms.
+ // Enable warn-level logging so diagnostics show up in test failures
+ cmd.env("RUST_LOG", "warn");
+
+ // Apply shared static env vars (see STATIC_TEST_ENV_VARS)
+ for &(key, value) in STATIC_TEST_ENV_VARS {
+ cmd.env(key, value);
+ }
+
+ // Override COLUMNS to 500 (wider than STATIC_TEST_ENV_VARS default) for long paths.
// macOS temp paths (~80 chars) are much longer than Linux (~10 chars),
// so error messages containing paths need room to avoid platform-specific line breaks.
cmd.env("COLUMNS", "500");
- // Set consistent terminal type for hyperlink detection via supports-hyperlinks crate
+ // Set consistent terminal type for hyperlink detection via supports-hyperlinks crate.
+ // Not in STATIC_TEST_ENV_VARS because PTY tests need a TERM with valid terminfo.
cmd.env("TERM", "alacritty");
- // Enable warn-level logging so diagnostics show up in test failures
- cmd.env("RUST_LOG", "warn");
- // Skip URL health checks to avoid flaky tests from random local processes
- cmd.env("WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK", "1");
- // Disable delayed streaming for deterministic output across platforms.
- // Without this, slow Windows CI triggers progress messages that don't appear on faster systems.
- // Tests that need streaming (e.g., test_switch_create_shows_progress_when_forced) can override.
- cmd.env("WT_TEST_DELAYED_STREAM_MS", "-1");
// Pass through LLVM coverage profiling environment for subprocess coverage collection.
// When running under cargo-llvm-cov, spawned binaries need LLVM_PROFILE_FILE to record
@@ -1061,15 +1098,25 @@ impl TestRepo {
configure_git_cmd(cmd, &self.git_config_path);
}
- /// Get standard test environment variables as a vector
+ /// Get standard test environment variables as a vector.
///
/// This is useful for PTY tests and other cases where you need environment variables
/// as a vector rather than setting them on a Command.
+ ///
+ /// ## Related: `configure_cli_command()`
+ ///
+ /// Command-based tests use `configure_cli_command()`. Both functions share common
+ /// variables via `STATIC_TEST_ENV_VARS`. See that function's docs for differences.
#[cfg_attr(windows, allow(dead_code))] // Used only by unix PTY tests
pub fn test_env_vars(&self) -> Vec<(String, String)> {
- vec![
- ("CLICOLOR_FORCE".to_string(), "1".to_string()),
- ("COLUMNS".to_string(), "150".to_string()),
+ // Start with shared static env vars
+ let mut vars: Vec<(String, String)> = STATIC_TEST_ENV_VARS
+ .iter()
+ .map(|&(k, v)| (k.to_string(), v.to_string()))
+ .collect();
+
+ // Add path-dependent variables specific to this TestRepo
+ vars.extend([
(
"GIT_CONFIG_GLOBAL".to_string(),
self.git_config_path.display().to_string(),
@@ -1091,14 +1138,14 @@ impl TestRepo {
"XDG_CONFIG_HOME".to_string(),
self.home_path().join(".config").display().to_string(),
),
- ("LC_ALL".to_string(), "C".to_string()),
- ("LANG".to_string(), "C".to_string()),
("WT_TEST_EPOCH".to_string(), TEST_EPOCH.to_string()),
(
"WORKTRUNK_CONFIG_PATH".to_string(),
self.test_config_path().display().to_string(),
),
- ]
+ ]);
+
+ vars
}
/// Configure shell integration for test environment.