mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fa03d9b913
* refactor: consolidate coercion helpers * fix: remove duplicate coercion imports * fix: preserve serialized coercion guard * chore: ratchet coercion helper carve-outs * fix(test): keep gauntlet subprocess startup lean * fix: preserve imported session timestamp semantics * fix: preserve catalog timestamp string semantics * chore: align plugin SDK surface ratchet * fix: preserve trajectory and SDK string contracts * fix(test): preserve QA record assertion semantics * fix: complete standalone record guard rename * refactor(cron): use canonical string coercion * fix(acpx): preserve Pi timestamp parsing * test(channels): adapt custody test harnesses * test(telegram): classify media harness as test support * test(acpx): split timestamp contract coverage * test(channels): support generated custody contracts * chore: ban the full coercion helper name set Extends the declaration guard to all eleven consolidated helper names and renames the cron schedule-identity readNumber wrapper to readScheduleInteger so the banned generic name cannot regrow. * fix(scripts): repair release-validation guard drift and lint cause Restores the renamed isJsonRecord guard in assertTrustedWorkflowHarness after main added isRecord call sites in parallel, and attaches the caught YAML error as the thrown error cause (preserve-caught-error was red on main). * fix: preserve Claude timestamp string semantics * fix: preserve persisted timestamp string semantics * fix: preserve date-first timestamp contracts * fix(openai): harden delegation failure formatting * chore: close coercion helper guard gaps * test(openai): model non-error delegation rejection * chore: refresh plugin SDK API contract * fix(tasks): use canonical string field reader * fix(ai): use canonical provider error field coercion * fix(browser): migrate native bootstrap coercion * docs(plugin-sdk): clarify text record export compatibility * fix(gateway): normalize approval execution identity * test(outbound): isolate message action poll harness
118 lines
4.2 KiB
TypeScript
118 lines
4.2 KiB
TypeScript
// Check File Utils tests cover check file utils script behavior.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
collectFilesSync,
|
|
isCodeFile,
|
|
listRepoFilesSync,
|
|
relativeToCwd,
|
|
toPosixPath,
|
|
} from "../../scripts/check-file-utils.js";
|
|
import { createScriptTestHarness } from "./test-helpers.js";
|
|
|
|
const execFileSyncMock = vi.hoisted(() => vi.fn(() => ""));
|
|
|
|
vi.mock("node:child_process", async (importOriginal) => {
|
|
const original = (await importOriginal()) as typeof import("node:child_process");
|
|
return { ...original, execFileSync: execFileSyncMock };
|
|
});
|
|
|
|
const { createTempDir } = createScriptTestHarness();
|
|
|
|
describe("scripts/check-file-utils isCodeFile", () => {
|
|
it("accepts source files and skips declarations", () => {
|
|
expect(isCodeFile("example.ts")).toBe(true);
|
|
expect(isCodeFile("example.mjs")).toBe(true);
|
|
expect(isCodeFile("example.d.ts")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("scripts/check-file-utils collectFilesSync", () => {
|
|
it("collects matching files while skipping common generated dirs", () => {
|
|
const rootDir = createTempDir("openclaw-check-file-utils-");
|
|
fs.mkdirSync(path.join(rootDir, "src", "nested"), { recursive: true });
|
|
fs.mkdirSync(path.join(rootDir, "dist"), { recursive: true });
|
|
fs.mkdirSync(path.join(rootDir, "docs", ".generated"), { recursive: true });
|
|
fs.writeFileSync(path.join(rootDir, "src", "keep.ts"), "");
|
|
fs.writeFileSync(path.join(rootDir, "src", "nested", "keep.test.ts"), "");
|
|
fs.writeFileSync(path.join(rootDir, "dist", "skip.ts"), "");
|
|
fs.writeFileSync(path.join(rootDir, "docs", ".generated", "skip.ts"), "");
|
|
|
|
const files = collectFilesSync(rootDir, {
|
|
includeFile: (filePath) => filePath.endsWith(".ts"),
|
|
}).map((filePath) => toPosixPath(path.relative(rootDir, filePath)));
|
|
|
|
expect(files.toSorted((left, right) => left.localeCompare(right))).toEqual([
|
|
"src/keep.ts",
|
|
"src/nested/keep.test.ts",
|
|
]);
|
|
});
|
|
|
|
it("supports custom skipped directories", () => {
|
|
const rootDir = createTempDir("openclaw-check-file-utils-");
|
|
fs.mkdirSync(path.join(rootDir, "fixtures"), { recursive: true });
|
|
fs.mkdirSync(path.join(rootDir, "src"), { recursive: true });
|
|
fs.writeFileSync(path.join(rootDir, "fixtures", "skip.ts"), "");
|
|
fs.writeFileSync(path.join(rootDir, "src", "keep.ts"), "");
|
|
|
|
const files = collectFilesSync(rootDir, {
|
|
includeFile: (filePath) => filePath.endsWith(".ts"),
|
|
skipDirNames: new Set(["fixtures"]),
|
|
}).map((filePath) => toPosixPath(path.relative(rootDir, filePath)));
|
|
|
|
expect(files).toEqual(["src/keep.ts"]);
|
|
});
|
|
});
|
|
|
|
describe("scripts/check-file-utils relativeToCwd", () => {
|
|
it("renders repo-relative paths when possible", () => {
|
|
expect(relativeToCwd(path.join(process.cwd(), "scripts", "check-file-utils.ts"))).toBe(
|
|
"scripts/check-file-utils.ts",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("scripts/check-file-utils listRepoFilesSync", () => {
|
|
afterEach(() => {
|
|
execFileSyncMock.mockReset();
|
|
});
|
|
|
|
it("bounds git ls-files with a timeout and kill signal", () => {
|
|
execFileSyncMock.mockReturnValue("src/keep.ts\nsrc/skip.d.ts\n");
|
|
|
|
expect(
|
|
listRepoFilesSync("/fake/repo", {
|
|
includeFile: (filePath) => isCodeFile(filePath),
|
|
}),
|
|
).toEqual(["src/keep.ts"]);
|
|
expect(execFileSyncMock).toHaveBeenCalledWith(
|
|
"git",
|
|
expect.arrayContaining(["-C", "/fake/repo", "ls-files", "--"]),
|
|
expect.objectContaining({
|
|
timeout: 30_000,
|
|
killSignal: "SIGKILL",
|
|
maxBuffer: 64 * 1024 * 1024,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("falls back to filesystem traversal when git ls-files times out", () => {
|
|
const error: NodeJS.ErrnoException & { signal?: string } = new Error("Command timed out");
|
|
error.code = "ETIMEDOUT";
|
|
error.signal = "SIGKILL";
|
|
execFileSyncMock.mockImplementation(() => {
|
|
throw error;
|
|
});
|
|
const rootDir = createTempDir("openclaw-check-file-utils-fallback-");
|
|
fs.mkdirSync(path.join(rootDir, "src"), { recursive: true });
|
|
fs.writeFileSync(path.join(rootDir, "src", "keep.ts"), "");
|
|
|
|
expect(
|
|
listRepoFilesSync(rootDir, {
|
|
includeFile: (filePath) => filePath.endsWith(".ts"),
|
|
}),
|
|
).toEqual(["src/keep.ts"]);
|
|
});
|
|
});
|