11import assert from 'node:assert/strict' ;
2+ import { execFile } from 'node:child_process' ;
23import { promises as fs } from 'node:fs' ;
34import path from 'node:path' ;
5+ import { promisify } from 'node:util' ;
46import { afterEach , test , vi } from 'vitest' ;
57import { AppError } from '@agent-device/kernel/errors' ;
68import { asOptionalRecord } from '@agent-device/kernel/record' ;
@@ -15,6 +17,7 @@ import {
1517import { mkdtempForTest } from './tmp-dir.fixtures.ts' ;
1618
1719const realFetch = globalThis . fetch ;
20+ const execFileAsync = promisify ( execFile ) ;
1821
1922afterEach ( ( ) => {
2023 globalThis . fetch = realFetch ;
@@ -150,3 +153,27 @@ test('appFileUploadForm carries a regular app file and refuses anything else typ
150153 await fs . rm ( tempDir , { recursive : true , force : true } ) ;
151154 }
152155} ) ;
156+
157+ test . skipIf ( process . platform === 'win32' ) (
158+ 'appFileUploadForm refuses a named pipe without reading it' ,
159+ async ( ) => {
160+ const tempDir = await mkdtempForTest ( 'agent-device-upload-form-fifo-' ) ;
161+ try {
162+ const fifoPath = path . join ( tempDir , 'App.ipa' ) ;
163+ await execFileAsync ( 'mkfifo' , [ fifoPath ] ) ;
164+
165+ await assert . rejects (
166+ appFileUploadForm ( fifoPath , 'file' , { provider : 'hub' , service : 'Hub' } ) ,
167+ ( error : unknown ) => {
168+ assert . ok ( error instanceof AppError ) ;
169+ assert . equal ( error . code , 'INVALID_ARGS' ) ;
170+ assert . equal ( error . message , `Hub can only upload a regular app file: ${ fifoPath } ` ) ;
171+ assert . equal ( error . details ?. appPath , fifoPath ) ;
172+ return true ;
173+ } ,
174+ ) ;
175+ } finally {
176+ await fs . rm ( tempDir , { recursive : true , force : true } ) ;
177+ }
178+ } ,
179+ ) ;
0 commit comments