test: close audit cleanup findings

This commit is contained in:
Federico Jaramillo Martinez
2026-07-03 21:40:36 +02:00
parent 10efb7f221
commit 8511604e83
7 changed files with 38 additions and 38 deletions
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from "vitest";
import { activateSelectableRow, activateSelectableRowFromKeyboard, handleSelectableRowKeyboard } from "./selectableRow";
import { activateSelectableRow, handleSelectableRowKeyboard } from "./selectableRow";
describe("selectable row activation", () => {
it("activates rows from non-interactive click targets", () => {
@@ -20,8 +20,8 @@ describe("selectable row activation", () => {
const enter = keyboardEventWithPath("Enter", matchTarget(() => false));
const space = keyboardEventWithPath(" ", matchTarget(() => false));
activateSelectableRowFromKeyboard(enter, enterAction);
activateSelectableRowFromKeyboard(space, spaceAction);
expect(handleSelectableRowKeyboard(enter, { activate: enterAction })).toBe(true);
expect(handleSelectableRowKeyboard(space, { activate: spaceAction })).toBe(true);
expect(enterAction).toHaveBeenCalledOnce();
expect(spaceAction).toHaveBeenCalledOnce();
@@ -33,7 +33,7 @@ describe("selectable row activation", () => {
const action = vi.fn();
const event = keyboardEventWithPath("Enter", matchTarget((selector: string) => selector.includes("button")));
activateSelectableRowFromKeyboard(event, action);
expect(handleSelectableRowKeyboard(event, { activate: action })).toBe(false);
expect(action).not.toHaveBeenCalled();
expect(event.preventDefault).not.toHaveBeenCalled();
+3 -9
View File
@@ -11,8 +11,9 @@ const interactiveSelector = [
].join(",");
type ComposedPathEvent = Pick<Event, "composedPath">;
type SelectableKeyboardEvent = ComposedPathEvent & Pick<KeyboardEvent, "key" | "preventDefault">;
type SelectableNavigationKeyboardEvent = SelectableKeyboardEvent & Partial<Pick<KeyboardEvent, "currentTarget" | "stopPropagation">>;
type SelectableNavigationKeyboardEvent = ComposedPathEvent
& Pick<KeyboardEvent, "key" | "preventDefault">
& Partial<Pick<KeyboardEvent, "currentTarget" | "stopPropagation">>;
export interface SelectableRowKeyboardOptions {
activate: () => void;
@@ -37,13 +38,6 @@ export function activateSelectableRow(event: ComposedPathEvent, action: () => vo
action();
}
export function activateSelectableRowFromKeyboard(event: SelectableKeyboardEvent, action: () => void): void {
if (event.key !== "Enter" && event.key !== " ") return;
if (isFromInteractiveElement(event)) return;
event.preventDefault();
action();
}
export function handleSelectableRowKeyboard(event: SelectableNavigationKeyboardEvent, options: SelectableRowKeyboardOptions): boolean {
if (isFromInteractiveElement(event)) return false;
if (event.key === "Enter" || event.key === " ") {
+22 -4
View File
@@ -37,10 +37,8 @@ describe("pi-web-docker documentation", () => {
readRepoFile("docker/pi-web-docker"),
]);
for (const command of PI_WEB_DOCKER_USER_COMMANDS) {
expect(dockerReadme).toContain(`| \`${command}\` |`);
expect(dockerEntrypoint).toContain(command);
}
expect(readDockerCommandMatrix(dockerReadme)).toEqual([...PI_WEB_DOCKER_USER_COMMANDS]);
expect(readEntrypointCommandCases(dockerEntrypoint)).toEqual(new Set(PI_WEB_DOCKER_USER_COMMANDS));
expect(dockerReadme).toContain("`pi-web-docker --dev status`");
expect(dockerReadme).toContain("`./docker/pi-web-docker --dev start`");
@@ -49,6 +47,26 @@ describe("pi-web-docker documentation", () => {
});
});
function readDockerCommandMatrix(dockerReadme: string): string[] {
const commandMatrixSection = dockerReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? "";
return Array.from(commandMatrixSection.matchAll(/^\| `([^`]+)` \|/gm), (match) => {
const command = match[1];
if (command === undefined) throw new Error("Docker command matrix row did not include a command");
return command;
});
}
function readEntrypointCommandCases(dockerEntrypoint: string): Set<string> {
const commandCaseBlock = dockerEntrypoint.slice(dockerEntrypoint.indexOf('case "$command_name" in'));
const commandCases = new Set<string>();
for (const line of commandCaseBlock.split("\n")) {
const match = /^ {2}([a-z][a-z-]*(?:\|[a-z][a-z-]*)*)(?:\|__run-detached)?\)$/.exec(line);
if (match?.[1] === undefined) continue;
for (const command of match[1].split("|")) commandCases.add(command);
}
return commandCases;
}
async function readRepoFile(relativePath: string): Promise<string> {
return await readFile(join(repoRoot, relativePath), "utf8");
}
+4 -1
View File
@@ -67,7 +67,10 @@ describe("PiWebPluginService", () => {
const service = new PiWebPluginService({ roots: [{ path: join(tempDir, "plugins"), source: "test", scope: "local" }], packageProvider: false });
const manifest = await service.manifest();
expect(manifest.plugins[0]?.module).toMatch(/^\/pi-web-plugins\/updates\/pi-web-plugin\.js\?v=\d+&piWebDockerMode=dev$/u);
const moduleUrl = new URL(manifest.plugins[0]?.module ?? "", "http://pi-web.test");
expect(moduleUrl.pathname).toBe("/pi-web-plugins/updates/pi-web-plugin.js");
expect(moduleUrl.searchParams.get("v")).toMatch(/^\d+$/u);
expect(moduleUrl.searchParams.get("piWebDockerMode")).toBe("dev");
});
it("discovers Pi package plugins through an injected package provider", async () => {
+2 -9
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { isSessionActive, sessionActivityLabel, isWorkspaceActivityActive } from "./activity";
import { isSessionActive, isWorkspaceActivityActive } from "./activity";
import type { SessionStatus, WorkspaceActivity } from "./apiTypes";
const idleStatus: SessionStatus = {
@@ -14,17 +14,10 @@ const idleStatus: SessionStatus = {
};
describe("activity helpers", () => {
it("detects and labels active session states consistently", () => {
it("detects active session states", () => {
expect(isSessionActive(idleStatus)).toBe(false);
expect(sessionActivityLabel(idleStatus)).toBeUndefined();
expect(isSessionActive({ ...idleStatus, isStreaming: true })).toBe(true);
expect(sessionActivityLabel({ ...idleStatus, isStreaming: true })).toBe("streaming");
expect(isSessionActive({ ...idleStatus, pendingMessageCount: 2 })).toBe(true);
expect(sessionActivityLabel({ ...idleStatus, pendingMessageCount: 2 })).toBe("2 pending");
expect(sessionActivityLabel(idleStatus, { sessionId: "s1", phase: "active", label: "running tool", detail: "read", at: "now" })).toBe("running tool: read");
});
it("detects workspace activity presence without exposing details", () => {
-10
View File
@@ -8,16 +8,6 @@ export function isSessionActive(status?: SessionStatus, activity?: SessionActivi
|| (status?.pendingMessageCount ?? 0) > 0;
}
export function sessionActivityLabel(status?: SessionStatus, activity?: SessionActivity): string | undefined {
if (activity?.phase === "active") return activity.detail !== undefined && activity.detail !== "" ? `${activity.label}: ${activity.detail}` : activity.label;
if (status === undefined) return undefined;
if (status.isCompacting) return "compacting";
if (status.isBashRunning) return "bash";
if (status.isStreaming) return "streaming";
if (status.pendingMessageCount > 0) return `${String(status.pendingMessageCount)} pending`;
return undefined;
}
export function isWorkspaceActivityActive(activity: WorkspaceActivity | undefined): boolean {
return activity !== undefined && (activity.hasSessionActivity || activity.hasTerminalActivity);
}