Overlay 2.0 (#12)

This commit is contained in:
2026-03-01 02:36:51 -08:00
committed by GitHub
parent 45df3c466b
commit 44c7761c7c
397 changed files with 15139 additions and 7127 deletions
@@ -64,6 +64,32 @@ test('subtitle processing skips duplicate subtitle emission', async () => {
assert.equal(tokenizeCalls, 1);
});
test('subtitle processing reuses cached tokenization for repeated subtitle text', async () => {
const emitted: SubtitleData[] = [];
let tokenizeCalls = 0;
const controller = createSubtitleProcessingController({
tokenizeSubtitle: async (text) => {
tokenizeCalls += 1;
return { text, tokens: [] };
},
emitSubtitle: (payload) => emitted.push(payload),
});
controller.onSubtitleChange('first');
await flushMicrotasks();
controller.onSubtitleChange('second');
await flushMicrotasks();
controller.onSubtitleChange('first');
await flushMicrotasks();
assert.equal(tokenizeCalls, 2);
assert.deepEqual(emitted, [
{ text: 'first', tokens: [] },
{ text: 'second', tokens: [] },
{ text: 'first', tokens: [] },
]);
});
test('subtitle processing falls back to plain subtitle when tokenization returns null', async () => {
const emitted: SubtitleData[] = [];
const controller = createSubtitleProcessingController({
@@ -112,3 +138,35 @@ test('subtitle processing refresh can use explicit text override', async () => {
assert.deepEqual(emitted, [{ text: 'initial', tokens: [] }]);
});
test('subtitle processing cache invalidation only affects future subtitle events', async () => {
const emitted: SubtitleData[] = [];
const callsByText = new Map<string, number>();
const controller = createSubtitleProcessingController({
tokenizeSubtitle: async (text) => {
callsByText.set(text, (callsByText.get(text) ?? 0) + 1);
return { text, tokens: [] };
},
emitSubtitle: (payload) => emitted.push(payload),
});
controller.onSubtitleChange('same');
await flushMicrotasks();
controller.onSubtitleChange('other');
await flushMicrotasks();
controller.onSubtitleChange('same');
await flushMicrotasks();
assert.equal(callsByText.get('same'), 1);
assert.equal(emitted.length, 3);
controller.invalidateTokenizationCache();
assert.equal(emitted.length, 3);
controller.onSubtitleChange('different');
await flushMicrotasks();
controller.onSubtitleChange('same');
await flushMicrotasks();
assert.equal(callsByText.get('same'), 2);
});