Files
openclaw/scripts/lib/channel-contract-test-plan.mjs
2026-04-20 17:59:51 +01:00

52 lines
1.6 KiB
JavaScript

import { existsSync, readdirSync } from "node:fs";
import { join, relative } from "node:path";
function listContractTestFiles(rootDir = "src/channels/plugins/contracts") {
if (!existsSync(rootDir)) {
return [];
}
return readdirSync(rootDir, { withFileTypes: true })
.filter((entry) => entry.isFile() && entry.name.endsWith(".test.ts"))
.map((entry) => join(rootDir, entry.name).replaceAll("\\", "/"))
.toSorted((a, b) => a.localeCompare(b));
}
export function createChannelContractTestShards() {
const rootDir = "src/channels/plugins/contracts";
const groups = {
"checks-fast-contracts-channels-registry-a": [],
"checks-fast-contracts-channels-registry-b": [],
"checks-fast-contracts-channels-core-a": [],
"checks-fast-contracts-channels-core-b": [],
};
const pushBalanced = (firstKey, secondKey, file) => {
const target = groups[firstKey].length <= groups[secondKey].length ? firstKey : secondKey;
groups[target].push(file);
};
for (const file of listContractTestFiles(rootDir)) {
const name = relative(rootDir, file).replaceAll("\\", "/");
if (name.startsWith("plugins-core.") || name.startsWith("plugin.")) {
pushBalanced(
"checks-fast-contracts-channels-core-a",
"checks-fast-contracts-channels-core-b",
file,
);
} else {
pushBalanced(
"checks-fast-contracts-channels-registry-a",
"checks-fast-contracts-channels-registry-b",
file,
);
}
}
return Object.entries(groups).map(([checkName, includePatterns]) => ({
checkName,
includePatterns,
task: "contracts-channels",
runtime: "node",
}));
}