Add QR codes to cards, stop inventing call number parts

Cards now carry a QR code holding the book's own record (call number,
title, authors, ISBN, year), and the scanner reads it back to find or
add that book.

Call number selection no longer pads catalogue numbers with generated
cutters. A number is "exact" only when it comes verbatim from a record
for this edition; a bare class is a hint that steers the other-edition
and similar-books lookups; a record fetched by LCCN must list the
book's ISBN to count as this edition. "Look up again" bypasses every
cached result, and shelf order breaks ties by author then title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 12:53:12 -07:00
1 parent 6cec404e21
commit ad2956e868
56 files changed
+4020 -156

No files matched your search

+68 -1
View File
@@ -10,7 +10,11 @@ const found: Resolution = {
callNumber: 'QA76.73.R87 K53 2018', sortKey: 'QA 76', confidence: 'exact', source: 'loc-isbn', dewey: null, reason: null,
};
function setup(resolve = async () => found, port?: number) {
function setupRecording(fresh: (boolean | undefined)[]) {
return setup(async (_i?: unknown, o?: { fresh?: boolean }) => { fresh.push(o?.fresh ?? false); return found; });
}
function setup(resolve: (i?: any, o?: any) => Promise<Resolution> = async () => found, port?: number) {
const db = openDb(':memory:');
const events = createEventBus();
const resolver = { resolve, search: async () => [{ title: 'Hit', authors: [], lcc: [] }] };
@@ -249,3 +253,66 @@ test('debug capture: saves a PNG, keeps the newest 30, refuses other bodies', as
assert.equal(readdirSync(join(dir, 'captures')).length, 30);
} finally { rmSync(dir, { recursive: true, force: true }); }
});
test('from-card: parses, adds a resolved book that is not queued, then finds it again', async () => {
const { req, db } = setup();
assert.equal((await req('POST', '/api/books/from-card', { text: 'https://example.com' })).status, 400);
assert.equal((await req('POST', '/api/books/from-card', {})).status, 400);
const text = 'PQ2230.A1 H8 1987 ~\nLes Misérables\nVictor Hugo\nbooksorter 1';
const first = await (await req('POST', '/api/books/from-card', { text })).json() as any;
assert.equal(first.existed, false);
assert.equal(first.book.status, 'resolved');
assert.equal(first.book.source, 'card');
assert.equal(first.book.confidence, 'approximate');
assert.equal(first.book.inQueue, false);
assert.equal(first.book.callNumber, 'PQ2230.A1 H8 1987');
assert.deepEqual(first.book.authors, ['Victor Hugo']);
// same title (any case, padded) with the same call number is the same book; a different call number is not
const again = await (await req('POST', '/api/books/from-card', { text: text.replace('Les Misérables', 'LES MISÉRABLES ') })).json() as any;
assert.equal(again.existed, true);
assert.equal(again.book.id, first.book.id);
const other = await (await req('POST', '/api/books/from-card', { text: text.replace('H8', 'H9') })).json() as any;
assert.equal(other.existed, false);
assert.equal(db.listBooks().length, 2);
});
test('from-card: a card with an ISBN matches by ISBN; cross-origin is refused', async () => {
const { req, db } = setup(undefined, 4321);
const text = 'QA76.73.R87 K53 2018\nThe Rust Programming Language\nSteve Klabnik\nISBN 9781593278281\n2018\nbooksorter 1';
const made = await (await req('POST', '/api/books/from-card', { text }, { origin: 'http://localhost:4321' })).json() as any;
assert.equal(made.book.isbn13, '9781593278281');
assert.equal(made.book.year, 2018);
const found = await (await req('POST', '/api/books/from-card', { text: text.replace('The Rust Programming Language', 'Other') }, { origin: 'http://localhost:4321' })).json() as any;
assert.equal(found.existed, true);
assert.equal(found.book.id, made.book.id);
assert.equal((await req('POST', '/api/books/from-card', { text }, { origin: 'http://evil.example' })).status, 403);
assert.equal(db.listBooks().length, 1);
});
test('retry asks the lookup to ignore its caches', async () => {
const fresh: (boolean | undefined)[] = [];
const { req, jobs } = setupRecording(fresh);
const s = await (await req('POST', '/api/scan', { isbn: '9781593278281' })).json() as any;
await jobs.idle();
assert.equal((await req('POST', `/api/books/${s.book.id}/retry`)).status, 200);
await jobs.idle();
assert.deepEqual(fresh, [false, true]);
});
test('print order and the book list break identical sort keys by author surname, then title', async () => {
const { req, db, pdfCalls } = setup();
const add = (title: string, authors: string[]) => db.insertPending({
title, authors, callNumber: 'GV199.42 2020', sortKey: 'GV 0199.42 2020', confidence: 'approximate', source: 'ol-edition',
status: 'resolved', manualOverride: false, inQueue: true,
}).book;
add('Zebra trails', ['Pat Young']); add('Sierra South', ['Kathy Morey']); add('Alpine', ['Pat Young']); add('Day hikes', ['Marlise Kast-Myers']);
assert.deepEqual(db.listBooks().map((b) => b.title), ['Day hikes', 'Sierra South', 'Alpine', 'Zebra trails']);
assert.equal((await req('GET', '/api/print.pdf')).status, 200);
assert.deepEqual(pdfCalls[0]!.cards.map((c) => c.title), ['Day hikes', 'Sierra South', 'Alpine', 'Zebra trails']);
});
test('a search result\'s LCCN (work-level) is not saved onto the book', async () => {
const { req } = setup();
const f = await (await req('POST', '/api/books/from-search', { result: { title: 'Hit', authors: ['X'], lccn: '96067014', lcc: [] } })).json() as any;
assert.equal(f.book.lccn, null);
});