pi-mono/packages/tui/test/fixtures/clipboard-reader.cjs
Armin Ronacher caf6dfe731
feat(tui): Simplify clipboard handling (#9163)
Replace the external clipboard dependency with small macOS, Windows,
and X11 helpers and integrate them into coding-agent.

Run native clipboard operations on worker threads and make command
fallbacks asynchronous. Preserve incremental X11 transfers, legacy text
encodings, native image formats, and existing Wayland and platform tools.

Include native prebuilds with ARM64 page alignment, packaging updates,
and regression coverage.
2026-09-05 23:52:32 +02:00

31 lines
1.3 KiB
JavaScript

const { createHash } = require("node:crypto");
const assert = require("node:assert/strict");
const { readFileSync } = require("node:fs");
(async () => {
let ticks = 0;
const timer = setInterval(() => ticks++, 10);
const started = performance.now();
try {
const helper = require(process.argv[2]);
const pending = helper[process.argv[3]]();
assert.ok(pending instanceof Promise, "Native reads must return promises");
const value = await pending;
const bytes = typeof value === "string" || Buffer.isBuffer(value) ? Buffer.from(value) : undefined;
console.log(JSON.stringify({
ok: true,
value: value === null || (typeof value === "string" && value.length <= 100) ? value : undefined,
unavailable: value === undefined || undefined,
length: bytes?.length,
hash: bytes && createHash("sha256").update(bytes).digest("hex"),
}));
} catch (error) {
console.log(JSON.stringify({ ok: false, error: String(error) }));
} finally {
clearInterval(timer);
if (performance.now() - started > 200) assert.ok(ticks > 5, "Clipboard I/O must not block the JS event loop");
// Check before Node exits: process exit must not hide a leaked child or zombie.
assert.equal(readFileSync(`/proc/self/task/${process.pid}/children`, "utf8").trim(), "");
}
})().catch((error) => { console.error(error); process.exitCode = 1; });