-
Notifications
You must be signed in to change notification settings - Fork 237
fix(webview): ignore blank or missing follow-up suggestion answers #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
easonLiangWorldedtech
wants to merge
5
commits into
Zoo-Code-Org:main
Choose a base branch
from
easonLiangWorldedtech:fix/blank-followup-suggestions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f61112
fix(webview): ignore blank or missing follow-up suggestion answers
easonliang28 0972810
harden(webview): normalize non-string chat input and cover remaining …
easonliang28 662e0e5
test(webview): cover the remaining normalized-input string operations
easonliang28 d9daf14
refactor(test): type follow-up auto-approval state instead of casting
easonliang28 9799cbb
test(webview): assert the normalized textarea value for malformed inputs
easonliang28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { checkAutoApproval } from ".." | ||
|
|
||
| describe("Follow-up question auto-approval", () => { | ||
| const baseState = { | ||
| autoApprovalEnabled: true, | ||
| alwaysAllowFollowupQuestions: true, | ||
| followupAutoApproveTimeoutMs: 10_000, | ||
| } | ||
|
|
||
| const followupText = (suggest: unknown) => JSON.stringify({ question: "Pick one?", suggest }) as string | ||
|
|
||
| const run = (state: Record<string, unknown>, text: string) => | ||
| checkAutoApproval({ state: state as never, ask: "followup", text }) | ||
|
|
||
| it("schedules a timeout that auto-answers with the first valid suggestion", async () => { | ||
| const result = await run(baseState, followupText([{ answer: "Yes, proceed" }])) | ||
|
|
||
| expect(result.decision).toBe("timeout") | ||
| if (result.decision === "timeout") { | ||
| expect(result.timeout).toBe(10_000) | ||
| expect(result.fn()).toEqual({ | ||
| askResponse: "messageResponse", | ||
| text: "Yes, proceed", | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| it("falls back to asking when the follow-up has no text payload", async () => { | ||
| // Exercises the `text || "{}"` fallback: a follow-up without any payload must | ||
| // not schedule an auto-answer timeout. | ||
| const result = await checkAutoApproval({ state: baseState as never, ask: "followup" }) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("skips a blank or missing first answer and uses the next valid suggestion (issue #1226)", async () => { | ||
| // Mirrors a malformed model response where JSON round-tripping drops | ||
| // `answer: undefined` and the first item is unusable. | ||
| const result = await run(baseState, followupText([{}, { answer: " " }, { answer: "Valid answer" }])) | ||
|
|
||
| expect(result.decision).toBe("timeout") | ||
| if (result.decision === "timeout") { | ||
| expect(result.fn()).toEqual({ | ||
| askResponse: "messageResponse", | ||
| text: "Valid answer", | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| it("falls back to asking when every suggestion answer is blank or missing (issue #1226)", async () => { | ||
| // Before the #1226 fix this scheduled a timeout that auto-answered the | ||
| // follow-up with `undefined` text, silently accepting an empty answer. | ||
| const result = await run(baseState, followupText([{ answer: "" }, { answer: " \n\t " }, {}])) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("falls back to asking when the suggestion answer is not a string", async () => { | ||
| const result = await run(baseState, followupText([{ answer: 42 }])) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("falls back to asking when the follow-up has no suggestions", async () => { | ||
| const result = await run(baseState, JSON.stringify({ question: "Pick one?" })) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("falls back to asking when the follow-up text is not valid JSON", async () => { | ||
| const result = await run(baseState, "not-json") | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("falls back to asking when the auto-approve timeout is not positive", async () => { | ||
| const result = await run({ ...baseState, followupAutoApproveTimeoutMs: 0 }, followupText([{ answer: "Yes" }])) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("does not auto-approve when follow-up auto-approval is disabled", async () => { | ||
| const result = await run( | ||
| { ...baseState, alwaysAllowFollowupQuestions: false }, | ||
| followupText([{ answer: "Yes" }]), | ||
| ) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
|
|
||
| it("does not auto-approve when global auto-approval is disabled", async () => { | ||
| const result = await run({ ...baseState, autoApprovalEnabled: false }, followupText([{ answer: "Yes" }])) | ||
|
|
||
| expect(result).toEqual({ decision: "ask" }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.