Files
orca/src/shared/display-name-from-work.test.ts
T
b18ec39e1f fix(naming): lead workspace and tab names with the work-item identifier (#8238)
* fix(naming): lead workspace and tab names with the work-item identifier

Auto-generated workspace names, branch-rename display names, and tab
titles now lead with the referenced PR/MR/issue/ticket — e.g.
`PR 1033 - Review` instead of a paraphrase like "Review community pr
1094" that buried or dropped the number. Identifiers are the highest-
signal, most searchable token, so leading with them makes the sidebar
and tabs scannable and disambiguates same-verb work items.

- New shared `work-item-reference.ts` extracts the identifier from the
  raw prompt: URLs are validated by path structure (owner/repo/pull/N,
  GitLab's `/-/` marker) so GitHub Enterprise / self-hosted GitLab still
  resolve while stray `/pull/<n>` paths (CDN, docs) do not; a ticket-
  prefix denylist keeps `SHA-256` / `UTF-8` / `ISO-8601` from being read
  as Jira/Linear keys.
- Reconciles the existing create-from-work-item naming (was action-first
  `Review PR 1033`) with the first-work auto-rename onto one identifier-
  first format via a shared `formatIdentifierFirst`, so the two paths
  can't drift.
- Fixes a pre-existing tab-title bug where markdown punctuation was
  stripped before URLs, splitting a GitLab `merge_requests` URL at its
  underscore and leaking "requests" into the title.

* fix(naming): keep emphasis-wrapped URLs intact in generated names

The URL/markdown strip reorder left the tab-title URL strip anchored on
\b, which fails when a URL is wrapped in markdown emphasis (_...pull/5_)
and leaked URL fragments into the title. Drop the \b anchor and trim
trailing markdown emphasis (*_~) in the URL identifier parser, keeping
interior underscores (merge_requests) intact. Adds regression tests.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Co-authored-by: Orca <help@stably.ai>
2026-07-11 14:14:12 -07:00

61 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { deriveWorkspaceDisplayName } from './display-name-from-work'
// Identifier extraction itself is covered in work-item-reference.test.ts; these
// cases exercise the end-to-end display-name composition.
describe('deriveWorkspaceDisplayName', () => {
it('leads with the identifier and a single action verb', () => {
expect(
deriveWorkspaceDisplayName({
prompt: 'Carefully evaluate https://github.com/o/r/pull/1033. Fix the merge conflict.',
slug: 'review-community-pr-conflict'
})
).toBe('PR 1033 - Review')
})
it('drops identifier tokens the slug also carried', () => {
expect(
deriveWorkspaceDisplayName({
prompt: 'look at this community PR https://github.com/o/r/pull/1094',
slug: 'review-community-pr-1094'
})
).toBe('PR 1094 - Review')
})
it('uses a namespaced ticket id bare, without a type prefix', () => {
expect(
deriveWorkspaceDisplayName({ prompt: 'fix ENG-456 crash', slug: 'fix-eng-456-crash' })
).toBe('ENG-456 - Fix')
})
it('returns the identifier alone when no action word survives', () => {
expect(deriveWorkspaceDisplayName({ prompt: 'PR 12', slug: 'pr-12' })).toBe('PR 12')
})
it('carries a collision suffix so same-target worktrees stay distinct', () => {
expect(
deriveWorkspaceDisplayName({
prompt: 'review https://github.com/o/r/pull/1033',
slug: 'review-conflict',
resolvedLeaf: 'review-conflict-2'
})
).toBe('PR 1033 - Review (2)')
})
it('falls back to the humanized leaf when no identifier is present', () => {
expect(
deriveWorkspaceDisplayName({ prompt: 'add a dark mode toggle', slug: 'add-dark-mode-toggle' })
).toBe('Add dark mode toggle')
})
it('humanizes the resolved leaf (with suffix) on the fallback path', () => {
expect(
deriveWorkspaceDisplayName({
prompt: 'add a logout button',
slug: 'add-logout-button',
resolvedLeaf: 'add-logout-button-2'
})
).toBe('Add logout button 2')
})
})