Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Rust agent-skillsclaude-codeclicode-migrationcodexffigolangjavajavascriptmcpmigrationnapiperformanceportingpyo3pythonrewriterubyrusttypescript
//! The skill tells an agent which commands to run, so a command it names that the CLI does not
//! have sends every run down a dead end. These checks read the skill files like an agent would.
mod common;
use std::collections::BTreeSet;
use std::path::PathBuf;
fn skill_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("skills/rust-anything")
}
/// Subcommand names listed under `Commands:` of `rust-anything <args> --help`.
fn subcommands(args: &[&str]) -> BTreeSet<String> {
let out = common::cli().args(args).arg("--help").output().unwrap();
let text = String::from_utf8_lossy(&out.stdout).into_owned();
let mut names = BTreeSet::new();
let mut in_commands = false;
for line in text.lines() {
if line.starts_with("Commands:") {
in_commands = true;
} else if in_commands {
let Some(rest) = line.strip_prefix(" ") else {
break;
};
if let Some(name) = rest.split_whitespace().next() {
names.insert(name.to_string());
}
}
}
names
}
/// The code in a markdown file: fenced lines whole, and inline backtick spans.
fn code_snippets(markdown: &str) -> Vec<String> {
let mut found = Vec::new();
let mut in_fence = false;
for line in markdown.lines() {
if line.trim_start().starts_with("```") {
in_fence = !in_fence;
} else if in_fence {
found.push(line.to_string());
} else {
found.extend(
line.split('`')
.skip(1)
.step_by(2)
.map(|span| span.to_string()),
);
}
}
found
}
fn skill_files() -> Vec<(String, String)> {
let mut files = Vec::new();
for dir in [skill_dir(), skill_dir().join("languages")] {
for entry in std::fs::read_dir(&dir).unwrap() {
let path = entry.unwrap().path();
if path.extension().is_some_and(|e| e == "md") {
let name = path
.strip_prefix(skill_dir())
.unwrap()
.to_string_lossy()
.into_owned();
files.push((name, std::fs::read_to_string(&path).unwrap()));
}
}
}
files.sort();
files
}
#[test]
fn contributing_lists_every_integration_test_suite() {
let guide = include_str!("../CONTRIBUTING.md");
let (_, after_heading) = guide
.split_once("- **Where tests go:**")
.expect("CONTRIBUTING.md has a Where tests go section");
let (listed, _) = after_heading
.split_once("- **Fixtures**")
.expect("Where tests go ends before Fixtures");
let tests = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
let mut missing = Vec::new();
for entry in std::fs::read_dir(tests).unwrap() {
let path = entry.unwrap().path();
if !path.is_file() || path.extension().is_none_or(|extension| extension != "rs") {
continue;
}
let name = path.file_name().unwrap().to_str().unwrap();
let suite = format!("tests/{name}");
if !listed.contains(&format!("`{suite}`")) {
missing.push(suite);
}
}
missing.sort();
assert!(
missing.is_empty(),
"Add these integration suites under Where tests go in CONTRIBUTING.md.\n{}",
missing.join("\n")
);
}
#[test]
fn contributing_setup_table_lists_every_language() {
let guide = include_str!("../CONTRIBUTING.md");
let (_, after_heading) = guide
.split_once("## Set up")
.expect("CONTRIBUTING.md has a Set up section");
let (_, table_start) = after_heading
.split_once("| For | Install |")
.expect("Set up section has a For | Install table");
let rows: Vec<&str> = table_start
.lines()
.skip(1)
.take_while(|line| line.starts_with('|'))
.collect();
let mut missing = Vec::new();
for lang in rust_anything::lang::Lang::ALL {
let prefix = format!("| {} |", lang.name());
if !rows.iter().any(|row| row.starts_with(&prefix)) {
missing.push(lang.name());
}
}
assert!(
missing.is_empty(),
"Add these languages to the Set up table in CONTRIBUTING.md: {}",
missing.join(", ")
);
}
#[test]
fn skill_front_matter_names_the_folder_and_describes_when_to_use_it() {
let text = std::fs::read_to_string(skill_dir().join("SKILL.md")).unwrap();
let rest = text.strip_prefix("---\n").expect("front matter");
let (front, _) = rest.split_once("\n---\n").expect("front matter end");
let field = |key: &str| {
front
.lines()
.find_map(|l| l.strip_prefix(&format!("{key}: ")))
.unwrap_or_else(|| panic!("front matter has no `{key}`"))
};
assert_eq!(field("name"), "rust-anything");
let description = field("description");
assert!(description.len() <= 1024, "{} chars", description.len());
assert!(description.contains("Use when"), "{description}");
}
#[test]
fn every_command_the_skill_names_exists() {
let top = subcommands(&[]);
let app = subcommands(&["app"]);
assert!(
top.contains("gate") && app.contains("record"),
"{top:?} {app:?}"
);
let word = |w: Option<&&str>| {
w.filter(|c| {
!c.starts_with(['-', '<'])
&& c.chars()
.all(|ch| ch.is_ascii_alphanumeric() || ch == '-' || ch == '_')
})
.map(|c| c.to_string())
};
let mut missing = Vec::new();
for (file, text) in skill_files() {
for snippet in code_snippets(&text) {
let words: Vec<&str> = snippet.split_whitespace().collect();
for (i, w) in words.iter().enumerate() {
let Some(cmd) = word(words.get(i + 1)).filter(|_| *w == "rust-anything") else {
continue;
};
let sub = word(words.get(i + 2)).filter(|_| cmd == "app");
match sub {
Some(sub) if top.contains(&cmd) && !app.contains(&sub) => {
missing.push(format!("{file}: rust-anything app {sub}"));
}
_ if !top.contains(&cmd) => {
missing.push(format!("{file}: rust-anything {cmd}"));
}
_ => {}
}
}
}
}
assert!(
missing.is_empty(),
"the skill names commands the CLI lacks: {missing:?}"
);
}
#[test]
fn english_website_language_overview_matches_the_status_table() {
let overview = include_str!("../website/pages/en/docs/languages/overview.md");
let status = include_str!("../docs/STATUS.md");
let (front, body) = overview.split_once("\n---\n").unwrap();
let intro = body
.lines()
.find(|line| !line.is_empty() && !line.starts_with('#'))
.unwrap();
let mut gaps = Vec::new();
for language in rust_anything::lang::Lang::ALL {
let name = language.name();
if !front.contains(name) || !intro.contains(name) {
gaps.push(format!(
"{name} is missing from the introduction or metadata"
));
}
let source_label = format!("| {name} |");
let expected = status
.lines()
.find(|line| line.starts_with(&source_label))
.and_then(|line| line.split('|').nth(2))
.map(str::trim)
.unwrap();
let website_link = format!("| [{name}](");
let shown = body
.lines()
.find(|line| line.starts_with(&source_label) || line.starts_with(&website_link))
.and_then(|line| line.split('|').nth(2))
.map(str::trim);
if shown != Some(expected) {
gaps.push(format!("{name} should be listed as {expected}"));
}
}
assert!(gaps.is_empty(), "{}", gaps.join("\n"));
}
#[test]
fn english_website_php_and_csharp_pages_describe_unit_bridges() {
for (language, page) in [
(
"PHP",
include_str!("../website/pages/en/docs/languages/php.md"),
),
(
"C#",
include_str!("../website/pages/en/docs/languages/csharp.md"),
),
] {
assert!(
page.lines()
.any(|line| line == format!("title: {language}")),
"{language} has an outdated title"
);
assert!(page.lines().any(|line| line == format!("# {language}")));
let today = page
.lines()
.find(|line| line.starts_with("| Today |"))
.unwrap();
assert!(
today.contains("Unit bridges") && today.contains("whole apps"),
"{language} omits a supported workflow: {today}"
);
}
}
#[test]
fn links_between_skill_files_resolve() {
let mut broken = Vec::new();
for (file, text) in skill_files() {
for part in text.split("](").skip(1) {
let target = part.split(')').next().unwrap();
if target.starts_with("http") || target.starts_with('#') {
continue;
}
let path = target.split('#').next().unwrap();
let base = skill_dir().join(&file);
if !base.parent().unwrap().join(path).exists() {
broken.push(format!("{file}: {target}"));
}
}
}
assert!(broken.is_empty(), "{broken:?}");
}
/// The names of the tools `rust-anything mcp` lists.
fn mcp_tool_names() -> Vec<String> {
use std::io::Write as _;
use std::process::Stdio;
let mut child = common::cli()
.arg("mcp")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
child
.stdin
.take()
.unwrap()
.write_all(
br#"{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test","version":"0"}}}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
"#,
)
.unwrap();
let out = child.wait_with_output().unwrap();
String::from_utf8(out.stdout)
.unwrap()
.lines()
.filter_map(|l| serde_json::from_str::<serde_json::Value>(l).ok())
.find(|m| m["id"] == 2)
.expect("tools/list answered")["result"]["tools"]
.as_array()
.unwrap()
.iter()
.map(|t| t["name"].as_str().unwrap().to_string())
.collect()
}
#[test]
fn the_skill_names_every_tool_the_mcp_server_lists() {
let skill = std::fs::read_to_string(skill_dir().join("SKILL.md")).unwrap();
let names = mcp_tool_names();
assert!(names.len() > 20, "tools/list gave {names:?}");
let missing: Vec<&String> = names
.iter()
.filter(|n| !skill.contains(&format!("`{n}`")))
.collect();
assert!(
missing.is_empty(),
"SKILL.md does not name these MCP tools: {missing:?}"
);
}
#[test]
fn the_agents_page_names_every_tool_the_mcp_server_lists() {
let page = std::fs::read_to_string(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("website/pages/en/docs/introduction/agents.md"),
)
.unwrap();
let names = mcp_tool_names();
assert!(names.len() > 20, "tools/list gave {names:?}");
let missing: Vec<&String> = names
.iter()
.filter(|n| !page.contains(&format!("`{n}`")))
.collect();
assert!(
missing.is_empty(),
"website/pages/en/docs/introduction/agents.md does not name these MCP tools: {missing:?}"
);
}
#[test]
fn the_languages_shadow_refuses_are_named_where_the_docs_tell_you_to_run_it() {
let dir = std::env::temp_dir().join(format!("ra-shadow-refusals-{}", std::process::id()));
let skill = std::fs::read_to_string(skill_dir().join("SKILL.md")).unwrap();
let step = skill
.split("## 4. Ship it safely")
.nth(1)
.and_then(|rest| rest.split("\n## ").next())
.expect("SKILL.md has a step 4");
let table = std::fs::read_to_string(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/how-it-works.md"),
)
.unwrap();
let row = table
.lines()
.find(|l| l.starts_with("| 4. Shadow |"))
.expect("how-it-works.md has a Shadow row");
let page = std::fs::read_to_string(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("website/pages/en/docs/concepts/shadow.md"),
)
.unwrap();
for (language, name) in [
("php", "PHP"),
("csharp", "C#"),
("powershell", "PowerShell"),
("swift", "Swift"),
] {
let crate_dir = dir.join(language);
std::fs::create_dir_all(&crate_dir).unwrap();
std::fs::write(
crate_dir.join(rust_anything::bridge::MANIFEST),
format!(
r#"{{"schema": "rust-anything/bridge@1", "root": ".", "unit": "a", "language": "{language}", "kind": "ffi", "crate_name": "a-rs", "exports": []}}"#
),
)
.unwrap();
let err = rust_anything::shadow::shadow(&crate_dir, None)
.unwrap_err()
.to_string();
assert!(err.contains("no shadow module"), "{name}: {err}");
assert!(
step.contains(name),
"step 4 of SKILL.md does not name {name}"
);
assert!(
row.contains(name),
"the Shadow row does not name {name}: {row}"
);
assert!(
page.contains(name),
"website/pages/en/docs/concepts/shadow.md does not name {name}"
);
}
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn the_skill_names_every_language_profile_refuses() {
use rust_anything::lang::Lang;
let dir = std::env::temp_dir().join(format!("ra-profile-refusals-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let skill = std::fs::read_to_string(skill_dir().join("SKILL.md")).unwrap();
let paragraph = skill
.split("It runs a real workload")
.nth(1)
.and_then(|rest| rest.split("\n\n").next())
.expect("SKILL.md describes what profile runs");
let words: Vec<&str> = paragraph
.split_whitespace()
.map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
.collect();
let page = std::fs::read_to_string(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("website/pages/en/docs/concepts/analyze.md"),
)
.unwrap();
let section = page
.split("`profile` runs a real workload")
.nth(1)
.and_then(|rest| rest.split("\n\n").next())
.expect("analyze.md describes what profile runs");
let page_words: Vec<&str> = section
.split_whitespace()
.map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
.collect();
for lang in [
Lang::C,
Lang::Kotlin,
Lang::Php,
Lang::Csharp,
Lang::Powershell,
Lang::Swift,
] {
// Refused before the workload runs, so `true` is never started.
let err = rust_anything::profile::profile(&dir, &["true".into()], Some(lang))
.expect_err(&format!("{} should be refused", lang.name()))
.to_string();
assert!(
err.contains("does not run"),
"{}: not the language refusal: {err}",
lang.name()
);
assert!(
words.contains(&lang.name()),
"the skill's profile paragraph does not name {}: {paragraph}",
lang.name()
);
assert!(
page_words.contains(&lang.name()),
"the profile paragraph of website/pages/en/docs/concepts/analyze.md does not name {}: {section}",
lang.name()
);
}
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn the_docs_name_every_language_bridge_refuses_batches_for() {
let dir = std::env::temp_dir().join(format!("ra-batch-refusals-{}", std::process::id()));
let skill = std::fs::read_to_string(skill_dir().join("SKILL.md")).unwrap();
let bullet = skill
.split("- Items and other arguments:")
.nth(1)
.and_then(|rest| rest.split("\n- ").next())
.expect("SKILL.md lists what a batch takes");
let words: Vec<&str> = bullet
.split_whitespace()
.map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
.collect();
let how_it_works = std::fs::read_to_string(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/how-it-works.md"),
)
.unwrap();
let claim = how_it_works
.lines()
.find_map(|l| {
l.split("gets batches")
.next()
.filter(|_| l.contains("gets batches"))
})
.expect("how-it-works.md says which languages get batches");
let claim_words: Vec<&str> = claim
.split_whitespace()
.map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
.collect();
for (language, name) in [
("c", "C"),
("php", "PHP"),
("csharp", "C#"),
("powershell", "PowerShell"),
("swift", "Swift"),
] {
let crate_dir = dir.join(language);
std::fs::create_dir_all(&crate_dir).unwrap();
std::fs::write(
crate_dir.join(rust_anything::bridge::MANIFEST),
format!(
r#"{{"schema": "rust-anything/bridge@1", "root": ".", "unit": "a", "language": "{language}", "kind": "ffi", "crate_name": "a-rs", "exports": []}}"#
),
)
.unwrap();
let err = rust_anything::bridge::add_batches(&crate_dir, &["f:a".to_string()])
.map(|_| ())
.unwrap_err()
.to_string();
assert!(err.contains("`--batch` is not available"), "{name}: {err}");
assert!(
words.contains(&name),
"the skill's batch bullet does not name {name}: {bullet}"
);
assert!(
claim_words.contains(&name),
"how-it-works.md does not name {name}: {claim}"
);
}
let _ = std::fs::remove_dir_all(&dir);
}