Skip to content

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

feat(approvals): add `wt config approvals list` and `clear --stale` (#3380)

Maximilian Roos9edf0aa6b3d1
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index cb5faed2e..aa5e83b3e 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -120,12 +120,13 @@ Examples that page: `--help`, `wt config show`, `wt hook show`, `wt step {commit
Build the whole output into a `String` first (don't stream), then:
```rust
-if let Err(e) = crate::help_pager::show_help_in_pager(&out, true) {
- log::debug!("Pager failed, falling back to stdout: {}", e);
- println!("{}", out);
-}
+crate::help_pager::show_help_in_pager(&out, true);
```
+The helper is infallible from the caller's perspective — it falls back to
+plain stdout itself when no pager is configured, stdout isn't a TTY, or the
+pager fails.
+
## Security
The split-trust design enforces two trust levels:
@@ -380,6 +381,13 @@ naturally come after the action.
| "Created new worktree for feature" | "Already on worktree for feature" |
| "Commands approved & saved" | "All commands already approved" |
+The same rule governs standalone symbols used as per-row markers in listings:
+✓ marks a completed action, never a state. A listing that reports per-item
+status marks it with ○ (state acknowledged) or ❯ (awaiting approval/user
+input) — the shared vocabulary of `wt hook show` and `wt config approvals
+list`. Reserve a per-row ✓ for outcomes of work the command just performed
+(shell-install action lines, `-v` subprocess trace glyphs).
+
**Hint vs Info:** Hints suggest user action or provide additional non-essential
context (supplementary details the user doesn't need but may find useful). Info
acknowledges state without changing anything.
diff --git a/docs/content/config.md b/docs/content/config.md
index 3c90f7e1c..475350cd2 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -761,12 +761,18 @@ Project hooks and project aliases prompt for approval on first run to prevent un
### Examples
+List commands and their approval status for current project:
+{{ terminal(cmd="wt config approvals list") }}
+
Pre-approve all hook and alias commands for current project:
{{ terminal(cmd="wt config approvals add") }}
Clear approvals for current project:
{{ terminal(cmd="wt config approvals clear") }}
+Clear only approvals for commands no longer in the project config:
+{{ terminal(cmd="wt config approvals clear --stale") }}
+
Clear global approvals:
{{ terminal(cmd="wt config approvals clear --global") }}
@@ -782,6 +788,7 @@ wt config approvals - Manage command approvals
Usage: <b><span class=c>wt config approvals</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;COMMAND&gt;</span>
<b><span class=g>Commands:</span></b>
+ <b><span class=c>list</span></b> List project commands and their approval status
<b><span class=c>add</span></b> Store approvals in approvals.toml
<b><span class=c>clear</span></b> Clear approved commands from approvals.toml
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 2dfc19435..f65c01052 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -763,6 +763,11 @@ Project hooks and project aliases prompt for approval on first run to prevent un
### Examples
+List commands and their approval status for current project:
+```bash
+$ wt config approvals list
+```
+
Pre-approve all hook and alias commands for current project:
```bash
$ wt config approvals add
@@ -773,6 +778,11 @@ Clear approvals for current project:
$ wt config approvals clear
```
+Clear only approvals for commands no longer in the project config:
+```bash
+$ wt config approvals clear --stale
+```
+
Clear global approvals:
```bash
$ wt config approvals clear --global
@@ -790,6 +800,7 @@ wt config approvals - Manage command approvals
Usage: wt config approvals [OPTIONS] <COMMAND>
Commands:
+ list List project commands and their approval status
add Store approvals in approvals.toml
clear Clear approved commands from approvals.toml
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 53773269f..5dc50b27e 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -230,9 +230,21 @@ This leaves any already-installed Worktrunk plugin unchanged."#
Uninstall,
}
-// Ordering: action + inverse adjacent (add, clear).
+// Ordering: read first (list), then action + inverse adjacent (add, clear).
#[derive(Subcommand)]
pub enum ApprovalsCommand {
+ /// List project commands and their approval status
+ #[command(
+ after_long_help = r#"Shows every command the project config declares — hooks, aliases, and commit-message guidance — grouped into APPROVED and UNAPPROVED sections. Approvals recorded for commands no longer in the project config (edited or removed since approval) are listed separately.
+
+## Examples
+
+```console
+$ wt config approvals list
+```"#
+ )]
+ List,
+
/// Store approvals in approvals.toml
#[command(
after_long_help = r#"Prompts for approval of all project commands and saves them to approvals.toml.
@@ -251,12 +263,17 @@ including previously approved ones."#
after_long_help = r#"Removes saved approvals, requiring re-approval on next command run.
By default, clears approvals for the current project. Use `--global` to clear
-all approvals across all projects."#
+all approvals across all projects, or `--stale` to clear only approvals for
+commands no longer in the project config (edited or removed since approval)."#
)]
Clear {
/// Clear global approvals
#[arg(short, long)]
global: bool,
+
+ /// Clear only stale approvals
+ #[arg(long, conflicts_with = "global")]
+ stale: bool,
},
}
@@ -531,6 +548,11 @@ $ wt config update --print
## Examples
+List commands and their approval status for current project:
+```console
+$ wt config approvals list
+```
+
Pre-approve all hook and alias commands for current project:
```console
$ wt config approvals add
@@ -541,6 +563,11 @@ Clear approvals for current project:
$ wt config approvals clear
```
+Clear only approvals for commands no longer in the project config:
+```console
+$ wt config approvals clear --stale
+```
+
Clear global approvals:
```console
$ wt config approvals clear --global
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 17fec1c06..4ce872e53 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -25,8 +25,8 @@ use color_print::cformat;
use worktrunk::config::{Approvals, require_approvals_path};
use worktrunk::git::{GitError, HookType};
use worktrunk::styling::{
- INFO_SYMBOL, WARNING_SYMBOL, eprint, eprintln, format_bash_with_gutter, format_with_gutter,
- hint_message, prompt_message, stderr, warning_message,
+ INFO_SYMBOL, WARNING_SYMBOL, eprint, eprintln, hint_message, prompt_message, stderr,
+ warning_message,
};
use super::hook_filter::{HookSource, ParsedFilter};
@@ -115,22 +115,9 @@ fn prompt_for_batch_approval(
);
for cmd in commands {
- // Format as: {phase} {bold}{name}{bold:#}:
// Uses INFO_SYMBOL (○) since this is a preview, not active execution
- let phase = cmd.phase.to_string();
- let label = match &cmd.command.name {
- Some(name) => cformat!("{INFO_SYMBOL} {phase} <bold>{name}</>:"),
- None => format!("{INFO_SYMBOL} {phase}:"),
- };
- eprintln!("{}", label);
- // Shell commands get bash syntax highlighting; the commit template
- // fragment is plain text (markdown-ish) and shouldn't be tokenized as
- // bash.
- let body = match cmd.phase {
- Phase::CommitTemplateAppend => format_with_gutter(&cmd.command.template, None),
- _ => format_bash_with_gutter(&cmd.command.template),
- };
- eprintln!("{}", body);
+ eprintln!("{} {}", INFO_SYMBOL, cmd.label());
+ eprintln!("{}", cmd.format_template());
}
// Check if stdin is a TTY before attempting to prompt
diff --git a/src/commands/config/approvals.rs b/src/commands/config/approvals.rs
index bbe85c2f9..454e3633e 100644
--- a/src/commands/config/approvals.rs
+++ b/src/commands/config/approvals.rs
@@ -1,45 +1,143 @@
//! Approvals commands for `wt config approvals` subcommand.
//!
+//! - `list_approvals` - Show approval status for all project commands
//! - `add_approvals` - Approve all project commands (hooks and aliases)
//! - `clear_approvals` - Clear approved commands
+use std::fmt::Write;
+
use anyhow::Context;
+use color_print::cformat;
use strum::IntoEnumIterator;
use worktrunk::HookType;
-use worktrunk::config::{Approvals, require_approvals_path};
+use worktrunk::config::{Approvals, ProjectConfig, require_approvals_path};
use worktrunk::git::{GitError, Repository};
-use worktrunk::styling::{eprintln, info_message, success_message};
+use worktrunk::styling::{
+ INFO_SYMBOL, PROMPT_SYMBOL, eprintln, format_bash_with_gutter, format_heading, hint_message,
+ info_message, success_message, warning_message,
+};
use crate::commands::command_approval::approve_command_batch;
use crate::commands::project_config::{
ApprovableCommand, collect_commands_for_aliases, collect_commands_for_hooks,
};
-/// Handle `wt config approvals add` command - approve all hook and alias commands in the project
-pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
- let repo = Repository::current()?;
- let project_id = repo.project_identifier()?;
- let approvals = Approvals::load().context("Failed to load approvals")?;
+/// Every approvable command a project config declares: hooks in lifecycle
+/// order, then aliases (alphabetical), then any commit-message guidance.
+/// The shared collection behind `wt config approvals {list,add}`.
+fn collect_approvable_commands(project_config: &ProjectConfig) -> Vec<ApprovableCommand> {
+ let all_hooks: Vec<_> = HookType::iter().collect();
+ let mut commands = collect_commands_for_hooks(project_config, &all_hooks);
+ commands.extend(collect_commands_for_aliases(project_config));
+ if let Some(fragment) = project_config.commit_template_append() {
+ commands.push(ApprovableCommand::commit_template_append(
+ fragment.to_string(),
+ ));
+ }
+ commands
+}
- // Load project config (error if missing - this command requires it)
+/// The project config, erroring when none exists. For the operations whose
+/// semantics need the config as their frame of reference (`add`, `clear
+/// --stale`); the read-only `list` instead treats absence as zero commands.
+fn require_project_config(repo: &Repository) -> anyhow::Result<ProjectConfig> {
let config_path = repo
.project_config_path()?
.context("Cannot determine project config location — no worktree found")?;
- let project_config = repo
+ Ok(repo
.load_project_config()?
- .ok_or(GitError::ProjectConfigNotFound { config_path })?;
+ .ok_or(GitError::ProjectConfigNotFound { config_path })?)
+}
- // Collect all commands from the project config: hooks first (lifecycle order),
- // then aliases (alphabetical via BTreeMap), then any commit-message guidance.
- let all_hooks: Vec<_> = HookType::iter().collect();
- let mut commands = collect_commands_for_hooks(&project_config, &all_hooks);
- commands.extend(collect_commands_for_aliases(&project_config));
- if let Some(fragment) = project_config.commit_template_append() {
- commands.push(ApprovableCommand::commit_template_append(
- fragment.to_string(),
- ));
+/// Handle `wt config approvals list` - show approval status for all project commands
+pub fn list_approvals() -> anyhow::Result<()> {
+ let repo = Repository::current()?;
+ let project_id = repo.project_identifier()?;
+ let approvals = Approvals::load().context("Failed to load approvals")?;
+
+ // A missing project config just means zero configured commands — recorded
+ // approvals for the project still list (as stale), so this never errors.
+ let commands = match repo.load_project_config()? {
+ Some(cfg) => collect_approvable_commands(&cfg),
+ None => Vec::new(),
+ };
+
+ let templates: Vec<&str> = commands
+ .iter()
+ .map(|cmd| cmd.command.template.as_str())
+ .collect();
+ let stale = approvals.stale_approvals(&project_id, &templates);
+
+ if commands.is_empty() && stale.is_empty() {
+ eprintln!("{}", info_message("No commands configured in project"));
+ return Ok(());
+ }
+
+ let (approved, unapproved): (Vec<_>, Vec<_>) = commands
+ .iter()
+ .partition(|cmd| approvals.is_command_approved(&project_id, &cmd.command.template));
+
+ let mut out = String::new();
+ let render_section =
+ |out: &mut String, title: &str, symbol: &str, section: &[&ApprovableCommand]| {
+ writeln!(out, "{}", format_heading(title, None))?;
+ if section.is_empty() {
+ writeln!(out, "{}", hint_message("(none)"))?;
+ }
+ for cmd in section {
+ writeln!(out, "{} {}", symbol, cmd.label())?;
+ writeln!(out, "{}", cmd.format_template())?;
+ }
+ anyhow::Ok(())
+ };
+ // Symbols match `wt hook show`: ○ approved (a state, not a success),
+ // ❯ awaiting approval.
+ if !commands.is_empty() {
+ render_section(&mut out, "APPROVED", INFO_SYMBOL, &approved)?;
+ out.push('\n');
+ render_section(&mut out, "UNAPPROVED", PROMPT_SYMBOL, &unapproved)?;
}
+ if !stale.is_empty() {
+ if !out.is_empty() {
+ out.push('\n');
+ }
+ writeln!(
+ out,
+ "{}",
+ warning_message("Approved commands no longer in project config:")
+ )?;
+ // Stale approvals are bare strings — the phase isn't recorded in
+ // approvals.toml — so bash formatting is the best default even though
+ // a stale commit-template fragment is prose.
+ for command in &stale {
+ writeln!(out, "{}", format_bash_with_gutter(command))?;
+ }
+ writeln!(
+ out,
+ "{}",
+ hint_message(cformat!(
+ "To clear stale approvals, run <underline>wt config approvals clear --stale</>"
+ ))
+ )?;
+ }
+
+ // Human-oriented sectioned output, plausibly more than a screen — page it
+ // like `wt hook show`. The helper TTY-detects, so piping stays plain.
+ crate::help_pager::show_help_in_pager(&out, true);
+
+ Ok(())
+}
+
+/// Handle `wt config approvals add` command - approve all hook and alias commands in the project
+pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
+ let repo = Repository::current()?;
+ let project_id = repo.project_identifier()?;
+ let approvals = Approvals::load().context("Failed to load approvals")?;
+
+ let project_config = require_project_config(&repo)?;
+ let commands = collect_approvable_commands(&project_config);
+
if commands.is_empty() {
eprintln!("{}", info_message("No commands configured in project"));
return Ok(());
@@ -80,10 +178,48 @@ pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
}
/// Handle `wt config approvals clear` command - clear approved commands
-pub fn clear_approvals(global: bool) -> anyhow::Result<()> {
+pub fn clear_approvals(global: bool, stale: bool) -> anyhow::Result<()> {
let mut approvals = Approvals::load().context("Failed to load approvals")?;
- if global {
+ if stale {
+ // Clear only approvals whose commands left the project config. A
+ // missing config is an error (matching `add`), not "everything is
+ // stale": approvals are keyed repo-wide while the config is resolved
+ // per-worktree, so a branch that merely lacks the file must not wipe
+ // the whole repo's approvals. Clearing everything is `clear`'s job.
+ let repo = Repository::current()?;
+ let project_id = repo.project_identifier()?;
+ let project_config = require_project_config(&repo)?;
+ let commands = collect_approvable_commands(&project_config);
+ let templates: Vec<&str> = commands
+ .iter()
+ .map(|cmd| cmd.command.template.as_str())
+ .collect();
+
+ let removed = approvals
+ .revoke_stale(&project_id, &templates, &require_approvals_path()?)
+ .context("Failed to clear stale approvals")?;
+
+ if removed.is_empty() {
+ eprintln!(
+ "{}",
+ info_message("No stale approvals to clear for this project")
+ );
+ return Ok(());
+ }
+
+ eprintln!(
+ "{}",
+ success_message(format!(
+ "Cleared {} stale approval{} for this project:",
+ removed.len(),
+ if removed.len() == 1 { "" } else { "s" }
+ ))
+ );
+ for command in &removed {
+ eprintln!("{}", format_bash_with_gutter(command));
+ }
+ } else if global {
// Count projects with approvals before clearing
let project_count = approvals
.projects()
diff --git a/src/commands/config/mod.rs b/src/commands/config/mod.rs
index 344638451..18ad24349 100644
--- a/src/commands/config/mod.rs
+++ b/src/commands/config/mod.rs
@@ -15,7 +15,7 @@ mod update;
// Re-export public functions
pub use alias::{handle_alias_dry_run, handle_alias_show};
-pub use approvals::{add_approvals, clear_approvals};
+pub use approvals::{add_approvals, clear_approvals, list_approvals};
pub use codex::{handle_codex_install, handle_codex_uninstall};
pub use create::handle_config_create;
pub use hints::{handle_hints_clear, handle_hints_get};
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index bc1211076..63f3d96b1 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -42,6 +42,7 @@ pub(crate) use config::{
handle_logs_list, handle_logs_profile, handle_opencode_install, handle_opencode_uninstall,
handle_state_clear, handle_state_clear_all, handle_state_get, handle_state_set,
handle_state_show, handle_vars_clear, handle_vars_get, handle_vars_list, handle_vars_set,
+ list_approvals,
};
pub(crate) use configure_shell::{
handle_configure_shell, handle_show_theme, handle_unconfigure_shell,
diff --git a/src/commands/project_config.rs b/src/commands/project_config.rs
index a559556b8..0a611b064 100644
--- a/src/commands/project_config.rs
+++ b/src/commands/project_config.rs
@@ -1,7 +1,9 @@
use std::fmt;
+use color_print::cformat;
use worktrunk::config::{Command, ProjectConfig};
use worktrunk::git::HookType;
+use worktrunk::styling::{format_bash_with_gutter, format_with_gutter};
/// What triggered a project command — determines the label in approval prompts.
#[derive(Clone)]
@@ -42,6 +44,26 @@ impl ApprovableCommand {
command: Command::new(None, text),
}
}
+
+ /// `phase name:` label shown before the command body, in the approval
+ /// prompt and the approvals listing.
+ pub fn label(&self) -> String {
+ let phase = &self.phase;
+ match &self.command.name {
+ Some(name) => cformat!("{phase} <bold>{name}</>:"),
+ None => format!("{phase}:"),
+ }
+ }
+
+ /// Gutter-formatted template. Shell commands get bash syntax
+ /// highlighting; the commit template fragment is plain text
+ /// (markdown-ish) and shouldn't be tokenized as bash.
+ pub fn format_template(&self) -> String {
+ match self.phase {
+ Phase::CommitTemplateAppend => format_with_gutter(&self.command.template, None),
+ _ => format_bash_with_gutter(&self.command.template),
+ }
+ }
}
/// Collect commands for the given hook types, preserving order of the provided hooks.
diff --git a/src/config/approvals.rs b/src/config/approvals.rs
index f3ae66625..81eabf41f 100644
--- a/src/config/approvals.rs
+++ b/src/config/approvals.rs
@@ -263,6 +263,26 @@ impl Approvals {
.iter()
.map(|(id, p)| (id.as_str(), p.approved_commands.as_slice()))
}
+
+ /// Approved commands for `project` that match none of `templates` (after
+ /// template-variable normalization) — approvals left behind when a config
+ /// command was edited or removed.
+ pub fn stale_approvals<'a>(&'a self, project: &str, templates: &[&str]) -> Vec<&'a str> {
+ let normalized: Vec<_> = templates
+ .iter()
+ .map(|t| normalize_template_vars(t))
+ .collect();
+ self.projects
+ .get(project)
+ .map(|p| {
+ p.approved_commands
+ .iter()
+ .filter(|c| !normalized.contains(&normalize_template_vars(c)))
+ .map(String::as_str)
+ .collect()
+ })
+ .unwrap_or_default()
+ }
}
// =========================================================================
@@ -395,6 +415,43 @@ impl Approvals {
})
}
+ /// Remove approvals for `project` that match none of `templates` (the
+ /// project's current command set) and save. Returns the removed commands.
+ ///
+ /// Staleness is recomputed under the file lock via [`Self::stale_approvals`],
+ /// so an approval another process records between the caller's read and
+ /// this call is never removed by mistake.
+ pub fn revoke_stale(
+ &mut self,
+ project: &str,
+ templates: &[&str],
+ approvals_path: &Path,
+ ) -> Result<Vec<String>, ConfigError> {
+ let mut removed = Vec::new();
+ self.with_locked_mutation(approvals_path, |approvals| {
+ let stale: Vec<String> = approvals
+ .stale_approvals(project, templates)
+ .into_iter()
+ .map(String::from)
+ .collect();
+ if stale.is_empty() {
+ return false;
+ }
+ let Some(project_config) = approvals.projects.get_mut(project) else {
+ return false;
+ };
+ project_config
+ .approved_commands
+ .retain(|c| !stale.contains(c));
+ if project_config.approved_commands.is_empty() {
+ approvals.projects.remove(project);
+ }
+ removed = stale;
+ true
+ })?;
+ Ok(removed)
+ }
+
/// Clear all approvals for all projects and save.
pub fn clear_all(&mut self, approvals_path: &Path) -> Result<(), ConfigError> {
self.with_locked_mutation(approvals_path, |approvals| {
@@ -944,6 +1001,75 @@ approved-command = ["npm test"]
approvals.revoke_project("project-a", &path).unwrap();
}
+ /// Stale = approved but matching no config template, with the same
+ /// normalization as `is_command_approved`: an approval saved with a
+ /// deprecated variable name still matches its canonical config command.
+ #[test]
+ fn test_stale_approvals() {
+ let (_temp_dir, path) = test_dir();
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_commands(
+ "project".to_string(),
+ vec![
+ "npm test".to_string(),
+ "echo {{ repo_root }}".to_string(),
+ "removed command".to_string(),
+ ],
+ &path,
+ )
+ .unwrap();
+
+ let stale = approvals.stale_approvals("project", &["npm test", "echo {{ repo_path }}"]);
+ assert_eq!(stale, vec!["removed command"]);
+ assert!(
+ approvals
+ .stale_approvals("other-project", &["npm test"])
+ .is_empty()
+ );
+ }
+
+ /// `revoke_stale` removes only approvals matching no template (same
+ /// normalization as `stale_approvals`), keeps the rest, and drops the
+ /// project entry entirely when nothing remains.
+ #[test]
+ fn test_revoke_stale() {
+ let (_temp_dir, path) = test_dir();
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_commands(
+ "project".to_string(),
+ vec![
+ "npm test".to_string(),
+ "echo {{ repo_root }}".to_string(),
+ "removed command".to_string(),
+ ],
+ &path,
+ )
+ .unwrap();
+
+ let templates = ["npm test", "echo {{ repo_path }}"];
+ let removed = approvals
+ .revoke_stale("project", &templates, &path)
+ .unwrap();
+ assert_eq!(removed, vec!["removed command"]);
+ assert!(approvals.is_command_approved("project", "npm test"));
+ assert!(approvals.is_command_approved("project", "echo {{ repo_root }}"));
+
+ // Nothing stale left — a second call is a no-op.
+ let removed = approvals
+ .revoke_stale("project", &templates, &path)
+ .unwrap();
+ assert!(removed.is_empty());
+
+ // Every remaining approval stale — the project entry disappears.
+ let removed = approvals.revoke_stale("project", &[], &path).unwrap();
+ assert_eq!(removed.len(), 2);
+ assert!(!approvals.projects.contains_key("project"));
+ }
+
#[test]
fn test_projects_accessor() {
let (_temp_dir, path) = test_dir();
diff --git a/src/main.rs b/src/main.rs
index 7913f5b6c..906cc7741 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -49,8 +49,9 @@ use commands::{
handle_opencode_uninstall, handle_promote, handle_rebase, handle_remove_command,
handle_show_theme, handle_squash, handle_state_clear, handle_state_clear_all, handle_state_get,
handle_state_set, handle_state_show, handle_switch_command, handle_unconfigure_shell,
- handle_vars_clear, handle_vars_get, handle_vars_list, handle_vars_set, run_hook, step_commit,
- step_copy_ignored, step_diff, step_eval, step_for_each, step_prune, step_relocate, step_tether,
+ handle_vars_clear, handle_vars_get, handle_vars_list, handle_vars_set, list_approvals,
+ run_hook, step_commit, step_copy_ignored, step_diff, step_eval, step_for_each, step_prune,
+ step_relocate, step_tether,
};
use cli::{
@@ -156,8 +157,9 @@ fn handle_hook_command(action: HookCommand, yes: bool) -> anyhow::Result<()> {
))
);
match action {
+ ApprovalsCommand::List => list_approvals(),
ApprovalsCommand::Add { all } => add_approvals(all),
- ApprovalsCommand::Clear { global } => clear_approvals(global),
+ ApprovalsCommand::Clear { global, stale } => clear_approvals(global, stale),
}
}
HookCommand::Run(args) => {
@@ -612,8 +614,9 @@ fn handle_config_command(action: ConfigCommand, yes: bool) -> anyhow::Result<()>
ConfigCommand::Show { full, format } => handle_config_show(full, format),
ConfigCommand::Update { print } => handle_config_update(yes, print),
ConfigCommand::Approvals { action } => match action {
+ ApprovalsCommand::List => list_approvals(),
ApprovalsCommand::Add { all } => add_approvals(all),
- ApprovalsCommand::Clear { global } => clear_approvals(global),
+ ApprovalsCommand::Clear { global, stale } => clear_approvals(global, stale),
},
ConfigCommand::Alias { action } => match action {
ConfigAliasCommand::Show { name } => handle_alias_show(name),
diff --git a/tests/integration_tests/approvals.rs b/tests/integration_tests/approvals.rs
index 8a40826c5..b70dbc21d 100644
--- a/tests/integration_tests/approvals.rs
+++ b/tests/integration_tests/approvals.rs
@@ -1,4 +1,4 @@
-//! Integration tests for add-approvals and clear-approvals commands
+//! Integration tests for the `wt config approvals` subcommands
use crate::common::{
BareRepoTest, TestRepo, TestRepoBase, make_snapshot_cmd, repo, set_temp_home_env,
@@ -31,6 +31,104 @@ fn snapshot_clear_approvals(test_name: &str, repo: &TestRepo, args: &[&str]) {
});
}
+/// Helper to snapshot the list command
+fn snapshot_list_approvals(test_name: &str, repo: &TestRepo) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "config", &[], None);
+ cmd.arg("approvals").arg("list");
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+// ============================================================================
+// list tests
+// ============================================================================
+
+#[rstest]
+fn test_list_approvals_no_config(repo: TestRepo) {
+ snapshot_list_approvals("list_approvals_no_config", &repo);
+}
+
+/// The main listing: hooks, an alias, and commit-message guidance, with a mix
+/// of approved and unapproved commands, plus a stale approval whose command
+/// was removed from the config.
+#[rstest]
+fn test_list_approvals_mixed(repo: TestRepo) {
+ // Remove origin so project_identifier uses the canonical worktree path —
+ // matches what `Repository::project_identifier` computes at runtime.
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.write_project_config(
+ r#"pre-merge = "cargo test"
+
+[post-start]
+dev = "npm run dev"
+
+[aliases]
+deploy = "echo deploying {{ branch }}"
+
+[commit.generation]
+template-append = "Use conventional commits."
+"#,
+ );
+ repo.commit("Add config");
+
+ let project_id = repo.project_id();
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_commands(
+ project_id,
+ vec![
+ "cargo test".to_string(),
+ "echo deploying {{ branch }}".to_string(),
+ "some removed command".to_string(),
+ ],
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_list_approvals("list_approvals_mixed", &repo);
+}
+
+/// With everything approved, the UNAPPROVED section shows an explicit
+/// `(none)` so the all-clear is visible at a glance.
+#[rstest]
+fn test_list_approvals_all_approved(repo: TestRepo) {
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.write_project_config(r#"pre-merge = "cargo test""#);
+ repo.commit("Add config");
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_command(
+ repo.project_id(),
+ "cargo test".to_string(),
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_list_approvals("list_approvals_all_approved", &repo);
+}
+
+/// Without a project config there is nothing to require approval, but
+/// approvals already on record still list — all as stale.
+#[rstest]
+fn test_list_approvals_stale_only(repo: TestRepo) {
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.commit("Initial commit");
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_command(
+ repo.project_id(),
+ "orphan command".to_string(),
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_list_approvals("list_approvals_stale_only", &repo);
+}
+
// ============================================================================
// add-approvals tests
// ============================================================================
@@ -182,6 +280,86 @@ fn test_clear_approvals_after_clear(repo: TestRepo) {
snapshot_clear_approvals("clear_approvals_after_clear", &repo, &[]);
}
+/// `clear --stale` removes only the approvals whose commands left the project
+/// config, echoing what was removed; valid approvals survive, so the follow-up
+/// list shows the remaining command approved with no stale block.
+#[rstest]
+fn test_clear_approvals_stale(repo: TestRepo) {
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.write_project_config(r#"pre-merge = "cargo test""#);
+ repo.commit("Add config");
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_commands(
+ repo.project_id(),
+ vec![
+ "cargo test".to_string(),
+ "some removed command".to_string(),
+ "other removed command".to_string(),
+ ],
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_clear_approvals("clear_approvals_stale", &repo, &["--stale"]);
+ snapshot_list_approvals("list_approvals_after_clear_stale", &repo);
+}
+
+/// With every approval matching a config command, `clear --stale` is a no-op.
+#[rstest]
+fn test_clear_approvals_stale_none(repo: TestRepo) {
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.write_project_config(r#"pre-merge = "cargo test""#);
+ repo.commit("Add config");
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_command(
+ repo.project_id(),
+ "cargo test".to_string(),
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_clear_approvals("clear_approvals_stale_none", &repo, &["--stale"]);
+}
+
+/// Without a project config there is no frame to compute staleness against,
+/// so `clear --stale` errors like `add` — it must NOT treat every recorded
+/// approval as stale and wipe the project's approvals.
+#[rstest]
+fn test_clear_approvals_stale_no_config(repo: TestRepo) {
+ repo.run_git(&["remote", "remove", "origin"]);
+ repo.commit("Initial commit");
+
+ let mut approvals = Approvals::default();
+ approvals
+ .approve_command(
+ repo.project_id(),
+ "orphan command".to_string(),
+ repo.test_approvals_path(),
+ )
+ .unwrap();
+
+ snapshot_clear_approvals("clear_approvals_stale_no_config", &repo, &["--stale"]);
+
+ // The recorded approval survives the failed clear.
+ let content = fs::read_to_string(repo.test_approvals_path()).unwrap();
+ assert!(content.contains("orphan command"));
+}
+
+/// `--stale` is scoped to the current project's config, so it cannot combine
+/// with `--global`.
+#[rstest]
+fn test_clear_approvals_stale_global_conflict(repo: TestRepo) {
+ snapshot_clear_approvals(
+ "clear_approvals_stale_global_conflict",
+ &repo,
+ &["--stale", "--global"],
+ );
+}
+
/// `clear` reads approvals from the legacy `[projects.X]` section in `config.toml`
/// when `approvals.toml` is absent, and clears them. Exercises the
/// `Approvals::load` fallback path documented in `src/config/approvals.rs`.
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale.snap
new file mode 100644
index 000000000..5985ffa0d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale.snap
@@ -0,0 +1,54 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - clear
+ - "--stale"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Cleared 2 stale approvals for this project:
+  some removed command
+  other removed command
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_global_conflict.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_global_conflict.snap
new file mode 100644
index 000000000..7b9d5102f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_global_conflict.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - clear
+ - "--stale"
+ - "--global"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 2
+----- stdout -----
+
+----- stderr -----
+error: the argument '--stale' cannot be used with '--global'
+
+Usage: wt config approvals clear --stale
+
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_no_config.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_no_config.snap
new file mode 100644
index 000000000..49a3c2b81
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_no_config.snap
@@ -0,0 +1,53 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - clear
+ - "--stale"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ No project configuration found
+↳ Create a config file at: _REPO_/.config/wt.toml
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_none.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_none.snap
new file mode 100644
index 000000000..b3cdd65e5
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_stale_none.snap
@@ -0,0 +1,52 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - clear
+ - "--stale"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No stale approvals to clear for this project
diff --git a/tests/snapshots/integration__integration_tests__approvals__list_approvals_after_clear_stale.snap b/tests/snapshots/integration__integration_tests__approvals__list_approvals_after_clear_stale.snap
new file mode 100644
index 000000000..d8c5f3315
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__list_approvals_after_clear_stale.snap
@@ -0,0 +1,56 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - list
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+APPROVED
+○ pre-merge:
+  cargo test
+
+UNAPPROVED
+↳ (none)
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__list_approvals_all_approved.snap b/tests/snapshots/integration__integration_tests__approvals__list_approvals_all_approved.snap
new file mode 100644
index 000000000..d8c5f3315
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__list_approvals_all_approved.snap
@@ -0,0 +1,56 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - list
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+APPROVED
+○ pre-merge:
+  cargo test
+
+UNAPPROVED
+↳ (none)
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__list_approvals_mixed.snap b/tests/snapshots/integration__integration_tests__approvals__list_approvals_mixed.snap
new file mode 100644
index 000000000..6ea922ab4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__list_approvals_mixed.snap
@@ -0,0 +1,65 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - list
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+APPROVED
+○ pre-merge:
+  cargo test
+○ alias deploy:
+  echo deploying {{ branch }}
+
+UNAPPROVED
+❯ post-start dev:
+  npm run dev
+❯ commit-template-append:
+  Use conventional commits.
+
+▲ Approved commands no longer in project config:
+  some removed command
+↳ To clear stale approvals, run wt config approvals clear --stale
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__list_approvals_no_config.snap b/tests/snapshots/integration__integration_tests__approvals__list_approvals_no_config.snap
new file mode 100644
index 000000000..f1766f2b7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__list_approvals_no_config.snap
@@ -0,0 +1,51 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - list
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No commands configured in project
diff --git a/tests/snapshots/integration__integration_tests__approvals__list_approvals_stale_only.snap b/tests/snapshots/integration__integration_tests__approvals__list_approvals_stale_only.snap
new file mode 100644
index 000000000..75f900c11
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__list_approvals_stale_only.snap
@@ -0,0 +1,53 @@
+---
+source: tests/integration_tests/approvals.rs
+info:
+ program: wt
+ args:
+ - config
+ - approvals
+ - list
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+▲ Approved commands no longer in project config:
+  orphan command
+↳ To clear stale approvals, run wt config approvals clear --stale
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_approvals.snap b/tests/snapshots/integration__integration_tests__help__help_config_approvals.snap
index 5dc26dc23..6ea7a6520 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_approvals.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_approvals.snap
@@ -38,6 +38,7 @@ wt config approvals - Manage command approvals
Usage: wt config approvals [OPTIONS] <COMMAND>
Commands:
+ list List project commands and their approval status
add Store approvals in approvals.toml
clear Clear approved commands from approvals.toml
@@ -65,12 +66,18 @@ Project hooks and project aliases prompt for approval on first run to prevent un
Examples
+List commands and their approval status for current project:
+  wt config approvals list
+
Pre-approve all hook and alias commands for current project:
  wt config approvals add
Clear approvals for current project:
  wt config approvals clear
+Clear only approvals for commands no longer in the project config:
+  wt config approvals clear --stale
+
Clear global approvals:
  wt config approvals clear --global
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_approvals_clear.snap b/tests/snapshots/integration__integration_tests__help__help_config_approvals_clear.snap
index 605224fcb..663acc75f 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_approvals_clear.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_approvals_clear.snap
@@ -42,6 +42,9 @@ Usage: wt config approvals clear [OPTIONS]
-g, --global
Clear global approvals
+ --stale
+ Clear only stale approvals
+
-h, --help
Print help (see a summary with '-h')
@@ -64,6 +67,7 @@ Usage: wt config approvals clear [OPTIONS]
Removes saved approvals, requiring re-approval on next command run.
By default, clears approvals for the current project. Use --global to clear
-all approvals across all projects.
+all approvals across all projects, or --stale to clear only approvals for
+commands no longer in the project config (edited or removed since approval).
----- stderr -----