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.

4.6 KB
Raw Blame
import type { Page } from '@stablyai/playwright-test'
import type { PRComment } from '../../../src/shared/github/comment-types'
import type { PRInfo } from '../../../src/shared/github/pull-request-types'
import { getDefaultSourceControlAiSettings } from '../../../src/shared/source-control-ai'

export type PRCommentsSidebarSeed = {
  worktreeId: string
  branch: string
  prNumber: number
}

export const FIXTURE_COMMENTS: PRComment[] = [
  {
    id: 101,
    author: 'coderabbitai',
    authorAvatarUrl: '',
    body: 'Please update this handler before merge.',
    createdAt: '2026-05-14T10:00:00.000Z',
    url: 'https://github.com/acme/orca/pull/73#discussion_r101',
    reactionSubjectId: 'PRRC_101',
    threadId: 'thread-open',
    path: 'src/handler.ts',
    isBot: true,
    isResolved: false
  },
  {
    id: 102,
    author: 'bob',
    authorAvatarUrl: '',
    body: 'LGTM on the overall approach.',
    createdAt: '2026-05-14T11:00:00.000Z',
    url: 'https://github.com/acme/orca/pull/73#issuecomment-102',
    reactionSubjectId: 'IC_102'
  },
  {
    id: 103,
    author: 'carol',
    authorAvatarUrl: '',
    body: 'Already fixed upstream.',
    createdAt: '2026-05-13T09:00:00.000Z',
    url: 'https://github.com/acme/orca/pull/73#discussion_r103',
    threadId: 'thread-resolved',
    path: 'src/legacy.ts',
    isResolved: true
  }
]

/** Seed an open PR on e2e-secondary with mixed comment triage states for sidebar tests. */
export async function seedPRCommentsSidebarFixture(page: Page): Promise<PRCommentsSidebarSeed> {
  const seed = {
    fixtureComments: FIXTURE_COMMENTS,
    sourceControlAiDefaults: getDefaultSourceControlAiSettings()
  }
  return page.evaluate(async ({ fixtureComments, sourceControlAiDefaults }) => {
    const store = window.__store
    if (!store) {
      throw new Error('window.__store is not available')
    }

    const state = store.getState()
    const worktrees = Object.values(state.worktreesByRepo).flat()
    const worktree = worktrees.find(
      (entry) => entry.branch.replace(/^refs\/heads\//, '') === 'e2e-secondary'
    )
    if (!worktree) {
      throw new Error('seeded e2e-secondary worktree not found')
    }

    state.setActiveWorktree(worktree.id)
    const repo = state.repos.find((entry) => entry.id === worktree.repoId)
    if (!repo) {
      throw new Error('active repo not found')
    }

    const branch = worktree.branch.replace(/^refs\/heads\//, '')
    const prNumber = 73
    const pr: PRInfo = {
      number: prNumber,
      title: 'E2E PR comments sidebar',
      state: 'open',
      url: `https://github.com/acme/orca/pull/${prNumber}`,
      checksStatus: 'pending',
      updatedAt: '2026-05-15T00:00:00.000Z',
      mergeable: 'MERGEABLE',
      prRepo: { owner: 'acme', repo: 'orca' }
    }
    const prCacheEntries = {
      [`${repo.id}::${branch}`]: {
        data: pr,
        fetchedAt: Date.now()
      },
      [`${repo.path}::${branch}`]: {
        data: pr,
        fetchedAt: Date.now()
      }
    }

    const comments = fixtureComments

    store.setState((current) => ({
      prCache: {
        ...current.prCache,
        ...prCacheEntries
      },
      repos: current.repos.map((candidate) =>
        candidate.id === repo.id ? { ...candidate, worktreeBaseRef: 'origin/main' } : candidate
      ),
      gitStatusByWorktree: {
        ...current.gitStatusByWorktree,
        [worktree.id]: []
      },
      remoteStatusesByWorktree: {
        ...current.remoteStatusesByWorktree,
        [worktree.id]: {
          hasUpstream: true,
          upstreamName: `origin/${branch}`,
          ahead: 0,
          behind: 0
        }
      },
      settings: current.settings
        ? {
            ...current.settings,
            sourceControlAi: {
              ...sourceControlAiDefaults,
              ...current.settings.sourceControlAi,
              enabled: true
            }
          }
        : current.settings,
      fetchPRForBranch: async (_repoPath: string, targetBranch: string) => {
        if (targetBranch !== branch) {
          return null
        }
        store.setState((next) => ({
          prCache: {
            ...next.prCache,
            ...prCacheEntries
          }
        }))
        return pr
      },
      fetchPRChecks: async () => [],
      fetchPRComments: async () => comments,
      setPRCommentReaction: async () => true,
      fetchUpstreamStatus: async (worktreeId) =>
        store.getState().remoteStatusesByWorktree[worktreeId] ?? null,
      setUpstreamStatus: () => undefined
    }))

    window.localStorage.setItem('orca:pr-comment-presentation', 'cards')

    return { worktreeId: worktree.id, branch, prNumber }
  }, seed)
}