mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
## Thinking Path > - Teams use Paperclip to manage agents and their work. > - Hosted teams can have a private Slack channel with the Paperclip team. > - A workspace member needs to know whether they can open the channel or still need the owner's invitation. > - Cloud supplies that information for the selected organization. > - This change puts a Slack button in the sidebar footer. It opens a dialog with the next action. ## Linked Issues or Issue Description **Subsystem affected** Workspace sidebar and the Cloud onboarding browser journey. **Problem or motivation** After setup, a user can lose track of the invitation to their organization's private feedback channel. **Proposed solution** Show the invitation status in a dialog. Offer a channel link when Cloud confirms the connection. **Roadmap alignment** This extends the existing hosted workspace navigation. The roadmap has no separate item for this shortcut. ## What Changed - Both sidebar variants use the existing portfolio request to show the Slack shortcut when Cloud supplies invitation details. - The icon uses grayscale at rest and brand colors on hover or keyboard focus. The button has an accessible name and a tooltip. - The Cloud onboarding journey selects Codex and confirms feedback intent when the first-account welcome appears. - Storybook covers pending and connected channels. ## Verification - The sidebar suite passed 36 tests. The Cloud onboarding journey suite passed 10 tests covering both the current and previous gateway layouts. - The Storybook catalog regenerated successfully. - In a local browser run, a fresh user completed signup, connected a test model, hired an agent, opened its chat, and opened and dismissed the Slack invitation. The test used a local Slack fixture. - The incremental verifier selected broad CI coverage for the runner journey change. All applicable checks passed on `ea9779abda`. A GitHub runner shut down during a server test shard. The shard and final verification gate passed on retry. [CI run](https://github.com/paperclipai/paperclip/actions/runs/45276376121/attempts/2) · [Greptile review (5/5)](https://github.com/paperclipai/paperclip/pull/22702#issuecomment-7115303606) ## Risks An older Cloud service can omit the optional feedback field. In that case, the sidebar keeps the existing layout. Cloud controls the channel destination and the invitation state. ## Model Used OpenAI GPT-6 in Codex, with repository tools and browser verification. ## 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 either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] 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 any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Scott Tong <1504818+scotttong@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
192 lines
13 KiB
TypeScript
192 lines
13 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { cloudOnboarding, type CloudOnboardingInput } from "./cloud-onboarding.js";
|
|
import { onboardingFirstTask } from "./onboarding-first-task.js";
|
|
import { retainOnboardingArtifact } from "./artifact-evidence.js";
|
|
import { JourneyError } from "./types.js";
|
|
import type { OnboardingPreAcceptanceEvidence } from "./onboarding-pre-acceptance.js";
|
|
|
|
vi.mock("@playwright/test", () => ({ expect: (locator: { isVisible(): Promise<boolean> }) => ({
|
|
toBeVisible: async () => { expect(await locator.isVisible()).toBe(true); },
|
|
not: { toBeVisible: async () => { expect(await locator.isVisible()).toBe(false); } },
|
|
}) }));
|
|
vi.mock("./onboarding-first-task.js", async () => {
|
|
const { retainOnboardingArtifact } = await import("./artifact-evidence.js");
|
|
return { onboardingFirstTask: vi.fn(async ({ proof, onArtifact }) => {
|
|
const artifact = retainOnboardingArtifact({ id: "artifact", originatingRunId: "artifact-run", bytes: Buffer.from(JSON.stringify(proof.expected)), proof });
|
|
onArtifact?.(artifact);
|
|
return { artifact };
|
|
}) };
|
|
});
|
|
|
|
type Entry = "beta-welcome" | "first-run" | "portfolio" | "create-form";
|
|
type Control = { role: string; name: string; scope?: string; fill?(value: string): void; click?(): void; select?(value: string): void };
|
|
|
|
/** Visible control contracts only; no browser, Cloud API, or provider is started. */
|
|
function fixture(entry: Entry, options: { legacyRunnerPicker?: boolean; intentFailure?: boolean; qualificationFailure?: boolean; traceFailure?: boolean } = {}) {
|
|
let stage: string = entry, name = "", apiMode = false, source = false, advanced = false, runnerOpen = false;
|
|
let modelsOpen = false, model = "", runner = "", saved = false, hired = false;
|
|
const fields: Record<string, string> = {}, events: string[] = [];
|
|
let hasCodex = false, intendsFeedback = false;
|
|
const gateway = { baseUrl: "https://owned-gateway.example.test/v1", model: "gpt-5.4-mini", apiKey: "synthetic-test-key" };
|
|
const connection = { id: "connection", name: "My owned-gateway.example.test", provider: "openai", method: "api_key", status: "connected" };
|
|
const create = () => {
|
|
expect(events).toContain("intent:workspace");
|
|
expect(name).toBe("Journey QA campaign");
|
|
events.push("create:workspace"); stage = "agent";
|
|
};
|
|
const controls = (): Control[] => {
|
|
if (stage === "beta-welcome") return [
|
|
{ role: "checkbox", name: "OpenAI Codex", click() { hasCodex = true; } },
|
|
{ role: "checkbox", name: "I intend to provide feedback on the Paperclip closed beta.", click() { intendsFeedback = true; } },
|
|
{ role: "button", name: "Continue", click() { expect(hasCodex && intendsFeedback).toBe(true); stage = "first-run"; } },
|
|
];
|
|
if (stage === "portfolio") return [{ role: "link", name: "Create a new organization", click() { stage = "create-form"; } }];
|
|
if (stage === "first-run" || stage === "create-form") return [
|
|
{ role: "textbox", name: stage === "first-run" ? "Name" : "Organization name", fill(value) { name = value; } },
|
|
{ role: "button", name: stage === "first-run" ? "Next" : "Create organization", click: create },
|
|
];
|
|
if (stage === "agent") return [
|
|
{ role: "heading", name: "Create your first agent" },
|
|
{ role: "textbox", name: "Agent name", fill(value) { name = value; } },
|
|
{ role: "button", name: "Next", click() { stage = "connect"; } },
|
|
];
|
|
if (stage === "started") return [];
|
|
if (hired) return [{ role: "button", name: "Get started", click() { stage = "started"; } }];
|
|
const result: Control[] = [
|
|
{ role: "button", name: apiMode ? "Use subscription instead" : "Use API key instead", click() { apiMode = !apiMode; } },
|
|
{ role: "radio", name: apiMode ? "OpenAI API key" : "OpenAI Subscription", click() { source = true; } },
|
|
];
|
|
if (source && apiMode && (advanced || options.legacyRunnerPicker)) result.push({ role: "button", name: "Use a custom gateway", click() { stage = "gateway"; } });
|
|
if (stage === "gateway") {
|
|
result.push({ role: "dialog", name: "Custom gateway connection" });
|
|
for (const field of ["Provider URL", "API key", ...(modelsOpen ? ["Model IDs"] : [])]) result.push({
|
|
role: "textbox", name: field, scope: "gateway", fill(value) { fields[field] = value; },
|
|
});
|
|
result.push({ role: "button", name: "Change", scope: "gateway", click() { modelsOpen = true; } },
|
|
{ role: "button", name: "Save connection", scope: "gateway", click() {
|
|
expect(fields).toEqual({ "Provider URL": gateway.baseUrl, "API key": gateway.apiKey, "Model IDs": gateway.model });
|
|
expect(events).toContain("intent:connection"); events.push("save:connection"); saved = true; stage = "connect";
|
|
} });
|
|
}
|
|
if (saved) result.push({ role: "combobox", name: "Model", select(value) { expect(value).toBe(gateway.model); model = value; } });
|
|
if (source) result.push({ role: "summary", name: "Advanced", click() { advanced = true; } });
|
|
if (advanced && options.legacyRunnerPicker) result.push({ role: "button", name: "Runner", click() { runnerOpen = true; } });
|
|
if (runnerOpen) result.push({ role: "option", name: "Paperclip Runner (default)", click() { runner = "paperclip"; runnerOpen = false; } });
|
|
if (saved && model && (!options.legacyRunnerPicker || runner)) result.push({ role: "button", name: "Connect", click() {
|
|
expect(events).toContain("qualified"); events.push("paid:connect"); hired = true;
|
|
} });
|
|
return result;
|
|
};
|
|
const match = (value: string, expected: string | RegExp) => typeof expected === "string" ? value === expected : expected.test(value);
|
|
const locator = (resolve: () => Control[]): any => ({
|
|
first() { return locator(() => resolve().slice(0, 1)); },
|
|
or(other: { resolve(): Control[] }) { return locator(() => [...resolve(), ...other.resolve()]); },
|
|
resolve,
|
|
async isVisible() { return resolve().length > 0; },
|
|
async check() { const control = resolve()[0]; if (control?.role !== "checkbox" || !control.click) throw new Error("No visible checkbox"); control.click(); },
|
|
async fill(value: string) { const control = resolve()[0]; if (!control?.fill) throw new Error("No visible text field"); control.fill(value); },
|
|
async click() { const control = resolve()[0]; if (!control?.click) throw new Error("No visible action"); events.push(`click:${control.name}`); control.click(); },
|
|
async selectOption(value: string) { const control = resolve()[0]; if (!control?.select) throw new Error("No visible native model picker"); control.select(value); },
|
|
async waitFor() { expect(resolve().length).toBeGreaterThan(0); },
|
|
filter({ hasText }: { hasText: string }) { return locator(() => resolve().filter(control => control.name.includes(hasText))); },
|
|
getByLabel(label: string) { return locator(() => controls().filter(control => control.scope === "gateway" && control.name === label)); },
|
|
getByRole(role: string, { name: label }: { name: string | RegExp }) {
|
|
return locator(() => controls().filter(control => control.scope === "gateway" && control.role === role && match(control.name, label)));
|
|
},
|
|
});
|
|
const page = {
|
|
on() { return this; },
|
|
off() { return this; },
|
|
getByLabel(label: string) { return locator(() => controls().filter(control => control.name === label && control.role === "textbox")); },
|
|
getByRole(role: string, { name: label }: { name: string | RegExp }) {
|
|
return locator(() => controls().filter(control => control.role === role && match(control.name, label)));
|
|
},
|
|
locator(selector: string) { expect(selector).toBe("summary"); return locator(() => controls().filter(control => control.role === "summary")); },
|
|
};
|
|
const context = { page, company: { id: "company" }, identity: { kind: "cloud" }, startingState: "recipe", api: {
|
|
origin: "https://tenant.example.test",
|
|
async get(route: string) {
|
|
if (route.endsWith("/ai-connections")) return { connections: saved ? [connection] : [] };
|
|
if (route.endsWith("/agents")) return hired ? [{ id: "agent", name, adapterType: "paperclip_runner", adapterConfig: { provider: "codex", model: gateway.model } }] : [];
|
|
throw new Error("Unexpected API read");
|
|
},
|
|
} };
|
|
const input = { page, campaignId: "campaign", deadlineAt: Date.now() + 60_000, gateway, maxRuns: 8, evidence: { checks: [] },
|
|
async beforeWorkspace() { if (options.intentFailure) throw new Error("ownership unavailable"); events.push("intent:workspace"); },
|
|
async workspaceCreated() { expect(stage).toBe("agent"); return context; },
|
|
async own(resource: { kind: string }) { events.push(`intent:${resource.kind}`); },
|
|
async phase() {}, async observeRun() {},
|
|
async qualify() { if (options.qualificationFailure) throw new Error("admission denied"); events.push("qualified"); },
|
|
async verifyExecution(_context: unknown, runIds: string[]) {
|
|
expect(runIds).toEqual(["artifact-run"]);
|
|
if (options.traceFailure) throw new Error("trace verification failed");
|
|
events.push("native:verified");
|
|
},
|
|
} as unknown as CloudOnboardingInput;
|
|
return { input, events };
|
|
}
|
|
|
|
describe("Cloud onboarding visible controls", () => {
|
|
it("retains pre-acceptance evidence while preserving the failed error and withholding completion markers", async () => {
|
|
const f = fixture("portfolio");
|
|
const receipt: OnboardingPreAcceptanceEvidence = { version: 1, checkpoint: "awaiting-proposal", violations: ["attachment_present"],
|
|
taskCount: 1, attachmentCount: 1, documentCount: 0, nonPlanningDocumentCount: 0,
|
|
firstTaskMatchesCanonicalParent: true, firstTaskStatus: "in_review", canonicalParentStatus: "in_review" };
|
|
vi.mocked(onboardingFirstTask).mockImplementationOnce(async input => {
|
|
input.onPreAcceptanceFailure?.(receipt);
|
|
throw new JourneyError("failed", "onboarding_work_before_acceptance");
|
|
});
|
|
await expect(cloudOnboarding(f.input)).rejects.toMatchObject({ outcome: "failed", code: "onboarding_work_before_acceptance" });
|
|
expect(JSON.parse(JSON.stringify(f.input.evidence)).onboardingPreAcceptance).toEqual(receipt);
|
|
expect(f.input.evidence.checks.map(check => check.id)).toEqual(["fresh-workspace", "ui-connection-and-native-agent"]);
|
|
expect(f.events).not.toContain("native:verified");
|
|
});
|
|
it.each(["beta-welcome", "first-run", "portfolio", "create-form"] as const)("creates from %s with intent before dispatch and qualification before paid Connect", async entry => {
|
|
const f = fixture(entry);
|
|
const result = await cloudOnboarding(f.input);
|
|
expect(result.startingState).toBe("onboarding");
|
|
expect(f.events.indexOf("intent:workspace")).toBeLessThan(f.events.indexOf("create:workspace"));
|
|
expect(f.events.indexOf("intent:connection")).toBeLessThan(f.events.indexOf("save:connection"));
|
|
expect(f.events.indexOf("qualified")).toBeLessThan(f.events.indexOf("paid:connect"));
|
|
expect(f.events).toContain("native:verified");
|
|
});
|
|
it("can still choose the native runner on tenants with a separate runner picker", async () => {
|
|
const f = fixture("first-run", { legacyRunnerPicker: true });
|
|
await cloudOnboarding(f.input);
|
|
expect(f.events).toContain("click:Paperclip Runner (default)");
|
|
expect(f.events).toContain("native:verified");
|
|
});
|
|
it("does not dispatch workspace creation without durable ownership", async () => {
|
|
const f = fixture("first-run", { intentFailure: true });
|
|
await expect(cloudOnboarding(f.input)).rejects.toThrow("ownership unavailable");
|
|
expect(f.events).not.toContain("create:workspace");
|
|
});
|
|
it("never presses paid Connect when route admission fails", async () => {
|
|
const f = fixture("portfolio", { qualificationFailure: true });
|
|
const previous = vi.mocked(onboardingFirstTask).mock.calls.length;
|
|
await expect(cloudOnboarding(f.input)).rejects.toThrow("admission denied");
|
|
expect(f.events).not.toContain("paid:connect");
|
|
expect(vi.mocked(onboardingFirstTask).mock.calls).toHaveLength(previous);
|
|
});
|
|
it("keeps verified artifact bytes and the independent oracle when later trace verification fails", async () => {
|
|
const f = fixture("portfolio", { traceFailure: true });
|
|
await expect(cloudOnboarding(f.input)).rejects.toThrow("trace verification failed");
|
|
const retained = JSON.parse(JSON.stringify(f.input.evidence)).artifact;
|
|
expect(JSON.parse(Buffer.from(retained.contentBase64, "base64").toString("utf8"))).toEqual(retained.expected);
|
|
expect(retained.originatingRunId).toBe("artifact-run");
|
|
expect(f.input.evidence.checks).not.toContainEqual({ id: "native-trace-verified", passed: true });
|
|
});
|
|
it("retains the artifact but fails the journey without pass markers when first-task readback fails", async () => {
|
|
const f = fixture("portfolio");
|
|
vi.mocked(onboardingFirstTask).mockImplementationOnce(async ({ proof, onArtifact }) => {
|
|
onArtifact?.(retainOnboardingArtifact({ id: "artifact", originatingRunId: "artifact-run", bytes: Buffer.from(JSON.stringify(proof.expected)), proof }));
|
|
throw new Error("first-task readback failed");
|
|
});
|
|
await expect(cloudOnboarding(f.input)).rejects.toThrow("first-task readback failed");
|
|
const retained = JSON.parse(JSON.stringify(f.input.evidence)).artifact;
|
|
expect(JSON.parse(Buffer.from(retained.contentBase64, "base64").toString("utf8"))).toEqual(retained.expected);
|
|
expect(f.input.evidence.checks.map(check => check.id)).toEqual(["fresh-workspace", "ui-connection-and-native-agent"]);
|
|
expect(f.events).not.toContain("native:verified");
|
|
});
|
|
});
|