`matcha new --runtime edge` scaffolds a Worker: `nodejs_compat`, `edgeHandler` as the default export, and wrangler's `[assets]` serving `./public` so `/` is the same page as on the other three runtimes and `/zen` the same stream from the worker. `matcha run` is `wrangler dev`, which is real workerd, so edge stops being a deploy-only target. Runtime detection puts `wrangler.toml` ahead of `package.json`, since an edge project has both, and the graph resolves under node — `src/app.ts` imports core, never `edgeHandler`. Getting there turned up a core defect, filed as Green-Tea/core#93: the npm ESM build cannot load on workerd at all. tsup's `createRequire(import.meta.url)` banner runs at module scope and `import.meta.url` is undefined there, so `@green-tea/core/edge` throws before any of its own code runs — while `src/node-require.ts` is written precisely to make that lazy and survivable. core's own edge test cannot see it: it bundles `src/`, so `dist/` is the one artifact users install and the one nothing exercises. The scaffold installs from JSR, which publishes source with no banner and boots clean; the `.npmrc` says why and links the issue, and both it and the alias can go once it is fixed. `matcha doctor` reports the misconfigurations that fail confusingly rather than loudly: `experimentalDecorators` missing, which turns every `@Route` into a syntax error blaming the decorator; a core pin that cannot resolve or that does not match what is installed; an entry that does not export `app`; and `@Ws` or multipart routes whose lazy-loaded peer dependency is absent, which compile and then fail at the first request. Every check is a file read — no runtime spawned, nothing fetched — so it works before the project installs. It reads the installed version from the package's own manifest rather than core's exported `VERSION`, which is stale in the published artifact (Green-Tea/core#92) and would give the wrong answer to the one check that exists to catch a wrong version. The starter smoke and the CI matrix gained edge as a fourth runtime. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012x1UPw987zNSxjH2DxHy2C
105 lines
4.5 KiB
Bash
Executable File
105 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Scaffolds a starter with the matcha binary, installs it, type-checks it, boots
|
|
# it, and asks it for its graph.
|
|
#
|
|
# This is the check the repository did not have. `cargo test` proves the CLI
|
|
# writes the files it means to write; it cannot prove those files describe a
|
|
# project the current `@green-tea/core` will run — which is exactly how the
|
|
# templates sat two core releases behind for two months without a red build.
|
|
#
|
|
# Usage: scripts/starter-smoke.sh <node|deno|bun>
|
|
set -euo pipefail
|
|
|
|
RUNTIME="${1:?usage: starter-smoke.sh <node|deno|bun|edge>}"
|
|
MATCHA="${MATCHA:-$PWD/target/debug/matcha}"
|
|
[ -x "$MATCHA" ] || { echo "no matcha binary at $MATCHA (cargo build first)" >&2; exit 2; }
|
|
|
|
case "$RUNTIME" in
|
|
node) TEMPLATE_PORT=3000; INSTALL=(npm install); CHECK=(npx --yes tsc --noEmit) ;;
|
|
deno) TEMPLATE_PORT=8000; INSTALL=(deno install); CHECK=(deno check src/main.ts) ;;
|
|
bun) TEMPLATE_PORT=8000; INSTALL=(bun install); CHECK=(bunx --bun tsc --noEmit) ;;
|
|
edge) TEMPLATE_PORT=8787; INSTALL=(npm install); CHECK=(npx --yes tsc --noEmit) ;;
|
|
*) echo "unknown runtime: $RUNTIME" >&2; exit 2 ;;
|
|
esac
|
|
|
|
# The starter hardcodes its port, so the script rewrites it to a free one rather
|
|
# than colliding with whatever the person running this already has on 3000. A
|
|
# check that only survives on a clean CI runner is a check nobody runs locally.
|
|
PORT="${PORT:-$((20000 + RANDOM % 20000))}"
|
|
|
|
WORK="$(mktemp -d)"
|
|
SERVER=""
|
|
cleanup() {
|
|
[ -n "$SERVER" ] && { pkill -P "$SERVER" 2>/dev/null || true; kill "$SERVER" 2>/dev/null || true; }
|
|
rm -rf "$WORK"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
cd "$WORK"
|
|
echo "▸ matcha new demo --runtime $RUNTIME"
|
|
"$MATCHA" new demo --runtime "$RUNTIME"
|
|
cd demo
|
|
if [ "$RUNTIME" = edge ]; then
|
|
# The edge starter's port is wrangler's, not the app's — src/main.ts only
|
|
# exports a fetch handler.
|
|
printf '\n[dev]\nport = %s\n' "$PORT" >> wrangler.toml
|
|
else
|
|
sed -i.bak "s/$TEMPLATE_PORT/$PORT/g" src/main.ts && rm -f src/main.ts.bak
|
|
fi
|
|
|
|
echo "▸ ${INSTALL[*]}"
|
|
"${INSTALL[@]}"
|
|
|
|
echo "▸ ${CHECK[*]}"
|
|
"${CHECK[@]}"
|
|
|
|
echo "▸ matcha run (boot on :$PORT)"
|
|
"$MATCHA" run >"$WORK/server.log" 2>&1 &
|
|
SERVER=$!
|
|
for _ in $(seq 1 60); do
|
|
curl -fsS -o /dev/null "http://localhost:$PORT/" 2>/dev/null && break
|
|
sleep 1
|
|
done
|
|
|
|
# The starter's two halves: the @Html page, and the @Sse stream that is the
|
|
# reason the starter is alive rather than a JSON hello.
|
|
# On edge, `/` is answered by wrangler's [assets] rather than by the worker —
|
|
# the page is the same one, from the same public/index.html.
|
|
code=$(curl -fsS -o /dev/null -w '%{http_code}' "http://localhost:$PORT/" 2>/dev/null || echo 000)
|
|
[ "$code" = 200 ] || { echo "GET / returned $code"; echo '--- server log ---'; cat "$WORK/server.log"; exit 1; }
|
|
# Read one frame and stop. `head -1` closing the pipe kills curl with SIGPIPE,
|
|
# which under `pipefail` fails the pipeline for a stream that arrived exactly as
|
|
# intended — hence the capture-then-compare instead of a piped `grep -q`.
|
|
zen="$(curl -fsS -N --max-time 5 "http://localhost:$PORT/zen" 2>/dev/null | head -1 || true)"
|
|
case "$zen" in
|
|
'data: {"zen":'*) ;;
|
|
*) echo "GET /zen did not stream an SSE frame (got: ${zen:-<nothing>})"; cat "$WORK/server.log"; exit 1 ;;
|
|
esac
|
|
echo "✓ serves / and streams /zen"
|
|
|
|
pkill -P "$SERVER" 2>/dev/null || true; kill "$SERVER" 2>/dev/null || true; SERVER=""
|
|
|
|
# Introspection runs against the same project, so it also proves the entry file
|
|
# the templates scaffold still exports the `app` that graph/explain import.
|
|
echo "▸ matcha graph"
|
|
"$MATCHA" graph | grep -q '^flowchart LR' || { echo "graph produced no mermaid"; exit 1; }
|
|
"$MATCHA" graph --format dot | grep -q '^digraph green_tea' || { echo "graph produced no DOT"; exit 1; }
|
|
"$MATCHA" explain /zen | grep -q '\[sse\]' || { echo "explain did not report the sse route"; exit 1; }
|
|
echo "✓ graph and explain resolve"
|
|
|
|
# Every `matcha add` capability, spliced into one controller and type-checked
|
|
# together. The stubs name core's real surface — `sse()` with an id, `@Ws` with
|
|
# `@inbound()`, `MultipartBody`, `@Transformer` — so this is the thing that
|
|
# notices when that surface moves. No peer dependency is installed on purpose:
|
|
# core lazy-requires `ws` and `busboy`, so neither is needed to compile, and a
|
|
# check that needed them would be hiding that fact.
|
|
echo "▸ matcha add (every capability)"
|
|
for cap in sse ws upload stream buffer; do
|
|
"$MATCHA" add "$cap" >/dev/null || { echo "matcha add $cap failed"; exit 1; }
|
|
done
|
|
"${CHECK[@]}" || { echo "the generated handlers do not type-check"; exit 1; }
|
|
echo "✓ every add capability type-checks"
|
|
|
|
echo "✓ $RUNTIME starter is good"
|