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.

5.0 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import {
  getLinearIssueWorkspaceName,
  getLinkedWorkItemWorkspaceName,
  getWorkspaceIntentName,
  resolveWorkspaceCreateName,
  slugifyForWorkspaceName
} from './workspace-name'

describe('slugifyForWorkspaceName', () => {
  it('keeps workspace seed slugs short, ascii-safe, and git-ref-safe', () => {
    expect(slugifyForWorkspaceName('../../Fix mobile Tasks 🚀')).toBe('fix-mobile-tasks')
    expect(slugifyForWorkspaceName('feature/add issue drawer')).toBe('feature-add-issue-drawer')
    expect(slugifyForWorkspaceName('a'.repeat(80))).toBe('a'.repeat(48))
  })

  it('removes apostrophes inside words instead of splitting them', () => {
    expect(slugifyForWorkspaceName("Can't enable browser notifications")).toBe(
      'cant-enable-browser-notifications'
    )
    expect(slugifyForWorkspaceName('Can’t enable browser notifications')).toBe(
      'cant-enable-browser-notifications'
    )
  })
})

describe('getLinkedWorkItemWorkspaceName', () => {
  it('keeps the canonical uppercase Jira key when the casing policy preserves it', () => {
    const item = {
      type: 'issue' as const,
      provider: 'jira' as const,
      number: 0,
      title: 'PROJ-7 Fix flaky import',
      jiraIdentifier: 'PROJ-7'
    }
    expect(getLinkedWorkItemWorkspaceName(item, { jiraIssueKeyCasing: 'preserve' })).toEqual({
      displayName: 'PROJ-7 Fix flaky import',
      seedName: 'PROJ-7-fix-flaky-import'
    })
    expect(
      getLinkedWorkItemWorkspaceName(item, { jiraIssueKeyCasing: 'lowercase' })?.seedName
    ).toBe('proj-7-fix-flaky-import')
  })
})

describe('Jira generated-name source identity', () => {
  it('ignores a stale Jira identifier on an explicitly different provider', () => {
    expect(
      getLinkedWorkItemWorkspaceName(
        {
          type: 'issue',
          provider: 'github',
          number: 7,
          title: 'PROJ-7 Fix login',
          jiraIdentifier: 'PROJ-7'
        },
        { jiraIssueKeyCasing: 'preserve' }
      )?.seedName
    ).toBe('proj-7-fix-login')
    expect(
      getLinkedWorkItemWorkspaceName(
        {
          type: 'issue',
          provider: 'linear',
          number: 0,
          title: 'Fix login',
          jiraIdentifier: 'PROJ-7',
          linearIdentifier: 'ENG-1'
        },
        { jiraIssueKeyCasing: 'preserve' }
      )?.seedName
    ).toBe('eng-1-fix-login')
  })
})

describe('getWorkspaceIntentName', () => {
  it('uses explicit user intent for linked issues without copying long titles', () => {
    expect(
      getWorkspaceIntentName({
        sourceText: 'https://github.com/mvanhorn/cli-printing-press/issues/2635 and fix it',
        workItem: {
          type: 'issue',
          number: 2635,
          title:
            "scorer/dogfood: live acceptance can't authenticate via the CLI's config/cookie credentials (scoped-home is env-only)"
        }
      })
    ).toEqual({
      displayName: 'Fix Issue 2635',
      seedName: 'fix-issue-2635'
    })
  })

  it('defaults PR and MR work to review-oriented identities', () => {
    expect(
      getWorkspaceIntentName({
        sourceText: 'https://github.com/acme/app/pull/1234 and check whether this is safe',
        workItem: {
          type: 'pr',
          number: 1234,
          title: 'Refactor account settings panel'
        }
      })
    ).toEqual({
      displayName: 'Review PR 1234',
      seedName: 'review-pr-1234'
    })
    expect(
      getWorkspaceIntentName({
        sourceText: 'fix https://gitlab.com/acme/app/-/merge_requests/77',
        workItem: {
          type: 'mr',
          provider: 'gitlab',
          number: 77,
          title: 'Resolve sync race'
        }
      })
    ).toEqual({
      displayName: 'Fix MR 77',
      seedName: 'fix-mr-77'
    })
  })

  it('does not treat an auto-generated slug as explicit user intent', () => {
    expect(
      getWorkspaceIntentName({
        sourceText: 'issue-123-fix-navbar',
        workItem: {
          type: 'issue',
          number: 456,
          title: 'Make importer handle archived rows'
        }
      })
    ).toEqual({
      displayName: 'Issue 456 Make Importer Handle',
      seedName: 'issue-456-make-importer-handle'
    })
  })
})

describe('getLinearIssueWorkspaceName', () => {
  it('keeps the combined Linear seed within the workspace-name limit', () => {
    const seed = getLinearIssueWorkspaceName({
      identifier: 'ENG-42',
      title: 'Implement a very long Linear issue title that should be truncated'
    })
    expect(seed.length).toBeLessThanOrEqual(48)
    expect(seed).toMatch(/^eng-42-/)
  })
})

describe('resolveWorkspaceCreateName', () => {
  it('preserves explicit user-entered names for the host worktree sanitizer', () => {
    expect(
      resolveWorkspaceCreateName({
        draft: 'feature/something',
        fallback: 'issue-123'
      })
    ).toBe('feature/something')
    expect(
      resolveWorkspaceCreateName({
        draft: '日本語 テスト',
        fallback: 'issue-123'
      })
    ).toBe('日本語 テスト')
  })
})