|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { mkdir, readFile, stat, writeFile } from "node:fs/promises"; |
| 3 | +import { join } from "node:path"; |
| 4 | +import test from "node:test"; |
| 5 | + |
| 6 | +import { installMarketplaceLocally } from "./install-local.mjs"; |
| 7 | +import { makeTempDir, writeJson, writePluginAt } from "./install-test-fixtures.mjs"; |
| 8 | + |
| 9 | +test("#given packaged lazycodex adapter #when installing locally #then uses bundled artifacts without source builds", async () => { |
| 10 | + // given |
| 11 | + const repoRoot = await makeTempDir(); |
| 12 | + const codexHome = await makeTempDir(); |
| 13 | + const binDir = await makeTempDir(); |
| 14 | + const codexPackageRoot = join(repoRoot, "packages", "omo-codex"); |
| 15 | + const pluginRoot = join(codexPackageRoot, "plugin"); |
| 16 | + const lspRuntimeRoot = join(repoRoot, "packages", "lsp-tools-mcp"); |
| 17 | + |
| 18 | + await writeJson(join(repoRoot, "package.json"), { |
| 19 | + name: "@code-yeongyu/lazycodex", |
| 20 | + version: "0.1.2", |
| 21 | + }); |
| 22 | + await writeJson(join(codexPackageRoot, "marketplace.json"), { |
| 23 | + name: "sisyphuslabs", |
| 24 | + plugins: [{ name: "omo", source: "./plugins/omo" }], |
| 25 | + }); |
| 26 | + await writePluginAt(pluginRoot, "omo", "0.1.0"); |
| 27 | + await writeJson(join(pluginRoot, ".mcp.json"), { |
| 28 | + mcpServers: { |
| 29 | + lsp: { |
| 30 | + command: "node", |
| 31 | + args: ["../../lsp-tools-mcp/dist/cli.js", "mcp"], |
| 32 | + cwd: ".", |
| 33 | + }, |
| 34 | + }, |
| 35 | + }); |
| 36 | + await mkdir(join(pluginRoot, "dist"), { recursive: true }); |
| 37 | + await writeFile(join(pluginRoot, "dist", "cli.js"), "#!/usr/bin/env node\nconsole.log('prebuilt')\n"); |
| 38 | + await writeJson(join(lspRuntimeRoot, "dist", "cli.js"), { executable: true }); |
| 39 | + |
| 40 | + const commands = []; |
| 41 | + |
| 42 | + // when |
| 43 | + const result = await installMarketplaceLocally({ |
| 44 | + repoRoot, |
| 45 | + codexHome, |
| 46 | + binDir, |
| 47 | + platform: "linux", |
| 48 | + runCommand: async (command, args, options) => { |
| 49 | + commands.push([command, args.join(" "), options.cwd]); |
| 50 | + }, |
| 51 | + log: () => {}, |
| 52 | + }); |
| 53 | + |
| 54 | + // then |
| 55 | + const pluginCacheRoot = join(codexHome, "plugins", "cache", "sisyphuslabs", "omo", "0.1.0"); |
| 56 | + const cachedMcp = JSON.parse(await readFile(join(pluginCacheRoot, ".mcp.json"), "utf8")); |
| 57 | + const cachedLspCli = join(pluginCacheRoot, "mcp", "lsp", "dist", "cli.js"); |
| 58 | + |
| 59 | + assert.deepEqual(result.installed.map((plugin) => `${plugin.name}@${plugin.version}`), ["omo@0.1.0"]); |
| 60 | + assert.deepEqual( |
| 61 | + commands.map(([command, args, cwd]) => [command, args, cwd]), |
| 62 | + [["npm", "install --omit=dev", pluginCacheRoot]], |
| 63 | + ); |
| 64 | + assert.deepEqual(cachedMcp.mcpServers.lsp.args, [cachedLspCli, "mcp"]); |
| 65 | + assert.equal((await stat(cachedLspCli)).isFile(), true); |
| 66 | + assert.notEqual(cachedMcp.mcpServers.lsp.args[0], join(lspRuntimeRoot, "dist", "cli.js")); |
| 67 | +}); |
0 commit comments