mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
186 lines
4.9 KiB
TypeScript
186 lines
4.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
CreateAgentRequestMessageSchema,
|
|
CreatePaseoWorktreeRequestSchema,
|
|
SendAgentMessageRequestSchema,
|
|
} from "./messages.js";
|
|
|
|
describe("shared messages attachments", () => {
|
|
it("keeps known attachments and drops unknown create-agent attachments", () => {
|
|
const parsed = CreateAgentRequestMessageSchema.parse({
|
|
type: "create_agent_request",
|
|
requestId: "req-1",
|
|
config: {
|
|
provider: "codex",
|
|
cwd: "/tmp/repo",
|
|
},
|
|
initialPrompt: "Review this PR",
|
|
attachments: [
|
|
{
|
|
type: "github_pr",
|
|
mimeType: "application/github-pr",
|
|
number: 123,
|
|
title: "Fix race in worktree setup",
|
|
url: "https://github.com/getpaseo/paseo/pull/123",
|
|
body: "Body",
|
|
baseRefName: "main",
|
|
headRefName: "fix/worktree-race",
|
|
},
|
|
{
|
|
type: "future_attachment",
|
|
mimeType: "application/future",
|
|
foo: "bar",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(parsed.attachments).toEqual([
|
|
{
|
|
type: "github_pr",
|
|
mimeType: "application/github-pr",
|
|
number: 123,
|
|
title: "Fix race in worktree setup",
|
|
url: "https://github.com/getpaseo/paseo/pull/123",
|
|
body: "Body",
|
|
baseRefName: "main",
|
|
headRefName: "fix/worktree-race",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("keeps known attachments and drops unknown send-message attachments", () => {
|
|
const parsed = SendAgentMessageRequestSchema.parse({
|
|
type: "send_agent_message_request",
|
|
requestId: "req-2",
|
|
agentId: "agent-1",
|
|
text: "Review",
|
|
attachments: [
|
|
{
|
|
type: "github_issue",
|
|
mimeType: "application/github-issue",
|
|
number: 55,
|
|
title: "Improve startup error details",
|
|
url: "https://github.com/getpaseo/paseo/issues/55",
|
|
body: "Body",
|
|
},
|
|
{
|
|
type: "future_attachment",
|
|
mimeType: "application/future",
|
|
foo: "bar",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(parsed.attachments).toEqual([
|
|
{
|
|
type: "github_issue",
|
|
mimeType: "application/github-issue",
|
|
number: 55,
|
|
title: "Improve startup error details",
|
|
url: "https://github.com/getpaseo/paseo/issues/55",
|
|
body: "Body",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("keeps known attachments and drops unknown worktree-create attachments", () => {
|
|
const parsed = CreatePaseoWorktreeRequestSchema.parse({
|
|
type: "create_paseo_worktree_request",
|
|
requestId: "req-3",
|
|
cwd: "/tmp/repo",
|
|
attachments: [
|
|
{
|
|
type: "github_pr",
|
|
mimeType: "application/github-pr",
|
|
number: 99,
|
|
title: "Fork-safe PR checkout",
|
|
url: "https://github.com/getpaseo/paseo/pull/99",
|
|
},
|
|
{
|
|
type: "future_attachment",
|
|
mimeType: "application/future",
|
|
foo: "bar",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(parsed.attachments).toEqual([
|
|
{
|
|
type: "github_pr",
|
|
mimeType: "application/github-pr",
|
|
number: 99,
|
|
title: "Fork-safe PR checkout",
|
|
url: "https://github.com/getpaseo/paseo/pull/99",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("parses old-shape create-worktree payloads without the new intent fields", () => {
|
|
const parsed = CreatePaseoWorktreeRequestSchema.parse({
|
|
type: "create_paseo_worktree_request",
|
|
requestId: "req-4",
|
|
cwd: "/tmp/repo",
|
|
attachments: [],
|
|
});
|
|
|
|
expect(parsed).toEqual({
|
|
type: "create_paseo_worktree_request",
|
|
requestId: "req-4",
|
|
cwd: "/tmp/repo",
|
|
attachments: [],
|
|
});
|
|
});
|
|
|
|
it("accepts and strips create-worktree intent fields compatibly", () => {
|
|
const parsed = CreatePaseoWorktreeRequestSchema.parse({
|
|
type: "create_paseo_worktree_request",
|
|
requestId: "req-5",
|
|
cwd: "/tmp/repo",
|
|
attachments: [],
|
|
action: "checkout",
|
|
refName: "feature/ref-picker",
|
|
githubPrNumber: 42,
|
|
futureField: "ignored",
|
|
});
|
|
|
|
expect(parsed).toEqual({
|
|
type: "create_paseo_worktree_request",
|
|
requestId: "req-5",
|
|
cwd: "/tmp/repo",
|
|
attachments: [],
|
|
action: "checkout",
|
|
refName: "feature/ref-picker",
|
|
githubPrNumber: 42,
|
|
});
|
|
});
|
|
|
|
it("accepts optional create-agent git intent fields and strips unknown git fields", () => {
|
|
const parsed = CreateAgentRequestMessageSchema.parse({
|
|
type: "create_agent_request",
|
|
requestId: "req-6",
|
|
config: {
|
|
provider: "codex",
|
|
cwd: "/tmp/repo",
|
|
},
|
|
attachments: [],
|
|
git: {
|
|
createWorktree: true,
|
|
worktreeSlug: "review-42",
|
|
action: "checkout",
|
|
refName: "head-ref",
|
|
githubPrNumber: 42,
|
|
futureGitField: "ignored",
|
|
},
|
|
});
|
|
|
|
expect(parsed.git).toEqual({
|
|
createWorktree: true,
|
|
worktreeSlug: "review-42",
|
|
action: "checkout",
|
|
refName: "head-ref",
|
|
githubPrNumber: 42,
|
|
});
|
|
});
|
|
});
|