Files
Reims-Go/internal/host/ime_hook_test.go
T
NwflowerandClaude Opus 5.5 b2237997f2 feat(input): send Chinese, emoji and host-IME text into the VM
- "Send text to VM..." dialog: arbitrary Unicode goes through Guest Tools
  (clipboard paste in the guest, agent v3 /v1/text-input long poll); without
  Guest Tools only US-keyboard ASCII is typed via QMP.
- Host IME / dictation: a low-level keyboard hook (internal/host/ime_*) catches
  VK_PACKET input aimed at a running VM window, coalesces bursts and forwards
  them in order through a per-VM queue (type_flow.go).
- reims-vgpu-window bridge: new runtime patch reims-vgpu-win32-unicode-input
  enables SDL text input and posts committed text to /v1/host-text; StartVM
  passes REIMS_GO_INPUT_URL/TOKEN to the window process. This also adds the
  patch file that patches/series.txt already listed.
- Guest Tools auth returns a field snapshot instead of copying the VM entry
  (it now holds a mutex and text queues).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 10:52:34 -07:00

69 lines
1.5 KiB
Go

package host
import (
"sync"
"testing"
"time"
"unicode/utf16"
)
func TestIMECoalescerCJKAndEmojiSurrogates(t *testing.T) {
type gotItem struct {
vm string
text string
}
var (
mu sync.Mutex
got []gotItem
done = make(chan struct{}, 4)
)
c := NewIMECoalescer(25*time.Millisecond, func(target IMETarget, text string) {
mu.Lock()
got = append(got, gotItem{vm: target.VMName, text: text})
mu.Unlock()
done <- struct{}{}
})
defer c.Close()
vmA := IMETarget{VMName: "mac-a", PID: 1001}
vmB := IMETarget{VMName: "mac-b", PID: 1002}
// Push Chinese + ASCII + Emoji (surrogate pair) rapidly -> single coalesced phrase.
for _, u := range utf16.Encode([]rune("你好ABC🎉")) {
c.Push(vmA, u)
}
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("timed out waiting for coalesced phrase")
}
// Switching target VM flushes immediately, and '\r' normalizes to '\n' + flushes.
c.Push(vmA, 'x')
c.Push(vmB, 'y')
c.Push(vmB, '\r')
for i := 0; i < 2; i++ {
select {
case <-done:
case <-time.After(time.Second):
t.Fatalf("timed out waiting for flush %d", i+2)
}
}
mu.Lock()
defer mu.Unlock()
if len(got) != 3 {
t.Fatalf("got %d flushes: %+v", len(got), got)
}
if got[0] != (gotItem{vm: "mac-a", text: "你好ABC🎉"}) {
t.Fatalf("flush[0] = %+v", got[0])
}
if got[1] != (gotItem{vm: "mac-a", text: "x"}) {
t.Fatalf("flush[1] = %+v", got[1])
}
if got[2] != (gotItem{vm: "mac-b", text: "y\n"}) {
t.Fatalf("flush[2] = %+v", got[2])
}
}