From 56ce9f198fd90b92948d49b77d12381457ba3c5a Mon Sep 17 00:00:00 2001 From: Richard McDaniel <1130888+rmcdaniel@users.noreply.github.com> Date: Thu, 26 Nov 2026 11:20:41 +0000 Subject: [PATCH] Retention plan follow-ups: re-plan hint, -r, rust-only list (server#522) Review follow-ups to #178: - After a stale or mismatched namespace:retention-apply, the suggested re-plan command repeats the proposal the apply tried: its --retention-mode and --retention, or the proposed policy in its --plan-file. A bare "dw namespace:retention-plan " would plan the current policy against itself. ErrorContext carries the command, built from the apply's own input. - namespace:retention-plan and namespace:retention-apply accept -r for --retention, as namespace:create and namespace:update do (catalog and catalog-additions). - rust/README lists every Rust-only command with its issue (cli#60, Server #522, #577, #519, #520, #1131, .github#220). Tests: a re-plan hint test (options, -r, forever, and both kinds of plan file, human and JSON), the refusal test now expects the attempted --retention, and a -r plan request. Co-Authored-By: Claude Opus 5.5 --- docs/cli-reference.md | 6 +- rust/README.md | 19 ++++-- rust/parity/catalog-additions.json | 10 ++-- rust/src/catalog.json | 10 ++-- rust/src/commands/retention_plan.rs | 22 +++++++ rust/src/error.rs | 10 +++- rust/src/main.rs | 2 + rust/tests/namespace_retention.rs | 90 ++++++++++++++++++++++++++++- 8 files changed, 151 insertions(+), 18 deletions(-) diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 34bc4ae..8166173 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -735,7 +735,7 @@ dw namespace:retention-plan billing --retention=7 --json > plan.json dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning ``` -`namespace:retention-plan` takes the proposed `--retention` days, +`namespace:retention-plan` takes the proposed `--retention` (`-r`) days, `--retention-mode` (`bounded` or `forever`), or both. A field you leave out keeps its current value. It shows the current and proposed policy with their cutoffs and whether the proposal is retroactive, meaning it makes closed runs @@ -778,6 +778,10 @@ exits 2: | `409 retention_plan_revision_mismatch` | The proposal sent is not the one that was planned. | Apply the plan's exact proposal, or plan this one. | | `422 retention_pruning_confirmation_required` | The proposal is retroactive and `--confirm-retroactive-pruning` was not passed. | Review `newly_eligible`, then repeat with the confirmation. | +After a stale or mismatched apply, the suggested `namespace:retention-plan` +command repeats the proposal you tried to apply: your `--retention` and +`--retention-mode`, or the proposed policy in the `--plan-file`. + With `--json` a refusal keeps the usual error envelope, with `reason`, `status_code` and the full body in `server_response`. diff --git a/rust/README.md b/rust/README.md index 73dee55..0ae6b08 100644 --- a/rust/README.md +++ b/rust/README.md @@ -194,10 +194,21 @@ option definitions and help text), generated from the pinned reference by read it, so they match 2.x even for commands not ported yet. The harness also checks `--help` for every catalog command. -Commands with no 2.x equivalent (the `batch:*` commands, cli#60, the task -queue activity dispatch commands, Server #577, and `workflow:update-outcome`, -Server #1131) are added from -`parity/catalog-additions.json` and marked `rust_only`. The harness +Commands with no 2.x equivalent are added from +`parity/catalog-additions.json` and marked `rust_only`: + +- `batch:cancel`, `batch:resume`, `batch:show`, `batch:signal` and + `batch:update` (cli#60); +- `namespace:retention-plan` and `namespace:retention-apply` (Server #522); +- `task-queue:activity-dispatch`, `task-queue:pause-activities` and + `task-queue:resume-activities` (Server #577); +- `task-queue:retirement` and `task-queue:retire` (Server #519); +- `workflow:history-archive` and `workflow:history-archive-check` + (Server #520); +- `workflow:update-outcome` (Server #1131); +- `workflow:version-usage` (durable-workflow/.github#220). + +`parity/test_parity.py` checks this list against the catalog. The harness announces them, does not compare their `--help`, and removes only them from the candidate's listings and completions before comparing, so the rest of each listing is still checked against 2.x. A namespace header is removed diff --git a/rust/parity/catalog-additions.json b/rust/parity/catalog-additions.json index ee516be..0602ad3 100644 --- a/rust/parity/catalog-additions.json +++ b/rust/parity/catalog-additions.json @@ -2564,7 +2564,7 @@ { "name": "namespace:retention-apply", "description": "Apply a planned retention policy only while the plan still holds", - "synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] ", + "synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] ", "aliases": [], "hidden": false, "help": "Apply a retention policy previewed with dw namespace:retention-plan, only\nwhile that plan still holds. Pass the same proposal with the plan's\n--policy-revision and --plan-revision, or pass the plan's saved JSON with\n--plan-file.\n\nA retroactive proposal, one that makes closed runs eligible for pruning\nthat the current policy keeps (fewer days, or bounded replacing forever),\nalso needs --confirm-retroactive-pruning, because pruning is irreversible.\n\nThe request is sent once and never resent. The Server checks the revisions\nand updates the policy in one transaction. A refusal changes nothing, and\ndw prints what to do next and exits 2:\n\n retention_policy_revision_stale (409): the namespace changed after the\n plan. Plan again and apply the new plan's revisions.\n retention_plan_revision_mismatch (409): the proposal is not the one that\n was planned.\n retention_pruning_confirmation_required (422): the proposal is\n retroactive and --confirm-retroactive-pruning was not passed.\n\nThe apply changes only the namespace's policy. Each later retention pass\nprunes the closed, unarchived runs past the cutoff at that pass, which can\ninclude runs that closed or aged after the plan. dw namespace:update\nstill activates a policy at once, without a plan. Needs an admin token and\nnative Server 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-apply billing --retention=7 --policy-revision=sha256:... --plan-revision=sha256:... --confirm-retroactive-pruning\n dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning", @@ -2635,7 +2635,7 @@ }, "retention": { "name": "--retention", - "shortcut": "", + "shortcut": "-r", "accept_value": true, "is_value_required": true, "is_multiple": false, @@ -2775,10 +2775,10 @@ { "name": "namespace:retention-plan", "description": "Preview a proposed retention policy without applying it", - "synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] ", + "synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] ", "aliases": [], "hidden": false, - "help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed --retention days, --retention-mode, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches --scan-limit (default 1000, at\nmost 10000) or --hold-scan-limit (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with dw namespace:retention-apply and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-plan billing --retention=7\n dw namespace:retention-plan archive --retention-mode=forever\n dw namespace:retention-plan billing --retention=7 --json > plan.json", + "help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed --retention days, --retention-mode, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches --scan-limit (default 1000, at\nmost 10000) or --hold-scan-limit (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with dw namespace:retention-apply and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-plan billing --retention=7\n dw namespace:retention-plan billing -r 7 --scan-limit=5000\n dw namespace:retention-plan archive --retention-mode=forever\n dw namespace:retention-plan billing --retention=7 --json > plan.json", "definition": { "arguments": { "name": { @@ -2846,7 +2846,7 @@ }, "retention": { "name": "--retention", - "shortcut": "", + "shortcut": "-r", "accept_value": true, "is_value_required": true, "is_multiple": false, diff --git a/rust/src/catalog.json b/rust/src/catalog.json index 46931b7..fb3a523 100644 --- a/rust/src/catalog.json +++ b/rust/src/catalog.json @@ -4386,7 +4386,7 @@ { "name": "namespace:retention-apply", "description": "Apply a planned retention policy only while the plan still holds", - "synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] ", + "synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] ", "aliases": [], "hidden": false, "help": "Apply a retention policy previewed with dw namespace:retention-plan, only\nwhile that plan still holds. Pass the same proposal with the plan's\n--policy-revision and --plan-revision, or pass the plan's saved JSON with\n--plan-file.\n\nA retroactive proposal, one that makes closed runs eligible for pruning\nthat the current policy keeps (fewer days, or bounded replacing forever),\nalso needs --confirm-retroactive-pruning, because pruning is irreversible.\n\nThe request is sent once and never resent. The Server checks the revisions\nand updates the policy in one transaction. A refusal changes nothing, and\ndw prints what to do next and exits 2:\n\n retention_policy_revision_stale (409): the namespace changed after the\n plan. Plan again and apply the new plan's revisions.\n retention_plan_revision_mismatch (409): the proposal is not the one that\n was planned.\n retention_pruning_confirmation_required (422): the proposal is\n retroactive and --confirm-retroactive-pruning was not passed.\n\nThe apply changes only the namespace's policy. Each later retention pass\nprunes the closed, unarchived runs past the cutoff at that pass, which can\ninclude runs that closed or aged after the plan. dw namespace:update\nstill activates a policy at once, without a plan. Needs an admin token and\nnative Server 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-apply billing --retention=7 --policy-revision=sha256:... --plan-revision=sha256:... --confirm-retroactive-pruning\n dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning", @@ -4457,7 +4457,7 @@ }, "retention": { "name": "--retention", - "shortcut": "", + "shortcut": "-r", "accept_value": true, "is_value_required": true, "is_multiple": false, @@ -4597,10 +4597,10 @@ { "name": "namespace:retention-plan", "description": "Preview a proposed retention policy without applying it", - "synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] ", + "synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] ", "aliases": [], "hidden": false, - "help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed --retention days, --retention-mode, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches --scan-limit (default 1000, at\nmost 10000) or --hold-scan-limit (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with dw namespace:retention-apply and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-plan billing --retention=7\n dw namespace:retention-plan archive --retention-mode=forever\n dw namespace:retention-plan billing --retention=7 --json > plan.json", + "help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed --retention days, --retention-mode, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches --scan-limit (default 1000, at\nmost 10000) or --hold-scan-limit (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with dw namespace:retention-apply and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\nExamples:\n\n dw namespace:retention-plan billing --retention=7\n dw namespace:retention-plan billing -r 7 --scan-limit=5000\n dw namespace:retention-plan archive --retention-mode=forever\n dw namespace:retention-plan billing --retention=7 --json > plan.json", "definition": { "arguments": { "name": { @@ -4668,7 +4668,7 @@ }, "retention": { "name": "--retention", - "shortcut": "", + "shortcut": "-r", "accept_value": true, "is_value_required": true, "is_multiple": false, diff --git a/rust/src/commands/retention_plan.rs b/rust/src/commands/retention_plan.rs index 0277c4e..f3bef12 100644 --- a/rust/src/commands/retention_plan.rs +++ b/rust/src/commands/retention_plan.rs @@ -266,6 +266,28 @@ pub fn apply(context: &Context, input: &Input) -> Result { Ok(0) } +/// The `dw namespace:retention-plan` command that plans again what a +/// refused apply tried: its `--retention-mode` and `--retention`, or the +/// proposed policy of its `--plan-file`. Planning with no proposal would +/// compare the current policy with itself. +pub fn replan_command(input: &Input) -> String { + let name = input.arg("name").unwrap_or_default(); + let mut command = format!("dw namespace:retention-plan {name}"); + let attempted = match input.opt_str("plan-file") { + Some(path) => plan_file_body(path, name).ok(), + None => proposal(input).ok(), + }; + if let Some(body) = attempted { + if let Some(mode) = body.get("retention_mode").and_then(Value::as_str) { + command.push_str(&format!(" --retention-mode={mode}")); + } + if let Some(days) = body.get("retention_days").and_then(Value::as_i64) { + command.push_str(&format!(" --retention={days}")); + } + } + command +} + /// The proposed `retention_mode` and `retention_days` from the options; a /// field left out keeps the namespace's current value on the Server. fn proposal(input: &Input) -> Result, CliError> { diff --git a/rust/src/error.rs b/rust/src/error.rs index afd17ff..88da633 100644 --- a/rust/src/error.rs +++ b/rust/src/error.rs @@ -179,6 +179,9 @@ pub struct ErrorContext<'a> { /// The request a failed `workflow:update` was sending, for its error /// diagnostics. pub update: Option, + /// The `namespace:retention-plan` command that plans again what a + /// refused `namespace:retention-apply` tried to apply. + pub retention_replan: Option, pub server_flag: Option, pub env_flag: Option, } @@ -299,7 +302,10 @@ fn retention_plan_recommendation(error: &CliError, context: &ErrorContext) -> Op .as_ref() .and_then(|body| scalar_text(body.get("namespace"))) .unwrap_or_else(|| "".into()); - let plan = format!("dw namespace:retention-plan {namespace}"); + let plan = context + .retention_replan + .clone() + .unwrap_or_else(|| format!("dw namespace:retention-plan {namespace}")); let reason = error.reason(); match (*status, reason) { (409, Some("retention_policy_revision_stale")) => { @@ -779,6 +785,7 @@ mod tests { request_id: None, keyed: false, update: None, + retention_replan: None, server_flag: None, env_flag: None, } @@ -867,6 +874,7 @@ mod tests { request_id: None, keyed: false, update: None, + retention_replan: None, server_flag: Some("http://127.0.0.1:1".into()), env_flag: None, }; diff --git a/rust/src/main.rs b/rust/src/main.rs index 4a3239e..9ecfe4c 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -509,6 +509,8 @@ fn report(error: &CliError, input: &Input, server_command: bool) -> i32 { keyed: commands::workflow_message::command_request_id().is_some(), update: (input.command == "workflow:update") .then(|| commands::workflow_message::UpdateErrorRequest::from_input(input)), + retention_replan: (input.command == "namespace:retention-apply") + .then(|| commands::retention_plan::replan_command(input)), server_flag: input.opt_str("server").map(str::to_string), env_flag: input.opt_str("env").map(str::to_string), }; diff --git a/rust/tests/namespace_retention.rs b/rust/tests/namespace_retention.rs index b21f9c0..7e0539b 100644 --- a/rust/tests/namespace_retention.rs +++ b/rust/tests/namespace_retention.rs @@ -405,6 +405,14 @@ fn a_forever_plan_sends_only_the_mode_and_its_apply_needs_no_confirmation() { ); assert!(!stdout.contains("is retroactive"), "{stdout}"); + // -r is --retention, as on namespace:create and namespace:update. + let server = Server::new(info(), vec![ok(shortening_plan())]); + stdout_text(&scratch.run( + &server.url, + &["namespace:retention-plan", "billing", "-r", "7"], + )); + assert_eq!(server.body(0), json!({"retention_days": 7})); + // A plan with no proposal compares the current policy with itself. let server = Server::new(info(), vec![ok(forever_plan())]); stdout_text(&scratch.run(&server.url, &["namespace:retention-plan", "billing"])); @@ -508,7 +516,7 @@ fn each_refused_apply_changes_nothing_and_says_what_to_do_next() { "Server error: The namespace changed after the plan. Request a new plan and apply its revisions.", "Reason: retention_policy_revision_stale", "Nothing was applied: the namespace changed after the plan. Its current policy revision is sha256:newer.", - " Try: dw namespace:retention-plan billing", + " Try: dw namespace:retention-plan billing --retention=7\n", ], ), ( @@ -522,7 +530,7 @@ fn each_refused_apply_changes_nothing_and_says_what_to_do_next() { vec![ "Reason: retention_plan_revision_mismatch", "Nothing was applied: the policy sent is not the policy that was planned.", - " Try: dw namespace:retention-plan billing", + " Try: dw namespace:retention-plan billing --retention=7\n", ], ), ( @@ -565,6 +573,84 @@ fn each_refused_apply_changes_nothing_and_says_what_to_do_next() { } } +fn stale() -> Reply { + refusal( + 409, + json!({ + "reason": "retention_policy_revision_stale", + "namespace": "billing", + "message": "The namespace changed after the plan. Request a new plan and apply its revisions.", + "policy_revision": "sha256:newer" + }), + ) +} + +#[test] +fn the_replan_hint_repeats_the_proposal_the_apply_tried() { + let scratch = Scratch::new(); + let path = scratch.0.join("plan.json"); + let plan_file = format!("--plan-file={}", path.display()); + for (plan, args, command) in [ + ( + None, + vec![ + "namespace:retention-apply", + "billing", + "-r", + "14", + "--retention-mode=bounded", + "--policy-revision=a", + "--plan-revision=b", + ], + "dw namespace:retention-plan billing --retention-mode=bounded --retention=14", + ), + ( + None, + vec![ + "namespace:retention-apply", + "billing", + "--retention-mode=forever", + "--policy-revision=a", + "--plan-revision=b", + ], + "dw namespace:retention-plan billing --retention-mode=forever", + ), + ( + Some(shortening_plan()), + vec!["namespace:retention-apply", "billing", &plan_file], + "dw namespace:retention-plan billing --retention-mode=bounded --retention=7", + ), + ( + Some(forever_plan()), + vec!["namespace:retention-apply", "billing", &plan_file], + "dw namespace:retention-plan billing --retention-mode=forever", + ), + ] { + if let Some(plan) = plan { + fs::write(&path, plan.to_string()).unwrap(); + } + let server = Server::new(info(), vec![stale()]); + let output = scratch.run(&server.url, &args); + assert_eq!(output.status.code(), Some(2), "{args:?}: {output:?}"); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert!( + stderr.contains(&format!(" Try: {command}\n")), + "{command}: {stderr}" + ); + + let server = Server::new(info(), vec![stale()]); + let mut json_args = args.clone(); + json_args.push("--json"); + let output = scratch.run(&server.url, &json_args); + let envelope: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!( + envelope["recommendations"][0]["command"], + json!(command), + "{envelope}" + ); + } +} + #[test] fn a_server_without_the_plan_routes_points_at_server_3_30() { let scratch = Scratch::new();