Files
TREK/server/tests/unit/nest/managed-ext.test.ts
T
Maurice 286b0b09ec feat(managed): the managed attachment point declares the routes it serves without a session, and the boot gate allows exactly those
Empty in this repository, as the module itself. An install that replaces the
module adds its anonymous routes in the same file, and the gate still fails on a
route missing there or an entry that went stale.
2026-11-08 23:33:52 +00:00

43 lines
2.0 KiB
TypeScript

/**
* The extension point is empty here, and adds nothing to the app.
*
* The value of this test is not that an empty module is empty. It is that the
* emptiness is checked at all: this is the seam where an install can attach its
* own screens, and the promise made to everyone else is that the public build
* carries none of them. A stray controller or provider slipping in would be
* invisible in review and obvious only to whoever it shipped to.
*/
import { MANAGED_PUBLIC_ROUTES, ManagedExtModule } from '../../../src/nest/managed/managed-ext.module';
import { MODULE_METADATA } from '@nestjs/common/constants';
import { Test } from '@nestjs/testing';
import { describe, it, expect } from 'vitest';
const meta = (key: string): unknown[] => (Reflect.getMetadata(key, ManagedExtModule) as unknown[]) ?? [];
describe('ManagedExtModule', () => {
it('MANAGED-EXT-001: contributes no controllers, providers, imports or exports', () => {
expect({
controllers: meta(MODULE_METADATA.CONTROLLERS),
providers: meta(MODULE_METADATA.PROVIDERS),
imports: meta(MODULE_METADATA.IMPORTS),
exports: meta(MODULE_METADATA.EXPORTS),
}).toEqual({ controllers: [], providers: [], imports: [], exports: [] });
});
it('MANAGED-EXT-003: declares no route that answers without a session', () => {
// The boot gate adds these to its allow-list; the public build adds nothing.
expect(MANAGED_PUBLIC_ROUTES).toEqual([]);
});
it('MANAGED-EXT-002: compiles as a module, so app.module can import it unconditionally', async () => {
// Unconditionally on purpose: a conditional import would tie the module graph
// to an env var, and the graph is built once per app while TREK_MANAGED is
// read live. An empty module costs nothing, so the flag never reaches here.
const built = await Test.createTestingModule({ imports: [ManagedExtModule] }).compile();
expect(built.get(ManagedExtModule, { strict: false })).toBeInstanceOf(ManagedExtModule);
await built.close();
});
});