refactor(test): share channel contract file discovery

This commit is contained in:
Vincent Koc 2026-06-07 03:59:03 +02:00
parent 2b7d7841d2
commit b804d20da7
No known key found for this signature in database

View file

@ -1,29 +1,9 @@
// Builds balanced Vitest shard plans for channel plugin contract tests.
import { spawnSync } from "node:child_process";
import { existsSync, readdirSync } from "node:fs";
import { join, relative } from "node:path";
import { relative } from "node:path";
import { listTrackedTestFiles } from "./list-test-files.mjs";
function listContractTestFiles(rootDir = "src/channels/plugins/contracts") {
const result = spawnSync("git", ["ls-files", "--", rootDir], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
});
if (result.status === 0) {
return result.stdout
.split("\n")
.map((line) => line.trim().replaceAll("\\", "/"))
.filter((line) => line.endsWith(".test.ts"))
.toSorted((a, b) => a.localeCompare(b));
}
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));
return listTrackedTestFiles(rootDir);
}
const CONTRACT_FILE_WEIGHTS = new Map([