mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-23 16:01:17 +00:00
97 lines
3.0 KiB
TypeScript
97 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
collectExtensionPluginSdkBoundaryInventory,
|
|
main,
|
|
} from "../scripts/check-extension-plugin-sdk-boundary.mjs";
|
|
|
|
const srcOutsideInventoryPromise =
|
|
collectExtensionPluginSdkBoundaryInventory("src-outside-plugin-sdk");
|
|
const pluginSdkInternalInventoryPromise =
|
|
collectExtensionPluginSdkBoundaryInventory("plugin-sdk-internal");
|
|
const relativeOutsidePackageInventoryPromise = collectExtensionPluginSdkBoundaryInventory(
|
|
"relative-outside-package",
|
|
);
|
|
const srcOutsideJsonOutputPromise = getJsonOutput("src-outside-plugin-sdk");
|
|
const pluginSdkInternalJsonOutputPromise = getJsonOutput("plugin-sdk-internal");
|
|
const relativeOutsidePackageJsonOutputPromise = getJsonOutput("relative-outside-package");
|
|
|
|
async function getJsonOutput(
|
|
mode: Parameters<typeof collectExtensionPluginSdkBoundaryInventory>[0],
|
|
) {
|
|
const captured = createCapturedIo();
|
|
const exitCode = await main([`--mode=${mode}`, "--json"], captured.io);
|
|
return {
|
|
exitCode,
|
|
stderr: captured.readStderr(),
|
|
json: JSON.parse(captured.readStdout()),
|
|
};
|
|
}
|
|
|
|
function createCapturedIo() {
|
|
let stdout = "";
|
|
let stderr = "";
|
|
return {
|
|
io: {
|
|
stdout: {
|
|
write(chunk) {
|
|
stdout += String(chunk);
|
|
},
|
|
},
|
|
stderr: {
|
|
write(chunk) {
|
|
stderr += String(chunk);
|
|
},
|
|
},
|
|
},
|
|
readStdout: () => stdout,
|
|
readStderr: () => stderr,
|
|
};
|
|
}
|
|
|
|
describe("extension src outside plugin-sdk boundary inventory", () => {
|
|
it("stays empty and sorted", async () => {
|
|
const inventory = await srcOutsideInventoryPromise;
|
|
const jsonResult = await srcOutsideJsonOutputPromise;
|
|
|
|
expect(inventory).toEqual([]);
|
|
expect(
|
|
[...inventory].toSorted(
|
|
(left, right) =>
|
|
left.file.localeCompare(right.file) ||
|
|
left.line - right.line ||
|
|
left.kind.localeCompare(right.kind) ||
|
|
left.specifier.localeCompare(right.specifier) ||
|
|
left.resolvedPath.localeCompare(right.resolvedPath) ||
|
|
left.reason.localeCompare(right.reason),
|
|
),
|
|
).toEqual(inventory);
|
|
expect(jsonResult.exitCode).toBe(0);
|
|
expect(jsonResult.stderr).toBe("");
|
|
expect(jsonResult.json).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("extension plugin-sdk-internal boundary inventory", () => {
|
|
it("stays empty", async () => {
|
|
const inventory = await pluginSdkInternalInventoryPromise;
|
|
const jsonResult = await pluginSdkInternalJsonOutputPromise;
|
|
|
|
expect(inventory).toEqual([]);
|
|
expect(jsonResult.exitCode).toBe(0);
|
|
expect(jsonResult.stderr).toBe("");
|
|
expect(jsonResult.json).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("extension relative-outside-package boundary inventory", () => {
|
|
it("stays empty", async () => {
|
|
const inventory = await relativeOutsidePackageInventoryPromise;
|
|
const jsonResult = await relativeOutsidePackageJsonOutputPromise;
|
|
|
|
expect(inventory).toEqual([]);
|
|
expect(jsonResult.exitCode).toBe(0);
|
|
expect(jsonResult.stderr).toBe("");
|
|
expect(jsonResult.json).toEqual([]);
|
|
});
|
|
});
|