test: consolidate OpenClaw test state fixtures (#113576)

* test: consolidate OpenClaw test state fixtures

* test(plugin-sdk): expose isolated test state

Promote the isolated OpenClaw test-state lifecycle through a narrow published Plugin SDK subpath so extension tests no longer import private core helpers. This intentional SDK surface addition is maintainer-approved.

* test: use SDK test-state seam in extensions

Route bundled extension suites through the focused repo-local Plugin SDK test-state entrypoint and remove the Codex projector harness exports made stale by fixture consolidation. Keep the seam out of production builds and published package artifacts while auditing its real consumers in the full-tree deadcode scan.

* test(plugins): map test-state in package boundaries
This commit is contained in:
Peter Steinberger
2026-07-25 05:30:52 -07:00
committed by GitHub
parent 3d1369ff4f
commit 332006bc1f
26 changed files with 285 additions and 378 deletions

View File

@@ -1,5 +1,4 @@
// Run context lifecycle contract tests cover plugin run context setup and cleanup.
import fs from "node:fs/promises";
import path from "node:path";
import {
createPluginRegistryFixture,
@@ -8,8 +7,8 @@ import {
import { afterEach, describe, expect, it, vi } from "vitest";
import { withTempConfig } from "../../gateway/test-temp-config.js";
import { emitAgentEvent, resetAgentEventsForTest } from "../../infra/agent-events.js";
import { resolvePreferredOpenClawTmpDir } from "../../infra/tmp-openclaw-dir.js";
import { loadSessionStore, updateSessionStore } from "../../plugin-sdk/session-store-runtime.js";
import { createOpenClawTestState } from "../../test-utils/openclaw-test-state.js";
import { runPluginHostCleanup } from "../host-hook-cleanup.js";
import {
clearPluginHostRuntimeState,
@@ -686,16 +685,16 @@ describe("plugin run context lifecycle", () => {
},
});
const stateDir = await fs.mkdtemp(
path.join(resolvePreferredOpenClawTmpDir(), "openclaw-run-context-restart-state-"),
);
const openClawState = await createOpenClawTestState({
layout: "state-only",
prefix: "openclaw-run-context-restart-state-",
});
const stateDir = openClawState.stateDir;
const storePath = path.join(stateDir, "sessions.json");
const tempConfig = {
session: { store: storePath },
};
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
try {
process.env.OPENCLAW_STATE_DIR = stateDir;
await withTempConfig({
cfg: tempConfig,
run: async () => {
@@ -748,12 +747,7 @@ describe("plugin run context lifecycle", () => {
},
});
} finally {
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
await fs.rm(stateDir, { recursive: true, force: true });
await openClawState.cleanup();
}
});