test(omo-claude): make sync-mcp self-healing and test:claude order-independent

sync-mcp rebuilds the lsp component if a prior sync wiped its dist; sync-mcp.test
builds in a before hook; checkVendored flags only real unbundled imports (a guarded
require.resolve fallback is allowed); test:claude runs the destructive sync-components
test in its own node --test pass so it never races the build-checking tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
YeonGyu-Kim
2026-05-29 14:11:57 +09:00
parent 027c543340
commit 9ddb2b9819
3 changed files with 26 additions and 10 deletions
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { before, test } from "node:test";
import { fileURLToPath } from "node:url";
import {
@@ -11,11 +11,19 @@ import {
LSP_DEST,
MCP_JSON_PATH,
checkVendored,
syncMcp,
} from "./sync-mcp.mjs";
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
const SCRIPT_PATH = join(SCRIPT_DIR, "sync-mcp.mjs");
// Self-contained: build + vendor + bundle so these assertions never depend on
// prior build state or test ordering (sync-components.test re-syncs the lsp
// component and wipes its dist; this rebuilds it before we check).
before(async () => {
await syncMcp({ build: true });
});
function runCli(args) {
return spawnSync(process.execPath, [SCRIPT_PATH, ...args], { encoding: "utf8" });
}
@@ -54,10 +62,14 @@ test("vendored server entrypoints exist", async () => {
}
});
test("lsp component hook is bundled (no bare @code-yeongyu/lsp-tools-mcp import)", async () => {
test("lsp component hook is bundled (no unbundled @code-yeongyu/lsp-tools-mcp import)", async () => {
const hook = await readFile(LSP_COMPONENT_HOOK, "utf8");
// A guarded require.resolve(...) fallback is allowed. An actual import/require
// statement is not (it would fail to resolve from a node_modules-free cache).
const unbundledImport =
/\bfrom\s*["'][^"']*@code-yeongyu\/lsp-tools-mcp|\brequire\s*\(\s*["'][^"']*@code-yeongyu\/lsp-tools-mcp/;
assert.ok(
!hook.includes("@code-yeongyu/lsp-tools-mcp"),
!unbundledImport.test(hook),
"the lsp component hook must inline lsp-tools-mcp so it resolves from a cache",
);
});