refactor(mesh)!: a manifest carries step names, not scoped tokens

Every exported token is request-scope now, so the lifetime field had one
value and told a reader nothing. No protocol bump: mesh is alpha, both
peers ship from this repo, and the number should mean incompatibility
between deployed versions.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-12 15:40:24 -05:00
1 parent f6c05a0929
commit 55890442fe
13 files changed
+104 -108

No files matched your search

+15 -4
View File
@@ -11,7 +11,7 @@ describe('protocol codec', () => {
{
type: 'manifest',
v: V,
scopes: [{ token: 'auth', scope: 'request' }],
steps: ['auth'],
routes: [{ method: 'GET', pattern: '/u/:id' }],
},
{ type: 'rpc-req', id: '1', kind: 'scope', name: 'auth', ctx: env },
@@ -21,6 +21,17 @@ describe('protocol codec', () => {
for (const f of frames) expect(decode(encode(f))).toEqual(f);
});
it('encodes a manifest of step names', () => {
const frame = decode(encode({ type: 'manifest', v: V, steps: ['auth'], routes: [] }));
expect(frame).toEqual({ type: 'manifest', v: V, steps: ['auth'], routes: [] });
});
it('rejects a manifest whose steps are not an array', () => {
expect(() => decode(JSON.stringify({ type: 'manifest', v: V, steps: 'auth', routes: [] }))).toThrow(
/steps and routes must be arrays/,
);
});
it('throws on malformed json', () => {
expect(() => decode('{not json')).toThrow();
});
@@ -46,7 +57,7 @@ describe('protocol codec', () => {
describe('protocol versioning', () => {
it('carries the protocol version on the handshake frames', () => {
const hello = decode(encode({ type: 'hello', v: V, secret: 's' }));
const manifest = decode(encode({ type: 'manifest', v: V, scopes: [], routes: [] }));
const manifest = decode(encode({ type: 'manifest', v: V, steps: [], routes: [] }));
expect(hello).toMatchObject({ v: V });
expect(manifest).toMatchObject({ v: V });
@@ -54,7 +65,7 @@ describe('protocol versioning', () => {
it('rejects a handshake frame with no version — an unversioned peer is not decodable', () => {
expect(() => decode(JSON.stringify({ type: 'hello', secret: 's' }))).toThrow(/malformed hello/i);
expect(() => decode(JSON.stringify({ type: 'manifest', scopes: [], routes: [] }))).toThrow(/malformed manifest/i);
expect(() => decode(JSON.stringify({ type: 'manifest', steps: [], routes: [] }))).toThrow(/malformed manifest/i);
});
});
@@ -64,7 +75,7 @@ describe('protocol field validation', () => {
it.each([
['hello without secret', { type: 'hello', v: V }],
['hello with non-string secret', { type: 'hello', v: V, secret: 42 }],
['manifest with non-array scopes', { type: 'manifest', v: V, scopes: 'nope', routes: [] }],
['manifest with non-array steps', { type: 'manifest', v: V, steps: 'nope', routes: [] }],
['rpc-req without id', { type: 'rpc-req', kind: 'scope', name: 'auth', ctx: env }],
['rpc-req without ctx', { type: 'rpc-req', id: '1', kind: 'scope', name: 'auth' }],
['rpc-req with unknown kind', { type: 'rpc-req', id: '1', kind: 'bogus', name: 'auth', ctx: env }],