docs(mesh): warn on shadowed remote routes, and tell the truth about mesh

Local routes are merged ahead of remote ones, so a local twin wins. That
precedence is worth keeping — your own code beating an imported one is how you
override a teapot — but it was an accident of [...local, ...remote] ordering with
nothing said, so a shadowed export looked like a broken teapot from the outside.
Warn, name the teapot, and leave the call to the developer.

The docs had gone stale in the way that started all of this. runtimes.md claimed
four times that mesh is Node-only; the mesh guide said finalization is deferred to
listen(); the changelog said "WebSocket and mesh remain Node-only". All false now.

The mesh guide gains what was enforced but never written down — which is how the
listen() trap got made in the first place, when the previous plan's "document it"
never landed:
- runs on Node/Deno/Bun, teapot and teacup, any combination; not on edge, and why
- no listen() required: the graph boots on first use
- buffered routes only, and why streams cannot cross an RPC hop
- one teapot per route, local-over-remote precedence, and the protocol version

Refs .specs/2026-07-15-green-tea-mesh-cross-runtime-plan.md Task 9

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-15 16:20:55 -05:00
1 parent 033af2d1fc
commit 34dbb32b2c
5 files changed
+159 -11

No files matched your search

+65 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect, vi } from 'vitest';
import { createApp, Provider, Step, Route, Get, Module, needs } from '../../src/index';
const SECRET = 's3cr3t';
@@ -45,6 +45,17 @@ class PlainCtl {
@Module({ mountpoint: '/', controllers: [PlainCtl] })
class PlainTeacupModule {}
// A teacup declaring a route locally at the same path a teapot exports it.
@Route('/dup')
class ShadowCtl {
@Get('/ping')
ping() {
return { from: 'local' };
}
}
@Module({ mountpoint: '/api', controllers: [ShadowCtl] })
class ShadowTeacupModule {}
describe('mesh skeleton integration', () => {
it('teacup resolves remote app-scope + request-scope into a local handler', async () => {
const teapot = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
@@ -119,6 +130,59 @@ describe('mesh skeleton integration', () => {
aServer.close();
});
it('gives a local route precedence over a remote one, and says so', async () => {
// Local-wins is the design: your own code beats an imported one, and it is how you
// override a teapot. But it used to be an accident of [...local, ...remote] ordering
// with nothing said, so a shadowed export looked like a broken teapot.
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const teapot = createApp({ modules: [DupTeapotModule], experimental: true, mesh: { secret: SECRET } });
const tServer = await teapot.listen(0);
const url = `ws://127.0.0.1:${(tServer.address() as any).port}/__mesh__/control`;
const teacup = createApp({
modules: [ShadowTeacupModule],
experimental: true,
mesh: { teapots: [{ url, secret: SECRET }] },
});
try {
const res = await teacup.fetch(new Request('http://x/api/dup/ping'));
expect(await res.json()).toEqual({ from: 'local' }); // local wins, not the teapot's {pong:true}
const warned = warn.mock.calls.map((c) => String(c[0])).join('\n');
expect(warned).toMatch(/GET \/api\/dup\/ping/);
expect(warned).toMatch(/local/i);
expect(warned).toContain(url); // which teapot got shadowed
} finally {
warn.mockRestore();
await teacup.close();
tServer.close();
}
});
it('does not warn when a remote route has no local twin', async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const teapot = createApp({ modules: [DupTeapotModule], experimental: true, mesh: { secret: SECRET } });
const tServer = await teapot.listen(0);
const url = `ws://127.0.0.1:${(tServer.address() as any).port}/__mesh__/control`;
const teacup = createApp({
modules: [PlainTeacupModule],
experimental: true,
mesh: { teapots: [{ url, secret: SECRET }] },
});
try {
await teacup.fetch(new Request('http://x/c/ok'));
const shadowWarnings = warn.mock.calls.filter((c) => String(c[0]).includes('precedence'));
expect(shadowWarnings).toEqual([]);
} finally {
warn.mockRestore();
await teacup.close();
tServer.close();
}
});
it('rejects a bad secret (teacup boot fails)', async () => {
const teapot = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
const tServer = await teapot.listen(0); const tPort = (tServer.address() as any).port;