Files
PaperClipAI/packages/paperclip-runner/examples/sdk.spec.ts
Dotta 560e7e48b5 feat(runner): add SDK and developer tooling (#12608)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The runner package already provides the production protocol and
execution spine.
> - Contributors still need stable SDK surfaces, deterministic test
tools, and local inspection tools.
> - Those surfaces share generated contracts and must change as one
package boundary.
> - This pull request adds the package-local SDK, labs, examples, and
drift checks.
> - The benefit is a reviewable developer platform that does not change
application execution selection.

## Linked Issues or Issue Description

**Subsystem affected**

`packages/paperclip-runner` — runner SDK, conformance tools, and
developer tooling.

**Problem or motivation**

The production runner spine is present, but package consumers cannot
build deterministic integrations, inspect sessions, or verify
provider-neutral behavior through supported surfaces.

**Proposed solution**

Add browser, React, standalone, live-session, scenario, conformance, and
evaluation surfaces. Add generated contract inventories and
package-local verification scripts. Keep production application routing
unchanged.

**Alternatives considered**

We considered splitting each generated catalog, SDK surface, and demo
into separate pull requests. Those changes share exports, fixtures, and
drift gates. Splitting them would create intermediate package states
that do not build.

**Roadmap alignment**

No overlapping item appears in `ROADMAP.md`. This work extends the
runner package that is already on `master`.

## What Changed

- Add browser, React, standalone, live-session, and issue-thread SDK
surfaces.
- Add deterministic mock control-plane, scenario, conformance, replay,
and evaluation tools.
- Add bounded Codex, OpenCode, and ACPX development transports and
fixtures.
- Keep deferred managed-provider execution fail-closed. Persisted
compatibility data remains readable.
- Add generated capability inventories with their source files and drift
checks.
- Add examples, package documentation, browser checks, and
clean-consumer checks.
- Preserve the reviewed protocol bounds, replay compatibility aliases,
process environment isolation, and semantic redaction limits.
- Update the ACPX package patch that the existing workspace patch
registry already tracks.
- Do not change `pnpm-lock.yaml`, repository workflows, server runtime
selection, or the application UI.

## Verification

GitHub Actions is the verification authority for this pull request. The
repository CI, package TypeScript and Rust checks, package tests,
generated-output drift checks, browser checks, security scans, and
Greptile review must pass on the exact head.

Local test suites were not run because this series uses parallel GitHub
Actions for verification.

## Risks

This is a large greenfield package change. The main risks are public
export drift, generated-output drift, and optional React consumer
compatibility. Package boundary checks, clean-consumer checks, and
browser tests cover those risks. Production adapter selection and server
execution are outside this pull request.

## Stack

1. **This PR:** runner SDK and developer tooling.
2. [Codex production server
integration](https://github.com/paperclipai/paperclip/pull/12616).
3. [Provider-neutral task-thread
UI](https://github.com/paperclipai/paperclip/pull/12617).

## Model Used

OpenAI Codex, GPT-5, high-reasoning mode, with tool use and code
execution.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have described the issue in-PR following the feature request
template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
Paperclip ticket id
- [ ] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-08-31 21:33:11 -05:00

266 lines
14 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
const DESKTOP = { width: 1440, height: 900 };
const MOBILE = { width: 390, height: 844 };
async function screenshotPair(page: Page, name: string, mobilePanel = "chat") {
await page.setViewportSize(DESKTOP);
await page.screenshot({ path: test.info().outputPath(`reference-${name}-1440x900.png`) });
await page.setViewportSize(MOBILE);
await expect(page.getByTestId("composer-input")).toBeVisible();
if (mobilePanel !== "chat") {
await page.getByRole("button", { name: "Menu" }).click();
await page.getByRole("menuitem", { name: mobilePanel === "session" ? "Session controls" : "Protocol inspector" }).click();
}
await expect(page.locator('[data-slot="runner-console-app"]')).toBeVisible();
await page.screenshot({ path: test.info().outputPath(`reference-${name}-390x844.png`) });
await page.setViewportSize(DESKTOP);
}
async function miniScreenshotPair(page: Page, name: string) {
await page.setViewportSize(DESKTOP);
await page.screenshot({ path: test.info().outputPath(`mini-${name}-1440x900.png`) });
await page.setViewportSize(MOBILE);
await page.screenshot({ path: test.info().outputPath(`mini-${name}-390x844.png`) });
await page.setViewportSize(DESKTOP);
}
async function openReference(page: Page) {
await page.setViewportSize(DESKTOP);
await page.goto("/reference-console/");
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();
await expect(page.getByTestId("console-version")).toHaveText("🖇️ v0.1.2");
await expect(page.getByTestId("manifest-list")).toBeVisible();
}
test("starts as a regular chat while keeping protocol debug available", async ({ page }) => {
await openReference(page);
await expect(page.getByRole("heading", { name: "Codex protocol chat" })).toBeVisible();
await page.getByTestId("composer-input").fill("Hello through the protocol");
await page.getByTestId("composer-send").click();
await expect(page.getByTestId("runner-transcript")).toContainText(
"normal chat carried through the runner protocol",
{ timeout: 15_000 },
);
await expect(page.locator("body")).not.toContainText("Live console boundary: operate only");
await page.getByTestId("toggle-inspector").click();
await expect(page.getByRole("complementary", { name: "Protocol inspector" })).toBeVisible();
});
async function runManifest(page: Page, id: string) {
await page.getByTestId(`manifest-${id}`).click();
await page.getByTestId("run-manifest").click();
await expect(page.getByTestId("connection-status")).toHaveText("connected", { timeout: 15_000 });
}
test.describe("SDK reference console evidence", () => {
test("captures idle and streaming states at both canonical viewports", async ({ page }) => {
await openReference(page);
await expect(page.getByTestId("empty-transcript")).toBeVisible();
await screenshotPair(page, "idle-empty");
await runManifest(page, "completion");
await expect(page.getByTestId("reasoning-item")).toBeVisible();
await expect(page.getByTestId("composer-send")).toHaveText("Steer");
const streamingAnswer = page.locator('.pcr-message[data-role="assistant"] .pcr-message-text');
await expect(streamingAnswer).toBeVisible({ timeout: 15_000 });
const firstFrame = await streamingAnswer.innerText();
await expect.poll(async () => (await streamingAnswer.innerText()).length).toBeGreaterThan(firstFrame.length);
await expect(page.locator('.pcr-message[data-role="assistant"]')).toHaveAttribute("data-state", /streaming|settled/);
await screenshotPair(page, "streaming-turn");
await expect(page.getByTestId("turn-completed")).toBeVisible({ timeout: 20_000 });
const responseVisibility = await page.locator('.pcr-message[data-role="assistant"]').last().evaluate((response) => {
const viewport = response.closest('[data-testid="runner-transcript"]');
if (!(viewport instanceof HTMLElement)) return false;
const responseBox = response.getBoundingClientRect();
const viewportBox = viewport.getBoundingClientRect();
return responseBox.top >= viewportBox.top && responseBox.top < viewportBox.bottom;
});
expect(responseVisibility).toBe(true);
expect(await page.locator("body").innerText()).not.toContain("Bearer ");
expect(await page.locator("body").innerText()).not.toContain("auth.json");
const terminal = page.locator('[data-testid="tool-item"][data-view="terminal"]').first();
await terminal.locator(":scope > summary").click();
await expect(terminal).toContainText("Input");
await expect(terminal).toContainText("Output");
const debugDetails = terminal.getByTestId("tool-debug-details");
await debugDetails.locator("summary").click();
await expect(debugDetails).toContainText("sourceEventId");
await expect(debugDetails).toContainText("item.completed");
await screenshotPair(page, "terminal-debug");
});
test("captures steering and interrupt states", async ({ page }) => {
await openReference(page);
await runManifest(page, "steering");
await expect(page.getByTestId("composer-send")).toHaveText("Steer");
await page.getByTestId("composer-input").fill("Keep it short.");
await page.getByTestId("composer-send").click();
await expect(page.getByTestId("steering-chip")).toContainText("acknowledged", { timeout: 15_000 });
await screenshotPair(page, "steering-acknowledged");
await page.getByRole("button", { name: "Reset demo state", exact: true }).click();
await page.getByTestId("reset-confirm").click();
await runManifest(page, "interrupt-during-generation");
await expect(page.getByTestId("runner-transcript")).toContainText("The tracer keeps", { timeout: 15_000 });
await page.getByTestId("composer-stop").click();
await expect(page.getByTestId("turn-interrupted")).toBeVisible({ timeout: 15_000 });
await screenshotPair(page, "interrupt");
});
test("captures request, goal, reconnect, replay, and failure states", async ({ page }) => {
await openReference(page);
await runManifest(page, "approvals");
await expect(page.getByTestId("request-card").first()).toHaveAttribute("data-status", "pending", { timeout: 15_000 });
await screenshotPair(page, "request-pending");
await page.getByTestId("request-action-accept").first().click();
await expect(page.getByTestId("request-card").first()).toHaveAttribute("data-status", "resolved", { timeout: 15_000 });
await screenshotPair(page, "request-resolved");
await page.getByRole("button", { name: "Reset demo state", exact: true }).click();
await page.getByTestId("reset-confirm").click();
await runManifest(page, "goals");
await page.getByRole("button", { name: "Goal", exact: true }).click();
await page.getByRole("menuitem", { name: "Set goal…" }).click();
await page.getByTestId("goal-objective").fill("Prove the SDK lifecycle.");
await page.getByTestId("goal-set-confirm").click();
await expect(page.getByTestId("goal-banner")).toContainText("Prove the SDK lifecycle.");
await screenshotPair(page, "goal-set", "session");
await page.setViewportSize(DESKTOP);
await page.getByTestId("drop-connection").click();
await expect(page.getByTestId("reconnect-banner")).toBeVisible();
await screenshotPair(page, "reconnect-banner");
await expect(page.getByTestId("connection-status")).toHaveText("connected", { timeout: 10_000 });
await page.getByTestId("toggle-replay").click();
await expect(page.getByTestId("replay-controls")).toBeVisible();
await page.getByRole("button", { name: "Step forward" }).click();
await screenshotPair(page, "replay-mode");
await page.setViewportSize(DESKTOP);
await page.getByTestId("toggle-replay").click();
await page.getByRole("button", { name: "Reset demo state", exact: true }).click();
await page.getByTestId("reset-confirm").click();
await runManifest(page, "failure");
await expect(page.getByTestId("turn-failed")).toBeVisible({ timeout: 20_000 });
await screenshotPair(page, "failed-turn");
});
});
test.describe("SDK mini consumer evidence", () => {
test("uses public render, token, request, reconnect, and replay extension points", async ({ page }) => {
await page.goto("/mini-consumer/");
await expect(page.getByRole("heading", { name: "Runner mini consumer" })).toBeVisible();
await miniScreenshotPair(page, "idle");
await page.getByRole("button", { name: "Start selected flow" }).click();
await expect(page.getByText("Mini renderer:").first()).toBeVisible({ timeout: 15_000 });
await miniScreenshotPair(page, "streaming-custom-renderer-token");
await page.getByTestId("composer-input").fill("Keep the mini answer short.");
await expect(page.getByTestId("composer-send")).toHaveText("Steer");
await page.getByTestId("composer-send").click();
await expect(page.getByTestId("mini-steering-chip")).toContainText("acknowledged", { timeout: 15_000 });
await expect(page.getByTestId("turn-completed")).toBeVisible({ timeout: 20_000 });
await page.getByLabel("Demo manifest").selectOption("interrupt-during-generation");
await page.getByRole("button", { name: "Start selected flow" }).click();
await expect(page.getByTestId("composer-send")).toHaveText("Steer", { timeout: 15_000 });
await page.getByTestId("composer-stop").click();
await expect(page.getByTestId("turn-interrupted")).toBeVisible({ timeout: 15_000 });
await page.getByLabel("Demo manifest").selectOption("approvals");
await page.getByRole("button", { name: "Start selected flow" }).click();
await expect(page.getByTestId("request-card").first()).toHaveAttribute("data-status", "pending", { timeout: 15_000 });
await miniScreenshotPair(page, "request-pending");
await page.getByTestId("request-action-accept").first().click();
await expect(page.getByTestId("request-card").first()).toHaveAttribute("data-status", "resolved", { timeout: 15_000 });
await page.getByTestId("mini-goal-set").click();
await expect(page.getByTestId("mini-goal-state")).toContainText("Exercise the public SDK.", { timeout: 15_000 });
await page.getByTestId("mini-goal-clear").click();
await expect(page.getByTestId("mini-goal-state")).toContainText("none", { timeout: 15_000 });
await page.getByRole("button", { name: "Drop connection" }).click();
await expect(page.getByTestId("reconnect-banner")).toBeVisible();
await miniScreenshotPair(page, "reconnect");
await expect(page.getByTestId("reconnect-banner")).toHaveCount(0, { timeout: 10_000 });
await page.getByRole("button", { name: "Enter replay" }).click();
await expect(page.getByTestId("replay-controls")).toBeVisible();
await page.getByTestId("replay-position").press("ArrowRight");
await expect(page.getByTestId("mini-replay-parity")).toContainText("match");
await miniScreenshotPair(page, "replay");
});
});
test("meets keyboard, accessibility, responsive, and grid contracts", async ({ page }) => {
await openReference(page);
await runManifest(page, "completion");
await expect(page.getByTestId("turn-completed")).toBeVisible({ timeout: 20_000 });
await page.getByTestId("composer-input").fill("first");
await page.getByTestId("composer-input").press("Shift+Enter");
await expect(page.getByTestId("composer-input")).toHaveValue("first\n");
await page.getByTestId("toggle-inspector").click();
await page.getByRole("tab", { name: "Events" }).focus();
await page.keyboard.press("ArrowRight");
await expect(page.getByRole("tab", { name: "Requests" })).toBeFocused();
const goalMenu = page.getByRole("button", { name: "Goal", exact: true });
await goalMenu.focus();
await page.keyboard.press("ArrowDown");
await expect(page.getByRole("menu")).toBeVisible();
await expect(page.getByRole("menuitem").first()).toBeFocused();
await page.keyboard.press("Escape");
await expect(goalMenu).toBeFocused();
await expect(page.getByRole("menu")).toHaveCount(0);
await goalMenu.press("ArrowDown");
await expect(page.getByRole("menu")).toBeVisible();
await expect(page.getByRole("menuitem").first()).toBeFocused();
await page.getByRole("menuitem", { name: "Set goal…" }).click();
await expect(page.getByRole("dialog", { name: "Set goal" })).toBeVisible();
await page.keyboard.press("Escape");
await expect(page.getByRole("dialog", { name: "Set goal" })).not.toBeVisible();
await page.getByTestId("toggle-replay").click();
await page.getByTestId("replay-position").focus();
await page.keyboard.press("ArrowRight");
await expect(page.getByTestId("replay-position")).toHaveValue("1");
await page.keyboard.press("Space");
await expect(page.getByTestId("replay-controls").getByRole("button", { name: "Pause", exact: true })).toBeVisible();
await page.getByTestId("toggle-replay").click();
const terminal = page.locator('[data-testid="tool-item"][data-view="terminal"]').first();
await terminal.locator(":scope > summary").click();
await terminal.getByTestId("tool-debug-details").locator("summary").click();
expect(await page.getByRole("log").count()).toBe(1);
expect(await page.locator('[aria-live="polite"]').count()).toBe(1);
const unnamed = await page.locator("button").evaluateAll((buttons) => buttons.filter((button) => (button.getAttribute("aria-label") ?? button.textContent ?? "").trim().length === 0).length);
expect(unnamed).toBe(0);
const boxes = await page.evaluate(() => {
const root = document.querySelector<HTMLElement>('[data-slot="runner-console-app"]')!;
const rail = document.querySelector<HTMLElement>(".pcr-console-rail")!;
const center = document.querySelector<HTMLElement>(".pcr-console-center")!;
return { root: root.getBoundingClientRect(), rail: rail.getBoundingClientRect(), center: center.getBoundingClientRect() };
});
expect(boxes.rail.right).toBeLessThanOrEqual(boxes.center.left);
expect(boxes.center.right).toBeLessThanOrEqual(boxes.root.right);
await page.setViewportSize(MOBILE);
await expect(page.getByTestId("composer-input")).toBeVisible();
await expect(page.getByRole("button", { name: "Menu" })).toBeVisible();
await page.getByRole("button", { name: "Menu" }).click();
await expect(page.getByRole("menuitem", { name: "Session controls" })).toBeVisible();
await expect(page.getByRole("menuitem", { name: "Protocol inspector" })).toBeVisible();
await page.keyboard.press("Escape");
expect(await page.getByRole("log").count()).toBe(1);
await expect(terminal.getByTestId("tool-debug-details")).toContainText("sourceEventId");
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow).toBeLessThanOrEqual(1);
});