mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-09 00:01:17 +00:00
test: baseline bundled runtime sidecar paths
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
pluginTestRepoRoot as repoRoot,
|
||||
writeJson,
|
||||
} from "./generated-plugin-test-helpers.js";
|
||||
import { collectBundledRuntimeSidecarPaths } from "./runtime-sidecar-paths-baseline.js";
|
||||
import { BUNDLED_RUNTIME_SIDECAR_PATHS } from "./runtime-sidecar-paths.js";
|
||||
|
||||
const BUNDLED_PLUGIN_METADATA_TEST_TIMEOUT_MS = 300_000;
|
||||
|
||||
@@ -59,6 +61,16 @@ describe("bundled plugin metadata", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"matches the checked-in runtime sidecar path baseline",
|
||||
{ timeout: BUNDLED_PLUGIN_METADATA_TEST_TIMEOUT_MS },
|
||||
() => {
|
||||
expect(BUNDLED_RUNTIME_SIDECAR_PATHS).toEqual(
|
||||
collectBundledRuntimeSidecarPaths({ rootDir: repoRoot }),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("captures setup-entry metadata for bundled channel plugins", () => {
|
||||
const discord = listBundledPluginMetadata().find((entry) => entry.dirName === "discord");
|
||||
expect(discord?.source).toEqual({ source: "./index.ts", built: "index.js" });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { listBundledPluginMetadata } from "./bundled-plugin-metadata.js";
|
||||
import { BUNDLED_RUNTIME_SIDECAR_PATHS } from "./runtime-sidecar-paths.js";
|
||||
|
||||
function assertUniqueValues<T extends string>(values: readonly T[], label: string): readonly T[] {
|
||||
const seen = new Set<string>();
|
||||
@@ -20,21 +20,6 @@ export function getPublicArtifactBasename(relativePath: string): string {
|
||||
return relativePath.split("/").at(-1) ?? relativePath;
|
||||
}
|
||||
|
||||
function buildBundledDistArtifactPath(dirName: string, artifact: string): string {
|
||||
return ["dist", "extensions", dirName, artifact].join("/");
|
||||
}
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_PATHS = assertUniqueValues(
|
||||
listBundledPluginMetadata()
|
||||
.flatMap((entry) =>
|
||||
(entry.runtimeSidecarArtifacts ?? []).map((artifact) =>
|
||||
buildBundledDistArtifactPath(entry.dirName, artifact),
|
||||
),
|
||||
)
|
||||
.toSorted((left, right) => left.localeCompare(right)),
|
||||
"bundled runtime sidecar path",
|
||||
);
|
||||
|
||||
const EXTRA_GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES = assertUniqueValues(
|
||||
[
|
||||
"action-runtime.runtime.js",
|
||||
|
||||
41
src/plugins/runtime-sidecar-paths-baseline.ts
Normal file
41
src/plugins/runtime-sidecar-paths-baseline.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { listBundledPluginMetadata } from "./bundled-plugin-metadata.js";
|
||||
|
||||
function buildBundledDistArtifactPath(dirName: string, artifact: string): string {
|
||||
return ["dist", "extensions", dirName, artifact].join("/");
|
||||
}
|
||||
|
||||
export function collectBundledRuntimeSidecarPaths(params?: {
|
||||
rootDir?: string;
|
||||
}): readonly string[] {
|
||||
return listBundledPluginMetadata(params)
|
||||
.flatMap((entry) =>
|
||||
(entry.runtimeSidecarArtifacts ?? []).map((artifact) =>
|
||||
buildBundledDistArtifactPath(entry.dirName, artifact),
|
||||
),
|
||||
)
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
export async function writeBundledRuntimeSidecarPathBaseline(params: {
|
||||
repoRoot: string;
|
||||
check: boolean;
|
||||
}): Promise<{ changed: boolean; jsonPath: string }> {
|
||||
const jsonPath = path.join(
|
||||
params.repoRoot,
|
||||
"scripts",
|
||||
"lib",
|
||||
"bundled-runtime-sidecar-paths.json",
|
||||
);
|
||||
const expectedJson = `${JSON.stringify(collectBundledRuntimeSidecarPaths(), null, 2)}\n`;
|
||||
const currentJson = fs.existsSync(jsonPath) ? fs.readFileSync(jsonPath, "utf8") : "";
|
||||
const changed = currentJson !== expectedJson;
|
||||
|
||||
if (!params.check && changed) {
|
||||
fs.mkdirSync(path.dirname(jsonPath), { recursive: true });
|
||||
fs.writeFileSync(jsonPath, expectedJson, "utf8");
|
||||
}
|
||||
|
||||
return { changed, jsonPath };
|
||||
}
|
||||
22
src/plugins/runtime-sidecar-paths.ts
Normal file
22
src/plugins/runtime-sidecar-paths.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import bundledRuntimeSidecarPaths from "../../scripts/lib/bundled-runtime-sidecar-paths.json" with { type: "json" };
|
||||
|
||||
function assertUniqueValues<T extends string>(values: readonly T[], label: string): readonly T[] {
|
||||
const seen = new Set<string>();
|
||||
const duplicates = new Set<string>();
|
||||
for (const value of values) {
|
||||
if (seen.has(value)) {
|
||||
duplicates.add(value);
|
||||
continue;
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
if (duplicates.size > 0) {
|
||||
throw new Error(`Duplicate ${label}: ${Array.from(duplicates).join(", ")}`);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_PATHS = assertUniqueValues(
|
||||
bundledRuntimeSidecarPaths,
|
||||
"bundled runtime sidecar path",
|
||||
);
|
||||
Reference in New Issue
Block a user