Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .pi/extensions/context-grep/README.md

This file was deleted.

49 changes: 0 additions & 49 deletions .pi/extensions/context-grep/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions .pi/extensions/context-grep/tsconfig.json

This file was deleted.

59 changes: 0 additions & 59 deletions .pi/extensions/context-grep/types/pi-coding-agent.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bproxy/cli",
"version": "0.8.0",
"version": "0.9.0",
"private": true,
"type": "module",
"bin": {
Expand Down
16 changes: 10 additions & 6 deletions cli/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { type ClientGlobalArgs, sendAction, validateResponse } from "../client.js";
import type { ActionParams, TabHandle } from "../types.js";
import { PROTOCOL_VERSION } from "../types.js";
import { extractUrl } from "./fetch-helper.js";
import { createTestStateDir } from "./helpers/test-state-dir.js";

Expand All @@ -25,7 +26,7 @@ const DEFAULT_RESPONSE_DATA = { text: "hello" };

function successResponse(id: string, data: unknown = DEFAULT_RESPONSE_DATA) {
return {
protocol_version: 1,
protocol_version: PROTOCOL_VERSION,
id,
ok: true,
data,
Expand All @@ -36,7 +37,7 @@ function successResponse(id: string, data: unknown = DEFAULT_RESPONSE_DATA) {

function errorResponse(id: string, code = "ELEMENT_NOT_FOUND") {
return {
protocol_version: 1,
protocol_version: PROTOCOL_VERSION,
id,
ok: false,
error: {
Expand Down Expand Up @@ -135,7 +136,7 @@ describe("validateResponse", () => {
});

it("rejects wrong protocol_version", () => {
const result = validateResponse({ ...successResponse(reqId), protocol_version: 2 }, reqId);
const result = validateResponse({ ...successResponse(reqId), protocol_version: 99 }, reqId);
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.reason).toContain("protocol_version");
Expand Down Expand Up @@ -184,7 +185,10 @@ describe("validateResponse", () => {
});

it("rejects error response without error object", () => {
const result = validateResponse({ protocol_version: 1, id: reqId, ok: false }, reqId);
const result = validateResponse(
{ protocol_version: PROTOCOL_VERSION, id: reqId, ok: false },
reqId,
);
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.reason).toContain("'error' object");
Expand All @@ -193,7 +197,7 @@ describe("validateResponse", () => {

it("rejects error response with error missing code", () => {
const result = validateResponse(
{ protocol_version: 1, id: reqId, ok: false, error: { category: "target" } },
{ protocol_version: PROTOCOL_VERSION, id: reqId, ok: false, error: { category: "target" } },
reqId,
);
expect(result.ok).toBe(false);
Expand Down Expand Up @@ -267,7 +271,7 @@ describe("sendAction", () => {
expect(calls).toHaveLength(1);
expect(calls[0]!.url).toBe("http://127.0.0.1:9615/");
const body = JSON.parse(calls[0]!.init.body as string);
expect(body.protocol_version).toBe(1);
expect(body.protocol_version).toBe(PROTOCOL_VERSION);
expect(body.id).toBe(reqId);
expect(body.action).toBe("text");
expect(body.params).toEqual({ selector: ".content" });
Expand Down
1 change: 1 addition & 0 deletions cli/src/__tests__/command-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const DESTRUCTIVE: Action[] = [
"tab.unpin",
"tab.open",
"tab.close",
"tab.activate",
"session.create",
"session.bind",
"session.unbind",
Expand Down
3 changes: 2 additions & 1 deletion cli/src/__tests__/command-test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { PROTOCOL_VERSION } from "@bproxy/shared";
import type { ClientGlobalArgs, SendOptions } from "../client.js";
import { sendAction } from "../client.js";
import { extractUrl } from "./fetch-helper.js";
Expand Down Expand Up @@ -34,7 +35,7 @@ export function makeGlobals(

export function successResponse(id: string, data: unknown = {}) {
return {
protocol_version: 1,
protocol_version: PROTOCOL_VERSION,
id,
ok: true,
data,
Expand Down
3 changes: 2 additions & 1 deletion cli/src/__tests__/commands-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { type ClientGlobalArgs, type SendOptions, sendAction } from "../client.js";
import { PROTOCOL_VERSION } from "../types.js";
import {
createMockFetch,
makeGlobals,
Expand All @@ -24,7 +25,7 @@ import { createTestStateDir } from "./helpers/test-state-dir.js";

function errorResponse(id: string, code: string, message = "error") {
return {
protocol_version: 1,
protocol_version: PROTOCOL_VERSION,
id,
ok: false,
error: { code, message },
Expand Down
62 changes: 62 additions & 0 deletions cli/src/__tests__/commands-read-parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,65 @@ describe("optional param omission patterns", () => {
expect(params).toEqual({ activate: true, debugger: true });
});
});

// ─── links numeric param parsing ────────────────────────────────────────

function parseInteger(raw: string, min: number): number | null {
if (!/^[0-9]+$/.test(raw)) return null;
const value = Number(raw);
if (!Number.isSafeInteger(value) || value < min) return null;
return value;
}

function parseLimit(raw: string): number | null {
return parseInteger(raw, 1);
}

function parseOffset(raw: string): number | null {
return parseInteger(raw, 0);
}

describe("links --limit parsing logic", () => {
it("parses valid positive integer", () => {
expect(parseLimit("50")).toBe(50);
});

it("rejects zero", () => {
expect(parseLimit("0")).toBeNull();
});

it("rejects negative number", () => {
expect(parseLimit("-5")).toBeNull();
});

it("rejects non-numeric string", () => {
expect(parseLimit("abc")).toBeNull();
});

it("rejects float string", () => {
expect(parseLimit("3.5")).toBeNull();
});
});

describe("links --offset parsing logic", () => {
it("parses valid non-negative integer", () => {
expect(parseOffset("0")).toBe(0);
expect(parseOffset("100")).toBe(100);
});

it("rejects negative number", () => {
expect(parseOffset("-1")).toBeNull();
});

it("rejects non-numeric string", () => {
expect(parseOffset("abc")).toBeNull();
});

it("rejects empty string", () => {
expect(parseOffset("")).toBeNull();
});

it("rejects float string", () => {
expect(parseOffset("3.5")).toBeNull();
});
});
Loading