Files
NetMesh/domain/imeControlledInput.test.ts
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

185 lines
4.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
resolveSupersededImeInputEvent,
shouldAdoptExternalImeControlledValue,
shouldCommitImeControlledChange,
} from "./imeControlledInput.ts";
test("does not commit controlled changes while an IME composition session is open", () => {
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: true,
nativeEventIsComposing: true,
}),
false,
);
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: true,
nativeEventIsComposing: false,
}),
false,
);
});
test("does not commit when the native event still reports composing", () => {
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
nativeEventIsComposing: true,
}),
false,
);
});
test("commits ordinary keystrokes outside composition", () => {
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
nativeEventIsComposing: false,
}),
true,
);
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
}),
true,
);
});
test("does not commit when composition was externally superseded", () => {
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
nativeEventIsComposing: false,
compositionExternallySuperseded: true,
}),
false,
);
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: true,
nativeEventIsComposing: false,
compositionExternallySuperseded: true,
}),
false,
);
});
test("adopts external value into draft only when not composing and values differ", () => {
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: false,
draftValue: "sou",
externalValue: "",
}),
true,
);
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: true,
draftValue: "sou",
externalValue: "",
}),
false,
);
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: false,
draftValue: "搜",
externalValue: "搜",
}),
false,
);
});
test("adopts external navigation-clear mid-composition when compose-start baseline is provided", () => {
// Parent cleared filter for different-directory navigation while IME was open.
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: true,
draftValue: "sou",
externalValue: "",
valueAtComposeStart: "old",
}),
true,
);
// External value still matches the compose-start baseline - keep draft for IME.
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: true,
draftValue: "sou",
externalValue: "old",
valueAtComposeStart: "old",
}),
false,
);
// Draft already matches external after a prior adopt - no-op.
assert.equal(
shouldAdoptExternalImeControlledValue({
isComposingSession: true,
draftValue: "",
externalValue: "",
valueAtComposeStart: "old",
}),
false,
);
});
test("suppresses post-composition onChange after external supersede and clears the latch once ended", () => {
// Mid-composition after navigation clear: ignore event, keep latch armed.
assert.deepEqual(
resolveSupersededImeInputEvent({
compositionExternallySuperseded: true,
isComposingSession: true,
nativeEventIsComposing: true,
}),
{ ignoreEventValue: true, clearSupersedeLatch: false },
);
// Post-compositionend follow-up change (composing=false): ignore once and clear.
assert.deepEqual(
resolveSupersededImeInputEvent({
compositionExternallySuperseded: true,
isComposingSession: false,
nativeEventIsComposing: false,
}),
{ ignoreEventValue: true, clearSupersedeLatch: true },
);
// No supersede: ordinary path.
assert.deepEqual(
resolveSupersededImeInputEvent({
compositionExternallySuperseded: false,
isComposingSession: false,
nativeEventIsComposing: false,
}),
{ ignoreEventValue: false, clearSupersedeLatch: false },
);
});
test("ordinary commits remain blocked only while the supersede latch is armed", () => {
// Documents the stuck-latch failure mode: if compositionend arms the latch and
// no post-composition onChange clears it, shouldCommitImeControlledChange stays
// false for ordinary keystrokes. UI must clear via onChange or a deferred fallback.
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
nativeEventIsComposing: false,
compositionExternallySuperseded: true,
}),
false,
);
assert.equal(
shouldCommitImeControlledChange({
isComposingSession: false,
nativeEventIsComposing: false,
compositionExternallySuperseded: false,
}),
true,
);
});