Skip to content

Commit ca2411d

Browse files
authored
Run UI unit tests in CI (#25792)
1 parent 6b85277 commit ca2411d

4 files changed

Lines changed: 53 additions & 7 deletions

File tree

packages/ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
},
2626
"scripts": {
2727
"typecheck": "tsgo --noEmit",
28+
"test": "bun test src",
29+
"test:ci": "mkdir -p .artifacts/unit && bun test src --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
2830
"dev": "vite",
2931
"generate:tailwind": "bun run script/tailwind.ts"
3032
},

packages/ui/src/components/session-diff.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ describe("session diff", () => {
1919
expect(text(view, "additions")).toBe("one\nthree\n")
2020
})
2121

22+
test("keeps missing final newlines from unified patches", () => {
23+
const diff = {
24+
file: "a.ts",
25+
patch:
26+
"Index: a.ts\n===================================================================\n--- a.ts\t\n+++ a.ts\t\n@@ -1,2 +1,2 @@\n one\n-two\n\\ No newline at end of file\n+three\n\\ No newline at end of file\n",
27+
additions: 1,
28+
deletions: 1,
29+
status: "modified" as const,
30+
}
31+
const view = normalize(diff)
32+
33+
expect(text(view, "deletions")).toBe("one\ntwo")
34+
expect(text(view, "additions")).toBe("one\nthree")
35+
})
36+
2237
test("converts legacy content into a patch", () => {
2338
const diff = {
2439
file: "a.ts",

packages/ui/src/components/session-diff.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,44 @@ function patch(diff: ReviewDiff) {
2929
if (typeof diff.patch === "string") {
3030
try {
3131
const [patch] = parsePatch(diff.patch)
32-
const beforeLines = []
33-
const afterLines = []
32+
const beforeLines: Array<{ text: string; newline: boolean }> = []
33+
const afterLines: Array<{ text: string; newline: boolean }> = []
34+
let previous: "-" | "+" | " " | undefined
3435

3536
for (const hunk of patch.hunks) {
3637
for (const line of hunk.lines) {
38+
if (line.startsWith("\\")) {
39+
if (previous === "-" || previous === " ") {
40+
const before = beforeLines.at(-1)
41+
if (before) before.newline = false
42+
}
43+
if (previous === "+" || previous === " ") {
44+
const after = afterLines.at(-1)
45+
if (after) after.newline = false
46+
}
47+
continue
48+
}
49+
3750
if (line.startsWith("-")) {
38-
beforeLines.push(line.slice(1))
51+
beforeLines.push({ text: line.slice(1), newline: true })
52+
previous = "-"
3953
} else if (line.startsWith("+")) {
40-
afterLines.push(line.slice(1))
54+
afterLines.push({ text: line.slice(1), newline: true })
55+
previous = "+"
4156
} else {
4257
// context line (starts with ' ')
43-
beforeLines.push(line.slice(1))
44-
afterLines.push(line.slice(1))
58+
beforeLines.push({ text: line.slice(1), newline: true })
59+
afterLines.push({ text: line.slice(1), newline: true })
60+
previous = " "
4561
}
4662
}
4763
}
4864

49-
return { before: beforeLines.join("\n"), after: afterLines.join("\n"), patch: diff.patch }
65+
return {
66+
before: beforeLines.map((line) => line.text + (line.newline ? "\n" : "")).join(""),
67+
after: afterLines.map((line) => line.text + (line.newline ? "\n" : "")).join(""),
68+
patch: diff.patch,
69+
}
5070
} catch {
5171
return { before: "", after: "", patch: diff.patch }
5272
}

turbo.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
"dependsOn": ["^build"],
2727
"outputs": [".artifacts/unit/junit.xml"],
2828
"passThroughEnv": ["*"]
29+
},
30+
"@opencode-ai/ui#test": {
31+
"dependsOn": ["^build"],
32+
"outputs": []
33+
},
34+
"@opencode-ai/ui#test:ci": {
35+
"dependsOn": ["^build"],
36+
"outputs": [".artifacts/unit/junit.xml"],
37+
"passThroughEnv": ["*"]
2938
}
3039
}
3140
}

0 commit comments

Comments
 (0)