Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

3.2 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import type { PRComment } from './github/comment-types'
import { createBotAuthorOverrideSet } from './pr-bot-author-overrides'
import {
  filterPRCommentsByAudience,
  getPRCommentAudienceCounts,
  isBotPRComment
} from './pr-comment-audience'

function comment(overrides: Partial<PRComment>): PRComment {
  return {
    id: overrides.id ?? 1,
    author: overrides.author ?? 'user',
    authorAvatarUrl: '',
    body: '',
    createdAt: '',
    url: '',
    ...overrides
  }
}

describe('pr comment audience filtering', () => {
  it('classifies provider metadata and automation logins', () => {
    expect(isBotPRComment(comment({ author: 'alice', isBot: true }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'github-actions[bot]' }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'renovate-bot' }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'preview-automation' }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'qodo-ai-reviewer', isBot: false }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'coderabbitai', isBot: false }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'sonarcloud' }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'codium-ai-reviewer' }))).toBe(true)
    expect(isBotPRComment(comment({ author: 'octocat' }))).toBe(false)
    expect(isBotPRComment(comment({ author: 'robotics-dev' }))).toBe(false)
    expect(isBotPRComment(comment({ author: 'human-botany' }))).toBe(false)
  })

  it('counts and filters human and bot comments', () => {
    const comments = [
      comment({ id: 1, author: 'yasinkavakli' }),
      comment({ id: 2, author: 'chatgpt-codex-connector', isBot: true }),
      comment({ id: 3, author: 'github-actions[bot]' })
    ]

    expect(getPRCommentAudienceCounts(comments)).toEqual({ all: 3, human: 1, bot: 2 })
    expect(filterPRCommentsByAudience(comments, 'all')).toBe(comments)
    expect(filterPRCommentsByAudience(comments, 'human').map((item) => item.id)).toEqual([1])
    expect(filterPRCommentsByAudience(comments, 'bot').map((item) => item.id)).toEqual([2, 3])
  })

  it('classifies manually overridden authors as bots regardless of heuristics', () => {
    const overrides = createBotAuthorOverrideSet([' GretelFlux ', '', 'other-bot-account'])

    expect(isBotPRComment(comment({ author: 'gretelflux' }))).toBe(false)
    expect(isBotPRComment(comment({ author: 'gretelflux' }), overrides)).toBe(true)
    expect(isBotPRComment(comment({ author: ' Gretelflux ' }), overrides)).toBe(true)
    expect(isBotPRComment(comment({ author: 'yasinkavakli' }), overrides)).toBe(false)
  })

  it('applies overrides to counts and filters', () => {
    const overrides = createBotAuthorOverrideSet(['gretelflux'])
    const comments = [
      comment({ id: 1, author: 'yasinkavakli' }),
      comment({ id: 2, author: 'gretelflux' }),
      comment({ id: 3, author: 'github-actions[bot]' })
    ]

    expect(getPRCommentAudienceCounts(comments, overrides)).toEqual({ all: 3, human: 1, bot: 2 })
    expect(filterPRCommentsByAudience(comments, 'human', overrides).map((item) => item.id)).toEqual(
      [1]
    )
    expect(filterPRCommentsByAudience(comments, 'bot', overrides).map((item) => item.id)).toEqual([
      2, 3
    ])
  })
})