Skip to content

Commit 85611e0

Browse files
steipeteRomneyDa
andauthored
test: keep plugin metadata readers process-stable (#129680)
Co-authored-by: Dallin Romney <[email protected]>
1 parent c07d0e4 commit 85611e0

2 files changed

Lines changed: 2 additions & 90 deletions

File tree

‎test/non-isolated-runner.test.ts‎

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ function fixtureFiles(): Record<string, string> {
5050
const agentEventsPath = JSON.stringify(path.join(repoRoot, "src", "infra", "agent-events.ts"));
5151
const loggingConsolePath = JSON.stringify(path.join(repoRoot, "src", "logging", "console.ts"));
5252
const loggingStatePath = JSON.stringify(path.join(repoRoot, "src", "logging", "state.ts"));
53-
const pluginMetadataStatePath = JSON.stringify(
54-
path.join(repoRoot, "src", "plugins", "current-plugin-metadata-state.ts"),
55-
);
56-
const pluginMetadataRuntimePath = JSON.stringify(
57-
path.join(repoRoot, "src", "plugins", "plugin-metadata-snapshot.runtime.ts"),
58-
);
59-
const pluginMetadataLifecyclePath = JSON.stringify(
60-
path.join(repoRoot, "src", "plugins", "plugin-metadata-lifecycle.ts"),
61-
);
6253

6354
return {
6455
"01-dep.ts": 'export function flavor(): string {\n return "real";\n}\n',
@@ -205,56 +196,6 @@ function fixtureFiles(): Record<string, string> {
205196
"});",
206197
"",
207198
].join("\n"),
208-
"07-a-plugin-metadata.test.ts": [
209-
`import { setCurrentPluginMetadataSnapshotState } from ${pluginMetadataStatePath};`,
210-
`import { getCurrentPluginMetadataSnapshotRuntime, registerPluginMetadataSnapshotReaders } from ${pluginMetadataRuntimePath};`,
211-
`import { registerPluginMetadataProcessMemoLifecycleClear } from ${pluginMetadataLifecyclePath};`,
212-
'import { expect, it } from "vitest";',
213-
'it("seeds process-global plugin metadata readers and their snapshot", () => {',
214-
' const snapshot = { source: "first-file" };',
215-
' const readerKey = Symbol.for("openclaw.pluginMetadataSnapshotReaders");',
216-
' const probeKey = Symbol.for("openclaw.test.pluginMetadataLifecycle");',
217-
" const store = globalThis as Record<PropertyKey, unknown>;",
218-
" const probe = { clears: 0, readers: store[readerKey] };",
219-
" store[probeKey] = probe;",
220-
" registerPluginMetadataProcessMemoLifecycleClear(() => { probe.clears += 1; });",
221-
' setCurrentPluginMetadataSnapshotState(snapshot, "first-file");',
222-
" registerPluginMetadataSnapshotReaders({",
223-
" getCurrentPluginMetadataSnapshot: () => snapshot,",
224-
" resolvePluginMetadataSnapshot: () => snapshot,",
225-
" });",
226-
" expect(getCurrentPluginMetadataSnapshotRuntime({ config: {} })).toBe(snapshot);",
227-
"});",
228-
"",
229-
].join("\n"),
230-
"07-b-plugin-metadata.test.ts": [
231-
`import { getCurrentPluginMetadataSnapshotState } from ${pluginMetadataStatePath};`,
232-
`import { getCurrentPluginMetadataSnapshotRuntime } from ${pluginMetadataRuntimePath};`,
233-
'import { expect, it } from "vitest";',
234-
'it("clears process-global plugin metadata snapshots and reader closures", () => {',
235-
' const readerKey = Symbol.for("openclaw.pluginMetadataSnapshotReaders");',
236-
' const probeKey = Symbol.for("openclaw.test.pluginMetadataLifecycle");',
237-
" const store = globalThis as Record<PropertyKey, unknown>;",
238-
" const probe = store[probeKey] as { clears: number; readers: object };",
239-
" const readers = store[readerKey] as Record<string, unknown>;",
240-
" expect({",
241-
" clears: probe.clears,",
242-
" getterPresent: typeof readers.getCurrentPluginMetadataSnapshot === 'function',",
243-
" resolverPresent: typeof readers.resolvePluginMetadataSnapshot === 'function',",
244-
" readerIdentityRetained: readers === probe.readers,",
245-
" snapshot: getCurrentPluginMetadataSnapshotState().snapshot,",
246-
" readerSnapshot: getCurrentPluginMetadataSnapshotRuntime({ config: {} }),",
247-
" }).toEqual({",
248-
" clears: 1,",
249-
" getterPresent: false,",
250-
" resolverPresent: false,",
251-
" readerIdentityRetained: true,",
252-
" snapshot: undefined,",
253-
" readerSnapshot: undefined,",
254-
" });",
255-
"});",
256-
"",
257-
].join("\n"),
258199
};
259200
}
260201

@@ -310,7 +251,7 @@ it("cleans every shared runner surface between files", async () => {
310251
// The collection failure is intentional. Every behavior test after it must
311252
// pass; any leaked surface turns the summary into a second failure.
312253
expect(output).toContain("synthetic collect failure");
313-
expect(output).toContain("1 failed | 13 passed");
254+
expect(output).toContain("1 failed | 11 passed");
314255
expect(output).not.toContain("first-file");
315256
} finally {
316257
await fs.rm(root, { recursive: true, force: true });

‎test/non-isolated-runner.ts‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { TestRunner, type RunnerTask, type RunnerTestFile, vi } from "vitest";
44
import { resetAgentEventsForTest } from "../src/infra/agent-events.js";
55
import { loggingState } from "../src/logging/state.js";
66
import { clearNamedPluginRuntimeStoresForTest } from "../src/plugin-sdk/runtime-store-registry.js";
7-
import { clearCurrentPluginMetadataSnapshot } from "../src/plugins/current-plugin-metadata-state.js";
8-
import { registerPluginMetadataSnapshotReaders } from "../src/plugins/plugin-metadata-snapshot.runtime.js";
97
import {
108
type CustomElementTracking,
119
dropRepoOwnedCustomElements,
@@ -334,31 +332,6 @@ function resetOpenClawSessionSuspensionState(): void {
334332
api?.resetSessionSuspensionStateForTest?.();
335333
}
336334

337-
function resetOpenClawPluginMetadataState(modules: EvaluatedModules): void {
338-
let clearLifecycle: (() => void) | undefined;
339-
for (const [modulePath, module] of modules.idToModuleMap) {
340-
if (
341-
modulePath.startsWith("mock:") ||
342-
!/\/src\/plugins\/plugin-metadata-lifecycle\.(?:ts|js)(?:\?.*)?$/u.test(modulePath) ||
343-
!module.exports ||
344-
typeof module.exports !== "object"
345-
) {
346-
continue;
347-
}
348-
const clear = Reflect.get(module.exports, "clearPluginMetadataLifecycleCaches");
349-
if (typeof clear === "function") {
350-
clearLifecycle = clear;
351-
}
352-
}
353-
(clearLifecycle ?? clearCurrentPluginMetadataSnapshot)();
354-
355-
// Existing lightweight bridges retain the slot, so reset reader closures in place.
356-
registerPluginMetadataSnapshotReaders({
357-
getCurrentPluginMetadataSnapshot: undefined,
358-
resolvePluginMetadataSnapshot: undefined,
359-
});
360-
}
361-
362335
const SERIALIZED_RESOLVE_MOCKS = Symbol.for("openclaw.serializedResolveMocks");
363336

364337
type SerializedResolveMocksState = {
@@ -500,12 +473,10 @@ export default class OpenClawNonIsolatedRunner extends TestRunner {
500473
// Named plugin runtimes intentionally survive duplicate module evaluation in production.
501474
// Clear their shared slots here so one test file cannot lend a partial runtime to the next.
502475
clearNamedPluginRuntimeStoresForTest();
503-
const evaluatedModules = internals.workerState.evaluatedModules as EvaluatedModules;
504-
resetOpenClawPluginMetadataState(evaluatedModules);
505476
dropTrackedRepoOwnedCustomElements();
506477
resetSharedDocumentBody();
507478
vi.resetModules();
508479
internals.moduleRunner?.mocker?.reset?.();
509-
resetEvaluatedModules(evaluatedModules, true);
480+
resetEvaluatedModules(internals.workerState.evaluatedModules as EvaluatedModules, true);
510481
}
511482
}

0 commit comments

Comments
 (0)