fix(debug): load OMP marketplace DAP adapters

This commit is contained in:
DanZAIO
2026-06-19 19:34:42 -03:00
parent c3cdde6c4d
commit dd7dcccc45
3 changed files with 54 additions and 4 deletions
@@ -2,9 +2,12 @@ import { afterEach, describe, expect, it, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { getAdapterConfigs, resolveAdapter, selectLaunchAdapter } from "@oh-my-pi/pi-coding-agent/dap/config";
import { getAdapterConfigs, resolveAdapter, selectLaunchAdapter } from "../../src/dap/config";
import { clearClaudePluginRootsCache, injectPluginDirRoots } from "../../src/discovery/helpers";
const tempDirs: string[] = [];
const ORIGINAL_OMP_PLUGIN_DIR = process.env.OMP_PLUGIN_DIR;
const ORIGINAL_OMP_MARKETPLACE_DIR = process.env.OMP_MARKETPLACE_DIR;
async function makeTempDir(prefix: string): Promise<string> {
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
@@ -14,6 +17,18 @@ async function makeTempDir(prefix: string): Promise<string> {
afterEach(async () => {
vi.restoreAllMocks();
if (ORIGINAL_OMP_PLUGIN_DIR === undefined) {
delete process.env.OMP_PLUGIN_DIR;
} else {
process.env.OMP_PLUGIN_DIR = ORIGINAL_OMP_PLUGIN_DIR;
}
if (ORIGINAL_OMP_MARKETPLACE_DIR === undefined) {
delete process.env.OMP_MARKETPLACE_DIR;
} else {
process.env.OMP_MARKETPLACE_DIR = ORIGINAL_OMP_MARKETPLACE_DIR;
}
await injectPluginDirRoots(os.homedir(), []);
clearClaudePluginRootsCache();
await Promise.all(tempDirs.splice(0).map(dir => fs.rm(dir, { recursive: true, force: true })));
});
@@ -107,6 +122,40 @@ describe("DAP adapter configuration", () => {
expect(selected?.launchDefaults).toEqual({ request: "launch", projectRoot: "." });
});
it("loads plugin DAP adapters from OMP marketplace catalogs", async () => {
const cwd = await makeTempDir("omp-dap-config-marketplace-");
const marketplaceRoot = path.join(cwd, "marketplaces", "test-market");
const pluginRoot = path.join(marketplaceRoot, "plugins", "acme-debug");
await fs.mkdir(path.join(marketplaceRoot, ".omp-plugin"), { recursive: true });
await fs.mkdir(path.join(pluginRoot, ".claude-plugin"), { recursive: true });
await fs.writeFile(path.join(cwd, "app.rb"), "puts 'hi'\n");
await fs.writeFile(
path.join(pluginRoot, ".claude-plugin", "plugin.json"),
JSON.stringify({ name: "acme-debug" }),
);
await fs.writeFile(
path.join(marketplaceRoot, ".omp-plugin", "marketplace.json"),
JSON.stringify({
plugins: [
{
name: "acme-debug",
dapAdapters: {
"acme-ruby": {
command: "ruby-debug-adapter",
fileTypes: [".rb"],
},
},
},
],
}),
);
process.env.OMP_PLUGIN_DIR = path.join(cwd, "plugins");
process.env.OMP_MARKETPLACE_DIR = path.join(cwd, "marketplaces");
await injectPluginDirRoots(cwd, [pluginRoot], cwd);
expect(getAdapterConfigs(cwd)["acme-ruby"]?.command).toBe("ruby-debug-adapter");
});
it("ignores invalid custom adapters without discarding valid configs", async () => {
const cwd = await makeTempDir("omp-dap-config-invalid-");
await fs.writeFile(