refactor: simplify test workflow helpers

This commit is contained in:
Peter Steinberger
2026-04-03 12:58:46 +01:00
parent 71a54d0c95
commit 685ef52284
8 changed files with 167 additions and 327 deletions

View File

@@ -1,99 +0,0 @@
import { describe, expect, it } from "vitest";
import { buildWorkflowManifest } from "../../scripts/ci-write-manifest-outputs.mjs";
describe("buildWorkflowManifest", () => {
it("builds static CI matrices from scope env", () => {
const manifest = buildWorkflowManifest({
GITHUB_EVENT_NAME: "pull_request",
OPENCLAW_CI_DOCS_ONLY: "false",
OPENCLAW_CI_DOCS_CHANGED: "false",
OPENCLAW_CI_RUN_NODE: "true",
OPENCLAW_CI_RUN_MACOS: "true",
OPENCLAW_CI_RUN_ANDROID: "true",
OPENCLAW_CI_RUN_WINDOWS: "true",
OPENCLAW_CI_RUN_SKILLS_PYTHON: "false",
OPENCLAW_CI_HAS_CHANGED_EXTENSIONS: "true",
OPENCLAW_CI_CHANGED_EXTENSIONS_MATRIX: '{"include":[{"extension":"discord"}]}',
});
expect(manifest.run_checks).toBe(true);
expect(manifest.checks_fast_matrix).toEqual({
include: [
{ check_name: "checks-fast-bundled", runtime: "node", task: "bundled" },
{ check_name: "checks-fast-extensions", runtime: "node", task: "extensions" },
{
check_name: "checks-fast-contracts-protocol",
runtime: "node",
task: "contracts-protocol",
},
],
});
expect(manifest.checks_matrix).toEqual({
include: [
{ check_name: "checks-node-test", runtime: "node", task: "test" },
{ check_name: "checks-node-channels", runtime: "node", task: "channels" },
],
});
expect(manifest.checks_windows_matrix).toEqual({
include: [{ check_name: "checks-windows-node-test", runtime: "node", task: "test" }],
});
expect(manifest.extension_fast_matrix).toEqual({
include: [{ check_name: "extension-fast-discord", extension: "discord" }],
});
expect(manifest.android_matrix).toHaveProperty("include");
expect(manifest.macos_node_matrix).toEqual({
include: [{ check_name: "macos-node", runtime: "node", task: "test" }],
});
});
it("includes the push-only compat lane on pushes", () => {
const manifest = buildWorkflowManifest({
GITHUB_EVENT_NAME: "push",
OPENCLAW_CI_DOCS_ONLY: "false",
OPENCLAW_CI_DOCS_CHANGED: "false",
OPENCLAW_CI_RUN_NODE: "true",
});
expect(manifest.checks_matrix).toEqual({
include: [
{ check_name: "checks-node-test", runtime: "node", task: "test" },
{ check_name: "checks-node-channels", runtime: "node", task: "channels" },
{
check_name: "checks-node-compat-node22",
runtime: "node",
task: "compat-node22",
node_version: "22.x",
cache_key_suffix: "node22",
},
],
});
});
it("suppresses heavy jobs for docs-only changes", () => {
const manifest = buildWorkflowManifest({
OPENCLAW_CI_DOCS_ONLY: "true",
OPENCLAW_CI_DOCS_CHANGED: "true",
OPENCLAW_CI_RUN_NODE: "true",
OPENCLAW_CI_RUN_WINDOWS: "true",
});
expect(manifest.run_checks).toBe(false);
expect(manifest.run_checks_windows).toBe(false);
expect(manifest.run_check_docs).toBe(true);
});
it("builds install-smoke outputs separately", () => {
const manifest = buildWorkflowManifest(
{
OPENCLAW_CI_DOCS_ONLY: "false",
OPENCLAW_CI_RUN_CHANGED_SMOKE: "true",
},
"install-smoke",
);
expect(manifest).toEqual({
docs_only: false,
run_install_smoke: true,
});
});
});

View File

@@ -28,8 +28,7 @@ function runScript(args: string[], cwd = process.cwd()) {
function findExtensionWithoutTests() {
const extensionId = listAvailableExtensionIds().find(
(candidate) =>
resolveExtensionTestPlan({ targetArg: candidate, cwd: process.cwd() }).testFiles.length === 0,
(candidate) => !resolveExtensionTestPlan({ targetArg: candidate, cwd: process.cwd() }).hasTests,
);
expect(extensionId).toBeDefined();
@@ -43,9 +42,8 @@ describe("scripts/test-extension.mjs", () => {
expect(plan.extensionId).toBe("slack");
expect(plan.extensionDir).toBe(bundledPluginRoot("slack"));
expect(plan.config).toBe("vitest.channels.config.ts");
expect(plan.testFiles.some((file) => file.startsWith(`${bundledPluginRoot("slack")}/`))).toBe(
true,
);
expect(plan.roots).toContain(bundledPluginRoot("slack"));
expect(plan.hasTests).toBe(true);
});
it("resolves provider extensions onto the extensions vitest config", () => {
@@ -53,19 +51,17 @@ describe("scripts/test-extension.mjs", () => {
expect(plan.extensionId).toBe("firecrawl");
expect(plan.config).toBe("vitest.extensions.config.ts");
expect(
plan.testFiles.some((file) => file.startsWith(`${bundledPluginRoot("firecrawl")}/`)),
).toBe(true);
expect(plan.roots).toContain(bundledPluginRoot("firecrawl"));
expect(plan.hasTests).toBe(true);
});
it("includes paired src roots when they contain tests", () => {
it("keeps extension-root plans lean when there is no paired core test root", () => {
const plan = resolveExtensionTestPlan({ targetArg: "line", cwd: process.cwd() });
expect(plan.roots).toContain(bundledPluginRoot("line"));
expect(plan.roots).not.toContain("src/line");
expect(plan.config).toBe("vitest.extensions.config.ts");
expect(plan.testFiles.some((file) => file.startsWith(`${bundledPluginRoot("line")}/`))).toBe(
true,
);
expect(plan.hasTests).toBe(true);
});
it("infers the extension from the current working directory", () => {
@@ -111,7 +107,8 @@ describe("scripts/test-extension.mjs", () => {
const plan = readPlan([extensionId]);
expect(plan.extensionId).toBe(extensionId);
expect(plan.testFiles).toEqual([]);
expect(plan.hasTests).toBe(false);
expect(plan.testFileCount).toBe(0);
});
it("treats extensions without tests as a no-op by default", () => {