test: baseline bundled runtime sidecar paths

This commit is contained in:
Peter Steinberger
2026-04-03 14:25:54 +01:00
parent 8fabfa5d1c
commit bb25a8050c
12 changed files with 154 additions and 21 deletions

View File

@@ -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" });

View File

@@ -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",

View 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 };
}

View 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",
);