MCP: CI laeuft ueberhaupt erstmal, und der Server ueberlebt seinen Client nicht

Fuer mcp/ gab es keinen CI-Job — weder die 33 Tests noch sonst irgendwas lief je
auf GitHub. Jetzt laeuft beides bei jedem PR, der mcp/ oder frontend/ anfasst.

Dazu der Check, den die Testsuite prinzipiell nicht machen kann: vitest loest
ueber Vite auf, also gehen dort import.meta.glob, ?raw und .jsx anstandslos
durch. Genau so kam ein Vite-only-Import in ein gemeinsames Lib-Modul und liess
33 gruene Tests ueber einem Server stehen, der beim Start starb.
check-node-loadable.mjs laeuft deshalb unter nacktem node — dass es ausserhalb
von vitest laeuft, IST der Test. Gegengeprueft: Bug wieder eingebaut → Exit 1
und history.js/progression.js/tools.js namentlich gemeldet; sauber → Exit 0.

Und der fs.watch-Handle haelt die Event-Loop offen, sobald es eine State-Datei
zu beobachten gibt — der Prozess ueberlebt damit den Client, der ihn gestartet
hat, obwohl die mcp/README genau das Gegenteil verspricht. Ein unref() reicht;
nachgemessen: mit State-Datei vorher Exit 124 (haengt), jetzt Exit 0, und der
Watcher invalidiert den Cache unveraendert weiter.
This commit is contained in:
Duarte Santos committed 2026-08-04 16:40:03 +02:00
1 parent e28345dd13
commit e007f76d43
5 files changed
+89 -2

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env node
/* Does the server's import graph still load under plain node?
*
* This exists because the test suite cannot answer that question. `npm test` runs vitest, and
* vitest resolves modules through Vite — `import.meta.glob`, `?raw`, a stray `.jsx` import all
* work there. The server does not run under Vite. So a Vite-only import can land in a shared
* lib module, leave all 33 tests green, and still kill the server at startup. That is exactly
* what happened once: `history.js` began importing `t` from `i18n.js` (import.meta.glob over
* the locale packs, plus React), and the server died on `import` with the suite none the wiser.
*
* Run by bare `node` on purpose — being outside vitest IS the check. Do not port this to a
* vitest test file; that would make it pass unconditionally.
*
* Importing the two entry modules is enough on its own: everything the server touches hangs off
* them, so a lib module that grows a browser-only dependency next year fails here without this
* list being updated. The named list below only exists to point at the culprit instead of at a
* stack trace ten frames deep.
*/
const LIB = new URL('../../frontend/src/lib/', import.meta.url)
// Every frontend/src/lib module the server reaches today. Named individually so a failure says
// which one, rather than which import chain.
const MODULES = [
'i18n-core.js', 'format.js', 'exercises.js', 'exercises-data.js',
'history.js', 'muscles.js', 'onerm.js', 'progression.js'
]
let failed = 0
for (const m of MODULES) {
try {
await import(new URL(m, LIB))
console.log(` ok ${m}`)
} catch (e) {
failed++
console.error(` FAIL ${m} — ${e.message}`)
}
}
// The real assertion: the server's own entry points, which pull the whole graph transitively.
// A module added to the graph later is covered by this even if the list above never learns it.
for (const entry of ['../src/state.js', '../src/tools.js']) {
try {
await import(new URL(entry, import.meta.url))
console.log(` ok mcp/${entry.replace('../', '')}`)
} catch (e) {
failed++
console.error(` FAIL mcp/${entry.replace('../', '')} — ${e.message}`)
}
}
if (failed) {
console.error(`\n${failed} module(s) do not load under plain node — the MCP server would not start.`)
process.exit(1)
}
console.log('\nthe whole MCP import graph loads under plain node.')