/** * Tests the plugin SDK public API baseline. */ import path from "node:path"; import { describe, expect, it } from "vitest"; import { normalizePluginSdkApiDeclarationText, normalizePluginSdkApiSourcePath, } from "./api-baseline.js"; describe("Plugin SDK API baseline", () => { it("normalizes declaration import paths to repo-relative paths", () => { const repoRoot = process.cwd(); const modelCatalogPath = path.join(repoRoot, "src", "agents", "agent-model-discovery"); const declaration = `export function setModelCatalogImportForTest(loader?: (() => Promise) | undefined): void;`; const normalized = normalizePluginSdkApiDeclarationText(repoRoot, declaration); expect(normalized).not.toContain(repoRoot); expect(normalized).toContain( 'import("src/agents/agent-model-discovery", { with: { "resolution-mode": "import" } })', ); }); it("normalizes dependency source paths to stable node_modules paths", () => { const repoRoot = path.join(path.sep, "workspace", "openclaw-worktree"); const linkedDependencyPath = path.join( path.sep, "workspace", "openclaw", "node_modules", "@openclaw", "fs-safe", "dist", "secret-file.d.ts", ); const pnpmDependencyPath = path.join( repoRoot, "node_modules", ".pnpm", "@openclaw+fs-safe@1.0.0", "node_modules", "@openclaw", "fs-safe", "dist", "secret-file.d.ts", ); expect(normalizePluginSdkApiSourcePath(repoRoot, linkedDependencyPath)).toBe( "node_modules/@openclaw/fs-safe/dist/secret-file.d.ts", ); expect(normalizePluginSdkApiSourcePath(repoRoot, pnpmDependencyPath)).toBe( "node_modules/@openclaw/fs-safe/dist/secret-file.d.ts", ); }); it("keeps repo source paths relative when a parent directory is named node_modules", () => { const repoRoot = path.join(path.sep, "workspace", "node_modules", "openclaw"); const sourcePath = path.join(repoRoot, "src", "plugin-sdk", "core.ts"); expect(normalizePluginSdkApiSourcePath(repoRoot, sourcePath)).toBe("src/plugin-sdk/core.ts"); }); });