From d7e6987637004d7884ca844e9520e2e3ff98fa6f Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Tue, 2 Sep 2025 15:03:08 -0500 Subject: [PATCH] feat(web): add extra unit test --- .../context/context-tokenization.tests.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/web/src/test/auto/headless/engine/predictive-text/worker-thread/context/context-tokenization.tests.ts b/web/src/test/auto/headless/engine/predictive-text/worker-thread/context/context-tokenization.tests.ts index 9edc611861..7d66c775cf 100644 --- a/web/src/test/auto/headless/engine/predictive-text/worker-thread/context/context-tokenization.tests.ts +++ b/web/src/test/auto/headless/engine/predictive-text/worker-thread/context/context-tokenization.tests.ts @@ -376,5 +376,44 @@ describe('ContextTokenization', function() { assert.equal(tokenization.tail.searchSpace.inputSequence.length, "thin".length); assert.sameOrderedMembers(tokenization.tokens.map(t => t.exampleInput), targetTexts); }); + + it('handles word-break boundary shifts at both ends during backward context-window slide', () => { + const baseTexts = [ + // Without any preceding adjacent char in view, we can only interpret + // the leading `'` as an opening single-quote. + /*isn*/ "'", "t", " ", "orange", " ", "juice", " ", "tasty", "?", " ", "I", " ", "find", " ", "" + ]; + + const baseTokenization = new ContextTokenization(baseTexts.map(t => toToken(t)), null); + + const targetTexts = [ + // With one preceding adjacent non-whitespace char in view, we now + // realize it was part of a word... and remove a wordbreak! + /*is"*/ "n't", " ", "orange", " ", "juice", " ", "tasty", "?", " ", "I", " ", "find" + ]; + const targetTokens = targetTexts.map((t) => ({text: t, isWhitespace: t == ' '})); + const inputTransformMap: Map = new Map(); + + inputTransformMap.set(0, { insert: '', deleteLeft: 1 }); + + const tokenization = baseTokenization.transitionTo( + targetTokens, { + canAlign: true, + leadTokenShift: -1, // "'", + leadEditLength: 1, // "t" / "n't" + matchLength: baseTexts.length - 4, + tailEditLength: 0, + tailTokenShift: -2 // " ", "" + }, + plainModel, + [{ sample: inputTransformMap, p: 1}] + ); + + assert.isOk(tokenization); + assert.equal(tokenization.tokens.length, targetTokens.length); + assert.equal(tokenization.tail.exampleInput, "find"); + assert.equal(tokenization.tail.searchSpace.inputSequence.length, "find".length); + assert.sameOrderedMembers(tokenization.tokens.map(t => t.exampleInput), targetTexts); + }); }); });