mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
fix(scripts): use direct-run helper for Windows guards (#110877)
* fix(scripts): normalize Windows direct-run guards * test(scripts): cover direct-run routing --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { detectChangedScope } from "../../scripts/ci-changed-scope.mjs";
|
||||
import { isDirectRunPath } from "../../scripts/lib/direct-run.mjs";
|
||||
|
||||
const DIRECT_RUN_SCRIPTS = [
|
||||
"scripts/android-app-i18n.ts",
|
||||
"scripts/android-pin-version.ts",
|
||||
"scripts/ci-run-timings.mjs",
|
||||
"scripts/e2e/lib/package-compat.mjs",
|
||||
"scripts/generate-bundled-channel-config-metadata.ts",
|
||||
"scripts/plan-release-workflow-matrix.mjs",
|
||||
"scripts/run-additional-boundary-checks.mjs",
|
||||
"scripts/verify-docker-attestations.mjs",
|
||||
] as const;
|
||||
|
||||
const EXECUTABLE_ENTRYPOINTS = [
|
||||
{
|
||||
args: ["--direct-run-smoke"],
|
||||
output: "Unknown CI run timing option: --direct-run-smoke",
|
||||
script: "scripts/ci-run-timings.mjs",
|
||||
status: 1,
|
||||
},
|
||||
{
|
||||
args: ["2026.4.25"],
|
||||
output: "1",
|
||||
script: "scripts/e2e/lib/package-compat.mjs",
|
||||
status: 0,
|
||||
},
|
||||
{
|
||||
args: [],
|
||||
output: "docker_e2e_count=",
|
||||
script: "scripts/plan-release-workflow-matrix.mjs",
|
||||
status: 0,
|
||||
},
|
||||
{
|
||||
args: ["--help"],
|
||||
output: "Usage: node scripts/run-additional-boundary-checks.mjs",
|
||||
script: "scripts/run-additional-boundary-checks.mjs",
|
||||
status: 0,
|
||||
},
|
||||
{
|
||||
args: ["--help"],
|
||||
output: "Usage: node scripts/verify-docker-attestations.mjs",
|
||||
script: "scripts/verify-docker-attestations.mjs",
|
||||
status: 0,
|
||||
},
|
||||
] as const;
|
||||
|
||||
function runEntrypoint(entrypoint: (typeof EXECUTABLE_ENTRYPOINTS)[number]) {
|
||||
return spawnSync(process.execPath, [path.resolve(entrypoint.script), ...entrypoint.args], {
|
||||
cwd: process.cwd(),
|
||||
encoding: "utf8",
|
||||
env: {
|
||||
...process.env,
|
||||
DOCKER_LANES: "",
|
||||
GITHUB_STEP_SUMMARY: "",
|
||||
INCLUDE_LIVE_SUITES: "",
|
||||
INCLUDE_RELEASE_PATH_SUITES: "",
|
||||
LIVE_MODEL_PROVIDERS: "",
|
||||
LIVE_SUITE_FILTER: "",
|
||||
RELEASE_TEST_PROFILE: "",
|
||||
},
|
||||
timeout: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
describe("script direct-run entrypoints", () => {
|
||||
it.each(EXECUTABLE_ENTRYPOINTS)("runs $script through its guarded CLI", (entrypoint) => {
|
||||
const result = runEntrypoint(entrypoint);
|
||||
const output = `${result.stdout}${result.stderr}`;
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.status).toBe(entrypoint.status);
|
||||
expect(output).toContain(entrypoint.output);
|
||||
});
|
||||
|
||||
it("matches Windows drive paths case-insensitively", () => {
|
||||
expect(
|
||||
isDirectRunPath(
|
||||
"C:\\repo\\scripts\\android-app-i18n.ts",
|
||||
"c:\\repo\\scripts\\android-app-i18n.ts",
|
||||
"win32",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each(DIRECT_RUN_SCRIPTS)("uses the canonical guard in %s", (script) => {
|
||||
const source = readFileSync(script, "utf8");
|
||||
|
||||
expect(source.match(/isDirectRunUrl\(process\.argv\[1\], import\.meta\.url\)/gu)).toHaveLength(
|
||||
1,
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
...DIRECT_RUN_SCRIPTS,
|
||||
"scripts/lib/direct-run.mjs",
|
||||
"test/scripts/direct-run-entrypoints.test.ts",
|
||||
])("routes %s through Windows CI", (changedPath) => {
|
||||
expect(detectChangedScope([changedPath]).runWindows).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -723,7 +723,10 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
],
|
||||
"scripts/e2e/lib/onboard/assert-config.mjs": ["test/scripts/onboard-config-fixtures.test.ts"],
|
||||
"scripts/e2e/lib/onboard/write-config.mjs": ["test/scripts/onboard-config-fixtures.test.ts"],
|
||||
"scripts/e2e/lib/package-compat.mjs": ["test/scripts/docker-build-helper.test.ts"],
|
||||
"scripts/e2e/lib/package-compat.mjs": [
|
||||
"test/scripts/direct-run-entrypoints.test.ts",
|
||||
"test/scripts/docker-build-helper.test.ts",
|
||||
],
|
||||
"scripts/e2e/agents-delete-shared-workspace-docker.sh": [
|
||||
"test/scripts/docker-e2e-plan.test.ts",
|
||||
"src/scripts/ci-changed-scope.test.ts",
|
||||
@@ -1700,7 +1703,10 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
"src/plugins/recommended-tool-installs.test.ts",
|
||||
"test/release-check.test.ts",
|
||||
],
|
||||
"scripts/lib/direct-run.mjs": ["test/scripts/changed-lanes.test.ts"],
|
||||
"scripts/lib/direct-run.mjs": [
|
||||
"test/scripts/changed-lanes.test.ts",
|
||||
"test/scripts/direct-run-entrypoints.test.ts",
|
||||
],
|
||||
"scripts/lib/npm-verify-exec.ts": ["test/scripts/npm-verify-exec.test.ts"],
|
||||
"scripts/lib/plugin-npm-runtime-build.mjs": [
|
||||
"test/scripts/plugin-npm-runtime-build-args.test.ts",
|
||||
@@ -1921,6 +1927,7 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
],
|
||||
"scripts/plan-release-workflow-matrix.mjs": [
|
||||
"test/scripts/release-workflow-matrix-plan.test.ts",
|
||||
"test/scripts/direct-run-entrypoints.test.ts",
|
||||
],
|
||||
"scripts/release-verify-beta.ts": ["test/scripts/release-wrapper-scripts.test.ts"],
|
||||
"scripts/validate-release-publish-approval.mjs": [
|
||||
|
||||
Reference in New Issue
Block a user