Page MenuHomePhorge

test_process_stdout_resize_signal.cjs
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

test_process_stdout_resize_signal.cjs

const { spawnSync } = require('child_process');
const path = require('path');
function fail(message) {
throw new Error(message);
}
function runInPty() {
const helper = path.join(__dirname, 'fixtures', 'process_stdout_resize_child.cjs');
const script = `
import fcntl, os, select, signal, struct, sys, termios, time
exec_path, helper = sys.argv[1], sys.argv[2]
pid, master = os.forkpty()
if pid == 0:
os.execv(exec_path, [exec_path, helper])
buf = bytearray()
sent = False
exit_code = None
deadline = time.time() + 7.0
while time.time() < deadline:
done, status = os.waitpid(pid, os.WNOHANG)
if done == pid:
exit_code = os.waitstatus_to_exitcode(status)
break
r, _, _ = select.select([master], [], [], 0.1)
if master not in r:
continue
try:
chunk = os.read(master, 4096)
except OSError:
break
if not chunk:
break
buf.extend(chunk)
if (not sent) and b'READY' in buf:
winsz = struct.pack('HHHH', 40, 120, 0, 0)
fcntl.ioctl(master, termios.TIOCSWINSZ, winsz)
os.kill(pid, signal.SIGWINCH)
sent = True
if exit_code is None:
os.kill(pid, signal.SIGKILL)
_, status = os.waitpid(pid, 0)
exit_code = os.waitstatus_to_exitcode(status)
while True:
r, _, _ = select.select([master], [], [], 0.05)
if master not in r:
break
try:
chunk = os.read(master, 4096)
except OSError:
break
if not chunk:
break
buf.extend(chunk)
sys.stdout.buffer.write(bytes(buf))
sys.exit(exit_code)
`;
if (process.platform === 'win32') {
console.log('skipping stdout resize signal test on win32');
process.exit(0);
}
return spawnSync('python3', ['-c', script, process.execPath, helper], {
encoding: 'utf8',
timeout: 9000,
});
}
const result = runInPty();
if (result.error && result.error.code === 'ENOENT') {
console.log('skipping stdout resize signal test because `python3` is unavailable');
process.exit(0);
}
if (result.error) throw result.error;
const output = `${result.stdout || ''}${result.stderr || ''}`;
if (result.status !== 0) {
fail(`child exited ${result.status}\n${output}`);
}
if (!output.includes('READY')) {
fail(`expected READY banner\n${output}`);
}
if (!output.includes('RESIZE 40 120')) {
fail(`expected resize output with updated tty dimensions\n${output}`);
}
if (output.includes('assignment to constant')) {
fail(`resize handling regressed with assignment-to-constant error\n${output}`);
}
console.log('process.stdout resize signal updates dimensions without crashing');

File Metadata

Mime Type
application/javascript
Expires
Fri, May 1, 7:02 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
543483
Default Alt Text
test_process_stdout_resize_signal.cjs (2 KB)

Event Timeline