Files
openclaw/extensions/mxc/test/plugin-root.test.ts
Peter Steinberger 568b920b21 feat(lint): enforce import ordering and deduplication (#124730)
* refactor(imports): dedupe and hoist imports

* feat(lint): enforce import/no-duplicates and import/first
2026-08-16 11:44:52 -07:00

37 lines
1.5 KiB
TypeScript

import fs, { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { describe, expect, it } from "vitest";
import { resolveMxcLauncherPath } from "../src/plugin-root.js";
describe("resolveMxcLauncherPath", () => {
it("throws when called from outside any plugin tree", () => {
const outside = pathToFileURL(path.resolve("README.md")).href;
expect(() => resolveMxcLauncherPath(outside)).toThrow(/cannot locate plugin root/);
});
it("returns the src .mjs in dev layout", () => {
const launcher = resolveMxcLauncherPath();
expect(launcher).toMatch(/mxc-spawn-launcher\.mjs$/);
expect(fs.existsSync(launcher)).toBe(true);
});
it("returns the package dist launcher in packed plugin layout", () => {
const root = mkdtempSync(path.join(tmpdir(), "mxc-packed-plugin-"));
try {
writeFileSync(path.join(root, "package.json"), "{}");
writeFileSync(path.join(root, "openclaw.plugin.json"), "{}");
const distDir = path.join(root, "dist");
fs.mkdirSync(distDir, { recursive: true });
const launcher = path.join(distDir, "mxc-spawn-launcher.mjs");
writeFileSync(launcher, "export {};\n");
const moduleUrl = pathToFileURL(path.join(distDir, "index.js")).href;
expect(resolveMxcLauncherPath(moduleUrl)).toBe(launcher);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
});