Add resolver, server, PDF rendering and web app

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 09:46:46 -07:00
1 parent 6a7fcdc4b8
commit bdfdf581f3
59 files changed
+4088

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { acceptRead, endRound, newReadState } from './readstate.ts';
const ISBN = '9780306406157';
test('single read emits nothing, second consecutive read emits', () => {
let r = acceptRead(newReadState(), ISBN, 0);
assert.equal(r.emit, null);
r = acceptRead(endRound(r.state, [ISBN]), ISBN, 150);
assert.equal(r.emit, ISBN);
assert.equal(r.reject, false);
});
test('a gap between reads resets the streak', () => {
let r = acceptRead(newReadState(), ISBN, 0);
const s = endRound(r.state, []);
r = acceptRead(s, ISBN, 150);
assert.equal(r.emit, null);
});
test('third read does not emit again; emits again after 5 s', () => {
let s = newReadState();
let t = 0;
const read = () => { const r = acceptRead(s, ISBN, t); s = endRound(r.state, [ISBN]); t += 150; return r; };
read();
assert.equal(read().emit, ISBN);
assert.equal(read().emit, null);
t = 5200;
assert.equal(read().emit, ISBN);
});
test('a UPC rejects once per 5 s', () => {
const upc = '036000291452';
let s = newReadState();
let t = 0;
const read = () => { const r = acceptRead(s, upc, t); s = endRound(r.state, [upc]); t += 150; return r; };
assert.equal(read().reject, false);
const second = read();
assert.equal(second.reject, true);
assert.equal(second.emit, null);
assert.equal(read().reject, false);
t = 6000;
assert.equal(read().reject, true);
});
test('bad check digit rejects', () => {
let s = newReadState();
let r = acceptRead(s, '9780306406158', 0); s = endRound(r.state, ['9780306406158']);
r = acceptRead(s, '9780306406158', 150);
assert.equal(r.reject, true);
});