Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

Merge #68

EL4CTEOa71d38827f39
diff --cc src/pipeline.rs
index db38232,4e14ba5..f4dbad7
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@@ -488,64 -518,40 +525,101 @@@ mod tests
assert!(feedback(&wrong).contains("failed"));
}
+ fn project(name: &str) -> (PathBuf, Port) {
+ let root = std::env::temp_dir().join(format!("fa-pipeline-{name}-{}", std::process::id()));
+ let _ = fs::remove_dir_all(&root);
+ let crate_dir = ".fast/ports/demo";
+ fs::create_dir_all(root.join(crate_dir).join("src")).unwrap();
+ fs::write(root.join(crate_dir).join("Cargo.toml"), "[package]\nname = \"demo\"\nversion = \"0.1.0\"\n")
+ .unwrap();
+ fs::write(root.join(crate_dir).join("src/lib.rs"), "pub fn f() {}\n").unwrap();
+ fs::write(root.join("app.py"), "def f():\n pass\n").unwrap();
+ let port = Port {
+ id: "demo".into(),
+ file: "app.py".into(),
+ module: "app".into(),
+ func: "f".into(),
+ ext: "fa_demo".into(),
+ crate_dir: crate_dir.into(),
+ recorded: 1,
+ calls_seen: 1,
+ verify: None,
+ enabled: false,
+ lang: Lang::Python,
+ owner: None,
+ line: 1,
+ sources: vec![],
+ };
+ (root, port)
+ }
+
+ #[test]
+ fn enable_requires_the_crate_that_passed_verify() {
+ let (root, mut port) = project("enable-hash");
+ let hash = backend::source_hash(&root.join(&port.crate_dir)).unwrap();
+ fs::write(root.join(&port.crate_dir).join("src/lib.rs"), "pub fn f() { panic!() }\n").unwrap();
+ port.verify = Some(Verify { built: true, total: 1, passed: 1, source_hash: Some(hash), ..Verify::default() });
+ let mut ctx = Ctx::open(&root).unwrap();
+ ctx.state.ports.insert(port.id.clone(), port);
+ ctx.save().unwrap();
+
+ let err = enable(&root, Some("demo"), false).unwrap_err();
+ assert!(err.to_string().contains("Rust changed since it passed verify"), "{err}");
+ assert!(!Ctx::open(&root).unwrap().state.ports["demo"].enabled);
+ let _ = fs::remove_dir_all(root);
+ }
+
+ #[test]
+ fn live_build_guard_covers_missing_changed_and_legacy_verify() {
+ let (root, mut port) = project("build-hash");
+ let ctx = Ctx::open(&root).unwrap();
+ assert!(crate_needs_verify(&ctx, &port).unwrap());
+
+ port.verify = Some(Verify::default());
+ assert!(!crate_needs_verify(&ctx, &port).unwrap(), "legacy verify without a hash keeps working");
+
+ let hash = backend::source_hash(&root.join(&port.crate_dir)).unwrap();
+ port.verify = Some(Verify { source_hash: Some(hash), ..Verify::default() });
+ assert!(!crate_needs_verify(&ctx, &port).unwrap());
+ fs::write(root.join(&port.crate_dir).join("Cargo.toml"), "not a valid manifest\n").unwrap();
+ assert!(crate_needs_verify(&ctx, &port).unwrap());
+ let _ = fs::remove_dir_all(root);
+ }
++
+ #[test]
+ fn snapshot_restores_crate_inputs_without_touching_run_artifacts() {
+ let dir = std::env::temp_dir().join(format!("fa-agent-snapshot-{}", std::process::id()));
+ let _ = fs::remove_dir_all(&dir);
+ fs::create_dir_all(dir.join("src/nested")).unwrap();
+ fs::write(dir.join("Cargo.toml"), "best manifest\n").unwrap();
+ fs::write(dir.join("Cargo.lock"), "best lock\n").unwrap();
+ fs::write(dir.join("src/lib.rs"), "best lib\n").unwrap();
+ fs::write(dir.join("src/nested/helper.rs"), "best helper\n").unwrap();
+ for name in ["TASK.md", "recordings.jsonl", "agent.log"] {
+ fs::write(dir.join(name), "before\n").unwrap();
+ }
+ let saved = snapshot(&dir).unwrap();
+
+ fs::write(dir.join("Cargo.toml"), "later manifest\n").unwrap();
+ fs::write(dir.join("Cargo.lock"), "later lock\n").unwrap();
+ fs::write(dir.join("src/lib.rs"), "later lib\n").unwrap();
+ fs::write(dir.join("src/extra.rs"), "later extra\n").unwrap();
+ fs::write(dir.join("build.rs"), "later build script\n").unwrap();
+ fs::remove_file(dir.join("src/nested/helper.rs")).unwrap();
+ for name in ["TASK.md", "recordings.jsonl", "agent.log"] {
+ fs::write(dir.join(name), "later evidence\n").unwrap();
+ }
+
+ restore_snapshot(&dir, &saved).unwrap();
+ assert_eq!(fs::read_to_string(dir.join("Cargo.toml")).unwrap(), "best manifest\n");
+ assert_eq!(fs::read_to_string(dir.join("Cargo.lock")).unwrap(), "best lock\n");
+ assert_eq!(fs::read_to_string(dir.join("src/lib.rs")).unwrap(), "best lib\n");
+ assert_eq!(fs::read_to_string(dir.join("src/nested/helper.rs")).unwrap(), "best helper\n");
+ assert!(!dir.join("src/extra.rs").exists());
+ assert!(!dir.join("build.rs").exists());
+ for name in ["TASK.md", "recordings.jsonl", "agent.log"] {
+ assert_eq!(fs::read_to_string(dir.join(name)).unwrap(), "later evidence\n");
+ }
+ let _ = fs::remove_dir_all(dir);
+ }
}