feat(mesh): boot the mesh graph from the app boot gate, not listen()
Only listen() spliced remote scopes and finalized the graph, and listen() builds a Node http.Server. Deno/Bun/edge serve through app.fetch and can never call it, so mesh was Node-only by construction: fetch() threw "unavailable before listen()" forever on those runtimes, telling operators to call something they had no way to call. buildAppFetch also hardcoded remoteRoutes to [], so even past the guard it would not have served a remote route. Move splice+finalize into the memoized boot gate that fetch, upgrade and listen already share, ahead of the providers — remote nodes must join before the topo sort. Await it before building the route table rather than after, since for a mesh app the table is not knowable until the splice has run. listen() keeps working by awaiting the same gate; the memoization means a fetch followed by a listen boots once, and concurrent first requests splice once. The fetch/upgrade guards are gone rather than reworded: they are now unreachable. inspect()/graph()/explain() keep theirs — they are synchronous and cannot await network I/O — but their message no longer claims listen() is the only way in. test/fetch.test.ts asserted the old contract (fetch throws until listen), i.e. the trap itself; it now pins that a mesh app serves without listen() and that listen() afterwards does not re-run provider factories. Refs .specs/2026-07-15-green-tea-mesh-cross-runtime-plan.md Task 5 Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+201
-49
No files matched your search
+12
-3
@@ -4,7 +4,10 @@ import type { InspectLine, Explain, ExplainNode, RoutePlan } from './types';
|
||||
|
||||
/** Lists the provider/step/handler chain for a route, in execution order. */
|
||||
export function inspectRoute(routePlans: RoutePlan[], routePath: string, booted: boolean): InspectLine[] {
|
||||
if (!booted) throw new Error('inspect() unavailable before listen() for mesh apps');
|
||||
if (!booted)
|
||||
throw new Error(
|
||||
'inspect() unavailable until a mesh app has booted — call listen(), or serve one request through app.fetch/app.upgrade, which splices the remote scopes in',
|
||||
);
|
||||
const plan = routePlans.find((candidate) => candidate.pattern === routePath);
|
||||
if (!plan) throw new Error(`no route: ${routePath}`);
|
||||
return [
|
||||
@@ -25,7 +28,10 @@ export function buildGraphView(
|
||||
routePlans: RoutePlan[],
|
||||
booted: boolean,
|
||||
): GraphView {
|
||||
if (!booted) throw new Error('graph() unavailable before listen() for mesh apps');
|
||||
if (!booted)
|
||||
throw new Error(
|
||||
'graph() unavailable until a mesh app has booted — call listen(), or serve one request through app.fetch/app.upgrade, which splices the remote scopes in',
|
||||
);
|
||||
return {
|
||||
nodes: [
|
||||
...providerNodes.map((node) => ({
|
||||
@@ -54,7 +60,10 @@ export function buildGraphView(
|
||||
|
||||
/** Explains a single route: its match criteria and the ordered chain with each node's needs/provides. */
|
||||
export function explainRoute(routePlans: RoutePlan[], routePath: string, booted: boolean): Explain {
|
||||
if (!booted) throw new Error('explain() unavailable before listen() for mesh apps');
|
||||
if (!booted)
|
||||
throw new Error(
|
||||
'explain() unavailable until a mesh app has booted — call listen(), or serve one request through app.fetch/app.upgrade, which splices the remote scopes in',
|
||||
);
|
||||
const plan = routePlans.find((candidate) => candidate.pattern === routePath);
|
||||
if (!plan) throw new Error(`no route: ${routePath}`);
|
||||
const toExplainNode = (node: GraphNode, kind: 'provider' | 'step'): ExplainNode => ({
|
||||
|
||||
Reference in new issue
Block a user