55 driveMailboxMail ,
66 latchMailboxMailDrive ,
77 MAILBOX_MAIL_WAKE_PREFIX ,
8+ mailboxMailErrorUriHint ,
89 mailboxMailReportUriHint ,
910 mailboxMailWakeLine ,
1011 occupancyShouldYieldWait ,
@@ -14,6 +15,7 @@ import {
1415 digestCollectedReports ,
1516 fleetDrySpillKey ,
1617 FLEET_DRY_REPORT_CHARS ,
18+ MAILBOX_DIGEST_SECTION_CHARS ,
1719 type FleetDryMailboxRecord ,
1820} from "./fleet-dry-drive.js" ;
1921import {
@@ -125,6 +127,22 @@ describe("buildMailboxMailPrompt", () => {
125127 expect ( prompt ) . toContain ( uri ) ;
126128 } ) ;
127129
130+ test ( "names error_uri with a read_file truncation notice" , ( ) => {
131+ const uri = `tool-output:///${ fleetDrySpillKey ( "worker-1" , "error" ) } ` ;
132+ const prompt = buildMailboxMailPrompt ( [
133+ {
134+ agent_id : "worker-1" ,
135+ status : "failed" ,
136+ error_uri : uri ,
137+ } ,
138+ ] ) ;
139+ expect ( prompt ) . toContain ( mailboxMailErrorUriHint ( ) ) ;
140+ expect ( prompt ) . toContain (
141+ "use read_file with that URI (offset/limit supported)" ,
142+ ) ;
143+ expect ( prompt ) . toContain ( uri ) ;
144+ } ) ;
145+
128146 test ( "does not paste a duplicate agent_id" , ( ) => {
129147 const prompt = buildMailboxMailPrompt ( [
130148 { agent_id : "w1" , status : "done" } ,
@@ -163,6 +181,10 @@ describe("digestCollectedReports", () => {
163181 "use read_file with that URI (offset/limit supported)" ,
164182 ) ;
165183 expect ( digest ?. report ) . not . toContain ( "SECRET_FINDINGS_BODY" ) ;
184+ expect ( digest ?. report ) . toContain (
185+ `${ ENVELOPE_REPORT . length . toLocaleString ( ) } more chars omitted here` ,
186+ ) ;
187+ expect ( digest ?. report ) . not . toMatch ( / — 0 m o r e c h a r s o m i t t e d / ) ;
166188 expect (
167189 new TextDecoder ( ) . decode (
168190 store . blobs . get ( fleetDrySpillKey ( "worker-1" , "report" ) ) ?. bytes ??
@@ -222,6 +244,63 @@ describe("digestCollectedReports", () => {
222244 expect ( digest ?. report ) . toContain ( "SECRET_FINDINGS_BODY" ) ;
223245 expect ( digest ?. summary ) . toBe ( "Shipped the digest." ) ;
224246 } ) ;
247+
248+ test ( "spill notice remaining is the omitted body when no prefix is kept" , async ( ) => {
249+ const store = fakeBlobStore ( ) ;
250+ const short = "short spilled body" ;
251+ const [ digest ] = await digestCollectedReports (
252+ [ { agent_id : "short" , status : "done" , report : short } ] ,
253+ store . writeBlob ,
254+ ) ;
255+ expect ( short . length ) . toBeLessThan ( MAILBOX_DIGEST_SECTION_CHARS ) ;
256+ expect ( digest ?. report ) . toContain (
257+ `${ short . length . toLocaleString ( ) } more chars omitted here` ,
258+ ) ;
259+ expect ( digest ?. report ) . not . toMatch ( / — 0 m o r e c h a r s o m i t t e d / ) ;
260+ expect ( digest ?. report ) . not . toContain ( short ) ;
261+ expect ( digest ?. report_uri ) . toBe (
262+ `tool-output:///${ fleetDrySpillKey ( "short" , "report" ) } ` ,
263+ ) ;
264+ } ) ;
265+
266+ test ( "oversized spilled report remaining is the full body, not length minus the digest cap" , async ( ) => {
267+ const store = fakeBlobStore ( ) ;
268+ const original = "x" . repeat ( MAILBOX_DIGEST_SECTION_CHARS + 80 ) ;
269+ const [ digest ] = await digestCollectedReports (
270+ [ { agent_id : "long" , status : "done" , report : original } ] ,
271+ store . writeBlob ,
272+ ) ;
273+ expect ( digest ?. report ) . toContain (
274+ `${ original . length . toLocaleString ( ) } more chars omitted here` ,
275+ ) ;
276+ expect ( digest ?. report ) . not . toContain (
277+ `${ ( original . length - MAILBOX_DIGEST_SECTION_CHARS ) . toLocaleString ( ) } more chars omitted here` ,
278+ ) ;
279+ } ) ;
280+
281+ test ( "spilled error names error_uri with truncation-notice language" , async ( ) => {
282+ const store = fakeBlobStore ( ) ;
283+ const error = "provider boom" ;
284+ const [ digest ] = await digestCollectedReports (
285+ [ { agent_id : "fail" , status : "failed" , error } ] ,
286+ store . writeBlob ,
287+ ) ;
288+ const errorUri = `tool-output:///${ fleetDrySpillKey ( "fail" , "error" ) } ` ;
289+ expect ( digest ?. error_uri ) . toBe ( errorUri ) ;
290+ expect ( digest ?. error ) . toContain ( "[output truncated" ) ;
291+ expect ( digest ?. error ) . toContain ( errorUri ) ;
292+ expect ( digest ?. error ) . toContain (
293+ `${ error . length . toLocaleString ( ) } more chars omitted here` ,
294+ ) ;
295+ expect ( digest ?. error ) . not . toMatch ( / — 0 m o r e c h a r s o m i t t e d / ) ;
296+ expect ( digest ?. error ) . not . toContain ( "provider boom" ) ;
297+ expect (
298+ new TextDecoder ( ) . decode (
299+ store . blobs . get ( fleetDrySpillKey ( "fail" , "error" ) ) ?. bytes ??
300+ new Uint8Array ( ) ,
301+ ) ,
302+ ) . toBe ( error ) ;
303+ } ) ;
225304} ) ;
226305
227306describe ( "driveMailboxMail" , ( ) => {
0 commit comments