Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: BB84 <110078428+BB-84C@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Sebastian <hasta84@gmail.com> Co-authored-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: Test User <test@test.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Rahul A Mistry <149420892+ProdigyRahul@users.noreply.github.com> Co-authored-by: Qiping Li <liqiping1991@gmail.com> Co-authored-by: liqiping <liqiping@msh.team> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Matthias Reso <13337103+mreso@users.noreply.github.com> Co-authored-by: tobwen <1864057+tobwen@users.noreply.github.com> Co-authored-by: Daniel Polito <danielbpolito@gmail.com> Co-authored-by: opencode <noreply@opencode.ai> Co-authored-by: Devin R Leopold <devin.leopold@gmail.com> Co-authored-by: Zach Bruggeman <mail@bruggie.com> Co-authored-by: Zach Bruggeman <zbruggeman@ramp.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: David Siewert <david1gruppenplan@gmail.com> Co-authored-by: Andrei Dziahel <develop7@develop7.info> Co-authored-by: adityachaudhary99 <adityaachaudhary2003@gmail.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Matt Carey <mcarey@cloudflare.com>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import type { SnapshotFileDiff } from "@opencode-ai/sdk/v2"
|
|
import type { FileDiffInfo } from "@opencode-ai/client/promise"
|
|
import type { Message } from "@opencode-ai/sdk/v2/client"
|
|
import { diffs, message } from "./diffs"
|
|
|
|
const item = {
|
|
file: "src/app.ts",
|
|
patch: "@@ -1 +1 @@\n-old\n+new\n",
|
|
additions: 1,
|
|
deletions: 1,
|
|
status: "modified",
|
|
} satisfies FileDiffInfo & SnapshotFileDiff
|
|
|
|
describe("diffs", () => {
|
|
test("keeps valid arrays", () => {
|
|
expect(diffs([item])).toEqual([item])
|
|
})
|
|
|
|
test("wraps a single diff object", () => {
|
|
expect(diffs(item)).toEqual([item])
|
|
})
|
|
|
|
test("reads keyed diff objects", () => {
|
|
expect(diffs({ a: item })).toEqual([item])
|
|
})
|
|
|
|
test("drops invalid entries", () => {
|
|
expect(
|
|
diffs([
|
|
item,
|
|
{ file: "src/bad.ts", additions: 1, deletions: 1 },
|
|
{ patch: item.patch, additions: 1, deletions: 1 },
|
|
]),
|
|
).toEqual([item])
|
|
})
|
|
})
|
|
|
|
describe("message", () => {
|
|
test("normalizes user summaries with object diffs", () => {
|
|
const input = {
|
|
id: "msg_1",
|
|
sessionID: "ses_1",
|
|
role: "user",
|
|
time: { created: 1 },
|
|
agent: "build",
|
|
model: { providerID: "openai", modelID: "gpt-5" },
|
|
summary: {
|
|
title: "Edit",
|
|
diffs: { a: item },
|
|
},
|
|
} as unknown as Message
|
|
|
|
expect(message(input)).toMatchObject({
|
|
summary: {
|
|
title: "Edit",
|
|
diffs: [item],
|
|
},
|
|
})
|
|
})
|
|
|
|
test("drops invalid user summaries", () => {
|
|
const input = {
|
|
id: "msg_1",
|
|
sessionID: "ses_1",
|
|
role: "user",
|
|
time: { created: 1 },
|
|
agent: "build",
|
|
model: { providerID: "openai", modelID: "gpt-5" },
|
|
summary: true,
|
|
} as unknown as Message
|
|
|
|
expect(message(input)).toMatchObject({ summary: undefined })
|
|
})
|
|
})
|