@@ -697,7 +697,7 @@ describe('createDefaultRunWrangler — post-spawn child `error` events confirm/q
697697 }
698698 } , 15_000 ) ;
699699
700- it ( 'a provider exiting after reporting success rejects unread stdin through its real pipe error ' , async ( ) => {
700+ it ( 'a provider exiting after reporting success rejects unread stdin' , async ( ) => {
701701 const script = join ( POST_SPAWN_TMP , 'exited-stdin.cjs' ) ;
702702 const pidFile = join ( POST_SPAWN_TMP , 'exited-stdin.pid' ) ;
703703 writeFileSync (
@@ -706,8 +706,8 @@ describe('createDefaultRunWrangler — post-spawn child `error` events confirm/q
706706 `fs.writeFileSync(${ JSON . stringify ( pidFile ) } , String(process.pid));\n` +
707707 `fs.writeSync(1, JSON.stringify({ operationResult: 1, data: { id: 'provider-id' } }));\n` +
708708 // Exit closes every inherited handle on Windows as well as POSIX. The
709- // oversized unread input is still pending, so the parent gets a real
710- // closed-pipe error (write EOF on Windows, EPIPE on POSIX) .
709+ // oversized unread input is still pending. Node may report a pipe
710+ // error or silently destroy stdin; neither can count as success .
711711 `process.exit(0);\n` ,
712712 ) ;
713713 let observedOutput = '' ;
@@ -748,9 +748,7 @@ describe('createDefaultRunWrangler — post-spawn child `error` events confirm/q
748748 expect ( result ! . status ) . toBe ( 1 ) ;
749749 // The stdin error owns termination even if exit 0 is concurrently observed.
750750 expect ( result ! . signal ) . toBe ( 'SIGKILL' ) ;
751- expect ( result ! . stderr ) . toMatch (
752- process . platform === 'win32' ? / w r i t e E O F | E P I P E | b r o k e n p i p e / i : / E P I P E | b r o k e n p i p e / i,
753- ) ;
751+ expect ( result ! . stderr ) . toMatch ( / w r i t e E O F | E P I P E | b r o k e n p i p e | c l o s e d s t d i n b e f o r e / i) ;
754752 expect ( result ! . stdout ) . toContain ( '"operationResult":1' ) ;
755753 expect ( result ! . data ) . toBeUndefined ( ) ;
756754 }
@@ -760,6 +758,60 @@ describe('createDefaultRunWrangler — post-spawn child `error` events confirm/q
760758 expect ( ( ) => process . kill ( pid , 0 ) ) . toThrow ( ) ;
761759 } , 15_000 ) ;
762760
761+ it ( 'rejects success when stdin closes without finishing or emitting an error' , async ( ) => {
762+ const script = join ( POST_SPAWN_TMP , 'unfinished-stdin.cjs' ) ;
763+ writeFileSync (
764+ script ,
765+ `process.stdout.write(JSON.stringify({ operationResult: 1, data: { id: 'provider-id' } }));\n` ,
766+ ) ;
767+ let stdinErrors = 0 ;
768+ const run = createRunner ( {
769+ launcher : [ process . execPath , script ] ,
770+ onSpawnedChild : ( child ) => {
771+ child . stdin ! . on ( 'error' , ( ) => stdinErrors ++ ) ;
772+ // Node destroys stdin when the child exits. A destroyed Writable need
773+ // not emit an error, even when its input was never flushed.
774+ child . stdin ! . destroy ( ) ;
775+ } ,
776+ } ) ;
777+ const result = await run (
778+ {
779+ type : 'hyperdrive.create' ,
780+ name : 'unfinished-stdin' ,
781+ binding : 'HYPERDRIVE' ,
782+ configPath : 'config.jsonc' ,
783+ } ,
784+ { accountId : 'acct' , input : 'unread input' } ,
785+ ) ;
786+ expect ( stdinErrors ) . toBe ( 0 ) ;
787+ expect ( result . status ) . toBe ( 1 ) ;
788+ expect ( result . data ) . toBeUndefined ( ) ;
789+ expect ( result . stderr ) . toContain ( 'stdin' ) ;
790+ } ) ;
791+
792+ it ( 'accepts success after the provider reads all stdin' , async ( ) => {
793+ const script = join ( POST_SPAWN_TMP , 'finished-stdin.cjs' ) ;
794+ writeFileSync (
795+ script ,
796+ `let length = 0;\n` +
797+ `process.stdin.on('data', chunk => { length += chunk.length; });\n` +
798+ `process.stdin.on('end', () => process.stdout.write(JSON.stringify({ operationResult: 1, data: { length } })));\n` ,
799+ ) ;
800+ const run = createRunner ( { launcher : [ process . execPath , script ] } ) ;
801+ const input = 'x' . repeat ( 2 * 1024 * 1024 ) ;
802+ const result = await run (
803+ {
804+ type : 'hyperdrive.create' ,
805+ name : 'finished-stdin' ,
806+ binding : 'HYPERDRIVE' ,
807+ configPath : 'config.jsonc' ,
808+ } ,
809+ { accountId : 'acct' , input } ,
810+ ) ;
811+ expect ( result . status ) . toBe ( 0 ) ;
812+ expect ( result . data ) . toEqual ( { length : input . length } ) ;
813+ } ) ;
814+
763815 it ( 'a stdin Writable error rejects buffered success only after the child is confirmed dead' , async ( ) => {
764816 const script = join ( POST_SPAWN_TMP , 'stdin-error.cjs' ) ;
765817 const pidFile = join ( POST_SPAWN_TMP , 'stdin-error.pid' ) ;
0 commit comments