cc-haha/src/utils/__tests__/sessionTitleText.test.ts
程序员阿江(Relakkes) 179f79b794 fix: sanitize generated session titles
Slash-command and skill prompts can enter the title-generation path as internal XML breadcrumbs. The async title request previously treated that transport metadata as user prose, so a generated ai-title could persist raw command tags and override the normal session title.

This routes title sources and generated title output through a shared sanitizer, preserving user-visible command names and arguments while dropping unrelated internal XML metadata. Desktop fallback title rendering now applies the same cleanup so existing transcripts with bad ai-title entries recover on read.

Constraint: Session titles can be produced by both desktop server logic and the SDK generate_session_title control request.
Rejected: Only clean desktop session display | leaves CLI and remote title generation able to persist bad titles again
Confidence: high
Scope-risk: moderate
Directive: Keep generated-title input and persisted-title readback on the shared sanitizer; do not add a title path that reads command XML directly.
Tested: bun test src/utils/__tests__/sessionTitle.test.ts src/utils/__tests__/sessionTitleText.test.ts
Tested: bun run check:server
Tested: bun run check:desktop
Tested: bun run verify (7 passed, 1 failed on existing aggregate agent-utils coverage baseline)
Not-tested: live model title-generation smoke
2026-05-09 22:34:27 +08:00

21 lines
763 B
TypeScript

import { describe, expect, test } from 'bun:test'
import { cleanSessionTitleSource } from '../sessionTitleText.js'
describe('sessionTitleText', () => {
test('converts slash command XML metadata into a user-facing title source', () => {
const raw = [
'<command-message>frontend-design</command-message>',
'<command-name>/frontend-design</command-name>',
'<command-args>@website 重新设计首页</command-args>',
].join('\n')
expect(cleanSessionTitleSource(raw)).toBe('/frontend-design @website 重新设计首页')
})
test('strips non-command internal XML wrappers from title sources', () => {
expect(cleanSessionTitleSource('<ide_opened_file>secret.ts</ide_opened_file>\nFix login'))
.toBe('Fix login')
})
})