mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 16:41:49 +00:00
test: combine extension import boundary checks
This commit is contained in:
142
test/extension-import-boundaries.test.ts
Normal file
142
test/extension-import-boundaries.test.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
collectExtensionPluginSdkBoundaryInventory,
|
||||
main as extensionPluginSdkMain,
|
||||
} from "../scripts/check-extension-plugin-sdk-boundary.mjs";
|
||||
import {
|
||||
collectSdkPackageExtensionImportBoundaryInventory,
|
||||
main as sdkPackageMain,
|
||||
} from "../scripts/check-sdk-package-extension-import-boundary.mjs";
|
||||
import {
|
||||
collectSrcExtensionImportBoundaryInventory,
|
||||
main as srcExtensionMain,
|
||||
} from "../scripts/check-src-extension-import-boundary.mjs";
|
||||
import { createCapturedIo } from "./helpers/captured-io.js";
|
||||
|
||||
const srcInventoryPromise = collectSrcExtensionImportBoundaryInventory();
|
||||
const srcJsonOutputPromise = getJsonOutput(srcExtensionMain, ["--json"]);
|
||||
const sdkPackageInventoryPromise = collectSdkPackageExtensionImportBoundaryInventory();
|
||||
const sdkPackageJsonOutputPromise = getJsonOutput(sdkPackageMain, ["--json"]);
|
||||
const srcOutsideInventoryPromise =
|
||||
collectExtensionPluginSdkBoundaryInventory("src-outside-plugin-sdk");
|
||||
const pluginSdkInternalInventoryPromise =
|
||||
collectExtensionPluginSdkBoundaryInventory("plugin-sdk-internal");
|
||||
const relativeOutsidePackageInventoryPromise = collectExtensionPluginSdkBoundaryInventory(
|
||||
"relative-outside-package",
|
||||
);
|
||||
const srcOutsideJsonOutputPromise = getJsonOutput(extensionPluginSdkMain, [
|
||||
"--mode=src-outside-plugin-sdk",
|
||||
"--json",
|
||||
]);
|
||||
const pluginSdkInternalJsonOutputPromise = getJsonOutput(extensionPluginSdkMain, [
|
||||
"--mode=plugin-sdk-internal",
|
||||
"--json",
|
||||
]);
|
||||
const relativeOutsidePackageJsonOutputPromise = getJsonOutput(extensionPluginSdkMain, [
|
||||
"--mode=relative-outside-package",
|
||||
"--json",
|
||||
]);
|
||||
|
||||
type CapturedIo = ReturnType<typeof createCapturedIo>["io"];
|
||||
|
||||
async function getJsonOutput(
|
||||
main: (argv: string[], io: CapturedIo) => Promise<number>,
|
||||
argv: string[],
|
||||
) {
|
||||
const captured = createCapturedIo();
|
||||
const exitCode = await main(argv, captured.io);
|
||||
return {
|
||||
exitCode,
|
||||
stderr: captured.readStderr(),
|
||||
json: JSON.parse(captured.readStdout()),
|
||||
};
|
||||
}
|
||||
|
||||
describe("src extension import boundary inventory", () => {
|
||||
it("stays empty", async () => {
|
||||
expect(await srcInventoryPromise).toEqual([]);
|
||||
});
|
||||
|
||||
it("produces stable sorted output", async () => {
|
||||
const first = await srcInventoryPromise;
|
||||
const second = await collectSrcExtensionImportBoundaryInventory();
|
||||
|
||||
expect(second).toEqual(first);
|
||||
});
|
||||
|
||||
it("script json output stays empty", async () => {
|
||||
const jsonOutput = await srcJsonOutputPromise;
|
||||
|
||||
expect(jsonOutput.exitCode).toBe(0);
|
||||
expect(jsonOutput.stderr).toBe("");
|
||||
expect(jsonOutput.json).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sdk/package extension import boundary inventory", () => {
|
||||
it("stays empty", async () => {
|
||||
expect(await sdkPackageInventoryPromise).toEqual([]);
|
||||
});
|
||||
|
||||
it("produces stable sorted output", async () => {
|
||||
const first = await sdkPackageInventoryPromise;
|
||||
const second = await collectSdkPackageExtensionImportBoundaryInventory();
|
||||
|
||||
expect(second).toEqual(first);
|
||||
});
|
||||
|
||||
it("script json output stays empty", async () => {
|
||||
const jsonOutput = await sdkPackageJsonOutputPromise;
|
||||
|
||||
expect(jsonOutput.exitCode).toBe(0);
|
||||
expect(jsonOutput.stderr).toBe("");
|
||||
expect(jsonOutput.json).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
@@ -1,76 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
collectExtensionPluginSdkBoundaryInventory,
|
||||
main,
|
||||
} from "../scripts/check-extension-plugin-sdk-boundary.mjs";
|
||||
import { createCapturedIo } from "./helpers/captured-io.js";
|
||||
|
||||
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()),
|
||||
};
|
||||
}
|
||||
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
collectSdkPackageExtensionImportBoundaryInventory,
|
||||
main,
|
||||
} from "../scripts/check-sdk-package-extension-import-boundary.mjs";
|
||||
import { createCapturedIo } from "./helpers/captured-io.js";
|
||||
|
||||
describe("sdk/package extension import boundary inventory", () => {
|
||||
it("stays empty", async () => {
|
||||
expect(await collectSdkPackageExtensionImportBoundaryInventory()).toEqual([]);
|
||||
});
|
||||
|
||||
it("produces stable sorted output", async () => {
|
||||
const first = await collectSdkPackageExtensionImportBoundaryInventory();
|
||||
const second = await collectSdkPackageExtensionImportBoundaryInventory();
|
||||
|
||||
expect(second).toEqual(first);
|
||||
});
|
||||
|
||||
it("script json output stays empty", async () => {
|
||||
const captured = createCapturedIo();
|
||||
const exitCode = await main(["--json"], captured.io);
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(captured.readStderr()).toBe("");
|
||||
expect(JSON.parse(captured.readStdout())).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
collectSrcExtensionImportBoundaryInventory,
|
||||
main,
|
||||
} from "../scripts/check-src-extension-import-boundary.mjs";
|
||||
import { createCapturedIo } from "./helpers/captured-io.js";
|
||||
|
||||
describe("src extension import boundary inventory", () => {
|
||||
it("stays empty", async () => {
|
||||
expect(await collectSrcExtensionImportBoundaryInventory()).toEqual([]);
|
||||
});
|
||||
|
||||
it("produces stable sorted output", async () => {
|
||||
const first = await collectSrcExtensionImportBoundaryInventory();
|
||||
const second = await collectSrcExtensionImportBoundaryInventory();
|
||||
|
||||
expect(second).toEqual(first);
|
||||
});
|
||||
|
||||
it("script json output stays empty", async () => {
|
||||
const captured = createCapturedIo();
|
||||
const exitCode = await main(["--json"], captured.io);
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(captured.readStderr()).toBe("");
|
||||
expect(JSON.parse(captured.readStdout())).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -25,11 +25,10 @@ export const boundaryTestFiles = [
|
||||
"src/infra/package-json.test.ts",
|
||||
"src/infra/path-env.test.ts",
|
||||
"src/infra/stable-node-path.test.ts",
|
||||
"test/extension-plugin-sdk-boundary.test.ts",
|
||||
"test/extension-import-boundaries.test.ts",
|
||||
"test/extension-test-boundary.test.ts",
|
||||
"test/plugin-extension-import-boundary.test.ts",
|
||||
"test/web-fetch-provider-boundary.test.ts",
|
||||
"test/web-search-provider-boundary.test.ts",
|
||||
"test/web-provider-boundary.test.ts",
|
||||
];
|
||||
|
||||
export const bundledPluginDependentUnitTestFiles = [
|
||||
|
||||
Reference in New Issue
Block a user