mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 16:43:43 +00:00
test(ci): add changed-scope shell-injection regression
This commit is contained in:
@@ -1,14 +1,29 @@
|
|||||||
import { createRequire } from "node:module";
|
import fs from "node:fs";
|
||||||
import { describe, expect, it } from "vitest";
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
const { detectChangedScope } = (await import("../../scripts/ci-changed-scope.mjs")) as unknown as {
|
const { detectChangedScope, listChangedPaths } =
|
||||||
detectChangedScope: (paths: string[]) => {
|
(await import("../../scripts/ci-changed-scope.mjs")) as unknown as {
|
||||||
runNode: boolean;
|
detectChangedScope: (paths: string[]) => {
|
||||||
runMacos: boolean;
|
runNode: boolean;
|
||||||
runAndroid: boolean;
|
runMacos: boolean;
|
||||||
runWindows: boolean;
|
runAndroid: boolean;
|
||||||
|
runWindows: boolean;
|
||||||
|
};
|
||||||
|
listChangedPaths: (base: string, head?: string) => string[];
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
const markerPaths: string[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const markerPath of markerPaths) {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(markerPath);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
markerPaths.length = 0;
|
||||||
|
});
|
||||||
|
|
||||||
describe("detectChangedScope", () => {
|
describe("detectChangedScope", () => {
|
||||||
it("fails safe when no paths are provided", () => {
|
it("fails safe when no paths are provided", () => {
|
||||||
@@ -88,4 +103,20 @@ describe("detectChangedScope", () => {
|
|||||||
runWindows: false,
|
runWindows: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("treats base and head as literal git args", () => {
|
||||||
|
const markerPath = path.join(
|
||||||
|
os.tmpdir(),
|
||||||
|
`openclaw-ci-changed-scope-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp`,
|
||||||
|
);
|
||||||
|
markerPaths.push(markerPath);
|
||||||
|
|
||||||
|
const injectedBase =
|
||||||
|
process.platform === "win32"
|
||||||
|
? `HEAD & echo injected > "${markerPath}" & rem`
|
||||||
|
: `HEAD; touch "${markerPath}" #`;
|
||||||
|
|
||||||
|
expect(() => listChangedPaths(injectedBase, "HEAD")).toThrow();
|
||||||
|
expect(fs.existsSync(markerPath)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user