mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-11-25 21:16:20 +08:00
feat(approvals): let wt config approvals add --yes record approvals without a TTY (#3819)
`wt config approvals add` refused every non-interactive run — even with `--yes`, whose hint then suggested the flag already passed — so there was no way to pre-approve a project's commands unattended. An orchestrator (tend's Codex Cloud container was the motivating case) had to hand-write `approvals.toml` from `wt config approvals list --format=json` output, a third-party reimplementation of `add` that breaks whenever the schema changes. The `wt config approvals` docs already promised "`--yes` to bypass prompts in CI" and described `stale` entries as "what `--yes` would silently re-approve"; behavior now matches them. The two `--yes` meanings stay distinct: on a command that runs project commands it grants consent for that run alone and records nothing (unchanged), while on `add` — whose product is the record — it lists what it trusts and writes it. `add` no longer routes through `approve_command_batch` (the execution gate) for this: it prompts or announces, then saves itself, which also makes a failed `approvals.toml` write fail the command instead of warning behind a `✓ saved` line and exit 0 — an orchestrator reading only the exit code would otherwise walk into the prompt it just paid to avoid. The non-interactive hint's pre-approval suggestion now carries `--yes` (`run wt config approvals add --yes`), since a hint reached in CI must name a command that runs there. Per the existing `list --format=json` docs, `add --yes` re-approves templates edited since an earlier approval without comment; the `add` help now says so and points at the `stale` field for reading them first, and the worktrunk skill's escalation rule tells agents not to reach for it on a user's behalf. > _This was written by Claude Code on behalf of max-sixty_
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
### Improved
|
||||
|
||||
- **`wt config approvals add --yes` records approvals without a terminal**: the command refused every non-interactive run, so a container that had just cloned a project could only pre-approve it by hand-writing `approvals.toml` from `wt config approvals list --format=json`. `--yes` now lists what it trusts and writes it. A save it cannot make fails the command rather than warning and exiting 0, since the record is all `add` produces — a change that applies to the interactive run too.
|
||||
|
||||
- **`remote_repo` names the repository as the remote spells it**: `repo` is the directory on disk, so a renamed clone reports the new name. `{{ remote_repo }}` takes it from the primary remote's URL, available everywhere `owner` is and unset when no remote parses. ([#3745](https://github.com/max-sixty/worktrunk/pull/3745), thanks @canac)
|
||||
|
||||
## 0.73.0
|
||||
|
||||
@@ -816,6 +816,9 @@ List commands and their approval status for current project:
|
||||
Pre-approve all hook and alias commands for current project:
|
||||
{{ terminal(cmd="wt config approvals add") }}
|
||||
|
||||
Pre-approve without prompting, for a container or CI job:
|
||||
{{ terminal(cmd="wt config approvals add --yes") }}
|
||||
|
||||
Clear approvals for current project:
|
||||
{{ terminal(cmd="wt config approvals clear") }}
|
||||
|
||||
@@ -830,7 +833,9 @@ Check whether an unattended run would stop for approval:
|
||||
|
||||
### How approvals work
|
||||
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves. Use `--yes` to bypass prompts in CI.
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves.
|
||||
|
||||
`--yes` bypasses the prompt, and what it leaves behind depends on the command it is passed to. On a command that runs project commands it grants consent for that run alone and records nothing, so the next run asks again. On `wt config approvals add` the record is the whole point, so the approvals are written — which is how an unattended environment pre-approves a project it has just cloned.
|
||||
|
||||
### Reading approval state
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"type": "skill-md",
|
||||
"description": "Guidance for Worktrunk (the `wt` CLI) — git worktree management, hooks, and config. Load when editing .config/wt.toml or ~/.config/worktrunk/config.toml; adding, modifying, or debugging hooks (post-merge, post-start, pre-commit, pre-merge, post-switch, etc.); configuring commit message generation or command aliases; or troubleshooting wt behavior. Also answers general worktrunk/wt questions.",
|
||||
"url": "./worktrunk/SKILL.md",
|
||||
"digest": "sha256:0a217b6b0a30588569bf97d5ad828d07aaf8241c67e2855ef461233098ec8c53"
|
||||
"digest": "sha256:3fc6de776a7db9b9f1f65e8312cf85baa8f9008c1c00144aa319cb8ac0d04af7"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -118,14 +118,14 @@ Agents running `wt merge`, `wt switch`, or other commands that trigger hooks wil
|
||||
○ post-merge install:
|
||||
cargo install --path .
|
||||
✗ Cannot prompt for approval in non-interactive environment
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add --yes
|
||||
```
|
||||
|
||||
The resolution is for the user to make the trust decision themselves:
|
||||
|
||||
- **`wt config approvals add`** — interactive prompt where the user reviews each command before it is stored to `~/.config/worktrunk/approvals.toml`. Run once per project; the approval persists across invocations until the command template changes or the project moves. This is the path to recommend — the user reviews and consents to exactly the commands that will run.
|
||||
|
||||
**When invoked as an agent, stop and escalate to the user.** Approving a project's hooks is a security decision about whether this repository should be trusted to run arbitrary commands on the user's machine — that decision belongs to the user, not the agent. Tell the user to run `wt config approvals add` and let them review the commands. Do not run `--yes` on the user's behalf: it skips the approval gate for that invocation, so reaching for it to unblock a command defeats the protection. `--yes` exists for CI/CD pipelines that already control their own hook contents; it is not a shortcut for an interactive agent to silence an approval prompt.
|
||||
**When invoked as an agent, stop and escalate to the user.** Approving a project's hooks is a security decision about whether this repository should be trusted to run arbitrary commands on the user's machine — that decision belongs to the user, not the agent. Tell the user to run `wt config approvals add` and let them review the commands. Do not reach for either `--yes` on the user's behalf: on the blocked command it skips the gate for that invocation, and `wt config approvals add --yes` records every command the project declares with nobody reading them. Both exist for CI/CD pipelines and containers that already control their own hook contents; neither is a shortcut for an interactive agent to silence an approval prompt.
|
||||
|
||||
## Advanced: agent handoffs
|
||||
|
||||
|
||||
@@ -824,6 +824,11 @@ Pre-approve all hook and alias commands for current project:
|
||||
$ wt config approvals add
|
||||
```
|
||||
|
||||
Pre-approve without prompting, for a container or CI job:
|
||||
```bash
|
||||
$ wt config approvals add --yes
|
||||
```
|
||||
|
||||
Clear approvals for current project:
|
||||
```bash
|
||||
$ wt config approvals clear
|
||||
@@ -846,7 +851,9 @@ $ wt config approvals list --format=json | jq -r .state
|
||||
|
||||
### How approvals work
|
||||
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves. Use `--yes` to bypass prompts in CI.
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves.
|
||||
|
||||
`--yes` bypasses the prompt, and what it leaves behind depends on the command it is passed to. On a command that runs project commands it grants consent for that run alone and records nothing, so the next run asks again. On `wt config approvals add` the record is the whole point, so the approvals are written — which is how an unattended environment pre-approves a project it has just cloned.
|
||||
|
||||
### Reading approval state
|
||||
|
||||
|
||||
@@ -118,14 +118,14 @@ Agents running `wt merge`, `wt switch`, or other commands that trigger hooks wil
|
||||
○ post-merge install:
|
||||
cargo install --path .
|
||||
✗ Cannot prompt for approval in non-interactive environment
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add --yes
|
||||
```
|
||||
|
||||
The resolution is for the user to make the trust decision themselves:
|
||||
|
||||
- **`wt config approvals add`** — interactive prompt where the user reviews each command before it is stored to `~/.config/worktrunk/approvals.toml`. Run once per project; the approval persists across invocations until the command template changes or the project moves. This is the path to recommend — the user reviews and consents to exactly the commands that will run.
|
||||
|
||||
**When invoked as an agent, stop and escalate to the user.** Approving a project's hooks is a security decision about whether this repository should be trusted to run arbitrary commands on the user's machine — that decision belongs to the user, not the agent. Tell the user to run `wt config approvals add` and let them review the commands. Do not run `--yes` on the user's behalf: it skips the approval gate for that invocation, so reaching for it to unblock a command defeats the protection. `--yes` exists for CI/CD pipelines that already control their own hook contents; it is not a shortcut for an interactive agent to silence an approval prompt.
|
||||
**When invoked as an agent, stop and escalate to the user.** Approving a project's hooks is a security decision about whether this repository should be trusted to run arbitrary commands on the user's machine — that decision belongs to the user, not the agent. Tell the user to run `wt config approvals add` and let them review the commands. Do not reach for either `--yes` on the user's behalf: on the blocked command it skips the gate for that invocation, and `wt config approvals add --yes` records every command the project declares with nobody reading them. Both exist for CI/CD pipelines and containers that already control their own hook contents; neither is a shortcut for an interactive agent to silence an approval prompt.
|
||||
|
||||
## Advanced: agent handoffs
|
||||
|
||||
|
||||
Generated
+8
-1
@@ -824,6 +824,11 @@ Pre-approve all hook and alias commands for current project:
|
||||
$ wt config approvals add
|
||||
```
|
||||
|
||||
Pre-approve without prompting, for a container or CI job:
|
||||
```bash
|
||||
$ wt config approvals add --yes
|
||||
```
|
||||
|
||||
Clear approvals for current project:
|
||||
```bash
|
||||
$ wt config approvals clear
|
||||
@@ -846,7 +851,9 @@ $ wt config approvals list --format=json | jq -r .state
|
||||
|
||||
### How approvals work
|
||||
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves. Use `--yes` to bypass prompts in CI.
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves.
|
||||
|
||||
`--yes` bypasses the prompt, and what it leaves behind depends on the command it is passed to. On a command that runs project commands it grants consent for that run alone and records nothing, so the next run asks again. On `wt config approvals add` the record is the whole point, so the approvals are written — which is how an unattended environment pre-approves a project it has just cloned.
|
||||
|
||||
### Reading approval state
|
||||
|
||||
|
||||
+17
-2
@@ -261,7 +261,15 @@ $ wt config approvals list --format=json | jq -r .state
|
||||
after_long_help = r#"Prompts for approval of all project commands and saves them to approvals.toml.
|
||||
|
||||
By default, shows only unapproved commands. Use `--all` to review all commands
|
||||
including previously approved ones."#
|
||||
including previously approved ones.
|
||||
|
||||
`--yes` writes the approvals without prompting, which is how a container or CI job pre-approves a project it has just cloned. It trusts every command the project config declares, including one whose template changed since an earlier approval. A caller that wants to look before granting them can list those first — see [Reading approval state](@/config.md#reading-approval-state).
|
||||
|
||||
## Examples
|
||||
|
||||
```console
|
||||
$ wt config approvals add --yes
|
||||
```"#
|
||||
)]
|
||||
Add {
|
||||
/// Show all commands
|
||||
@@ -571,6 +579,11 @@ Pre-approve all hook and alias commands for current project:
|
||||
$ wt config approvals add
|
||||
```
|
||||
|
||||
Pre-approve without prompting, for a container or CI job:
|
||||
```console
|
||||
$ wt config approvals add --yes
|
||||
```
|
||||
|
||||
Clear approvals for current project:
|
||||
```console
|
||||
$ wt config approvals clear
|
||||
@@ -593,7 +606,9 @@ $ wt config approvals list --format=json | jq -r .state
|
||||
|
||||
## How approvals work
|
||||
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves. Use `--yes` to bypass prompts in CI.
|
||||
Approved commands are saved to `~/.config/worktrunk/approvals.toml`. Re-approval is required when the command template changes or the project moves.
|
||||
|
||||
`--yes` bypasses the prompt, and what it leaves behind depends on the command it is passed to. On a command that runs project commands it grants consent for that run alone and records nothing, so the next run asks again. On `wt config approvals add` the record is the whole point, so the approvals are written — which is how an unattended environment pre-approves a project it has just cloned.
|
||||
|
||||
## Reading approval state
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ use super::project_config::{ApprovableCommand, Phase, collect_commands_for_hooks
|
||||
/// Shows command templates to the user (what gets saved to config), not expanded values.
|
||||
/// This ensures users see exactly what they're approving.
|
||||
///
|
||||
/// `yes` grants consent for this invocation alone: nothing is recorded, so the
|
||||
/// next run asks again. Recording without a prompt is `wt config approvals
|
||||
/// add --yes`'s job ([`crate::commands::add_approvals`]), which doesn't pass
|
||||
/// through this gate.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `commands_already_filtered`: If true, commands list is pre-filtered; skip filtering by approval status
|
||||
pub fn approve_command_batch(
|
||||
@@ -70,7 +75,9 @@ pub fn approve_command_batch(
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// Only save approvals when interactively approved, not when using --yes
|
||||
// Only save approvals when interactively approved, not when using --yes.
|
||||
// A failed save costs one more prompt next run, not the command the user
|
||||
// actually ran, so it warns rather than errors.
|
||||
if !yes {
|
||||
let mut fresh_approvals = Approvals::load().context("Failed to load approvals")?;
|
||||
let commands: Vec<String> = needs_approval
|
||||
@@ -95,30 +102,56 @@ pub fn approve_command_batch(
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn prompt_for_batch_approval(
|
||||
commands: &[&ApprovableCommand],
|
||||
project_id: &str,
|
||||
) -> anyhow::Result<bool> {
|
||||
// Extract just the directory name for display
|
||||
let project_name = Path::new(project_id)
|
||||
/// The project's directory name, which is what a user recognizes; the full
|
||||
/// identifier is a path or a remote URL.
|
||||
fn display_project_name(project_id: &str) -> &str {
|
||||
Path::new(project_id)
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or(project_id);
|
||||
let count = commands.len();
|
||||
let plural = if count == 1 { "" } else { "s" };
|
||||
|
||||
eprintln!(
|
||||
"{}",
|
||||
cformat!(
|
||||
"{WARNING_SYMBOL} <yellow><bold>{project_name}</> needs approval to execute <bold>{count}</> command{plural}:</>"
|
||||
)
|
||||
);
|
||||
.unwrap_or(project_id)
|
||||
}
|
||||
|
||||
/// The batch as the user sees it: a header, then each command's label and its
|
||||
/// template. Shared by the prompt and by `--yes` on `wt config approvals add`.
|
||||
fn print_command_batch(header: &str, commands: &[&ApprovableCommand]) {
|
||||
eprintln!("{header}");
|
||||
for cmd in commands {
|
||||
// Uses INFO_SYMBOL (○) since this is a preview, not active execution
|
||||
eprintln!("{} {}", INFO_SYMBOL, cmd.label());
|
||||
eprintln!("{}", cmd.format_template());
|
||||
}
|
||||
}
|
||||
|
||||
/// The batch `wt config approvals add --yes` is about to trust. Nothing is
|
||||
/// being asked, but the batch still prints: it is the record of what an
|
||||
/// unattended run just approved. Lives beside [`prompt_for_batch_approval`]
|
||||
/// so the two headers stay parallel.
|
||||
pub fn announce_batch_approval(commands: &[&ApprovableCommand], project_id: &str) {
|
||||
let project_name = display_project_name(project_id);
|
||||
let count = commands.len();
|
||||
let plural = if count == 1 { "" } else { "s" };
|
||||
print_command_batch(
|
||||
&cformat!(
|
||||
"{WARNING_SYMBOL} <yellow>Approving <bold>{count}</> command{plural} for <bold>{project_name}</> (--yes):</>"
|
||||
),
|
||||
commands,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn prompt_for_batch_approval(
|
||||
commands: &[&ApprovableCommand],
|
||||
project_id: &str,
|
||||
) -> anyhow::Result<bool> {
|
||||
let project_name = display_project_name(project_id);
|
||||
let count = commands.len();
|
||||
let plural = if count == 1 { "" } else { "s" };
|
||||
|
||||
print_command_batch(
|
||||
&cformat!(
|
||||
"{WARNING_SYMBOL} <yellow><bold>{project_name}</> needs approval to execute <bold>{count}</> command{plural}:</>"
|
||||
),
|
||||
commands,
|
||||
);
|
||||
|
||||
// Check if stdin is a TTY before attempting to prompt
|
||||
// This happens AFTER showing the commands so they appear in CI/CD logs
|
||||
|
||||
@@ -19,7 +19,7 @@ use worktrunk::styling::{
|
||||
};
|
||||
|
||||
use crate::cli::SwitchFormat;
|
||||
use crate::commands::command_approval::approve_command_batch;
|
||||
use crate::commands::command_approval::{announce_batch_approval, prompt_for_batch_approval};
|
||||
use crate::commands::project_config::{
|
||||
ApprovableCommand, collect_commands_for_aliases, collect_commands_for_hooks,
|
||||
};
|
||||
@@ -189,10 +189,17 @@ pub fn list_approvals(format: SwitchFormat) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
/// Handle `wt config approvals add` command - approve all hook and alias commands in the project
|
||||
pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
|
||||
///
|
||||
/// `yes` skips the review prompt, which is what makes the command usable
|
||||
/// unattended: the approvals are still written, so an orchestrator can
|
||||
/// pre-approve a project's commands before any `wt` run that would execute
|
||||
/// them. Templates edited since an earlier approval are re-approved without
|
||||
/// comment — read `wt config approvals list --format=json`'s `stale` first to
|
||||
/// see them.
|
||||
pub fn add_approvals(show_all: bool, yes: bool) -> anyhow::Result<()> {
|
||||
let repo = Repository::current()?;
|
||||
let project_id = repo.project_identifier()?;
|
||||
let approvals = Approvals::load().context("Failed to load approvals")?;
|
||||
let mut approvals = Approvals::load().context("Failed to load approvals")?;
|
||||
|
||||
let project_config = require_project_config(&repo)?;
|
||||
let commands = collect_approvable_commands(&project_config);
|
||||
@@ -219,20 +226,33 @@ pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
|
||||
commands
|
||||
};
|
||||
|
||||
// Call the approval prompt (yes=false to require interactive approval and save)
|
||||
// When show_all=true, we've already included all commands in commands_to_approve
|
||||
// When show_all=false, we've already filtered to unapproved commands
|
||||
// So we pass skip_approval_filter=true to prevent double-filtering
|
||||
let approved =
|
||||
approve_command_batch(&commands_to_approve, &project_id, &approvals, false, true)?;
|
||||
|
||||
// Show result
|
||||
if approved {
|
||||
eprintln!("{}", success_message("Commands approved & saved to config"));
|
||||
// Unlike the execution gate (`approve_command_batch`), whose `--yes`
|
||||
// consents to one run and records nothing, the record is this command's
|
||||
// product: it saves on either path, and a failed save fails the command —
|
||||
// an orchestrator that pre-approves and reads only the exit code would
|
||||
// otherwise walk into the prompt it just paid to avoid.
|
||||
let batch: Vec<&_> = commands_to_approve.iter().collect();
|
||||
let approved = if yes {
|
||||
announce_batch_approval(&batch, &project_id);
|
||||
true
|
||||
} else {
|
||||
prompt_for_batch_approval(&batch, &project_id)?
|
||||
};
|
||||
|
||||
if !approved {
|
||||
eprintln!("{}", info_message("Commands declined"));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let templates: Vec<String> = commands_to_approve
|
||||
.iter()
|
||||
.map(|cmd| cmd.command.template.clone())
|
||||
.collect();
|
||||
approvals
|
||||
.approve_commands(project_id, templates, &require_approvals_path()?)
|
||||
.context("Failed to save command approval")?;
|
||||
|
||||
eprintln!("{}", success_message("Commands approved & saved to config"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -1385,7 +1385,11 @@ impl GitError {
|
||||
|
||||
GitError::NotInteractive => {
|
||||
let title = self.title();
|
||||
let approvals_cmd = suggest_command("config", &["approvals", "add"], &[]);
|
||||
// The pre-approval route is itself unattended, so it carries
|
||||
// `--yes` — a hint reached in CI must name a command that runs
|
||||
// there. Raised from `wt config approvals add` itself, that
|
||||
// suggestion is the exact fix: append the flag.
|
||||
let approvals_cmd = suggest_command("config approvals add", &[], &["--yes"]);
|
||||
write!(
|
||||
f,
|
||||
"{}\n{}",
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@ fn handle_hook_command(action: HookCommand, yes: bool) -> anyhow::Result<()> {
|
||||
);
|
||||
match action {
|
||||
ApprovalsCommand::List { format } => list_approvals(format),
|
||||
ApprovalsCommand::Add { all } => add_approvals(all),
|
||||
ApprovalsCommand::Add { all } => add_approvals(all, yes),
|
||||
ApprovalsCommand::Clear { global, stale } => clear_approvals(global, stale),
|
||||
}
|
||||
}
|
||||
@@ -641,7 +641,7 @@ fn handle_config_command(action: ConfigCommand, yes: bool) -> anyhow::Result<()>
|
||||
ConfigCommand::Update { print } => handle_config_update(yes, print),
|
||||
ConfigCommand::Approvals { action } => match action {
|
||||
ApprovalsCommand::List { format } => list_approvals(format),
|
||||
ApprovalsCommand::Add { all } => add_approvals(all),
|
||||
ApprovalsCommand::Add { all } => add_approvals(all, yes),
|
||||
ApprovalsCommand::Clear { global, stale } => clear_approvals(global, stale),
|
||||
},
|
||||
ConfigCommand::Alias { action } => match action {
|
||||
|
||||
@@ -47,7 +47,9 @@ use std::path::Path;
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `subcommand` - The subcommand name (e.g., "remove", "switch", "merge")
|
||||
/// * `subcommand` - The subcommand name (e.g., "remove", "switch", "merge").
|
||||
/// A nested subcommand is written out in full here ("config approvals add"),
|
||||
/// so that any flags land after it rather than mid-path.
|
||||
/// * `args` - Positional arguments (branch names, paths, etc.)
|
||||
/// * `flags` - Additional flags to suggest (e.g., "--force", "-D")
|
||||
///
|
||||
|
||||
@@ -509,9 +509,10 @@ fn test_truly_concurrent_approve_with_threads() {
|
||||
|
||||
///
|
||||
/// This tests the lower-level `approve_command()` method fails when permissions
|
||||
/// are denied. The higher-level `approve_command_batch()` catches this error and
|
||||
/// displays a warning (see src/commands/command_approval.rs:82-85), allowing
|
||||
/// commands to execute even when the approval can't be saved.
|
||||
/// are denied. On an execution path the higher-level `approve_command_batch()`
|
||||
/// catches this error and displays a warning, allowing commands to execute even
|
||||
/// when the approval can't be saved; `wt config approvals add` instead
|
||||
/// propagates it, since the record is all that command produces.
|
||||
///
|
||||
/// TODO: Find a way to test permission errors without skipping when running as root.
|
||||
/// Currently skips in containerized environments (Claude Code web, Docker) where
|
||||
@@ -575,14 +576,11 @@ fn test_permission_error_prevents_save() {
|
||||
"Expected save to fail due to permissions, but it succeeded"
|
||||
);
|
||||
|
||||
// In the actual code (approve_command_batch), when this error occurs:
|
||||
// 1. It's caught with `if let Err(e) = fresh_config.save()`
|
||||
// 2. Warning is printed: "🟡 Failed to save command approval: {error}"
|
||||
// 3. Hint is printed: "💡 Approval will be requested again next time."
|
||||
// 4. Function returns Ok(true) - execution continues!
|
||||
//
|
||||
// The approval succeeds (commands execute) even though saving failed.
|
||||
// This test verifies the save operation correctly fails with permission errors.
|
||||
// This test verifies the save operation correctly fails with permission
|
||||
// errors. What `approve_command_batch` does with that failure is covered by
|
||||
// `test_add_approvals_yes_fails_when_approvals_cannot_be_saved`
|
||||
// (propagates, for `wt config approvals add`) and by the warning path it
|
||||
// takes for a command that merely runs project commands.
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Integration tests for the `wt config approvals` subcommands
|
||||
|
||||
use crate::common::{
|
||||
BareRepoTest, TestRepo, TestRepoBase, make_snapshot_cmd, repo, set_temp_home_env,
|
||||
setup_snapshot_settings, setup_snapshot_settings_with_home, setup_temp_snapshot_settings,
|
||||
temp_home, wt_command,
|
||||
BareRepoTest, TestRepo, TestRepoBase, make_snapshot_cmd, make_snapshot_cmd_with_global_flags,
|
||||
repo, set_temp_home_env, setup_snapshot_settings, setup_snapshot_settings_with_home,
|
||||
setup_temp_snapshot_settings, temp_home, wt_command,
|
||||
};
|
||||
use insta_cmd::assert_cmd_snapshot;
|
||||
use rstest::rstest;
|
||||
@@ -179,6 +179,73 @@ fn test_hook_approvals_emits_deprecation_warning(
|
||||
});
|
||||
}
|
||||
|
||||
/// `--yes` is what makes `add` usable unattended: with no terminal to prompt
|
||||
/// on it lists what it trusts and writes the approvals. The flag is global, so
|
||||
/// it records the same thing on either side of the subcommand.
|
||||
#[rstest]
|
||||
fn test_add_approvals_yes_records_without_a_terminal(repo: TestRepo) {
|
||||
repo.run_git(&["remote", "remove", "origin"]);
|
||||
repo.write_project_config(
|
||||
r#"pre-merge = "cargo test"
|
||||
|
||||
[aliases]
|
||||
deploy = "echo deploying"
|
||||
"#,
|
||||
);
|
||||
repo.commit("Add config");
|
||||
|
||||
snapshot_add_approvals("add_approvals_yes", &repo, &["--yes"]);
|
||||
|
||||
let recorded = fs::read_to_string(repo.test_approvals_path()).unwrap();
|
||||
assert!(recorded.contains("cargo test"), "{recorded}");
|
||||
assert!(recorded.contains("echo deploying"), "{recorded}");
|
||||
|
||||
// Same run again from the global flag position, which reaches the command
|
||||
// through clap's global `--yes` rather than the subcommand's own parse.
|
||||
fs::remove_file(repo.test_approvals_path()).unwrap();
|
||||
let output = make_snapshot_cmd_with_global_flags(&repo, "config", &[], None, &["--yes"])
|
||||
.args(["approvals", "add"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success(), "{output:?}");
|
||||
assert_eq!(
|
||||
fs::read_to_string(repo.test_approvals_path()).unwrap(),
|
||||
recorded
|
||||
);
|
||||
}
|
||||
|
||||
/// The record is all `add` produces, so a write it cannot make fails the
|
||||
/// command. A warning plus exit 0 would leave an orchestrator that pre-approves
|
||||
/// and reads the exit code walking into the prompt it just paid to avoid.
|
||||
#[rstest]
|
||||
fn test_add_approvals_yes_fails_when_approvals_cannot_be_saved(repo: TestRepo) {
|
||||
repo.write_project_config(r#"pre-merge = "cargo test""#);
|
||||
repo.commit("Add config");
|
||||
|
||||
// A regular file where the approvals directory would go: creating the
|
||||
// parent fails on every platform, with no permission bits involved.
|
||||
let blocker = repo.test_approvals_path().with_file_name("blocker");
|
||||
fs::write(&blocker, "").unwrap();
|
||||
|
||||
let output = repo
|
||||
.wt_command()
|
||||
.args(["config", "approvals", "add", "--yes"])
|
||||
.env("WORKTRUNK_APPROVALS_PATH", blocker.join("approvals.toml"))
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(!output.status.success(), "{output:?}");
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("Failed to save command approval"),
|
||||
"{stderr}"
|
||||
);
|
||||
assert!(
|
||||
!stderr.contains("Commands approved"),
|
||||
"a failed write must not report success: {stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Regression: `wt config approvals add` must walk project aliases as well as
|
||||
/// hooks. With only an alias declared (no hook commands), the alias should
|
||||
/// appear in the approval batch.
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ expression: render_cases(cases)
|
||||
## non-interactive
|
||||
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
## LLM command failed
|
||||
|
||||
|
||||
+16
-3
@@ -8,12 +8,23 @@ info:
|
||||
- test-non-tty
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -36,8 +47,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -51,4 +64,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start [1mthird[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Third command'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -16,4 +16,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start [1mpwd[22m:
|
||||
[107m [0m [2m[0m[2m[34mcd[0m[2m [0m[2m[32m{{[0m[2m worktree_path [0m[2m[32m}}[0m[2m [0m[2m[36m&&[0m[2m [0m[2m[34mpwd[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -14,4 +14,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start [1mtest[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Running tests...'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Worktree path: {{ worktree_path }}'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start [1mthird[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Third command'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ exit_code: 1
|
||||
[2m○[22m pre-merge [1mlint[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Running project lint'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m pre-merge [1mtest[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Running project test'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m post-merge:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Post-merge cleanup for {{ branch }}'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m pre-merge:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Running pre-merge checks on {{ branch }}'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test command'[0m[2m [0m[2m[36m>[0m[2m output.txt[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+16
-3
@@ -9,12 +9,23 @@ info:
|
||||
- "--all"
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -37,8 +48,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -52,4 +65,4 @@ exit_code: 1
|
||||
[2m○[22m pre-start:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'test'[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+15
-3
@@ -9,10 +9,20 @@ info:
|
||||
- "--all"
|
||||
env:
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
LANG: C
|
||||
LC_ALL: C
|
||||
@@ -30,8 +40,10 @@ info:
|
||||
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
---
|
||||
@@ -44,4 +56,4 @@ exit_code: 1
|
||||
○ pre-start:
|
||||
echo 'hello'
|
||||
✗ Cannot prompt for approval in non-interactive environment
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add
|
||||
↳ To skip prompts in CI/CD, add --yes; to pre-approve commands, run wt config approvals add --yes
|
||||
|
||||
+16
-3
@@ -8,12 +8,23 @@ info:
|
||||
- add
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -36,8 +47,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -51,4 +64,4 @@ exit_code: 1
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m deploying [0m[2m[32m{{[0m[2m branch [0m[2m[32m}}[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
---
|
||||
source: tests/integration_tests/approvals.rs
|
||||
info:
|
||||
program: wt
|
||||
args:
|
||||
- config
|
||||
- approvals
|
||||
- add
|
||||
- "--yes"
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
LC_ALL: C
|
||||
LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
|
||||
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_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
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 -----
|
||||
[33m▲[39m [33mApproving [1m2[22m commands for [1mrepo[22m (--yes):[39m
|
||||
[2m○[22m pre-merge:
|
||||
[107m [0m [2m[0m[2m[34mcargo[0m[2m test[0m
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m deploying[0m
|
||||
[32m✓[39m [32mCommands approved & saved to config[39m
|
||||
@@ -36,6 +36,7 @@ info:
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
---
|
||||
@@ -81,6 +82,9 @@ List commands and their approval status for current project:
|
||||
Pre-approve all hook and alias commands for current project:
|
||||
[107m [0m [2m[0m[2m[34mwt[0m[2m config approvals add[0m
|
||||
|
||||
Pre-approve without prompting, for a container or CI job:
|
||||
[107m [0m [2m[0m[2m[34mwt[0m[2m config approvals add [0m[2m[36m--yes[0m
|
||||
|
||||
Clear approvals for current project:
|
||||
[107m [0m [2m[0m[2m[34mwt[0m[2m config approvals clear[0m
|
||||
|
||||
@@ -95,7 +99,9 @@ Check whether an unattended run would stop for approval:
|
||||
|
||||
[1m[32mHow approvals work[0m
|
||||
|
||||
Approved commands are saved to [2m~/.config/worktrunk/approvals.toml[0m. Re-approval is required when the command template changes or the project moves. Use [2m--yes[0m to bypass prompts in CI.
|
||||
Approved commands are saved to [2m~/.config/worktrunk/approvals.toml[0m. Re-approval is required when the command template changes or the project moves.
|
||||
|
||||
[2m--yes[0m bypasses the prompt, and what it leaves behind depends on the command it is passed to. On a command that runs project commands it grants consent for that run alone and records nothing, so the next run asks again. On [2mwt config approvals add[0m the record is the whole point, so the approvals are written — which is how an unattended environment pre-approves a project it has just cloned.
|
||||
|
||||
[1m[32mReading approval state[0m
|
||||
|
||||
|
||||
@@ -10,6 +10,14 @@ info:
|
||||
env:
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
LANG: C
|
||||
LC_ALL: C
|
||||
LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
|
||||
@@ -26,8 +34,10 @@ info:
|
||||
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
---
|
||||
@@ -66,4 +76,10 @@ Prompts for approval of all project commands and saves them to approvals.toml.
|
||||
By default, shows only unapproved commands. Use [2m--all[0m to review all commands
|
||||
including previously approved ones.
|
||||
|
||||
[2m--yes[0m writes the approvals without prompting, which is how a container or CI job pre-approves a project it has just cloned. It trusts every command the project config declares, including one whose template changed since an earlier approval. A caller that wants to look before granting them can list those first — see Reading approval state.
|
||||
|
||||
[1m[32mExamples[0m
|
||||
|
||||
[107m [0m [2m[0m[2m[34mwt[0m[2m config approvals add [0m[2m[36m--yes[0m
|
||||
|
||||
----- stderr -----
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ exit_code: 1
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m deploying[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+16
-3
@@ -7,12 +7,23 @@ info:
|
||||
- deploy
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -35,8 +46,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -50,4 +63,4 @@ exit_code: 1
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m deploying [0m[2m[32m{{[0m[2m branch [0m[2m[32m}}[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+16
-3
@@ -7,12 +7,23 @@ info:
|
||||
- deploy
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -35,8 +46,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -50,4 +63,4 @@ exit_code: 1
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m deploying[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
+16
-3
@@ -8,12 +8,23 @@ info:
|
||||
- "--help"
|
||||
env:
|
||||
APPDATA: "[TEST_CONFIG_HOME]"
|
||||
CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
|
||||
CLICOLOR_FORCE: "1"
|
||||
COLUMNS: "500"
|
||||
GIT_ALLOW_PROTOCOL: file
|
||||
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_AUTHOR_EMAIL: test@example.com
|
||||
GIT_AUTHOR_NAME: Test User
|
||||
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
|
||||
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
|
||||
GIT_CONFIG_SYSTEM: /dev/null
|
||||
GIT_COMMITTER_EMAIL: test@example.com
|
||||
GIT_COMMITTER_NAME: Test User
|
||||
GIT_CONFIG_COUNT: "2"
|
||||
GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_KEY_0: user.useConfigOnly
|
||||
GIT_CONFIG_KEY_1: rerere.enabled
|
||||
GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
|
||||
GIT_CONFIG_VALUE_0: "true"
|
||||
GIT_CONFIG_VALUE_1: "false"
|
||||
GIT_TERMINAL_PROMPT: "0"
|
||||
HOME: "[TEST_HOME]"
|
||||
LANG: C
|
||||
@@ -36,8 +47,10 @@ info:
|
||||
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
|
||||
WORKTRUNK_TEST_NUSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PARENT_SHELL: ""
|
||||
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
|
||||
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
|
||||
WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
|
||||
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
|
||||
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
|
||||
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
|
||||
@@ -51,4 +64,4 @@ exit_code: 1
|
||||
[2m○[22m alias [1mdeploy[22m:
|
||||
[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m{{[0m[2m args [0m[2m[32m}}[0m
|
||||
[31m✗[39m [31mCannot prompt for approval in non-interactive environment[39m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add[24m[22m
|
||||
[2m↳[22m [2mTo skip prompts in CI/CD, add [4m--yes[24m; to pre-approve commands, run [4mwt config approvals add --yes[24m[22m
|
||||
|
||||
Reference in New Issue
Block a user