Skip to content

Commit 46f15e4

Browse files
committed
test(release): preserve fixture runtime status
1 parent 2a733a1 commit 46f15e4

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎scripts/e2e/lib/release-user-journey/write-clickclack-plugin.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,15 @@ const clickclackPlugin = {
362362
label: snapshot.configured ? "configured" : "missing config",
363363
detail: snapshot.baseUrl ?? "",
364364
}),
365-
buildAccountSnapshot: ({ account }) => ({
365+
buildAccountSnapshot: ({ account, runtime }) => ({
366366
accountId: account.accountId,
367367
enabled: account.enabled,
368368
configured: account.configured,
369369
baseUrl: account.baseUrl,
370+
running: runtime?.running ?? false,
371+
lastStartAt: runtime?.lastStartAt ?? null,
372+
lastStopAt: runtime?.lastStopAt ?? null,
373+
lastError: runtime?.lastError ?? null,
370374
}),
371375
},
372376
outbound: {

‎test/scripts/release-user-journey-assertions.test.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
55
import { createServer, type AddressInfo, type Socket } from "node:net";
66
import { tmpdir } from "node:os";
77
import path from "node:path";
8+
import { pathToFileURL } from "node:url";
89
import { afterEach, describe, expect, it } from "vitest";
910
import { WebSocket } from "ws";
1011
import {
@@ -16,6 +17,8 @@ import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
1617

1718
const ASSERTIONS_SCRIPT = "scripts/e2e/lib/release-user-journey/assertions.mjs";
1819
const CLICKCLACK_FIXTURE_SCRIPT = "scripts/e2e/lib/release-user-journey/clickclack-fixture.mjs";
20+
const CLICKCLACK_PLUGIN_WRITER_SCRIPT =
21+
"scripts/e2e/lib/release-user-journey/write-clickclack-plugin.mjs";
1922
const DISABLE_EXPERIMENTAL_WARNING = "--disable-warning=ExperimentalWarning";
2023
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
2124

@@ -418,6 +421,72 @@ describe("release user journey assertions", () => {
418421
}
419422
});
420423

424+
it("preserves runtime state in generated ClickClack status snapshots", async () => {
425+
type GeneratedClickClackPlugin = {
426+
status: {
427+
buildAccountSnapshot: (params: {
428+
account: { accountId: string; enabled: boolean; configured: boolean; baseUrl: string };
429+
runtime?: {
430+
running?: boolean;
431+
lastStartAt?: number;
432+
lastStopAt?: number;
433+
lastError?: string;
434+
};
435+
}) => Record<string, unknown>;
436+
};
437+
};
438+
439+
const pluginDir = path.join(tempDirs.make("openclaw-release-clickclack-plugin-"), "plugin");
440+
const writer = spawnSync(process.execPath, [CLICKCLACK_PLUGIN_WRITER_SCRIPT, pluginDir], {
441+
encoding: "utf8",
442+
});
443+
expect(writer.status, writer.stderr).toBe(0);
444+
445+
const generatedModule = (await import(
446+
pathToFileURL(path.join(pluginDir, "index.mjs")).href
447+
)) as {
448+
default: {
449+
register: (api: {
450+
registerChannel: (registration: { plugin: GeneratedClickClackPlugin }) => void;
451+
}) => void;
452+
};
453+
};
454+
let plugin: GeneratedClickClackPlugin | undefined;
455+
generatedModule.default.register({
456+
registerChannel: (registration) => {
457+
plugin = registration.plugin;
458+
},
459+
});
460+
if (!plugin) {
461+
throw new Error("generated ClickClack plugin did not register its channel");
462+
}
463+
464+
expect(
465+
plugin.status.buildAccountSnapshot({
466+
account: {
467+
accountId: "default",
468+
enabled: true,
469+
configured: true,
470+
baseUrl: "http://127.0.0.1:1234",
471+
},
472+
runtime: {
473+
running: true,
474+
lastStartAt: 123,
475+
lastStopAt: 45,
476+
lastError: "prior disconnect",
477+
},
478+
}),
479+
).toMatchObject({
480+
accountId: "default",
481+
configured: true,
482+
enabled: true,
483+
running: true,
484+
lastStartAt: 123,
485+
lastStopAt: 45,
486+
lastError: "prior disconnect",
487+
});
488+
});
489+
421490
it("cancels successful ClickClack inbound response bodies", async () => {
422491
const root = mkdtempSync(path.join(tmpdir(), "openclaw-release-user-assertions-"));
423492
const home = path.join(root, "home");

0 commit comments

Comments
 (0)