mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2026-02-16 16:42:29 +01:00
fix(ai): prevent async suggestion duplication
- Add buffer validation to check suggestion starts with buffer - Discard stale suggestions that don't match current content Fixes text duplication bug when accepting async suggestions after buffer changes during suggestion fetch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8f1d53df7a
commit
55cd4ec23d
3 changed files with 85 additions and 1 deletions
|
|
@ -405,3 +405,29 @@ EOFCURL
|
|||
wait_for { session.content }.to eq('temp 0.3')
|
||||
end
|
||||
end
|
||||
|
||||
context 'suggestion buffer validation' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai)"] }
|
||||
|
||||
context 'when suggestion does not match current buffer' do
|
||||
let(:before_sourcing) do
|
||||
-> {
|
||||
session.run_command('curl() {
|
||||
if [[ "$*" == *"max-time"* ]]; then
|
||||
cat <<EOFCURL
|
||||
{"choices":[{"message":{"content":"git status --long"}}]}
|
||||
200
|
||||
EOFCURL
|
||||
fi
|
||||
}')
|
||||
}
|
||||
end
|
||||
|
||||
it 'discards suggestion that does not match buffer' do
|
||||
# Suggestion is "git status --long" but buffer is unrelated
|
||||
session.send_string('ls')
|
||||
wait_for { session.content }.to_not match(/git status/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue