fix(add): merge imports into existing brace + capability idempotency; fmt

- wire::add_import now merges a new symbol into an already-present
  `import { ... } from '<from>';` brace instead of appending a second,
  colliding import line for the same module (a duplicate ESM binding
  is a hard SyntaxError/TS2300, not a harmless dupe as previously
  assumed). Falls back to appending a new line when the module isn't
  imported yet, or if the brace-merge edit fails the parses_clean
  guard.
- cmd_add::run gains a capability-level idempotency guard, keyed on
  each capability's unique route-path literal, so `matcha add <cap>`
  run twice no longer appends a duplicate handler + route.
- cargo fmt --all across the crate; drop the stale #[allow(dead_code)]
  on wire::parses_clean now that it's demonstrably live.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-11 13:52:21 -05:00
1 parent bc013fde9f
commit 757b729986
10 files changed
+329 -79

No files matched your search

+38 -10
View File
@@ -5,9 +5,12 @@ use tempfile::tempdir;
#[test]
fn new_scaffolds_into_named_dir() {
let d = tempdir().unwrap();
Command::cargo_bin("matcha").unwrap()
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "my-api"]).assert().success();
.args(["new", "my-api"])
.assert()
.success();
let root = d.path().join("my-api");
assert!(root.join("src/app.module.ts").exists());
assert!(root.join("public/index.html").exists());
@@ -17,9 +20,12 @@ fn new_scaffolds_into_named_dir() {
fn new_refuses_existing_dir() {
let d = tempdir().unwrap();
std::fs::create_dir(d.path().join("taken")).unwrap();
Command::cargo_bin("matcha").unwrap()
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "taken"]).assert().failure();
.args(["new", "taken"])
.assert()
.failure();
}
#[test]
@@ -29,15 +35,37 @@ fn new_clones_local_template() {
let src = d.path().join("src-tmpl");
std::fs::create_dir_all(src.join("public")).unwrap();
std::fs::write(src.join("public/marker.txt"), "hi").unwrap();
Proc::new("git").args(["init", "-q"]).current_dir(&src).status().unwrap();
Proc::new("git").args(["add", "."]).current_dir(&src).status().unwrap();
Proc::new("git").args(["-c","user.email=t@t","-c","user.name=t",
"commit","-qm","init"]).current_dir(&src).status().unwrap();
Proc::new("git")
.args(["init", "-q"])
.current_dir(&src)
.status()
.unwrap();
Proc::new("git")
.args(["add", "."])
.current_dir(&src)
.status()
.unwrap();
Proc::new("git")
.args([
"-c",
"user.email=t@t",
"-c",
"user.name=t",
"commit",
"-qm",
"init",
])
.current_dir(&src)
.status()
.unwrap();
let url = format!("file://{}", src.display());
Command::cargo_bin("matcha").unwrap()
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["new", "cloned", "--template-url", &url]).assert().success();
.args(["new", "cloned", "--template-url", &url])
.assert()
.success();
assert!(d.path().join("cloned/public/marker.txt").exists());
assert!(!d.path().join("cloned/.git").exists()); // .git stripped
}