repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix win32 test failures

0cb189e73d8554047b6c656c53193a59ad130f51

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Handle EOF when child stdin closes early on Windows.

Resolve rtk through PATHEXT so test PATH shims and cmd wrappers run correctly.

Changed files (2)

extensions/rtk/index.ts

Modified
1 +import { constants } from "node:fs";
2 +import { access } from "node:fs/promises";
3 +import { delimiter, join } from "node:path";
1 4 import type {
5 + ExecOptions,
2 6 ExtensionAPI,
3 7 ExtensionContext,
4 8 } from "@earendil-works/pi-coding-agent";
64 68 | { kind: "fallback" }
65 69 | { kind: "unchanged" };
71 +async function rtkCommand(): Promise<string> {
72 + if (process.platform !== "win32") return "rtk";
73 + const pathKey = Object.keys(process.env).find(
74 + (k) => k.toLowerCase() === "path",
75 + );
76 + const dirs = (pathKey ? process.env[pathKey] : "")?.split(delimiter) ?? [];
77 + const exts = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD")
78 + .split(";")
79 + .filter(Boolean);
80 + for (const dir of dirs) {
81 + for (const ext of exts) {
82 + const candidate = join(dir, `rtk${ext.toLowerCase()}`);
83 + try {
84 + await access(candidate, constants.F_OK);
85 + return candidate;
86 + } catch {}
87 + }
88 + }
89 + return "rtk";
92 +async function execRtk(
93 + pi: ExtensionAPI,
94 + args: string[],
95 + options?: ExecOptions,
96 +): Promise<ExecResult> {
97 + const command = await rtkCommand();
98 + if (process.platform === "win32" && /\.(?:cmd|bat)$/iu.test(command)) {
99 + return (await pi.exec(
100 + process.env.ComSpec || process.env.COMSPEC || "cmd.exe",
101 + ["/d", "/c", "call", command, ...args],
102 + options,
103 + )) as ExecResult;
105 + return (await pi.exec(command, args, options)) as ExecResult;
67 108 function execCode(error: unknown): number | null {
68 109 if (typeof error !== "object" || error === null) return null;
69 110 const maybe = error as {
82 123 signal?: AbortSignal,
83 124 ): Promise<RewriteOutcome> {
85 - const result = (await pi.exec("rtk", ["rewrite", command], {
126 + const result = await execRtk(pi, ["rewrite", command], {
86 127 timeout: TIMEOUT_MS,
87 128 signal,
88 - })) as ExecResult;
129 + });
89 130 if (result.killed) return { kind: "unchanged" };
90 131 if (result.code === 1) return { kind: "fallback" };
91 132 if (result.code !== 0 && result.code !== 3) return { kind: "unchanged" };
100 141 async function rtkStatus(pi: ExtensionAPI): Promise<RtkStatus> {
102 - const result = (await pi.exec("rtk", ["--version"], {
143 + const result = await execRtk(pi, ["--version"], {
103 144 timeout: TIMEOUT_MS,
104 - })) as ExecResult;
145 + });
105 146 if (result.code !== 0) return { ok: false, reason: "missing" };
106 147 const text = (result.stdout ?? result.stderr ?? "").trim();
107 148 return supported(parseRtkVersion(text))

extensions/web/spawn.ts

Modified
28 28 proc.stdout.on("data", (d: Buffer) => (stdout += d));
29 29 proc.stderr.on("data", (d: Buffer) => (stderr += d));
30 30 proc.stdin.on("error", (err: NodeJS.ErrnoException) => {
31 - if (err.code !== "EPIPE") fail(err);
31 + if (err.code !== "EPIPE" && err.code !== "EOF") fail(err);
33 33 proc.on("close", (code) => {
34 34 if (settled) return;