@@ -23,6 +23,7 @@ import { buildSkillWorkshopMocks } from "./control-ui-mock-skill-workshop.js";
2323
2424type CliOptions = {
2525 allowedHosts : string [ ] ;
26+ fixture ?: "board" ;
2627 host : string ;
2728 port : number ;
2829} ;
@@ -40,6 +41,30 @@ const TOTAL_TELEGRAM_SESSIONS = 180;
4041
4142const repoRoot = path . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , ".." ) ;
4243const uiRoot = path . join ( repoRoot , "ui" ) ;
44+ const boardFixturePath = "/__fixtures/board/" ;
45+ const boardFixtureHtml = `<!doctype html>
46+ <html lang="en">
47+ <head>
48+ <meta charset="UTF-8" />
49+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
50+ <title>OpenClaw Board Fixture</title>
51+ <link rel="stylesheet" href="/src/styles.css" />
52+ <style>
53+ body { margin: 0; min-width: 320px; min-height: 100vh; background: #0f1115; }
54+ .board-fixture-shell { box-sizing: border-box; margin: 0 auto; max-width: 1440px; padding: 36px; }
55+ .board-fixture-header { align-items: end; display: flex; justify-content: space-between; margin-bottom: 24px; }
56+ .board-fixture-header span { color: #747e8d; font: 10px ui-monospace, monospace; letter-spacing: .15em; }
57+ .board-fixture-header h1 { color: #e5e7eb; font-size: 24px; letter-spacing: -.03em; margin: 5px 0 0; }
58+ .board-fixture-status { color: #8892a0; font: 11px ui-monospace, monospace; }
59+ .board-fixture-status i { background: #4ec9a8; border-radius: 50%; display: inline-block; height: 7px; margin-right: 6px; width: 7px; }
60+ @media (max-width: 700px) { .board-fixture-shell { padding: 18px; } }
61+ </style>
62+ </head>
63+ <body>
64+ <div id="app"></div>
65+ <script type="module" src="/src/test-helpers/board-fixture.ts"></script>
66+ </body>
67+ </html>` ;
4368
4469function mockFileHash ( value : string ) : string {
4570 return createHash ( "sha256" ) . update ( value , "utf8" ) . digest ( "hex" ) ;
@@ -63,6 +88,10 @@ function parseArgs(args: string[]): CliOptions {
6388 options . host = args [ ++ i ] ?? options . host ;
6489 } else if ( arg . startsWith ( "--host=" ) ) {
6590 options . host = arg . slice ( "--host=" . length ) || options . host ;
91+ } else if ( arg === "--fixture" ) {
92+ options . fixture = parseFixture ( args [ ++ i ] ) ;
93+ } else if ( arg . startsWith ( "--fixture=" ) ) {
94+ options . fixture = parseFixture ( arg . slice ( "--fixture=" . length ) ) ;
6695 } else if ( arg === "--port" ) {
6796 options . port = parsePort ( args [ ++ i ] , options . port ) ;
6897 } else if ( arg . startsWith ( "--port=" ) ) {
@@ -72,6 +101,16 @@ function parseArgs(args: string[]): CliOptions {
72101 return options ;
73102}
74103
104+ function parseFixture ( value : string | undefined ) : "board" | undefined {
105+ if ( ! value ) {
106+ return undefined ;
107+ }
108+ if ( value !== "board" ) {
109+ throw new Error ( `Unknown Control UI mock fixture: ${ value } ` ) ;
110+ }
111+ return value ;
112+ }
113+
75114function parsePort ( value : string | undefined , fallback : number ) : number {
76115 const parsed = Number ( value ) ;
77116 return Number . isInteger ( parsed ) && parsed > 0 && parsed < 65_536 ? parsed : fallback ;
@@ -1421,18 +1460,42 @@ function createMockGatewayPlugin(scenario: ControlUiMockGatewayScenario): Plugin
14211460 } ;
14221461}
14231462
1463+ function createBoardFixturePlugin ( ) : Plugin {
1464+ return {
1465+ name : "openclaw-control-ui-board-fixture" ,
1466+ configureServer ( server ) {
1467+ server . middlewares . use ( boardFixturePath , ( _req , res , next ) => {
1468+ void server
1469+ . transformIndexHtml ( boardFixturePath , boardFixtureHtml )
1470+ . then ( ( html ) => {
1471+ res . statusCode = 200 ;
1472+ res . setHeader ( "content-type" , "text/html; charset=utf-8" ) ;
1473+ res . end ( html ) ;
1474+ } )
1475+ . catch ( ( error : unknown ) => {
1476+ next ( error as Error ) ;
1477+ } ) ;
1478+ } ) ;
1479+ } ,
1480+ } ;
1481+ }
1482+
14241483function hostForUrl ( boundAddress : string , requestedHost : string ) : string {
14251484 const host = boundAddress === "0.0.0.0" || boundAddress === "::" ? requestedHost : boundAddress ;
14261485 const reachableHost = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host ;
14271486 return reachableHost . includes ( ":" ) ? `[${ reachableHost } ]` : reachableHost ;
14281487}
14291488
1430- function resolveServerUrl ( server : ViteDevServer , requestedHost : string ) : string {
1489+ function resolveServerUrl (
1490+ server : ViteDevServer ,
1491+ requestedHost : string ,
1492+ pathname = "/chat" ,
1493+ ) : string {
14311494 const address = server . httpServer ?. address ( ) ;
14321495 if ( ! address || typeof address === "string" ) {
14331496 throw new Error ( "Control UI mock server did not expose a TCP port" ) ;
14341497 }
1435- return `http://${ hostForUrl ( address . address , requestedHost ) } :${ address . port } /chat ` ;
1498+ return `http://${ hostForUrl ( address . address , requestedHost ) } :${ address . port } ${ pathname } ` ;
14361499}
14371500
14381501async function waitForShutdown ( ) : Promise < void > {
@@ -1459,9 +1522,12 @@ const server = await createServer({
14591522 } ,
14601523 logLevel : "error" ,
14611524 optimizeDeps : {
1525+ ...( options . fixture === "board"
1526+ ? { entries : [ path . join ( uiRoot , "src" , "test-helpers" , "board-fixture.ts" ) ] }
1527+ : { } ) ,
14621528 include : [ "lit/directives/repeat.js" ] ,
14631529 } ,
1464- plugins : [ createMockGatewayPlugin ( scenario ) ] ,
1530+ plugins : [ createMockGatewayPlugin ( scenario ) , createBoardFixturePlugin ( ) ] ,
14651531 publicDir : path . join ( uiRoot , "public" ) ,
14661532 resolve : {
14671533 alias : [
@@ -1481,5 +1547,8 @@ const server = await createServer({
14811547
14821548await server . listen ( ) ;
14831549console . log ( `[control-ui-mock] ${ resolveServerUrl ( server , options . host ) } ` ) ;
1550+ console . log (
1551+ `[control-ui-mock] board fixture: ${ resolveServerUrl ( server , options . host , boardFixturePath ) } ` ,
1552+ ) ;
14841553await waitForShutdown ( ) ;
14851554await server . close ( ) ;
0 commit comments