feat(graph): draw the graph, and stop scaffolding a two-month-old core
The CLI's last feature work was 12 July; core has shipped 26.8 and 26.9 since. Two consequences, fixed together because they share an entry-file convention. Every runtime overlay pinned `^26.7.0-beta.0`. Core is prerelease-only, and npm's semver excludes a prerelease from any range whose comparators carry a different major.minor.patch — so that caret is not a loose pin, it is a pin to the oldest matching prerelease that nothing can move off. Every project `matcha new` has produced since July installed 26.7.0-beta.0 and could not upgrade: no logger, no request budget, no resumable `@Sse` id, and none of the crashes 26.9 fixed. The pin is now exact, lives in one `CORE_VERSION` const, and Deno resolves through JSR — which is core's native path for Deno and the one 26.9 repaired. Nothing caught that because CI never ran JavaScript. `cargo test` proves the CLI writes the files it means to write; it cannot prove those files describe a project the current core will run. `scripts/starter-smoke.sh` scaffolds, installs, type-checks, boots, curls `/` and the `/zen` stream, and introspects a real starter per runtime; a weekly job fails when the pin falls behind the `beta` dist-tag. The smoke immediately found a second defect: the bun overlay carried no Bun types, so `tsc --noEmit` — and therefore `matcha create --check` — failed on every bun project the CLI has ever scaffolded. `matcha graph` and `matcha explain <pattern>` close the widest gap in the surface: the framework's claim is that an API is a graph rather than a middleware chain, `toMermaid`/`toDOT`/`graph`/`explain` have been exported all along, and the CLI could not draw any of it. Both reach the app through `app.ready()`, which resolves the graph and is documented as deliberately not running provider factories — asking for a diagram must not open your database connections. Formatting lives in the generated script rather than in Rust, which keeps serde out for output `console.log` already has the values for. That needed an app the CLI can import without binding a port, so the starter now composes the graph in `src/app.ts` and leaves `src/main.ts` holding only the serve call. `create module` follows, preferring `src/app.ts` and falling back to `src/main.ts` so projects scaffolded before the split keep working. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012x1UPw987zNSxjH2DxHy2C
This commit is contained in:
21 files changed
+747
-27
No files matched your search
+3
-1
@@ -11,7 +11,9 @@ fn help_lists_all_subcommands() {
|
||||
.stdout(contains("new"))
|
||||
.stdout(contains("run"))
|
||||
.stdout(contains("create"))
|
||||
.stdout(contains("add"));
|
||||
.stdout(contains("add"))
|
||||
.stdout(contains("graph"))
|
||||
.stdout(contains("explain"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -84,3 +84,38 @@ fn create_module_writes_and_registers_in_createapp() {
|
||||
assert!(main.contains("AppModule, UsersModule"));
|
||||
assert!(main.contains("import { UsersModule }"));
|
||||
}
|
||||
|
||||
/// A project scaffolded today composes its graph in `src/app.ts`, so that is
|
||||
/// where a new module has to be registered. `src/main.ts` only serves, and
|
||||
/// wiring a module into it would put the module in a file that never calls
|
||||
/// `createApp` — silently, since `add_to_createapp_modules` would simply find
|
||||
/// nothing to edit and the CLI would print its "add it manually" hint.
|
||||
#[test]
|
||||
fn create_module_prefers_app_ts_over_main_ts() {
|
||||
let d = tempdir().unwrap();
|
||||
std::fs::create_dir_all(d.path().join("src")).unwrap();
|
||||
std::fs::write(
|
||||
d.path().join("src/app.ts"),
|
||||
"import { createApp } from '@green-tea/core';\nimport { AppModule } from './app.module';\n\nexport const app = createApp({ modules: [AppModule] });\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
d.path().join("src/main.ts"),
|
||||
"import { app } from './app';\n\napp.listen(3000);\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Command::cargo_bin("matcha")
|
||||
.unwrap()
|
||||
.current_dir(d.path())
|
||||
.args(["create", "module", "Users"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let app_ts = std::fs::read_to_string(d.path().join("src/app.ts")).unwrap();
|
||||
assert!(app_ts.contains("AppModule, UsersModule"));
|
||||
assert!(app_ts.contains("import { UsersModule }"));
|
||||
|
||||
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||
assert!(!main.contains("UsersModule"), "main.ts was edited: {main}");
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
}
|
||||
Reference in new issue
Block a user