@@ -6,6 +6,16 @@ import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
66import { resetLogger , setLoggerOverride } from "../logging.js" ;
77
88const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
9+ const metadataBoundaries = [
10+ "configured stat" ,
11+ "rolling readdir" ,
12+ "candidate stat" ,
13+ "final stat" ,
14+ ] as const ;
15+ const operationalErrorCodes = [ "EACCES" , "EIO" , "EMFILE" ] as const ;
16+ const operationalMetadataFailures = metadataBoundaries . flatMap ( ( boundary ) =>
17+ operationalErrorCodes . map ( ( code ) => ( { boundary, code } ) ) ,
18+ ) ;
919
1020const resolvedRedaction = { mode : "tools" as const , patterns : [ / c u s t o m - s e c r e t - [ a - z ] + / g] } ;
1121type PositionalRead = (
@@ -123,6 +133,44 @@ describe("readConfiguredLogTail", () => {
123133 expect ( result . lines [ 0 ] ?. trimEnd ( ) ) . toBe ( "first-line-in-window" ) ;
124134 } ) ;
125135
136+ it . each ( operationalMetadataFailures ) (
137+ "rethrows $code from the $boundary boundary" ,
138+ async ( { boundary, code } ) => {
139+ const tempDir = tempDirs . make ( "openclaw-log-tail-" ) ;
140+ const configured = path . join ( tempDir , "openclaw-2026-01-22.log" ) ;
141+ const candidate = path . join ( tempDir , "openclaw-2026-01-21.log" ) ;
142+ const error = Object . assign ( new Error ( `${ code } injected` ) , { code } ) ;
143+ const realStat = fs . stat . bind ( fs ) ;
144+
145+ if ( boundary === "candidate stat" ) {
146+ await fs . writeFile ( candidate , "candidate\n" ) ;
147+ } else if ( boundary !== "rolling readdir" ) {
148+ await fs . writeFile ( configured , "configured\n" ) ;
149+ }
150+ setLoggerOverride ( { file : configured } ) ;
151+
152+ if ( boundary === "configured stat" ) {
153+ vi . spyOn ( fs , "stat" ) . mockRejectedValueOnce ( error ) ;
154+ } else if ( boundary === "rolling readdir" ) {
155+ vi . spyOn ( fs , "readdir" ) . mockRejectedValueOnce ( error ) ;
156+ } else if ( boundary === "candidate stat" ) {
157+ vi . spyOn ( fs , "stat" ) . mockImplementation ( async ( ...args : Parameters < typeof fs . stat > ) => {
158+ if ( String ( args [ 0 ] ) === candidate ) {
159+ throw error ;
160+ }
161+ return realStat ( ...args ) ;
162+ } ) ;
163+ } else {
164+ vi . spyOn ( fs , "stat" )
165+ . mockImplementationOnce ( ( ...args : Parameters < typeof fs . stat > ) => realStat ( ...args ) )
166+ . mockRejectedValueOnce ( error ) ;
167+ }
168+
169+ const { readConfiguredLogTail } = await import ( "./log-tail.js" ) ;
170+ await expect ( readConfiguredLogTail ( ) ) . rejects . toBe ( error ) ;
171+ } ,
172+ ) ;
173+
126174 it ( "falls back only within the active profile's rolling log family" , async ( ) => {
127175 const tempDir = tempDirs . make ( "openclaw-log-tail-" ) ;
128176 const missing = path . join ( tempDir , "openclaw-2026-01-22.log" ) ;
0 commit comments