repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix: support Termux test execution

4b7df8ec3264b6346e043c24984a69200e1200d1

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (6)

extensions/git-safe/__tests__/harness.test.ts

Modified
1 1 import {
2 + accessSync,
2 3 chmodSync,
4 + constants,
3 5 copyFileSync,
4 6 mkdirSync,
5 7 mkdtempSync,
31 33 return path.resolve(import.meta.dirname, "../../rtk/index.ts");
36 +function bashShebang(): string {
37 + if (process.platform === "win32") return "#!/usr/bin/env bash";
38 + const candidates = [
39 + process.env.SHELL,
40 + ...(process.env.PATH ?? "")
41 + .split(path.delimiter)
42 + .filter(Boolean)
43 + .map((directory) => path.join(directory, "bash")),
44 + "/bin/bash",
45 + ];
46 + for (const candidate of candidates) {
47 + if (!candidate || path.basename(candidate) !== "bash") continue;
48 + try {
49 + accessSync(candidate, constants.X_OK);
50 + return `#!${candidate}`;
51 + } catch {}
52 + }
53 + throw new Error("bash executable not found");
34 56 function installFakeGit(root: string): { bin: string; executable: string } {
35 57 const bin = path.join(root, "fake-bin");
36 58 mkdirSync(bin);
80 102 writeFileSync(
83 - "#!/usr/bin/env bash",
105 + bashShebang(),
84 106 "if [[ \"$*\" == '--list-cmds=builtins' ]]; then printf 'status\\n'; exit 0; fi",
85 107 "if [[ \"$*\" == *'config --get alias.'* ]]; then exit 1; fi",
86 108 "printf 'FAKE_GIT\\n'",
100 122 writeFileSync(
103 - "#!/usr/bin/env bash",
125 + bashShebang(),
104 126 "if [[ \"$1\" == '--version' ]]; then printf 'rtk 0.42.4\\n'; exit 0; fi",
105 127 "if [[ \"$1\" == 'rewrite' && \"$2\" == 'git commit --no-verify' ]]; then printf 'rtk git commit --no-verify\\n'; exit 0; fi",
106 128 "if [[ \"$1\" == 'rewrite' && \"$2\" == 'git status' ]]; then printf 'rtk git status\\n'; exit 0; fi",
226 248 await expectRejected(command);
228 - });
250 + }, 60_000);
230 252 it("rejects temporary aliases that create no-verify inside Git", async () => {
231 253 await startWithFakeGit();
323 345 expect(result.output, command).toContain("FAKE_GIT");
326 - });
348 + }, 60_000);
328 350 it("blocks literal command-git bypasses before execution", async () => {
329 351 await startWithFakeGit();

extensions/git-safe/__tests__/spawn.test.ts

Modified
17 17 const result = await spawnWithTimeout(
18 18 process.execPath,
19 19 ["-e", "process.stdout.write(process.env.GIT_TERMINAL_PROMPT ?? '')"],
20 - { timeout: 1_000 },
20 + { timeout: 5_000 },
23 23 expect(result).toMatchObject({ stdout: "0", code: 0, killed: false });

extensions/nu-bang/__tests__/real-world-full.test.ts

Modified
325 325 test("shows nu's native delimiter diagnostics", async () => {
326 326 const result = await run("[1 2 3");
327 327 expect(result.exitCode).toBe(1);
328 - expect(result.output).toContain("Unexpected end of code");
328 + expect(result.output).toContain("Unclosed delimiter");
331 331 test("reports a missing working directory clearly", async () => {

extensions/the-system/__tests__/the-system.test.ts

Modified
382 382 args: ["file.md"],
383 383 wait: false,
385 + assert.deepEqual(
386 + editorCandidates("file.md", { TERMUX_VERSION: "0.118" }, "android").at(0),
388 + command: "termux-open",
389 + args: ["file.md"],
390 + wait: false,
391 + },
392 + );

extensions/the-system/open-editor.ts

Modified
33 33 Boolean(item),
35 35 .map((item) => ({ ...item, args: [...item.args, file], wait: true }));
36 - return [...configured, ...platformCandidates(file, platform)];
36 + return [...configured, ...platformCandidates(file, env, platform)];
39 39 export function parseEditorCommand(
48 48 function platformCandidates(
49 49 file: string,
50 + env: NodeJS.ProcessEnv,
50 51 platform: NodeJS.Platform,
51 52 ): EditorCandidate[] {
52 - if (process.env.TERMUX_VERSION)
53 + if (platform === "android" && env.TERMUX_VERSION)
53 54 return [{ command: "termux-open", args: [file], wait: false }];
54 55 if (platform === "darwin")
55 56 return [{ command: "open", args: ["-t", file], wait: false }];

extensions/tune/__tests__/remaining.test.ts

Modified
1 1 import * as fs from "node:fs";
2 +import { tmpdir } from "node:os";
2 3 import * as path from "node:path";
3 -import { afterEach, beforeAll, describe, expect, it } from "vitest";
4 +import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
4 5 import {
5 6 buildTuneCompactionSummary,
6 7 tuneSummaryPathsFor,
10 11 import { reconstructJsonlState } from "../jsonl.ts";
11 12 import { resolveTuneShortcuts } from "../shortcuts.ts";
13 -const TESTDIR = "/tmp/pi-ext-20260530-164209-project";
14 -const LOCK_TESTDIR = "/tmp/pi-ext-tune-lock";
14 +const TESTDIR = fs.mkdtempSync(path.join(tmpdir(), "pi-ext-tune-"));
15 +const LOCK_TESTDIR = path.join(TESTDIR, "lock");
15 16 const TEST_JSONL =
17 18 '{"type":"config","name":"Optimize sqrt/sin loop","metricName":"total_ms","metricUnit":"ms","bestDirection":"lower"}',
32 33 fs.rmSync(LOCK_TESTDIR, { recursive: true, force: true });
36 +afterAll(() => {
37 + fs.rmSync(TESTDIR, { recursive: true, force: true });
38 +});
35 40 // ── 1. COMPACTION RESUME ────────────────────────────────────────────────
37 42 describe("compaction resume", () => {