fix(native-chat): reject noncanonical stored conversation names

This commit is contained in:
Merge Sim
2026-09-10 17:24:08 -07:00
parent 92c79ec8d1
commit b4ccebfbc0
3 changed files with 18 additions and 2 deletions
@@ -33,6 +33,18 @@ describe('agent session record conversationName validation', () => {
false
)
})
it('rejects persisted names that bypassed canonical normalization', () => {
expect(
isAgentSessionRecord({
...agentSessionRecordFixture(),
conversationName: 'Fix\u202Egnp.exe probe'
})
).toBe(false)
expect(
isAgentSessionRecord({ ...agentSessionRecordFixture(), conversationName: 'Fix\nthe probe' })
).toBe(false)
})
})
describe('setAgentSessionRecordConversationName', () => {
@@ -38,10 +38,13 @@ describe('normalizeAgentSessionConversationName', () => {
})
describe('isAgentSessionConversationName', () => {
it('accepts a bounded non-empty string and nothing else', () => {
it('accepts only bounded canonical names', () => {
expect(isAgentSessionConversationName('Fix the probe')).toBe(true)
expect(isAgentSessionConversationName('')).toBe(false)
expect(isAgentSessionConversationName('a'.repeat(201))).toBe(false)
expect(isAgentSessionConversationName(' Fix the probe ')).toBe(false)
expect(isAgentSessionConversationName('Fix\nthe probe')).toBe(false)
expect(isAgentSessionConversationName('Fix\u202Egnp.exe probe')).toBe(false)
expect(isAgentSessionConversationName(7)).toBe(false)
})
})
@@ -61,6 +61,7 @@ export function isAgentSessionConversationName(value: unknown): value is string
return (
typeof value === 'string' &&
value.length > 0 &&
value.length <= AGENT_SESSION_CONVERSATION_NAME_MAX_LENGTH
value.length <= AGENT_SESSION_CONVERSATION_NAME_MAX_LENGTH &&
normalizeAgentSessionConversationName(value) === value
)
}