Fix ask_user_question review findings

This commit is contained in:
Yichen Jiang
2026-06-29 10:49:07 +08:00
parent 08fc8467bc
commit 51700d4685
38 changed files with 611 additions and 54 deletions

View File

@@ -261,7 +261,7 @@ export function createStdioChat(ctx: Context, config: Config, runtime: StdioRunt
return
}
const allowCustom = pending.request.allowCustom ?? true
const allowCustom = options.length === 0 || (pending.request.allowCustom ?? true)
if (allowCustom && text !== '') {
finishQuestion(pending, { answer: text })
return

View File

@@ -328,6 +328,19 @@ describe('createStdioChat input', () => {
await expect(answer).resolves.toEqual({ answer: 'Use defaults' })
})
it('accepts free-form input for an optionless question even when allowCustom is false', async () => {
const { ctx, input } = await setup()
const answer = ctx.userInteraction.ask({
question: 'Choose?',
allowCustom: false,
})
await new Promise(r => setImmediate(r))
input.feed('Use the default path')
await expect(answer).resolves.toEqual({ answer: 'Use the default path' })
})
it('rejects an active question when its signal aborts', async () => {
const { ctx } = await setup()
const controller = new AbortController()