|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * Sharing route-ledger conformance — the package-local guard every |
| 5 | + * `*-route-ledger.ts` pairs with. `registerShareableObjectsRoutes` is a |
| 6 | + * standalone, synchronous function that calls `http.get` and touches neither |
| 7 | + * argument before a request arrives, so a capturing mock `IHttpServer` |
| 8 | + * enumerates its real surface (the seam the messaging, print, storage and |
| 9 | + * settings ledgers use), and the two directions fail here by name on every |
| 10 | + * `pnpm test` of this package. |
| 11 | + */ |
| 12 | + |
| 13 | +import { describe, it, expect, vi } from 'vitest'; |
| 14 | +import { registerShareableObjectsRoutes } from './shareable-objects-routes.js'; |
| 15 | +import { SHARING_ROUTE_LEDGER } from './sharing-route-ledger.js'; |
| 16 | + |
| 17 | +function createMockServer() { |
| 18 | + return { |
| 19 | + get: vi.fn(), |
| 20 | + post: vi.fn(), |
| 21 | + put: vi.fn(), |
| 22 | + delete: vi.fn(), |
| 23 | + patch: vi.fn(), |
| 24 | + use: vi.fn(), |
| 25 | + listen: vi.fn().mockResolvedValue(undefined), |
| 26 | + close: vi.fn().mockResolvedValue(undefined), |
| 27 | + }; |
| 28 | +} |
| 29 | + |
| 30 | +function enumerateRoutes(): Set<string> { |
| 31 | + const server = createMockServer(); |
| 32 | + registerShareableObjectsRoutes(server as any, {} as any); |
| 33 | + const keys = new Set<string>(); |
| 34 | + for (const verb of ['get', 'post', 'put', 'patch', 'delete'] as const) { |
| 35 | + for (const call of server[verb].mock.calls) keys.add(`${verb.toUpperCase()} ${call[0]}`); |
| 36 | + } |
| 37 | + return keys; |
| 38 | +} |
| 39 | + |
| 40 | +const ledgerKeys = (): Set<string> => new Set(SHARING_ROUTE_LEDGER.map((e) => e.route)); |
| 41 | + |
| 42 | +describe('sharing route ledger ↔ registerShareableObjectsRoutes enumeration', () => { |
| 43 | + it('every mounted route has a ledger entry', () => { |
| 44 | + const ledger = ledgerKeys(); |
| 45 | + const missing = [...enumerateRoutes()].filter((k) => !ledger.has(k)); |
| 46 | + expect(missing, `sharing routes with no ledger entry: ${missing.join(', ')}`).toEqual([]); |
| 47 | + }); |
| 48 | + |
| 49 | + it('every ledger entry is really mounted by the registrar', () => { |
| 50 | + const live = enumerateRoutes(); |
| 51 | + const stale = [...ledgerKeys()].filter((k) => !live.has(k)); |
| 52 | + expect(stale, `sharing ledger entries the registrar no longer mounts: ${stale.join(', ')}`).toEqual([]); |
| 53 | + }); |
| 54 | + |
| 55 | + it('the ledger is compared against a real enumeration, not an empty one', () => { |
| 56 | + const live = enumerateRoutes(); |
| 57 | + expect(live.size).toBeGreaterThan(0); |
| 58 | + expect(live.size).toBe(ledgerKeys().size); |
| 59 | + expect(SHARING_ROUTE_LEDGER.every((e) => e.disposition === 'sdk' || (e.note ?? '').length > 0)).toBe(true); |
| 60 | + }); |
| 61 | +}); |
0 commit comments