Skip to content

Commit 289e60b

Browse files
ravarora2BuzzPRReviewAssistant1
andcommitted
fix(desktop): refine CLI migration failures
Use the CLI bad-input status for obsolete desktop invocations. Check the bundled command inventory and stop executable regression tests before identity startup. Co-authored-by: BuzzPRReviewAssistant1 <a581a7e8115222acdc32ffb14bfce55d48c24478d98e155f8eba126b69b83c7b@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <[email protected]>
1 parent 95ae66e commit 289e60b

4 files changed

Lines changed: 89 additions & 5 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ that agent in Buzz; they do not notify the external app through this connection.
248248

249249
- Desktop packages include a `buzz` command line client. On macOS, use
250250
`Buzz.app/Contents/Resources/bin/buzz`. Recognized CLI commands sent to the
251-
old `Contents/MacOS/buzz` path fail with exit code 2 instead of running the
252-
command. Update scripts or PATH links to use the bundled CLI.
251+
old `Contents/MacOS/buzz` path fail with exit code 1 (bad input) instead of
252+
running the command. Update scripts or PATH links to use the bundled CLI.
253253
- Plugins can add features. **Settings → Plugins → Manage plugins** controls
254254
them. Do not assume a particular optional plugin is on.
255255
- Some plugins let the person's other agents on this computer, such as Claude

‎scripts/test-buzz-cli.mjs‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Stage the bundled buzz CLI the way a desktop build does, then run the staged file.
2+
import assert from "node:assert/strict";
23
import { spawnSync } from "node:child_process";
3-
import { join } from "node:path";
4+
import { mkdtempSync, rmSync } from "node:fs";
5+
import { tmpdir } from "node:os";
6+
import { join, resolve } from "node:path";
47
import { fileURLToPath } from "node:url";
58

69
const root = fileURLToPath(new URL("../", import.meta.url));
@@ -23,3 +26,54 @@ if (help.status !== 0 || !/\bUsage:\s+buzz\b/.test(help.stdout)) {
2326
process.exit(1);
2427
}
2528
console.log(`${binary} --help ok`);
29+
30+
// Derive the inventory from the CLI we actually bundle, rather than copying the
31+
// guard's list. Only two-space entries are roots; deeper entries are subcommands.
32+
const commands = [...help.stdout.matchAll(/^ {2}([a-z][a-z-]*)\s/gm)].map(
33+
(match) => match[1],
34+
);
35+
assert(
36+
commands.length > 0,
37+
"Bundled CLI help advertised no top-level commands",
38+
);
39+
const build = spawnSync("cargo", ["build", "--locked", "-p", "Buzz"], {
40+
cwd: root,
41+
stdio: "inherit",
42+
});
43+
if (build.error) throw build.error;
44+
assert.equal(build.status, 0, "Could not build the desktop executable");
45+
const desktop = resolve(
46+
root,
47+
process.env.CARGO_TARGET_DIR || "target",
48+
"debug",
49+
process.platform === "win32" ? "Buzz.exe" : "Buzz",
50+
);
51+
const home = mkdtempSync(join(tmpdir(), "buzz-cli-contract-"));
52+
try {
53+
for (const command of commands) {
54+
const result = spawnSync(desktop, [command], {
55+
encoding: "utf8",
56+
timeout: 10_000,
57+
env: {
58+
...process.env,
59+
HOME: home,
60+
XDG_CONFIG_HOME: home,
61+
XDG_DATA_HOME: home,
62+
XDG_CACHE_HOME: home,
63+
APPDATA: home,
64+
LOCALAPPDATA: home,
65+
// Fail before identity/Keychain access if a command escapes the guard.
66+
BUZZ_NATIVE_MCP_PORT: "invalid",
67+
BUZZ_DEV_VIEWER: "",
68+
},
69+
});
70+
if (result.error) throw result.error;
71+
assert.equal(result.status, 1, `${command}: expected bad-input exit`);
72+
assert.equal(result.stdout, "", `${command}: unexpected stdout`);
73+
assert.match(result.stderr, /^This executable is the Buzz desktop app;/);
74+
assert.match(result.stderr, /no CLI command was executed/);
75+
}
76+
} finally {
77+
rmSync(home, { recursive: true, force: true });
78+
}
79+
console.log(`Desktop rejects all ${commands.length} bundled CLI commands`);

‎src-tauri/src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() -> std::process::ExitCode {
1616
Buzz.app/Contents/Resources/bin/buzz). Update your script or PATH \
1717
to point to that executable."
1818
);
19-
return std::process::ExitCode::from(2);
19+
return std::process::ExitCode::from(1);
2020
}
2121
buzz_foundation_lib::run();
2222
std::process::ExitCode::SUCCESS

‎src-tauri/tests/legacy_cli_invocation.rs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ use std::process::{Command, Output, Stdio};
44
use std::time::{Duration, Instant};
55

66
fn invoke(args: &[&str]) -> Output {
7+
let home = tempfile::tempdir().unwrap();
78
let mut child = Command::new(env!("CARGO_BIN_EXE_Buzz"))
89
.args(args)
10+
.env("HOME", home.path())
11+
.env("XDG_CONFIG_HOME", home.path())
12+
.env("XDG_DATA_HOME", home.path())
13+
.env("XDG_CACHE_HOME", home.path())
14+
.env("APPDATA", home.path())
15+
.env("LOCALAPPDATA", home.path())
16+
// Directory overrides do not isolate Keychain. If recognition regresses,
17+
// this existing refusal stops run() before identity, erase work or IPC.
18+
.env("BUZZ_NATIVE_MCP_PORT", "invalid")
19+
.env("BUZZ_DEV_VIEWER", "")
920
.stdin(Stdio::null())
1021
.stdout(Stdio::piped())
1122
.stderr(Stdio::piped())
@@ -33,7 +44,7 @@ fn legacy_cli_commands_fail_without_echoing_payloads() {
3344
vec!["--format", "compact", "channels", "list"],
3445
] {
3546
let output = invoke(&args);
36-
assert_eq!(output.status.code(), Some(2));
47+
assert_eq!(output.status.code(), Some(1));
3748
assert!(output.stdout.is_empty());
3849
let stderr = String::from_utf8(output.stderr).unwrap();
3950
assert!(stderr.contains("Buzz desktop app"));
@@ -44,3 +55,22 @@ fn legacy_cli_commands_fail_without_echoing_payloads() {
4455
assert!(!stderr.contains("private-key-payload"));
4556
}
4657
}
58+
59+
#[test]
60+
fn ordinary_launch_arguments_reach_the_pre_identity_startup_refusal() {
61+
for args in [
62+
vec![],
63+
vec!["buzz://message?channel=messages&id=help"],
64+
vec!["-psn_0_12345"],
65+
vec!["-NSDocumentRevisionsDebugMode", "messages"],
66+
vec!["unknown-launch-argument", "messages"],
67+
vec!["--", "messages", "send"],
68+
] {
69+
let output = invoke(&args);
70+
assert_eq!(output.status.code(), Some(1));
71+
assert!(output.stdout.is_empty());
72+
let stderr = String::from_utf8(output.stderr).unwrap();
73+
assert!(stderr.starts_with("Cannot enable native MCP: "), "{stderr}");
74+
assert!(!stderr.contains("no CLI command was executed"));
75+
}
76+
}

0 commit comments

Comments
 (0)