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
//! What the documentation does not show: a CLI option and a server route that the code declares
//! and that neither the README nor its examples exercise. Recorded from the documentation alone,
//! such an original leaves the option (the route) in the registry with no case: `app lift` must
//! refuse it, by its exact id, down to the MCP tools.
//!
//! The originals are recorded by the real recorder (`app record`): the CLI is a standard-library
//! argparse script, the server a Flask script whose import lands on a stand-in in
//! `site-packages/` (Flask is not installed where the tests run). Skipped without `python3`; the
//! test that builds a front door is also skipped without `cargo`.
mod common;
use std::path::{Path, PathBuf};
use rust_anything::app::{self, RecordOptions};
use rust_anything::front_door::{self, FrontDoorOptions};
use rust_anything::lift::{self, LiftOptions};
use rust_anything::obligations::evidence::{BINDINGS_FILE, Evidence, Link, evidence};
use rust_anything::obligations::standing::{
ADR_FILE, DECISIONS_FILE, Standing, attest, lift_blockers, standing, waive,
};
use rust_anything::obligations::{self, Family};
use serde_json::{Value, json};
/// What changes from one original to the other.
struct Original {
fixture: &'static str,
run: [&'static str; 2],
name: Option<&'static str>,
http: bool,
/// The obligation that the documentation does not show.
id: &'static str,
/// An `--inputs` line that really exercises it.
hit: &'static str,
/// An `--inputs` line that names it and only fails.
miss: &'static str,
}
const CLI: Original = Original {
fixture: "obligations-undocumented-cli",
run: ["python3", "greet.py"],
name: Some("greet"),
http: false,
id: "flag:greet.py#hello/--shout",
hit: r#"{"name":"shout","args":["hello","ada","--shout"]}"#,
miss: r#"{"name":"shout-bad","args":["hello","ada","--shout","--times","many"]}"#,
};
const SERVER: Original = Original {
fixture: "obligations-undocumented-server",
run: ["python3", "app.py"],
name: None,
http: true,
id: "route:app.py#GET /reports/<name>",
hit: r#"{"name":"daily-report","method":"GET","path":"/reports/daily"}"#,
miss: r#"{"name":"missing-report","method":"GET","path":"/reports/nope"}"#,
};
const ORIGINALS: [&Original; 2] = [&CLI, &SERVER];
fn copy_dir(from: &Path, to: &Path) {
std::fs::create_dir_all(to).unwrap();
for entry in std::fs::read_dir(from).unwrap().flatten() {
let target = to.join(entry.file_name());
if entry.file_type().unwrap().is_dir() {
copy_dir(&entry.path(), &target);
} else {
std::fs::copy(entry.path(), &target).unwrap();
}
}
}
/// A folder of its own, outside the working repository: its name is only used by this test.
fn scratch(tag: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!(
"rust-anything-undocumented-{}-{tag}",
std::process::id()
));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
dir
}
fn python3() -> bool {
common::have("python3")
}
/// The original in its own folder, recorded from its documentation and, when there are any, the
/// `--inputs` lines given.
fn recorded(original: &Original, tag: &str, inputs: &[&str]) -> PathBuf {
let root = scratch(&format!("{}-{tag}", original.http));
let repo = root.join("repo");
copy_dir(
&Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join(original.fixture),
&repo,
);
let file = root.join("inputs.jsonl");
let given = if inputs.is_empty() {
None
} else {
std::fs::write(&file, inputs.join("\n") + "\n").unwrap();
Some(file.as_path())
};
let outcome = app::record(&RecordOptions {
repo: &repo,
run: &original.run.map(String::from),
inputs: given,
normalize: &[],
name: original.name,
traps: false,
timeout_secs: None,
http: Some(original.http),
server_args: None,
fresh: None,
pace_ms: None,
port: None,
float_tolerance: None,
float_files: &[],
effects: None,
ready_secs: None,
ready_request: None,
sandbox: false,
})
.unwrap();
// The two README examples, and the lines given.
assert_eq!(outcome.cases, 2 + inputs.len(), "{outcome:?}");
repo
}
fn uncovered(s: &Standing) -> Vec<&str> {
s.blocking.uncovered.iter().map(|u| u.id.as_str()).collect()
}
fn evidence_of(repo: &Path) -> Evidence {
let ledger = obligations::ledger(repo, None).unwrap();
evidence(repo, &ledger).unwrap()
}
fn state_of(ev: &Evidence, id: &str) -> Link {
ev.entries
.iter()
.find(|e| e.id == id)
.unwrap_or_else(|| panic!("{id} is not in the evidence"))
.state
}
/// What a person would do for everything else: every obligation without a case, except `keep`, is
/// waived with a reason, and every family the registry does not prove complete is attested.
/// Nothing is said about `keep`.
fn settle_all_but(repo: &Path, keep: &str) {
let before = standing(repo).unwrap();
let ids: Vec<String> = before
.blocking
.uncovered
.iter()
.filter(|u| u.id != keep)
.map(|u| u.id.clone())
.collect();
if !ids.is_empty() {
waive(
repo,
&ids,
"fixture: another obligation, not the one under test",
)
.unwrap();
}
let families: Vec<Family> = before.blocking.families.iter().map(|f| f.family).collect();
if !families.is_empty() {
attest(
repo,
&families,
"fixture: nobody reads more than its detectors list",
)
.unwrap();
}
let after = standing(repo).unwrap();
assert!(after.blocking.families.is_empty(), "{after:#?}");
assert!(after.blocking.wildcards.is_empty(), "{after:#?}");
assert!(after.blocking.fallbacks.is_empty(), "{after:#?}");
}
/// An MCP tool call as the server makes it: the result of `tools/call`.
fn mcp(tool: &str, arguments: Value) -> Value {
rust_anything::mcp::handle(&json!({ "jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": { "name": tool, "arguments": arguments } }))
.unwrap()["result"]
.clone()
}
fn strings(value: &Value) -> Vec<String> {
value
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_string())
.collect()
}
#[test]
fn recorded_from_the_documentation_alone_the_item_is_listed_without_a_case() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "listed", &[]);
let ledger = obligations::ledger(&repo, None).unwrap();
assert!(ledger.obligations.iter().any(|o| o.id == id), "{id}");
assert_eq!(state_of(&evidence_of(&repo), id), Link::Uncovered, "{id}");
let s = standing(&repo).unwrap();
assert!(uncovered(&s).contains(&id), "{id}: {:?}", uncovered(&s));
let shown = repo.display().to_string();
let lines = lift_blockers(&s, &shown);
assert!(lines.iter().any(|l| l.contains(id)), "{id}: {lines:#?}");
// The MCP tools say the same thing, with the same sentences.
let check = mcp("obligations_check", json!({ "repo": repo }));
assert_eq!(check["isError"], false, "{check}");
let c = &check["structuredContent"];
assert_eq!(c["clear"], false, "{id}");
assert_eq!(strings(&c["lift_blockers"]), lines, "{id}");
assert!(
c["blocking"]["uncovered"]
.as_array()
.unwrap()
.iter()
.any(|u| u["id"] == id),
"{id}: {c}"
);
let listed = mcp("obligations", json!({ "repo": repo }));
assert!(
listed["structuredContent"]["obligations"]
.as_array()
.unwrap()
.iter()
.any(|o| o["id"] == id),
"{id}"
);
let proof = mcp("obligations", json!({ "repo": repo, "evidence": true }));
let entry = proof["structuredContent"]["entries"]
.as_array()
.unwrap()
.iter()
.find(|e| e["id"] == id)
.unwrap()
.clone();
assert_eq!(entry["state"], "uncovered", "{id}");
assert_eq!(entry["case_count"], 0, "{id}");
}
}
#[test]
fn the_real_lift_and_app_lift_refuse_for_it_by_its_exact_id() {
if !python3() || !common::have("cargo") {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "lift", &[]);
let door = front_door::front_door(&FrontDoorOptions {
repo: &repo,
library: false,
check: true,
commands: &[],
})
.unwrap();
let replay = door.replay.expect("the front door was built and replayed");
assert_eq!(replay.passed, replay.total, "{:?}", replay.failures);
let refused = lift::lift(&LiftOptions { repo: &repo }).unwrap();
assert!(!refused.lifted, "{id}");
let shown = repo.display().to_string();
let line = refused
.blockers
.iter()
.find(|b| b.contains(id))
.unwrap_or_else(|| panic!("{id}: {:#?}", refused.blockers));
assert!(
line.contains(&format!("`rust-anything obligations {shown} --check`")),
"{line}"
);
// `app_lift` through the MCP server: an error with its own code, with the command that
// says what to do; each blocker stays in the text.
let result = mcp("app_lift", json!({ "repo": repo }));
assert_eq!(result["isError"], true, "{id}: {result}");
let s = &result["structuredContent"];
assert_eq!(s["code"], "obligations_open", "{id}");
assert_eq!(s["retryable"], false, "{id}");
assert_eq!(
s["next"],
format!("rust-anything obligations {shown} --check"),
"{id}"
);
assert!(s["message"].as_str().unwrap().contains(id), "{id}: {s}");
for blocker in &refused.blockers {
assert!(s["message"].as_str().unwrap().contains(blocker.as_str()));
}
let check = mcp("obligations_check", json!({ "repo": repo }));
assert_eq!(check["structuredContent"]["clear"], false, "{id}");
assert!(
strings(&check["structuredContent"]["lift_blockers"])
.iter()
.any(|l| l.contains(id)),
"{id}"
);
}
}
#[test]
fn once_everything_else_is_settled_the_item_alone_blocks() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "alone", &[]);
settle_all_but(&repo, id);
let s = standing(&repo).unwrap();
assert_eq!(uncovered(&s), [id], "{id}");
assert_eq!(s.blocking_count(), 1, "{id}: {s:#?}");
assert!(s.blocks(), "{id}");
let lines = lift_blockers(&s, &repo.display().to_string());
assert_eq!(lines.len(), 1, "{id}: {lines:#?}");
assert!(lines[0].contains(id), "{id}: {lines:#?}");
let check = mcp("obligations_check", json!({ "repo": repo }));
let c = &check["structuredContent"];
assert_eq!(c["clear"], false, "{id}");
assert_eq!(strings(&c["lift_blockers"]), lines, "{id}");
}
}
#[test]
fn a_case_that_really_exercises_it_removes_it() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "hit", &[original.hit]);
let ev = evidence_of(&repo);
assert_eq!(state_of(&ev, id), Link::Matched, "{id}");
let s = standing(&repo).unwrap();
assert!(!uncovered(&s).contains(&id), "{id}: {:?}", uncovered(&s));
let lines = lift_blockers(&s, &repo.display().to_string());
assert!(lines.iter().all(|l| !l.contains(id)), "{id}: {lines:#?}");
// With the rest settled as a person would, nothing blocks any more: `clear` is true, and
// only then.
settle_all_but(&repo, "nothing: every other item is settled");
let check = mcp("obligations_check", json!({ "repo": repo }));
let c = &check["structuredContent"];
assert_eq!(c["clear"], true, "{id}: {c}");
assert_eq!(c["lift_blockers"], json!([]), "{id}");
}
}
#[test]
fn a_waiver_with_a_reason_removes_it_and_leaves_an_adr() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "waive", &[]);
settle_all_but(&repo, id);
let reason = "the README never shows it and the user said it needs no case";
let done = waive(&repo, &[id.to_string()], reason).unwrap();
assert_eq!(done.items, [id], "{id}");
let s = standing(&repo).unwrap();
assert!(!s.blocks(), "{id}: {s:#?}");
let item = s.waived.iter().find(|w| w.id == id).unwrap();
assert_eq!(item.reason, reason, "{id}");
assert_eq!(item.adr, done.adr, "{id}");
// The ADR and the decision entry carry the id and the reason.
let adr = std::fs::read_to_string(repo.join(ADR_FILE)).unwrap();
assert!(adr.contains(&done.adr) && adr.contains(id), "{id}: {adr}");
assert!(adr.contains(reason), "{id}: {adr}");
let decisions = std::fs::read_to_string(repo.join(DECISIONS_FILE)).unwrap();
assert!(decisions.contains(id), "{id}: {decisions}");
let check = mcp("obligations_check", json!({ "repo": repo }));
assert_eq!(check["structuredContent"]["clear"], true, "{id}");
// Without a reason, nothing is waived.
let other = recorded(original, "waive-empty", &[]);
settle_all_but(&other, id);
assert!(waive(&other, &[id.to_string()], " ").is_err(), "{id}");
assert!(uncovered(&standing(&other).unwrap()).contains(&id), "{id}");
}
}
#[test]
fn a_case_that_only_fails_on_it_does_not_cover_it() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
let repo = recorded(original, "miss", &[original.miss]);
// The failing case was recorded, with its failure: a non-zero status for a CLI, a 404
// answer for a route.
let recorded_case = if original.http {
repo.join("rust/app-cases/http/missing-report.toml")
} else {
// A CLI case: `rust/app-cases/<name>.toml`.
repo.join("rust/app-cases/shout-bad.toml")
};
assert!(recorded_case.is_file(), "{id}: {}", recorded_case.display());
let case = std::fs::read_to_string(&recorded_case).unwrap();
let failed = if original.http {
case.contains("status = 404")
} else {
case.contains("status.code = 2")
};
assert!(failed, "{id}: the case does not record its failure: {case}");
assert_eq!(state_of(&evidence_of(&repo), id), Link::Uncovered, "{id}");
let s = standing(&repo).unwrap();
assert!(uncovered(&s).contains(&id), "{id}: {:?}", uncovered(&s));
// And it does not hide a case that succeeds: the two together cover the obligation.
let both = recorded(original, "miss-and-hit", &[original.miss, original.hit]);
assert_eq!(state_of(&evidence_of(&both), id), Link::Matched, "{id}");
}
}
#[test]
fn a_binding_to_a_failing_case_closes_it_without_an_adr_which_is_why_it_is_the_users_call() {
if !python3() {
return;
}
for original in ORIGINALS {
let id = original.id;
// The case records only a failure (exit 2; answer 404): the rules do not read it.
let repo = recorded(original, "bind", &[original.miss]);
settle_all_but(&repo, id);
let case = if original.http {
"http:missing-report"
} else {
"cli:shout-bad"
};
let before = mcp("obligations_check", json!({ "repo": repo }));
let b = &before["structuredContent"];
assert_eq!(b["clear"], false, "{id}");
assert_eq!(b["closed_by_binding"], json!([]), "{id}");
// O23: a binding holds, even toward a case the rules refuse.
let adr_before = std::fs::read_to_string(repo.join(ADR_FILE)).unwrap();
let decisions_before = std::fs::read_to_string(repo.join(DECISIONS_FILE)).unwrap();
std::fs::write(
repo.join(BINDINGS_FILE),
format!(
"[[bind]]\nobligation = \"{id}\"\ncases = [\"{case}\"]\nreason = \"pinned: nobody checked\"\n"
),
)
.unwrap();
let s = standing(&repo).unwrap();
assert!(!uncovered(&s).contains(&id), "{id}: {:?}", uncovered(&s));
assert!(!s.blocks(), "{id}: {s:#?}");
// No ADR, no decision: neither a waiver nor an attestation mentions it.
assert_eq!(
std::fs::read_to_string(repo.join(ADR_FILE)).unwrap(),
adr_before,
"{id}"
);
assert_eq!(
std::fs::read_to_string(repo.join(DECISIONS_FILE)).unwrap(),
decisions_before,
"{id}"
);
assert!(s.waived.iter().all(|w| w.id != id), "{id}");
// The tool does not say "nothing to see": it shows what is closed by a binding.
let after = mcp("obligations_check", json!({ "repo": repo }));
let a = &after["structuredContent"];
assert_eq!(a["clear"], true, "{id}: {a}");
assert_eq!(a["closed_by_binding"], json!([id]), "{id}: {a}");
assert!(
a["waived"]
.as_array()
.unwrap()
.iter()
.all(|w| w["id"] != id),
"{id}"
);
}
}