mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
test(runner): delete duplicate SQLite replay (#121983)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
committed by
GitHub
parent
1ec893a80a
commit
fba9a094db
@@ -377,89 +377,3 @@ it("clears agent run registry state between files", async () => {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("disposes embedded-agent SQLite state before running the next file", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-sqlite-lifecycle-runner-"));
|
||||
const orderLogPath = path.join(root, "order.log");
|
||||
const forceClearPath = path.join(
|
||||
repoRoot,
|
||||
"src",
|
||||
"agents",
|
||||
"embedded-agent-runner",
|
||||
"runs.force-clear-terminal.test.ts",
|
||||
);
|
||||
const persistencePath = path.join(
|
||||
repoRoot,
|
||||
"src",
|
||||
"agents",
|
||||
"embedded-agent-runner",
|
||||
"runs.persistence.test.ts",
|
||||
);
|
||||
try {
|
||||
const embeddedConfigPath = JSON.stringify(
|
||||
path.join(repoRoot, "test", "vitest", "vitest.agents-embedded-agent.config.ts"),
|
||||
);
|
||||
await fs.symlink(
|
||||
path.join(repoRoot, "node_modules"),
|
||||
path.join(root, "node_modules"),
|
||||
"junction",
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(root, "vitest.config.ts"),
|
||||
[
|
||||
`import { createAgentsEmbeddedVitestConfig } from ${embeddedConfigPath};`,
|
||||
'import { BaseSequencer } from "vitest/node";',
|
||||
"class AlphabeticalSequencer extends BaseSequencer {",
|
||||
' override async sort(files: Parameters<BaseSequencer["sort"]>[0]) {',
|
||||
" return [...files].sort((a, b) => a.moduleId.localeCompare(b.moduleId));",
|
||||
" }",
|
||||
"}",
|
||||
"const base = createAgentsEmbeddedVitestConfig();",
|
||||
"export default {",
|
||||
" ...base,",
|
||||
` cacheDir: ${JSON.stringify(path.join(root, ".vite"))},`,
|
||||
" test: {",
|
||||
" ...base.test,",
|
||||
" exclude: [],",
|
||||
" isolate: false,",
|
||||
" fileParallelism: false,",
|
||||
" maxWorkers: 1,",
|
||||
" sequence: { ...base.test?.sequence, sequencer: AlphabeticalSequencer },",
|
||||
" },",
|
||||
"};",
|
||||
"",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const vitestEntry = path.join(repoRoot, "node_modules", "vitest", "vitest.mjs");
|
||||
const result = await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
vitestEntry,
|
||||
"run",
|
||||
"src/agents/embedded-agent-runner/runs.force-clear-terminal.test.ts",
|
||||
"src/agents/embedded-agent-runner/runs.persistence.test.ts",
|
||||
"--config",
|
||||
path.join(root, "vitest.config.ts"),
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
env: { ...childEnv(), OPENCLAW_VITEST_FILE_ORDER_LOG: orderLogPath },
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
expect(`${result.stdout}\n${result.stderr}`).toMatch(/Test Files\s+2 passed \(2\)/u);
|
||||
await expect(fs.readFile(orderLogPath, "utf8")).resolves.toBe(
|
||||
[
|
||||
`START ${forceClearPath}`,
|
||||
`END ${forceClearPath}`,
|
||||
`START ${persistencePath}`,
|
||||
`END ${persistencePath}`,
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Non-isolated runner helps execute tests without Vitest isolation.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { TestRunner, type RunnerTask, type RunnerTestFile, vi } from "vitest";
|
||||
import { resetAgentEventsForTest } from "../src/infra/agent-events.js";
|
||||
@@ -327,10 +326,6 @@ export default class OpenClawNonIsolatedRunner extends TestRunner {
|
||||
restoreRealTimers();
|
||||
restoreNativeTimerGlobals();
|
||||
restoreSharedTestHomeAfterEnvUnstub(getSharedTestHome());
|
||||
const orderLogPath = process.env.OPENCLAW_VITEST_FILE_ORDER_LOG?.trim();
|
||||
if (orderLogPath) {
|
||||
fs.appendFileSync(orderLogPath, `START ${file.filepath}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
override async onBeforeRunTask(test: RunnerTask) {
|
||||
@@ -352,19 +347,12 @@ export default class OpenClawNonIsolatedRunner extends TestRunner {
|
||||
// the next file's vi.mock factories silently never applied. The worker loop
|
||||
// calls startTests per file, so this hook runs after every file regardless
|
||||
// of its collect/run outcome.
|
||||
override onAfterRunFiles(files?: RunnerTestFile[]) {
|
||||
override onAfterRunFiles() {
|
||||
super.onAfterRunFiles();
|
||||
if (this.config.isolate) {
|
||||
return;
|
||||
}
|
||||
|
||||
const orderLogPath = process.env.OPENCLAW_VITEST_FILE_ORDER_LOG?.trim();
|
||||
if (orderLogPath) {
|
||||
for (const file of files ?? []) {
|
||||
fs.appendFileSync(orderLogPath, `END ${file.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.
|
||||
|
||||
Reference in New Issue
Block a user