From aaef6cf5b74adb023463c7f5083a6c8e13fcc8f2 Mon Sep 17 00:00:00 2001 From: Ngoc Trung Date: Wed, 23 Sep 2026 10:30:02 +0700 Subject: [PATCH] fix(app): validate module mountpoints at runtime Signed-off-by: Ngoc Trung --- src/app/index.ts | 1 + test/app.test.ts | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/index.ts b/src/app/index.ts index 1a0107b..f6bdf41 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -560,6 +560,7 @@ function collectModules(modules: Ctor[], viewsCtx: ViewsContext): Registry { for (const mod of modules) { const moduleMeta = getModuleMeta(mod); if (!moduleMeta) throw new Error(`${mod.name} is not a @Module`); + if (!moduleMeta.mountpoint) throw new Error(`${mod.name} @Module metadata is missing mountpoint`); const origin = `module:${mod.name}`; collectProviders(moduleMeta.providers ?? [], origin, registry); collectSteps(moduleMeta.steps ?? [], origin, registry); diff --git a/test/app.test.ts b/test/app.test.ts index e01cbac..8249744 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -1,6 +1,6 @@ import 'reflect-metadata'; import { describe, expect, it, test, vi } from 'vitest'; -import { Provider, Step, Route, Get, Post, Module, Transformer } from '../src/metadata'; +import { Provider, Step, Route, Get, Post, Module, Transformer, getModuleMeta } from '../src/metadata'; import { JsonTransformer } from '../src/transformers'; import { Unauthorized } from '../src/signals'; import { createApp } from '../src/app'; @@ -40,6 +40,24 @@ test('inspect lists the ordered chain with origins', () => { expect(lines.map((l) => `${l.kind}:${l.name}`)).toEqual(['provider:db', 'step:user', 'handler:getUser']); }); +test('runtime module metadata without mountpoint names module and missing field', () => { + @Route('/broken') + class BrokenCtl { + @Get('/') + get() { + return { ok: true }; + } + } + + @Module({ mountpoint: '/broken', controllers: [BrokenCtl] }) + class BrokenModule {} + const metadata = getModuleMeta(BrokenModule); + if (!metadata) throw new Error('test setup failed'); + Object.defineProperty(metadata, 'mountpoint', { value: undefined }); + + expect(() => createApp({ modules: [BrokenModule] })).toThrow(/BrokenModule.*mountpoint/); +}); + test('ready() is a no-op on a non-mesh app, so one protocol works for both', async () => { // The point: code holding an `App` should not have to know whether it is a mesh app. // `await app.ready(); app.graph()` is uniform — here it changes nothing and boots nothing.