mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-13 23:36:58 +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
100
openclaw/test/non-isolated-runner.ts
Normal file
100
openclaw/test/non-isolated-runner.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { TestRunner, type RunnerTestSuite, vi } from "vitest";
|
||||
|
||||
type EvaluatedModuleNode = {
|
||||
promise?: unknown;
|
||||
exports?: unknown;
|
||||
evaluated?: boolean;
|
||||
importers: Set<string>;
|
||||
};
|
||||
|
||||
type EvaluatedModules = {
|
||||
idToModuleMap: Map<string, EvaluatedModuleNode>;
|
||||
};
|
||||
|
||||
const SHARED_TEST_SETUP = Symbol.for("openclaw.sharedTestSetup");
|
||||
|
||||
function getSharedTestHome(): string | undefined {
|
||||
const globalState = globalThis as typeof globalThis & {
|
||||
[SHARED_TEST_SETUP]?: { tempHome?: string };
|
||||
};
|
||||
return globalState[SHARED_TEST_SETUP]?.tempHome ?? process.env.OPENCLAW_TEST_HOME;
|
||||
}
|
||||
|
||||
function resetEvaluatedModules(modules: EvaluatedModules, resetMocks: boolean) {
|
||||
const skipPaths = [
|
||||
/\/vitest\/dist\//,
|
||||
/vitest-virtual-\w+\/dist/u,
|
||||
/@vitest\/dist/u,
|
||||
...(resetMocks ? [] : [/^mock:/u]),
|
||||
];
|
||||
|
||||
modules.idToModuleMap.forEach((node, modulePath) => {
|
||||
if (skipPaths.some((pattern) => pattern.test(modulePath))) {
|
||||
return;
|
||||
}
|
||||
node.promise = undefined;
|
||||
node.exports = undefined;
|
||||
node.evaluated = false;
|
||||
node.importers.clear();
|
||||
});
|
||||
}
|
||||
|
||||
function restoreSharedTestHomeAfterEnvUnstub(testHomeRaw: string | undefined): void {
|
||||
const testHome = testHomeRaw?.trim();
|
||||
if (!testHome) {
|
||||
return;
|
||||
}
|
||||
|
||||
process.env.HOME = testHome;
|
||||
process.env.USERPROFILE = testHome;
|
||||
process.env.OPENCLAW_TEST_HOME = testHome;
|
||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
delete process.env.OPENCLAW_AGENT_DIR;
|
||||
delete process.env.PI_CODING_AGENT_DIR;
|
||||
process.env.XDG_CONFIG_HOME = path.join(testHome, ".config");
|
||||
process.env.XDG_DATA_HOME = path.join(testHome, ".local", "share");
|
||||
process.env.XDG_STATE_HOME = path.join(testHome, ".local", "state");
|
||||
process.env.XDG_CACHE_HOME = path.join(testHome, ".cache");
|
||||
}
|
||||
|
||||
export default class OpenClawNonIsolatedRunner extends TestRunner {
|
||||
override onCollectStart(file: { filepath: string }) {
|
||||
super.onCollectStart(file);
|
||||
restoreSharedTestHomeAfterEnvUnstub(getSharedTestHome());
|
||||
const orderLogPath = process.env.OPENCLAW_VITEST_FILE_ORDER_LOG?.trim();
|
||||
if (orderLogPath) {
|
||||
fs.appendFileSync(orderLogPath, `START ${file.filepath}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
override async onAfterRunSuite(suite: RunnerTestSuite) {
|
||||
await super.onAfterRunSuite(suite);
|
||||
if (this.config.isolate || !("filepath" in suite) || typeof suite.filepath !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
const orderLogPath = process.env.OPENCLAW_VITEST_FILE_ORDER_LOG?.trim();
|
||||
if (orderLogPath) {
|
||||
fs.appendFileSync(orderLogPath, `END ${suite.filepath}\n`);
|
||||
}
|
||||
|
||||
// Mirror the missing cleanup from Vitest isolate mode so shared workers do
|
||||
// not carry file-scoped timers, stubs, spies, or stale module state
|
||||
// forward into the next file.
|
||||
if (vi.isFakeTimers()) {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
const testHome = getSharedTestHome();
|
||||
vi.unstubAllEnvs();
|
||||
restoreSharedTestHomeAfterEnvUnstub(testHome);
|
||||
vi.clearAllMocks();
|
||||
vi.resetModules();
|
||||
this.moduleRunner?.mocker?.reset?.();
|
||||
resetEvaluatedModules(this.workerState.evaluatedModules as EvaluatedModules, true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue