pi-ext
bugabingas pi extensions
owned by admin
Replaced UV version subprocess with synchronous executable access checks over PATH; reload tax fell 86% Win32, seven controlled-PATH tests passed
91ad67e76aadb438888bfc8835588ad685d4b522
Oliver Krylow <o.krylow@isp-insoft.de> ·
SSH signature · not checked
Browse filesCompare with HEAD
Result: {"status":"keep","uv_reload_tax_ms":11.263,"elapsed_s":341.8,"win32_start_reload_ms":8422.463,"win32_extension_tax_ms":2916.592,"win32_startup_ms":6947.187,"win32_reload_ms":1475.276,"wsl_start_reload_ms":2206.537,"wsl_extension_tax_ms":979.081,"wsl_uv_reload_tax_ms":5.159}
Changed files (2)
extensions/uv/__tests__/harness.test.ts
Modified 8 +import { tmpdir }
from "node:os";
9 +import { join }
from "node:path";
1 10 import { afterEach, describe, expect, it }
from "vitest";
2 11 import { createTestSession, type TestSession }
from "../../../test/harness";
3 12 import uvExtension, { __test }
from "../index";
5 14 let t
: TestSession | undefined;
15 +let fakeBin
: string | undefined;
19 + if (fakeBin)
rmSync(fakeBin, { recursive:
true, force:
true });
21 + fakeBin
= undefined;
12 24 describe(
"uv extension", ()
=> {
16 28 expect(t.session.extensionRunner.extensions).
toHaveLength(
1);
31 + it(
"detects a controlled executable on PATH through the extension",
async ()
=> {
32 + fakeBin
= mkdtempSync(
join(
tmpdir(),
"pi-uv-bin-"));
33 + if (
process.
platform === "win32") {
34 + copyFileSync(
process.
execPath,
join(fakeBin,
"uv.exe"));
36 + const uv
= join(fakeBin,
"uv");
37 + writeFileSync(uv,
"#!/bin/sh\nexit 0\n",
"utf8");
38 + chmodSync(uv,
0o755);
41 + t
= await createTestSession({
42 + env: { PATH: fakeBin },
43 + extensionFactories: [uvExtension],
46 + expect(t.events.
uiCallsFor(
"notify")).
toEqual([]);
49 + it(
"warns through the extension when PATH has no uv executable",
async ()
=> {
50 + fakeBin
= mkdtempSync(
join(
tmpdir(),
"pi-uv-bin-"));
51 + t
= await createTestSession({
52 + env: { PATH: fakeBin },
53 + extensionFactories: [uvExtension],
56 + expect(t.events.
uiCallsFor(
"notify").
at(
-1)?.args).
toEqual([
57 + "uv extension: uv not found on PATH",
19 62 it(
"blocks pip-family commands with uv guidance", ()
=> {
20 63 expect(__test.
getBlockedCommandMessage(
"pip install rich")).
toContain(
extensions/uv/index.ts
Modified 1 -import { spawnSync }
from "node:child_process";
1 +import { accessSync, constants }
from "node:fs";
2 2 import { delimiter, join }
from "node:path";
4 4 type BashSpawnContext,
11 11 "intercepted-commands",
14 -function uvInstalled()
: boolean {
15 - const result
= spawnSync(
"uv", [
"--version"], { stdio:
"ignore" });
16 - return !result.error
&& result.
status === 0;
14 +function uvInstalled(env
= process.
env, platform
= process.
platform)
: boolean {
15 + const names
= platform
=== "win32" ? [
"uv.exe",
"uv.cmd",
"uv.bat"]
: [
"uv"];
16 + const mode
= platform
=== "win32" ? constants.F_OK
: constants.X_OK;
17 + for (
const directory
of (env[
pathEnvKey(env)]
?? "").
split(delimiter)) {
18 + for (
const name
of names) {
20 + accessSync(
join(directory.
replace(
/^"|"$/gu,
""), name), mode);
19 28 function pathEnvKey(env
: NodeJS.
ProcessEnv)
: string {
107 -export const __test
= { getBlockedCommandMessage, prependInterceptedCommands };
116 +export const __test
= {
117 + getBlockedCommandMessage,
118 + prependInterceptedCommands,
109 122 export default function uvExtension(pi
: ExtensionAPI) {
110 123 pi.
on(
"session_start", (_event, ctx)
=> {