Files
matcha/tests/graph.rs
T
chrnx 5c8f72b409 feat(openapi): the OpenAPI document, and the paperwork the crate shipped without
`Cargo.toml` has declared `license = "MIT"` since the first release and the
published crate carried no license text, so anyone vendoring the source had the
claim without the grant. `LICENSE` is that text. `DCO` is the certificate the
README has been requiring a sign-off against without shipping, and
`CONTRIBUTING.md` says how — including that GitHub is a mirror of `main` and
tags, so a pull request there is carried upstream by a maintainer rather than
merged, which would put the two forges out of sync.

`CHANGELOG.md` reconstructs 26.7.0 and 26.8.0-beta.0 from their tags. The CLI
ships on its own version line, so the header says what that does and does not
mean about the core version a scaffold is pinned to, and each entry says when
that pin moved.

`matcha openapi` prints core's structural OpenAPI 3.1 for the route table —
`--title`, `--api-version`, `--out`. It reuses the entry resolution and the
generated-script runner that `graph` and `explain` already had, so it is the
same `app.ready()` that resolves the graph without booting providers. Structural
is the honest word: paths, methods and parameters come from the decorators, and
nothing invents a response schema.

The loose end from the capability table is closed. `cli.rs` still carried its own
copies of the `create` kinds and the `add` capabilities, so adding either meant
editing two files that could disagree — a value the parser accepts and the
dispatcher rejects. Both now read the list from the module that owns it, and the
three `create` piece kinds became rows in a table rather than near-identical
match arms, which also retires a `too_many_arguments` allow.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-05 16:01:49 -05:00

76 lines
2.3 KiB
Rust

use assert_cmd::Command;
use predicates::str::contains;
use tempfile::tempdir;
/// Both introspection commands need a file that exports the app. Without one
/// there is nothing to import, and the failure has to name the fix — a stack
/// trace from a runtime that could not resolve a module does not.
#[test]
fn graph_without_an_entry_says_what_is_missing() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("graph")
.assert()
.failure()
.stderr(contains("--entry"))
.stderr(contains("export const app = createApp"));
}
#[test]
fn explain_rejects_an_entry_that_does_not_exist() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["explain", "/users", "--entry", "src/nope.ts"])
.assert()
.failure()
.stderr(contains("no such entry"));
}
/// Runtime detection comes after the entry is found, so a project with an entry
/// and no manifest is a distinct failure with its own message.
#[test]
fn graph_without_a_runtime_says_so() {
let d = tempdir().unwrap();
std::fs::create_dir_all(d.path().join("src")).unwrap();
std::fs::write(d.path().join("src/app.ts"), "export const app = {};\n").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("graph")
.assert()
.failure()
.stderr(contains("no runtime detected"));
}
#[test]
fn graph_rejects_an_unknown_format() {
let d = tempdir().unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["graph", "--format", "svg"])
.assert()
.failure();
}
/// openapi shares graph's entry resolution, so it shares its failure modes —
/// including the one that has to name the fix.
#[test]
fn openapi_without_an_entry_says_what_is_missing() {
let d = tempdir().unwrap();
std::fs::write(d.path().join("package.json"), "{}").unwrap();
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.arg("openapi")
.assert()
.failure()
.stderr(contains("--entry"));
}