repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

test: stabilize cross-platform extension fixtures

b8d762c3d5436a7aa52a9d15fa2d21eb3ae27d29

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

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (6)

extensions/lazy/__tests__/harness.test.ts

Modified
171 171 it("agent_end notifies for newly added lazy markers", async () => {
172 172 t = await createTestSession({ extensions: [extensionPath()] });
173 173 execFileSync("git", ["init", "-q"], { cwd: t.cwd });
174 + execFileSync("git", ["config", "core.autocrlf", "false"], {
175 + cwd: t.cwd,
176 + });
174 177 execFileSync("git", ["config", "user.email", "lazy@example.invalid"], {
175 178 cwd: t.cwd,

extensions/leaks/__fuzz__/replay.ts

Modified
1 1 import { test } from "@fast-check/vitest";
2 2 import type { Arbitrary } from "fast-check";
4 +export function isSelectedProperty(
5 + id: string,
6 + selected = process.env.FC_TEST,
7 +): boolean {
8 + return !selected || selected === id;
9 +}
4 11 export function prop<T extends Record<string, Arbitrary<unknown>>>(
5 12 id: string,
6 13 arbitraries: T,
7 14 numRuns = 1_000,
9 - const selected = !process.env.FC_TEST || process.env.FC_TEST === id;
16 + const selected = isSelectedProperty(id);
10 17 const runner = selected ? test : test.skip;
11 18 return runner.prop(arbitraries, {
12 19 numRuns,

extensions/leaks/__tests__/demo-corpus.test.ts

Modified
53 53 return walk(root)
54 54 .filter((file) => !readFileSync(file).includes(0))
55 55 .map((file) => {
56 - const relativePath = path.relative(root, file);
56 + const relativePath = path.relative(root, file).split(path.sep).join("/");
57 57 const source = readFileSync(file, "utf8");
58 58 const result = engine.redactText(source, "provider");
59 59 const spans = __test.selectSecretSpans(source, [
63 63 return {
64 64 relativePath,
65 - fixtureClass: relativePath.split(path.sep)[0] ?? relativePath,
65 + fixtureClass: relativePath.split("/")[0] ?? relativePath,
66 66 redactionCount: result.count,
67 67 labels: [...new Set(result.labels)].toSorted(),
68 68 spans: spans.map((span) => ({
72 72 })),
73 73 restoredExactly: engine.restoreText(result.text) === source,
75 - });
75 + })
76 + .toSorted((a, b) =>
77 + a.relativePath < b.relativePath
78 + ? -1
79 + : a.relativePath > b.relativePath
80 + ? 1
81 + : 0,
82 + );
78 85 function walk(dir: string): string[] {

extensions/leaks/__tests__/fuzz-runner.test.ts

Modified
1 1 import { spawnSync } from "node:child_process";
2 2 import process from "node:process";
3 3 import { describe, expect, it } from "vitest";
4 +import { isSelectedProperty } from "../__fuzz__/replay.ts";
5 6 describe("leaks fuzz runner", () => {
6 - it("selects and replays exactly one named property", () => {
7 - const result = spawnSync(process.execPath, ["scripts/run_leaks_fuzz.mjs"], {
8 - cwd: process.cwd(),
9 - encoding: "utf8",
10 - env: {
11 - ...process.env,
12 - FC_TEST: "jwt-positive",
13 - FC_SEED: "123",
14 - },
15 - });
16 - expect(result.status).toBe(0);
17 - expect(result.stdout).toMatch(/Tests\s+1 passed/);
7 + it("selects exactly one named property", () => {
8 + expect(isSelectedProperty("jwt-positive", "jwt-positive")).toBe(true);
9 + expect(isSelectedProperty("jwt-negative", "jwt-positive")).toBe(false);
10 + expect(isSelectedProperty("jwt-negative", undefined)).toBe(true);
20 13 it("rejects unknown property selectors", () => {

extensions/leaks/__tests__/harness.test.ts

Modified
54 54 (item) =>
55 55 item.type === "custom" && item.customType === "leaks-mapping-v1",
57 - if (!entry || entry.type !== "custom") throw new Error("missing mapping");
57 + if (entry?.type !== "custom") throw new Error("missing mapping");
58 58 return (entry.data as { placeholder: string }).placeholder;

extensions/leaks/__tests__/lifecycle.test.ts

Modified
82 82 const restored = engine.restoreDeep(proto).value;
83 83 expect(Object.hasOwn(restored, "__proto__")).toBe(true);
84 - expect(restored.__proto__).toBe(fixture);
84 + expect(Object.getOwnPropertyDescriptor(restored, "__proto__")?.value).toBe(
85 + fixture,
86 + );
87 89 it("blocks hydrated property-name collisions", () => {