65 lines · 3.7 KB · JavaScript
RawDownload
'use strict';// node check.js  (run with `env -u ELECTRON_RUN_AS_NODE node check.js` if that variable is set)const assert = require('assert');const P = require('./main.js'); // dictionary: spoken form -> replacement, whole words, any caseconst dict = [{ word: 'btw', to: 'by the way' }, { word: 'Ada' }, { word: 'kubectl', to: 'Kubectl' }];assert.strictEqual(P.applyDictionary('btw the build is done, BTW.', dict), 'by the way the build is done, by the way.');assert.strictEqual(P.applyDictionary('subtwig', dict), 'subtwig');assert.strictEqual(P.applyDictionary('run kubectl now', dict), 'run Kubectl now'); // snippets: trigger phrase (any case, optional trailing punctuation) becomes a placeholder, then the textconst snips = [{ trigger: 'my email address', text: 'ada@example.com' }];let r = P.expandSnippets('Send it to my email address.', snips);assert.strictEqual(r.text, 'Send it to [[S0]]');assert.strictEqual(P.restoreSnippets(r.text, r.slots), 'Send it to ada@example.com');r = P.expandSnippets('My email, address', snips);assert.strictEqual(P.restoreSnippets(r.text, r.slots), 'ada@example.com');assert.strictEqual(P.expandSnippets('my emails addressed', snips).slots.length, 0); // app categories drive the Styleassert.strictEqual(P.appCategory('Signal'), 'personal');assert.strictEqual(P.appCategory('Slack'), 'work');assert.strictEqual(P.appCategory('Brave-browser', 'Inbox (3) - Gmail'), 'email');assert.strictEqual(P.appCategory('St'), 'other');assert.ok(P.isTerminal('St') && P.isTerminal('kitty') && !P.isTerminal('Brave-browser')); // statsassert.strictEqual(P.countWords('  one two\nthree '), 3);assert.strictEqual(P.wpm(57, 30000), 114);assert.strictEqual(P.wpm(10, 0), 0); // whisper noise markersassert.strictEqual(P.stripMarkers(' [BLANK_AUDIO] '), '');assert.strictEqual(P.stripMarkers('Hello (music playing) there'), 'Hello there'); // WAV writer: 44-byte header + 16-bit samples, clippedconst wav = P.wavBuffer(new Float32Array([0, 1, -1, 2]));assert.strictEqual(wav.length, 44 + 8);assert.strictEqual(wav.toString('ascii', 0, 4), 'RIFF');assert.strictEqual(wav.readUInt32LE(24), 16000);assert.deepStrictEqual([wav.readInt16LE(44), wav.readInt16LE(46), wav.readInt16LE(48), wav.readInt16LE(50)], [0, 32767, -32767, 32767]); // cleanup guard: edits that only delete or fix case pass, answers do notassert.ok(P.drift('um find me the best book for poetry', 'Find me the best book for poetry.') === 0);assert.ok(P.drift('Find me the best book for learning poetic meaning.', "I can't find the best book for learning poetic meaning.") > 0);assert.ok(P.drift('what is the capital of france', 'Paris is the capital and largest city of France.') > 0.35);const msgs = P.cleanupMessages('light', 'veryCasual', 'personal', 'hi [[S0]]');assert.strictEqual(msgs.at(-1).content, '<dictation>hi [[S0]]</dictation>');assert.strictEqual(msgs[2].content, 'can you send me the report by friday?'); assert.strictEqual(P.keyLabel(108), 'Right Alt');assert.strictEqual(P.keyLabel(70), 'F4'); // assistant prompt carries the focused window when knownassert.ok(P.assistantPrompt('open firefox', { cls: 'St', title: 'nvim' }).endsWith('open firefox\n\nFocused window: St "nvim"'));assert.ok(P.assistantPrompt('open firefox').endsWith('open firefox'));assert.ok(P.assistantPrompt('x', {}, ' be brief ').includes("standing instructions:\nbe brief\n\nVoice command"));assert.ok(!P.assistantPrompt('x', {}, '  ').includes('standing')); // CLI output: grok JSON stream -> last result, plain text unchangedassert.strictEqual(P.cliResult('{"type":"message","text":"I will run date"}\n{"type":"result","result":"It is 3pm."}\n'), 'It is 3pm.');assert.strictEqual(P.cliResult('Done, Firefox is on tag 2.'), 'Done, Firefox is on tag 2.'); console.log('check.js: ok');