Done the way the owner asked and the spike mapped: the crate and the manifests renamed, then what the build reported fixed. Layers: 138 "proto unresolved" errors across 169 files; cargo fmt reordering imports; six fixture paths built as strings in brokerd's and bxctl's tests, which the compiler cannot see, and comments naming crates/proto/; the crate-dependency check and its self-test. One more the spike did not reach: a `\nproto =` key inside a printf format in the self-test, which a word-boundary replacement skips because `n` and `p` are both word characters. make gate: gate: ok, 944 tests; no new entry in /tmp. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
//! The four tools' arguments: `brokerd` writes them to a container's standard input, `toolkit`
|
|
//! reads them back, and both use these types. Do not edit.
|
|
|
|
use bxcore::tools::{HttpFetchArgs, ReadFileArgs, ShellArgs, WriteFileArgs};
|
|
|
|
#[test]
|
|
fn each_type_round_trips_in_field_order() {
|
|
let read = ReadFileArgs {
|
|
path: "/n/a.md".to_string(),
|
|
};
|
|
assert_eq!(
|
|
serde_json::to_string(&read).unwrap(),
|
|
r#"{"path":"/n/a.md"}"#
|
|
);
|
|
let write = WriteFileArgs {
|
|
path: "/n/a.md".to_string(),
|
|
content: "hi\n".to_string(),
|
|
};
|
|
let text = serde_json::to_string(&write).unwrap();
|
|
assert_eq!(text, r#"{"path":"/n/a.md","content":"hi\n"}"#);
|
|
assert_eq!(serde_json::from_str::<WriteFileArgs>(&text).unwrap(), write);
|
|
let fetch = HttpFetchArgs {
|
|
url: "https://example.com/".to_string(),
|
|
};
|
|
assert_eq!(
|
|
serde_json::to_string(&fetch).unwrap(),
|
|
r#"{"url":"https://example.com/"}"#
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_shell_cwd_is_left_out_when_absent_and_may_be_null_or_missing() {
|
|
let bare = ShellArgs {
|
|
command: "ls".to_string(),
|
|
cwd: None,
|
|
};
|
|
assert_eq!(serde_json::to_string(&bare).unwrap(), r#"{"command":"ls"}"#);
|
|
for text in [r#"{"command":"ls"}"#, r#"{"command":"ls","cwd":null}"#] {
|
|
assert_eq!(serde_json::from_str::<ShellArgs>(text).unwrap(), bare);
|
|
}
|
|
let with = ShellArgs {
|
|
command: "ls".to_string(),
|
|
cwd: Some("/n".to_string()),
|
|
};
|
|
assert_eq!(
|
|
serde_json::to_string(&with).unwrap(),
|
|
r#"{"command":"ls","cwd":"/n"}"#
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_and_missing_fields_are_refused() {
|
|
assert!(serde_json::from_str::<ReadFileArgs>(r#"{"path":"/a","mode":"x"}"#).is_err());
|
|
assert!(serde_json::from_str::<ReadFileArgs>(r#"{}"#).is_err());
|
|
assert!(serde_json::from_str::<WriteFileArgs>(r#"{"path":"/a"}"#).is_err());
|
|
assert!(serde_json::from_str::<ShellArgs>(r#"{"command":"ls","env":{}}"#).is_err());
|
|
assert!(
|
|
serde_json::from_str::<HttpFetchArgs>(r#"{"url":"https://a.b/","method":"POST"}"#).is_err()
|
|
);
|
|
}
|