mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 04:00:44 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
121
openclaw/test/scripts/test-report-utils.test.ts
Normal file
121
openclaw/test/scripts/test-report-utils.test.ts
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
collectVitestFileDurations,
|
||||
normalizeTrackedRepoPath,
|
||||
tryReadJsonFile,
|
||||
} from "../../scripts/test-report-utils.mjs";
|
||||
|
||||
const { spawnSyncMock } = vi.hoisted(() => ({
|
||||
spawnSyncMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("node:child_process", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
|
||||
return {
|
||||
...actual,
|
||||
spawnSync: spawnSyncMock,
|
||||
};
|
||||
});
|
||||
|
||||
describe("scripts/test-report-utils normalizeTrackedRepoPath", () => {
|
||||
it("normalizes repo-local absolute paths to repo-relative slash paths", () => {
|
||||
const absoluteFile = path.join(process.cwd(), "src", "tools", "example.test.ts");
|
||||
|
||||
expect(normalizeTrackedRepoPath(absoluteFile)).toBe("src/tools/example.test.ts");
|
||||
});
|
||||
|
||||
it("preserves external absolute paths as normalized absolute paths", () => {
|
||||
const externalFile = path.join(path.parse(process.cwd()).root, "tmp", "outside.test.ts");
|
||||
|
||||
expect(normalizeTrackedRepoPath(externalFile)).toBe(externalFile.split(path.sep).join("/"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/test-report-utils collectVitestFileDurations", () => {
|
||||
it("extracts per-file durations and applies file normalization", () => {
|
||||
const report = {
|
||||
testResults: [
|
||||
{
|
||||
name: path.join(process.cwd(), "src", "alpha.test.ts"),
|
||||
startTime: 100,
|
||||
endTime: 460,
|
||||
assertionResults: [{}, {}],
|
||||
},
|
||||
{
|
||||
name: "src/zero.test.ts",
|
||||
startTime: 300,
|
||||
endTime: 300,
|
||||
assertionResults: [{}],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(collectVitestFileDurations(report, normalizeTrackedRepoPath)).toEqual([
|
||||
{
|
||||
file: "src/alpha.test.ts",
|
||||
durationMs: 360,
|
||||
testCount: 2,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/test-report-utils tryReadJsonFile", () => {
|
||||
it("returns the fallback when the file is missing", () => {
|
||||
const missingPath = path.join(os.tmpdir(), `openclaw-missing-${Date.now()}.json`);
|
||||
|
||||
expect(tryReadJsonFile(missingPath, { ok: true })).toEqual({ ok: true });
|
||||
});
|
||||
|
||||
it("reads valid JSON files", () => {
|
||||
const tempPath = path.join(os.tmpdir(), `openclaw-json-${Date.now()}.json`);
|
||||
fs.writeFileSync(tempPath, JSON.stringify({ ok: true }));
|
||||
|
||||
try {
|
||||
expect(tryReadJsonFile(tempPath, null)).toEqual({ ok: true });
|
||||
} finally {
|
||||
fs.unlinkSync(tempPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/test-report-utils runVitestJsonReport", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
spawnSyncMock.mockReset();
|
||||
});
|
||||
|
||||
it("launches Vitest through pnpm exec", async () => {
|
||||
spawnSyncMock.mockReturnValue({ status: 0 });
|
||||
const reportPath = path.join(os.tmpdir(), `openclaw-vitest-json-${Date.now()}.json`);
|
||||
const { runVitestJsonReport } = await import("../../scripts/test-report-utils.mjs");
|
||||
|
||||
expect(
|
||||
runVitestJsonReport({
|
||||
config: "test/vitest/vitest.unit.config.ts",
|
||||
reportPath,
|
||||
}),
|
||||
).toBe(reportPath);
|
||||
|
||||
expect(spawnSyncMock).toHaveBeenCalledWith(
|
||||
"pnpm",
|
||||
[
|
||||
"exec",
|
||||
"vitest",
|
||||
"run",
|
||||
"--config",
|
||||
"test/vitest/vitest.unit.config.ts",
|
||||
"--reporter=json",
|
||||
"--outputFile",
|
||||
reportPath,
|
||||
],
|
||||
expect.objectContaining({
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue