|
5 | 5 | formatPromptTooLargeError, |
6 | 6 | buildCommentKeyDigest, |
7 | 7 | appendCommentAnchor, |
| 8 | + findStickyCommentIds, |
8 | 9 | } from "../../src/cli/cmd/github" |
9 | 10 | import type { MessageV2 } from "../../src/session/message-v2" |
10 | 11 | import { SessionID, MessageID, PartID } from "../../src/session/schema" |
@@ -256,3 +257,74 @@ describe("appendCommentAnchor", () => { |
256 | 257 | expect(parts[parts.length - 2]).toBe("content") |
257 | 258 | }) |
258 | 259 | }) |
| 260 | + |
| 261 | +describe("findStickyCommentIds", () => { |
| 262 | + test("matches comments by anchor and opencode bot author", () => { |
| 263 | + const ids = findStickyCommentIds( |
| 264 | + [ |
| 265 | + { |
| 266 | + id: 1, |
| 267 | + user: { login: "opencode-agent[bot]" }, |
| 268 | + body: "body\n<!-- opencode:comment-key:sha256:abc -->", |
| 269 | + }, |
| 270 | + ], |
| 271 | + "<!-- opencode:comment-key:sha256:abc -->", |
| 272 | + ["opencode-agent[bot]"], |
| 273 | + ) |
| 274 | + |
| 275 | + expect(ids).toEqual([1]) |
| 276 | + }) |
| 277 | + |
| 278 | + test("matches comments by anchor and github-actions bot author", () => { |
| 279 | + const ids = findStickyCommentIds( |
| 280 | + [ |
| 281 | + { |
| 282 | + id: 2, |
| 283 | + user: { login: "github-actions[bot]" }, |
| 284 | + body: "body\n<!-- opencode:comment-key:sha256:abc -->", |
| 285 | + }, |
| 286 | + ], |
| 287 | + "<!-- opencode:comment-key:sha256:abc -->", |
| 288 | + ["opencode-agent[bot]", "github-actions[bot]"], |
| 289 | + ) |
| 290 | + |
| 291 | + expect(ids).toEqual([2]) |
| 292 | + }) |
| 293 | + |
| 294 | + test("does not match comments from other authors", () => { |
| 295 | + const ids = findStickyCommentIds( |
| 296 | + [ |
| 297 | + { |
| 298 | + id: 3, |
| 299 | + user: { login: "someone-else" }, |
| 300 | + body: "body\n<!-- opencode:comment-key:sha256:abc -->", |
| 301 | + }, |
| 302 | + ], |
| 303 | + "<!-- opencode:comment-key:sha256:abc -->", |
| 304 | + ["opencode-agent[bot]", "github-actions[bot]"], |
| 305 | + ) |
| 306 | + |
| 307 | + expect(ids).toEqual([]) |
| 308 | + }) |
| 309 | + |
| 310 | + test("returns matching ids in API order", () => { |
| 311 | + const ids = findStickyCommentIds( |
| 312 | + [ |
| 313 | + { |
| 314 | + id: 4, |
| 315 | + user: { login: "github-actions[bot]" }, |
| 316 | + body: "body\n<!-- opencode:comment-key:sha256:abc -->", |
| 317 | + }, |
| 318 | + { |
| 319 | + id: 5, |
| 320 | + user: { login: "github-actions[bot]" }, |
| 321 | + body: "body\n<!-- opencode:comment-key:sha256:abc -->", |
| 322 | + }, |
| 323 | + ], |
| 324 | + "<!-- opencode:comment-key:sha256:abc -->", |
| 325 | + ["github-actions[bot]"], |
| 326 | + ) |
| 327 | + |
| 328 | + expect(ids).toEqual([4, 5]) |
| 329 | + }) |
| 330 | +}) |
0 commit comments