86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
buildBranchNamePrompt,
|
|
humanizeBranchSlug,
|
|
isAutoGeneratedCreatureBranchName,
|
|
sanitizeBranchSlug
|
|
} from './branch-name-from-work'
|
|
|
|
describe('sanitizeBranchSlug', () => {
|
|
it('lowercases and kebab-cases free-form model output', () => {
|
|
expect(sanitizeBranchSlug('Fix the auth bug')).toBe('fix-the-auth-bug')
|
|
})
|
|
|
|
it('caps at four words', () => {
|
|
expect(sanitizeBranchSlug('add dark mode toggle to settings page')).toBe('add-dark-mode-toggle')
|
|
})
|
|
|
|
it('honors a custom word cap', () => {
|
|
expect(sanitizeBranchSlug('add dark mode toggle', 2)).toBe('add-dark')
|
|
})
|
|
|
|
it('collapses punctuation, quotes, and slashes into single hyphens', () => {
|
|
expect(sanitizeBranchSlug('"feat/login_flow!!"')).toBe('feat-login-flow')
|
|
})
|
|
|
|
it('returns empty string when nothing usable remains', () => {
|
|
expect(sanitizeBranchSlug(' !!! ___ ')).toBe('')
|
|
expect(sanitizeBranchSlug('')).toBe('')
|
|
})
|
|
})
|
|
|
|
describe('isAutoGeneratedCreatureBranchName', () => {
|
|
it('matches a creature name case-insensitively', () => {
|
|
expect(isAutoGeneratedCreatureBranchName('Nautilus')).toBe(true)
|
|
expect(isAutoGeneratedCreatureBranchName('octopus')).toBe(true)
|
|
})
|
|
|
|
it('matches numbered collision variants', () => {
|
|
expect(isAutoGeneratedCreatureBranchName('Nautilus-2')).toBe(true)
|
|
expect(isAutoGeneratedCreatureBranchName('Seahorse-17')).toBe(true)
|
|
})
|
|
|
|
it('rejects user-chosen and work-derived names', () => {
|
|
expect(isAutoGeneratedCreatureBranchName('fix-auth-bug')).toBe(false)
|
|
expect(isAutoGeneratedCreatureBranchName('my-feature')).toBe(false)
|
|
expect(isAutoGeneratedCreatureBranchName('')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('humanizeBranchSlug', () => {
|
|
it('turns a kebab slug into a readable label', () => {
|
|
expect(humanizeBranchSlug('supported-models-list')).toBe('Supported models list')
|
|
expect(humanizeBranchSlug('fix-auth')).toBe('Fix auth')
|
|
})
|
|
|
|
it('returns empty string for an empty slug', () => {
|
|
expect(humanizeBranchSlug('')).toBe('')
|
|
})
|
|
})
|
|
|
|
describe('buildBranchNamePrompt', () => {
|
|
it('includes the user prompt and omits the assistant section when absent', () => {
|
|
const prompt = buildBranchNamePrompt({ firstPrompt: 'Add a logout button' })
|
|
expect(prompt).toContain('Add a logout button')
|
|
expect(prompt).not.toContain("Agent's initial response")
|
|
})
|
|
|
|
it('includes the assistant response when present', () => {
|
|
const prompt = buildBranchNamePrompt({
|
|
firstPrompt: 'Add a logout button',
|
|
assistantMessage: "I'll wire it into the header."
|
|
})
|
|
expect(prompt).toContain("Agent's initial response")
|
|
expect(prompt).toContain("I'll wire it into the header.")
|
|
})
|
|
|
|
it('appends custom branch-name instructions when present', () => {
|
|
const prompt = buildBranchNamePrompt(
|
|
{ firstPrompt: 'Add a logout button' },
|
|
'Prefer product nouns.'
|
|
)
|
|
expect(prompt).toContain('Additional user instructions:')
|
|
expect(prompt).toContain('Prefer product nouns.')
|
|
})
|
|
})
|