1package soy.iko.opencode
3import org.junit.Assert.assertEquals
4import org.junit.Assert.assertFalse
5import org.junit.Assert.assertTrue
7import soy.iko.opencode.data.model.Agent
8import soy.iko.opencode.data.model.Command
9import soy.iko.opencode.data.network.OpencodeJson
10import soy.iko.opencode.ui.components.DiffLine
11import soy.iko.opencode.ui.components.looksLikeDiff
12import soy.iko.opencode.ui.components.parseDiff
13import kotlinx.serialization.builtins.ListSerializer
17 private fun <T> decode(s: kotlinx.serialization.KSerializer<T>, json: String): T =
18 OpencodeJson.decodeFromString(s, json)
20 // --- Agent / Command decoding ---
23 fun decodesAgentList() {
26 { "name": "build", "description": "Build and implement code", "mode": "primary",
27 "builtIn": true, "tools": {}, "options": {} },
28 { "name": "custom", "mode": "subagent", "builtIn": false }
31 val agents = decode(ListSerializer(Agent.serializer()), json)
32 assertEquals(2, agents.size)
33 assertEquals("build", agents[0].name)
34 assertTrue(agents[0].isPrimary)
35 assertTrue(agents[0].builtIn)
36 assertEquals("Build and implement code", agents[0].displayDescription)
37 assertFalse(agents[1].isPrimary)
38 assertEquals("Custom agent", agents[1].displayDescription)
42 fun decodesCommandList() {
45 { "name": "compact", "description": "Compact the session",
46 "template": "Summarize the conversation so far", "subtask": false },
47 { "name": "test", "agent": "build", "template": "Run the tests" }
50 val commands = decode(ListSerializer(Command.serializer()), json)
51 assertEquals(2, commands.size)
52 assertEquals("compact", commands[0].name)
53 assertEquals("Compact the session", commands[0].displayDescription)
54 assertEquals("build", commands[1].agent)
57 // --- Diff parsing ---
60 fun parsesUnifiedDiff() {
71 val lines = parseDiff(diff)
72 assertTrue(lines[0] is DiffLine.FileHeader)
73 assertTrue(lines[1] is DiffLine.FileHeader)
74 assertTrue(lines[2] is DiffLine.Hunk)
75 assertTrue(lines[3] is DiffLine.Context)
76 assertTrue(lines[4] is DiffLine.Remove)
77 assertTrue(lines[5] is DiffLine.Add)
78 assertTrue(lines[6] is DiffLine.Add)
79 assertTrue(lines[7] is DiffLine.Context)
80 assertEquals(" println(\"old\")", (lines[4] as DiffLine.Remove).text)
81 assertEquals(" println(\"new\")", (lines[5] as DiffLine.Add).text)
85 fun looksLikeDiffDetectsRealDiffs() {
91 assertTrue(looksLikeDiff(realDiff))
93 val plainText = "This is just a regular message from the assistant."
94 assertFalse(looksLikeDiff(plainText))
98 fun looksLikeDiffIgnoresStrayMarkers() {
99 assertFalse(looksLikeDiff("not a diff at all"))
100 assertFalse(looksLikeDiff("just some + text - here"))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list