test(ai-chat): cover role-pick autoStart logic + the rolePickedNoSend reset (#149 review)
Review of #156 (Request changes) flagged the new CLIENT logic as untested. Extract the decision logic from chat-thread.tsx into pure, unit-testable helpers and cover both branches the reviewer called out: - `roleLaunchMessage(role, default)` — the three-way handleRolePick behavior: autoStart=false -> null (send nothing); autoStart=true + custom -> trimmed message; autoStart=true + empty/null/whitespace -> default fallback. - `shouldResetRolePicked(chatId, roleId, flag)` — the #149 render-phase reset; the regression test asserts the stuck-flag case (New chat after an autoStart=false pick -> cards return) that the pre-fix code never handled, and that a still-bound role keeps the cards hidden. chat-thread.tsx now calls these helpers (behavior unchanged). 9 new pure tests. Also folded the review's cosmetic suggestion: `x ? x : null` -> `x || null` in ai-agent-roles.repo.ts (identical for string|null|undefined). Client tsc clean; role-launch + role-cards green; repo spec green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ export class AiAgentRoleRepo {
|
||||
enabled: values.enabled ?? true,
|
||||
autoStart: values.autoStart ?? true,
|
||||
// Empty string is treated as "no custom text" => null.
|
||||
launchMessage: values.launchMessage ? values.launchMessage : null,
|
||||
launchMessage: values.launchMessage || null,
|
||||
})
|
||||
.returningAll()
|
||||
.executeTakeFirst();
|
||||
@@ -133,7 +133,7 @@ export class AiAgentRoleRepo {
|
||||
if (patch.autoStart !== undefined) set.autoStart = patch.autoStart;
|
||||
if (patch.launchMessage !== undefined) {
|
||||
// Empty string clears to null (client default launch message).
|
||||
set.launchMessage = patch.launchMessage ? patch.launchMessage : null;
|
||||
set.launchMessage = patch.launchMessage || null;
|
||||
}
|
||||
await db
|
||||
.updateTable('aiAgentRoles')
|
||||
|
||||
Reference in New Issue
Block a user