@@ -445,6 +445,54 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
445445 }
446446 } ) ;
447447
448+ it ( "bounds npm install failure logs to the configured tail" , ( ) => {
449+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-e2e-instance-install-log-" ) ) ;
450+ try {
451+ const timeoutArgsPath = path . join ( tempDir , "timeout-args.txt" ) ;
452+ const logPath = path . join ( tempDir , "install.log" ) ;
453+ const packagePath = path . join ( tempDir , "openclaw.tgz" ) ;
454+ const prefixPath = path . join ( tempDir , "prefix" ) ;
455+ writePackageFixture ( packagePath ) ;
456+ writeFakeTimeout ( path . join ( tempDir , "timeout" ) , true ) ;
457+ writeBashExecutable ( path . join ( tempDir , "npm" ) , [
458+ 'printf "DO_NOT_PRINT_OLD_NPM_LOG\\n"' ,
459+ 'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done' ,
460+ 'printf "\\nrecent npm tail\\n"' ,
461+ "exit 42" ,
462+ ] ) ;
463+
464+ const result = spawnSync (
465+ "/bin/bash" ,
466+ [
467+ "-c" ,
468+ [
469+ "set -euo pipefail" ,
470+ `source ${ shellQuote ( helperPath ) } ` ,
471+ `openclaw_e2e_install_package ${ shellQuote ( logPath ) } ${ shellQuote ( "fixture package" ) } ${ shellQuote ( prefixPath ) } ` ,
472+ ] . join ( "; " ) ,
473+ ] ,
474+ {
475+ encoding : "utf8" ,
476+ env : shellTestEnv ( {
477+ PATH : `${ tempDir } ${ path . delimiter } ${ hostPath } ` ,
478+ OPENCLAW_CURRENT_PACKAGE_TGZ : packagePath ,
479+ OPENCLAW_E2E_LOG_TAIL_BYTES : "80" ,
480+ OPENCLAW_E2E_NPM_INSTALL_TIMEOUT : "42s" ,
481+ OPENCLAW_TEST_TIMEOUT_ARGS : timeoutArgsPath ,
482+ } ) ,
483+ } ,
484+ ) ;
485+
486+ expect ( result . status ) . toBe ( 1 ) ;
487+ expect ( result . stderr ) . toContain ( "npm install failed for fixture package" ) ;
488+ expect ( result . stderr ) . toContain ( "recent npm tail" ) ;
489+ expect ( result . stderr ) . not . toContain ( "DO_NOT_PRINT_OLD_NPM_LOG" ) ;
490+ expect ( fs . readFileSync ( logPath , "utf8" ) ) . toContain ( "DO_NOT_PRINT_OLD_NPM_LOG" ) ;
491+ } finally {
492+ fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
493+ }
494+ } ) ;
495+
448496 it ( "bounds commands with the Node watchdog when timeout is unavailable" , ( ) => {
449497 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-e2e-instance-node-watchdog-" ) ) ;
450498 try {
@@ -912,6 +960,54 @@ exit 1
912960 }
913961 } ) ;
914962
963+ it ( "bounds logged command failure output to the configured tail" , ( ) => {
964+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-e2e-instance-run-log-tail-" ) ) ;
965+ const logLabel = path . basename ( tempDir ) ;
966+ const logDir = path . join ( tempDir , "logs" ) ;
967+ try {
968+ const timeoutArgsPath = path . join ( tempDir , "timeout-args.txt" ) ;
969+ writeFakeTimeout ( path . join ( tempDir , "timeout" ) , true ) ;
970+ writeBashExecutable ( path . join ( tempDir , "fixture-command" ) , [
971+ 'printf "DO_NOT_PRINT_OLD_COMMAND_LOG\\n"' ,
972+ 'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done' ,
973+ 'printf "\\nrecent command tail\\n"' ,
974+ "exit 23" ,
975+ ] ) ;
976+
977+ const result = spawnSync (
978+ "/bin/bash" ,
979+ [
980+ "-c" ,
981+ [
982+ "set -euo pipefail" ,
983+ `source ${ shellQuote ( helperPath ) } ` ,
984+ `openclaw_e2e_run_logged ${ shellQuote ( logLabel ) } fixture-command` ,
985+ ] . join ( "; " ) ,
986+ ] ,
987+ {
988+ encoding : "utf8" ,
989+ env : shellTestEnv ( {
990+ PATH : `${ tempDir } ${ path . delimiter } ${ hostPath } ` ,
991+ OPENCLAW_E2E_COMMAND_TIMEOUT : "17s" ,
992+ OPENCLAW_E2E_LOG_DIR : logDir ,
993+ OPENCLAW_E2E_LOG_TAIL_BYTES : "80" ,
994+ OPENCLAW_TEST_TIMEOUT_ARGS : timeoutArgsPath ,
995+ } ) ,
996+ } ,
997+ ) ;
998+
999+ expect ( result . status ) . toBe ( 1 ) ;
1000+ expect ( result . stdout ) . toContain ( "recent command tail" ) ;
1001+ expect ( result . stdout ) . not . toContain ( "DO_NOT_PRINT_OLD_COMMAND_LOG" ) ;
1002+ const [ logFile ] = fs . readdirSync ( logDir ) ;
1003+ expect ( fs . readFileSync ( path . join ( logDir , logFile ) , "utf8" ) ) . toContain (
1004+ "DO_NOT_PRINT_OLD_COMMAND_LOG" ,
1005+ ) ;
1006+ } finally {
1007+ fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
1008+ }
1009+ } ) ;
1010+
9151011 it ( "installs the trash shim under isolated test state" , ( ) => {
9161012 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-e2e-trash-shim-" ) ) ;
9171013 try {
0 commit comments