Extract client SDK package (#1052)
* Extract client SDK package * Polish SDK client identity defaults * Build client before dependent CI jobs * Restore daemon client server export * Extract protocol and client SDK packages * Fix provider override schema validation * Fix app test daemon client imports * Simplify workspace build targets * Fix CLI test server build bootstrap * Run SDK package tests in CI * Fix rebase package split drift * Restore lockfile registry metadata * Update SDK config test for prompt default * Move terminal stream router test to client package * Fix rebase drift for protocol imports * Fix SDK agent capability fixture * Restore legacy server client exports * Fix server export compatibility test * Advertise custom mode icon client capability * Remove server daemon-client exports * Format rebased mode control import * Fix rebase drift for protocol imports Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split shared/ paths that this branch moves into @getpaseo/protocol. Redirect those imports to the protocol package so typecheck stays green after the rebase.
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
CheckoutPrStatusResponseSchema,
|
||||
PullRequestTimelineRequestSchema,
|
||||
PullRequestTimelineResponseSchema,
|
||||
SessionInboundMessageSchema,
|
||||
SessionOutboundMessageSchema,
|
||||
} from "./messages.js";
|
||||
|
||||
describe("pull request timeline message schemas", () => {
|
||||
test("requires request identity fields", () => {
|
||||
expect(() =>
|
||||
PullRequestTimelineRequestSchema.parse({
|
||||
type: "pull_request_timeline_request",
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
test("parses request fields", () => {
|
||||
const parsed = PullRequestTimelineRequestSchema.parse({
|
||||
type: "pull_request_timeline_request",
|
||||
cwd: "/tmp/repo",
|
||||
prNumber: 42,
|
||||
repoOwner: "getpaseo",
|
||||
repoName: "paseo",
|
||||
requestId: "request-1",
|
||||
});
|
||||
|
||||
expect(parsed).toEqual({
|
||||
type: "pull_request_timeline_request",
|
||||
cwd: "/tmp/repo",
|
||||
prNumber: 42,
|
||||
repoOwner: "getpaseo",
|
||||
repoName: "paseo",
|
||||
requestId: "request-1",
|
||||
});
|
||||
});
|
||||
|
||||
test("parses request through the inbound message union", () => {
|
||||
const parsed = SessionInboundMessageSchema.parse({
|
||||
type: "pull_request_timeline_request",
|
||||
cwd: "/tmp/repo",
|
||||
prNumber: 42,
|
||||
repoOwner: "getpaseo",
|
||||
repoName: "paseo",
|
||||
requestId: "request-1",
|
||||
});
|
||||
|
||||
expect(parsed).toEqual({
|
||||
type: "pull_request_timeline_request",
|
||||
cwd: "/tmp/repo",
|
||||
prNumber: 42,
|
||||
repoOwner: "getpaseo",
|
||||
repoName: "paseo",
|
||||
requestId: "request-1",
|
||||
});
|
||||
});
|
||||
|
||||
test("defaults optional response payload and malformed timeline item fields", () => {
|
||||
const parsed = PullRequestTimelineResponseSchema.parse({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
items: [{}, { kind: "review" }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed).toEqual({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
cwd: "",
|
||||
prNumber: null,
|
||||
items: [
|
||||
{
|
||||
id: "",
|
||||
kind: "comment",
|
||||
author: "unknown",
|
||||
body: "",
|
||||
createdAt: 0,
|
||||
url: "",
|
||||
},
|
||||
{
|
||||
id: "",
|
||||
kind: "review",
|
||||
author: "unknown",
|
||||
body: "",
|
||||
createdAt: 0,
|
||||
url: "",
|
||||
reviewState: "commented",
|
||||
},
|
||||
],
|
||||
truncated: false,
|
||||
error: null,
|
||||
requestId: "",
|
||||
githubFeaturesEnabled: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("normalizes unknown timeline item kinds to comments", () => {
|
||||
const parsed = PullRequestTimelineResponseSchema.parse({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
items: [
|
||||
{
|
||||
id: "future-1",
|
||||
kind: "unknown_future_kind",
|
||||
author: "octocat",
|
||||
body: "Future daemon item",
|
||||
createdAt: 1710000000000,
|
||||
url: "https://github.com/getpaseo/paseo/pull/42#future-1",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.payload.items).toEqual([
|
||||
{
|
||||
id: "future-1",
|
||||
kind: "comment",
|
||||
author: "octocat",
|
||||
body: "Future daemon item",
|
||||
createdAt: 1710000000000,
|
||||
url: "https://github.com/getpaseo/paseo/pull/42#future-1",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("parses response through the outbound message union", () => {
|
||||
const parsed = SessionOutboundMessageSchema.parse({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
cwd: "/tmp/repo",
|
||||
prNumber: 42,
|
||||
items: [
|
||||
{
|
||||
id: "review-1",
|
||||
kind: "review",
|
||||
author: "octocat",
|
||||
body: "Looks good",
|
||||
createdAt: 1710000000000,
|
||||
url: "https://github.com/getpaseo/paseo/pull/42#pullrequestreview-1",
|
||||
reviewState: "approved",
|
||||
},
|
||||
{
|
||||
id: "comment-1",
|
||||
kind: "comment",
|
||||
author: "hubot",
|
||||
body: "Left a note",
|
||||
createdAt: 1710000001000,
|
||||
url: "https://github.com/getpaseo/paseo/pull/42#issuecomment-1",
|
||||
},
|
||||
],
|
||||
truncated: true,
|
||||
error: { kind: "unknown", message: "rate limited" },
|
||||
requestId: "request-1",
|
||||
githubFeaturesEnabled: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.type).toBe("pull_request_timeline_response");
|
||||
});
|
||||
|
||||
test("normalizes future error kinds to unknown", () => {
|
||||
const parsed = PullRequestTimelineResponseSchema.parse({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
error: { kind: "future_kind", message: "x" },
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.payload.error).toEqual({ kind: "unknown", message: "x" });
|
||||
});
|
||||
|
||||
test.each(["rate_limited", "", undefined])(
|
||||
"normalizes malformed error kind %j to unknown",
|
||||
(kind) => {
|
||||
const parsed = PullRequestTimelineResponseSchema.parse({
|
||||
type: "pull_request_timeline_response",
|
||||
payload: {
|
||||
error: { kind },
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed.payload.error).toEqual({ kind: "unknown", message: "" });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("checkout PR status compatibility", () => {
|
||||
test("an old client schema parses a new daemon checkout PR status response", () => {
|
||||
const oldClientCheckoutPrStatusResponseSchema = z.object({
|
||||
type: z.literal("checkout_pr_status_response"),
|
||||
payload: z.object({
|
||||
cwd: z.string(),
|
||||
status: z
|
||||
.object({
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
state: z.string(),
|
||||
baseRefName: z.string(),
|
||||
headRefName: z.string(),
|
||||
isMerged: z.boolean(),
|
||||
checks: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
status: z.string(),
|
||||
url: z.string().nullable(),
|
||||
}),
|
||||
)
|
||||
.optional()
|
||||
.default([]),
|
||||
checksStatus: z.string().optional(),
|
||||
reviewDecision: z.string().nullable().optional(),
|
||||
})
|
||||
.nullable(),
|
||||
githubFeaturesEnabled: z.boolean(),
|
||||
error: z.unknown().nullable(),
|
||||
requestId: z.string(),
|
||||
}),
|
||||
});
|
||||
const newDaemonPayload = CheckoutPrStatusResponseSchema.parse({
|
||||
type: "checkout_pr_status_response",
|
||||
payload: {
|
||||
cwd: "/tmp/repo",
|
||||
status: {
|
||||
number: 42,
|
||||
url: "https://github.com/getpaseo/paseo/pull/42",
|
||||
title: "Wire real PR pane data",
|
||||
state: "OPEN",
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/pr-pane",
|
||||
isMerged: false,
|
||||
isDraft: true,
|
||||
checks: [
|
||||
{
|
||||
name: "server-tests",
|
||||
status: "success",
|
||||
url: "https://github.com/getpaseo/paseo/actions/runs/123",
|
||||
workflow: "Server CI",
|
||||
duration: "2m 14s",
|
||||
},
|
||||
],
|
||||
checksStatus: "success",
|
||||
reviewDecision: "APPROVED",
|
||||
},
|
||||
githubFeaturesEnabled: true,
|
||||
error: null,
|
||||
requestId: "request-compat",
|
||||
},
|
||||
});
|
||||
|
||||
expect(oldClientCheckoutPrStatusResponseSchema.parse(newDaemonPayload)).toEqual({
|
||||
type: "checkout_pr_status_response",
|
||||
payload: {
|
||||
cwd: "/tmp/repo",
|
||||
status: {
|
||||
url: "https://github.com/getpaseo/paseo/pull/42",
|
||||
title: "Wire real PR pane data",
|
||||
state: "OPEN",
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/pr-pane",
|
||||
isMerged: false,
|
||||
checks: [
|
||||
{
|
||||
name: "server-tests",
|
||||
status: "success",
|
||||
url: "https://github.com/getpaseo/paseo/actions/runs/123",
|
||||
},
|
||||
],
|
||||
checksStatus: "success",
|
||||
reviewDecision: "APPROVED",
|
||||
},
|
||||
githubFeaturesEnabled: true,
|
||||
error: null,
|
||||
requestId: "request-compat",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user