@@ -3,12 +3,13 @@ import { execFileSync } from "node:child_process";
33import fs from "node:fs/promises" ;
44import path from "node:path" ;
55import { resolvePreferredOpenClawTmpDir , withTempWorkspace } from "openclaw/plugin-sdk/temp-path" ;
6- import { describe , expect , it } from "vitest" ;
6+ import { describe , expect , it , vi } from "vitest" ;
77import {
88 compareNormalizedPaths ,
99 getBundleHashRepoInputPaths ,
1010 getLocalRolldownCliCandidates ,
1111 isBundleHashInputPath ,
12+ listTrackedInputFiles ,
1213} from "./bundle-a2ui.mjs" ;
1314
1415describe ( "scripts/bundle-a2ui.mjs" , ( ) => {
@@ -62,43 +63,66 @@ describe("scripts/bundle-a2ui.mjs", () => {
6263 ) ;
6364 } ) ;
6465
66+ it ( "bounds tracked-input discovery and treats a timeout as a fallback" , ( ) => {
67+ const repoRoot = path . resolve ( "repo-root" ) ;
68+ const runGit = vi . fn ( ( ) => ( { status : null , stdout : "" } ) ) ;
69+
70+ expect ( listTrackedInputFiles ( runGit , repoRoot ) ) . toBeNull ( ) ;
71+ expect ( runGit ) . toHaveBeenCalledWith (
72+ "git" ,
73+ [ "ls-files" , "--" , "package.json" , "pnpm-lock.yaml" , "extensions/canvas/src/host/a2ui-app" ] ,
74+ {
75+ cwd : repoRoot ,
76+ encoding : "utf8" ,
77+ killSignal : "SIGKILL" ,
78+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
79+ timeout : 5_000 ,
80+ } ,
81+ ) ;
82+ } ) ;
83+
6584 it . skipIf ( process . platform === "win32" ) (
66- "falls back when tracked-input discovery stalls " ,
85+ "matches the tracked-input hash when Git discovery fails " ,
6786 async ( ) => {
6887 await withTempWorkspace (
69- { rootDir : resolvePreferredOpenClawTmpDir ( ) , prefix : "openclaw-a2ui-git-timeout -" } ,
88+ { rootDir : resolvePreferredOpenClawTmpDir ( ) , prefix : "openclaw-a2ui-git-fallback -" } ,
7089 async ( { dir } ) => {
7190 const fakeBinDir = path . join ( dir , "bin" ) ;
7291 const fakeGitPath = path . join ( fakeBinDir , "git" ) ;
7392 const outputFile = path . join ( dir , "a2ui.bundle.js" ) ;
7493 const hashFile = path . join ( dir , "a2ui.bundle.hash" ) ;
94+ const scriptPath = path . resolve ( "extensions/canvas/scripts/bundle-a2ui.mjs" ) ;
95+ const baseEnv = {
96+ ...process . env ,
97+ OPENCLAW_A2UI_BUNDLE_HASH_FILE : hashFile ,
98+ OPENCLAW_A2UI_BUNDLE_OUT : outputFile ,
99+ } ;
75100 await fs . mkdir ( fakeBinDir , { recursive : true } ) ;
76- await fs . writeFile (
77- fakeGitPath ,
78- `#!${ process . execPath } \nsetTimeout(() => {}, 30_000);\n` ,
79- "utf8" ,
80- ) ;
101+ await fs . writeFile ( fakeGitPath , `#!${ process . execPath } \nprocess.exit(1);\n` , "utf8" ) ;
81102 await fs . chmod ( fakeGitPath , 0o755 ) ;
82103
83- execFileSync (
84- process . execPath ,
85- [ path . resolve ( "extensions/canvas/scripts/bundle-a2ui.mjs" ) ] ,
86- {
87- cwd : process . cwd ( ) ,
88- encoding : "utf8" ,
89- env : {
90- ...process . env ,
91- OPENCLAW_A2UI_BUNDLE_HASH_FILE : hashFile ,
92- OPENCLAW_A2UI_BUNDLE_OUT : outputFile ,
93- PATH : `${ fakeBinDir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` ,
94- } ,
95- killSignal : "SIGKILL" ,
96- timeout : 12_000 ,
104+ execFileSync ( process . execPath , [ scriptPath ] , {
105+ cwd : process . cwd ( ) ,
106+ encoding : "utf8" ,
107+ env : baseEnv ,
108+ killSignal : "SIGKILL" ,
109+ timeout : 12_000 ,
110+ } ) ;
111+ const trackedHash = await fs . readFile ( hashFile , "utf8" ) ;
112+
113+ execFileSync ( process . execPath , [ scriptPath ] , {
114+ cwd : process . cwd ( ) ,
115+ encoding : "utf8" ,
116+ env : {
117+ ...baseEnv ,
118+ PATH : `${ fakeBinDir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` ,
97119 } ,
98- ) ;
120+ killSignal : "SIGKILL" ,
121+ timeout : 12_000 ,
122+ } ) ;
99123
124+ await expect ( fs . readFile ( hashFile , "utf8" ) ) . resolves . toBe ( trackedHash ) ;
100125 await expect ( fs . stat ( outputFile ) ) . resolves . toBeDefined ( ) ;
101- await expect ( fs . stat ( hashFile ) ) . resolves . toBeDefined ( ) ;
102126 } ,
103127 ) ;
104128 } ,
0 commit comments