@@ -5,6 +5,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
55import { createServer , type AddressInfo , type Socket } from "node:net" ;
66import { tmpdir } from "node:os" ;
77import path from "node:path" ;
8+ import { pathToFileURL } from "node:url" ;
89import { afterEach , describe , expect , it } from "vitest" ;
910import { WebSocket } from "ws" ;
1011import {
@@ -16,6 +17,8 @@ import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
1617
1718const ASSERTIONS_SCRIPT = "scripts/e2e/lib/release-user-journey/assertions.mjs" ;
1819const 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" ;
1922const DISABLE_EXPERIMENTAL_WARNING = "--disable-warning=ExperimentalWarning" ;
2023const 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