@@ -3900,6 +3900,96 @@ test("intermediate validation cannot tamper with fresh runtime outputs before ar
39003900 ) ;
39013901} ) ;
39023902
3903+ test ( "changed-gate fallback preserves and protects pending fresh runtime output" , ( ) => {
3904+ for ( const tamperWithFreshRuntime of [ false , true ] ) {
3905+ const cwd = gitPackageFixture ( {
3906+ "build:ci-artifacts" : "node scripts/build-runtime.mjs" ,
3907+ "test:serial" : "node --test" ,
3908+ } ) ;
3909+ fs . appendFileSync ( path . join ( cwd , ".gitignore" ) , "dist/\n" ) ;
3910+ const scripts = path . join ( cwd , "scripts" ) ;
3911+ fs . mkdirSync ( scripts , { recursive : true } ) ;
3912+ fs . writeFileSync ( path . join ( scripts , "build-runtime.mjs" ) , "// trusted fixture shim\n" ) ;
3913+ fs . writeFileSync (
3914+ path . join ( scripts , "dist-runtime-build-artifact.mjs" ) ,
3915+ [
3916+ 'import fs from "node:fs";' ,
3917+ 'if (fs.readFileSync("dist/runtime.js", "utf8") !== "fresh runtime\\n") process.exit(71);' ,
3918+ 'const archive = process.argv[process.argv.indexOf("--archive") + 1];' ,
3919+ 'fs.writeFileSync(archive, "runtime archive proof\\n");' ,
3920+ "" ,
3921+ ] . join ( "\n" ) ,
3922+ ) ;
3923+ fs . mkdirSync ( path . join ( cwd , "test" ) , { recursive : true } ) ;
3924+ fs . writeFileSync ( path . join ( cwd , "test" , "example.test.ts" ) , "export const value = 1;\n" ) ;
3925+ git ( cwd , "add" , "." ) ;
3926+ git ( cwd , "commit" , "-m" , "initial" ) ;
3927+ attachOrigin ( cwd ) ;
3928+ fs . writeFileSync ( path . join ( cwd , "test" , "example.test.ts" ) , "export const value = 2;\n" ) ;
3929+
3930+ const binDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "clawsweeper-runtime-fallback-" ) ) ;
3931+ writeNodeCommandShim (
3932+ binDir ,
3933+ "pnpm" ,
3934+ [
3935+ 'const fs = require("node:fs");' ,
3936+ "const args = process.argv.slice(2);" ,
3937+ 'if (args.includes("build:ci-artifacts")) {' ,
3938+ ' fs.mkdirSync("dist", { recursive: true });' ,
3939+ ' fs.writeFileSync("dist/runtime.js", "fresh runtime\\n");' ,
3940+ "}" ,
3941+ 'if (args.includes("check:changed")) {' ,
3942+ ' console.error("terminating stalled Vitest process");' ,
3943+ " process.exit(1);" ,
3944+ "}" ,
3945+ ...( tamperWithFreshRuntime
3946+ ? [
3947+ 'if (args.includes("test:serial")) {' ,
3948+ ' fs.writeFileSync("dist/runtime.js", "tampered runtime\\n");' ,
3949+ "}" ,
3950+ ]
3951+ : [ ] ) ,
3952+ ] . join ( "\n" ) ,
3953+ ) ;
3954+
3955+ const smoke =
3956+ "node scripts/dist-runtime-build-artifact.mjs pack-and-smoke --archive dist-runtime-build.tar.zst" ;
3957+ const execute = ( ) =>
3958+ withPathOnlyPrefix ( binDir , ( ) =>
3959+ runAllowedValidationCommands (
3960+ [ "pnpm build:ci-artifacts" , "pnpm check:changed" , smoke ] ,
3961+ cwd ,
3962+ validationOptions ( "openclaw/openclaw" , {
3963+ allowExpensiveValidation : true ,
3964+ pinnedBaseRef : "origin/main" ,
3965+ toolchain : {
3966+ packageManager : "pnpm" ,
3967+ baseValidationCommands : [ ] ,
3968+ changedGate : { command : "pnpm check:changed" , requiredScript : "check:changed" } ,
3969+ } ,
3970+ } ) ,
3971+ ) ,
3972+ ) ;
3973+
3974+ if ( tamperWithFreshRuntime ) {
3975+ assert . throws (
3976+ execute ,
3977+ / u n s a f e v a l i d a t i o n c o m m a n d m u t a t e d f r e s h r u n t i m e b u i l d o u t p u t \( p n p m t e s t : s e r i a l t e s t \/ e x a m p l e \. t e s t \. t s \) / ,
3978+ ) ;
3979+ continue ;
3980+ }
3981+
3982+ assert . deepEqual ( execute ( ) , [
3983+ "pnpm build:ci-artifacts" ,
3984+ "git diff --check origin/main...HEAD" ,
3985+ "pnpm test:serial test/example.test.ts" ,
3986+ smoke ,
3987+ ] ) ;
3988+ assert . equal ( fs . readFileSync ( path . join ( cwd , "dist" , "runtime.js" ) , "utf8" ) , "fresh runtime\n" ) ;
3989+ assert . equal ( fs . existsSync ( path . join ( cwd , "dist-runtime-build.tar.zst" ) ) , false ) ;
3990+ }
3991+ } ) ;
3992+
39033993test ( "OpenClaw archive smoke cannot pass by reusing a pre-existing stale build" , ( ) => {
39043994 const cwd = gitPackageFixture ( { "build:ci-artifacts" : "node scripts/build-runtime.mjs" } ) ;
39053995 fs . appendFileSync ( path . join ( cwd , ".gitignore" ) , "dist/\n" ) ;
0 commit comments