@@ -27,6 +27,7 @@ import * as Exit from "effect/Exit";
2727import * as Fiber from "effect/Fiber" ;
2828import * as FileSystem from "effect/FileSystem" ;
2929import * as Layer from "effect/Layer" ;
30+ import * as Logger from "effect/Logger" ;
3031import * as Queue from "effect/Queue" ;
3132import * as Schema from "effect/Schema" ;
3233import * as Sink from "effect/Sink" ;
@@ -4295,8 +4296,16 @@ describe("PiAdapterV2", () => {
42954296} ) ;
42964297
42974298describe ( "PiRpc framing" , ( ) => {
4298- it . effect ( "reassembles records across chunk boundaries and strips CR" , ( ) =>
4299- Effect . gen ( function * ( ) {
4299+ it . effect ( "reassembles records and warns when dropping oversized records" , ( ) => {
4300+ const warnings : Array < ReadonlyArray < unknown > > = [ ] ;
4301+ const warned = Deferred . makeUnsafe < void > ( ) ;
4302+ const logCapture = Logger . make < unknown , void > ( ( { logLevel, message } ) => {
4303+ if ( logLevel === "Warn" && Array . isArray ( message ) ) {
4304+ warnings . push ( message ) ;
4305+ Deferred . doneUnsafe ( warned , Effect . void ) ;
4306+ }
4307+ } ) ;
4308+ return Effect . gen ( function * ( ) {
43004309 const stdout = yield * Queue . unbounded < Uint8Array > ( ) ;
43014310 const spawner = ChildProcessSpawner . make ( ( ) =>
43024311 Effect . succeed (
@@ -4327,9 +4336,11 @@ describe("PiRpc framing", () => {
43274336 yield * push ( '{"type":"agent_' ) ;
43284337 yield * push ( 'start"}\r\n{"type":"agent_settled"}\nnot json\n{"type":"queue_update"}\n' ) ;
43294338
4330- yield * push ( '{"type":"must_not_emit","text":"' ) ;
4339+ const head = '{"type":"must_not_emit","text":"' ;
4340+ yield * push ( head ) ;
43314341 const chunk = new TextEncoder ( ) . encode ( "x" . repeat ( 8 * 1024 * 1024 ) ) ;
43324342 for ( let index = 0 ; index < 32 ; index ++ ) yield * Queue . offer ( stdout , chunk ) ;
4343+ yield * Deferred . await ( warned ) ;
43334344 yield * push ( '"}\n{"type":"after_oversized"}\n' ) ;
43344345
43354346 const first = yield * Queue . take ( connection . events ) ;
@@ -4339,8 +4350,20 @@ describe("PiRpc framing", () => {
43394350 const third = yield * Queue . take ( connection . events ) ;
43404351 assert . equal ( third [ "type" ] , "queue_update" ) ;
43414352 assert . equal ( ( yield * Queue . take ( connection . events ) ) [ "type" ] , "after_oversized" ) ;
4342- } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
4343- ) ;
4353+ assert . lengthOf ( warnings , 1 ) ;
4354+ const [ text , annotations ] = warnings [ 0 ] ?? [ ] ;
4355+ assert . equal ( text , "Dropping oversized pi stdout record." ) ;
4356+ assert . deepEqual ( annotations , {
4357+ recordLength : head . length + 28 * chunk . length ,
4358+ maxRecordLength : 232084864 ,
4359+ } ) ;
4360+ } ) . pipe (
4361+ Effect . scoped ,
4362+ Effect . provide (
4363+ Layer . merge ( NodeServices . layer , Logger . layer ( [ logCapture ] , { mergeWithExisting : false } ) ) ,
4364+ ) ,
4365+ ) ;
4366+ } ) ;
43444367} ) ;
43454368
43464369describe ( "PiRpc early process exit" , ( ) => {
0 commit comments