forked from akai/readest
ed8956e9ed
* feat(koplugin/library): data layer + busted harness + design doc - LibraryStore: per-user SQLite index merging cloud + local books by partial-md5 hash. listBooks/listBookshelfBooks/listBookshelfGroups, upsertBook with cloud_present/local_present OR-merge + _force/clear sentinels, parseSyncRow, getChangedBooks for tombstone push. - EXTS table mirroring web's document.ts. - busted harness with KOReader stubs (G_reader_settings, DataStorage, lua-ljsqlite3 against :memory:); spec_helper, exts_spec, smoke_spec, librarystore_spec covering schema, sort, group nesting, dedupe. - Library design doc + spec README. - pnpm test:lua wired through root + app package.json; lint-koplugin recurses into library/ + spec/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(koplugin/library): cloud sync — push, pull, upload, delete, downloads - Spore methods: pullBooks (incremental /sync), getDownloadUrl, getUploadUrl, listFiles, deleteFile. - syncbooks.lua: pushBook + pushChangedBooks (advances watermark to max(updated_at, deleted_at)), syncBooks(opts, mode) for push/pull/both, downloadBook + downloadCover (sync socket.http with file sink; cover download via fork+poll with single-slot queue + visible-page filter + coalesced refresh), uploadBook (presigned-PUT flow + best-effort cover), deleteCloudFiles (list-then-delete-each, mirrors cloudService.deleteBook). - SyncAuth.withFreshToken wrapper resolves the ensureClient race; 401/403 unified across syncconfig + syncannotations. - Cloud + local book covers shared by partial-md5 hash; cover.png cached at <settings>/readest_covers/<hash>.png with sentinel for known 404s. - syncbooks_spec covers row-to-wire conversion + file_key shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(koplugin/library): local discovery — sidecar scanner + cover provider - localscanner.lightScan iterates ReadHistory entries, reads partial_md5_checksum from .sdr sidecars, and upserts local rows. Slow filesystem walks deferred to fullSidecarWalk (24h-gated). - coverprovider wraps BookInfoManager:getBookInfo for local books with graceful FakeCover fallback when coverbrowser is absent. - localscanner_spec + coverprovider_spec. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(koplugin/library): UI — widget, item, view menu, FileManager hooks - librarywidget: full-screen Menu mixed in with CoverMenu + Mosaic/List per zen_ui's group_view pattern. Title-bar tap → view menu, search via left icon, drill-in/back for grouping. Async cloud sync deferred via scheduleIn so the menu paints before HTTP fires. - libraryitem: BIM patch for cloud-only (readest-cloud://) and group (readest-group://) URIs; group-cover composer (2x2 mosaic for grid, same in list) with cache key derived from the actual first-N hashes for content-based invalidation; ListMenuItem update + paintTo patches for wider list-mode cover strip and cloud-up/down icon overlay. - libraryviewmenu: ButtonDialog with View/Group by/Sort by/Actions. Default Group by = Groups (parity with web), values authors/groups. - librarypaint: partial-page e-ink repaint shim adapted from zen_ui. - main.lua: Library menu entry, dispatcher actions (Open Library / Push / Pull as general; progress + annotations as reader-only), "Add to Readest" button in FileManager's long-press file dialog (dedupe by partial_md5; bumps updated_at when present, inserts a fresh local-only row otherwise; un-tombstones via _clear_fields). Push books on Library open when auto_sync is on, pull-only otherwise. - Long-press action sheet with Readest BookDetailView parity: Remove from Cloud & Device / Cloud Only / Device Only, Upload to Cloud, Download Book / Cover / All. - Cloud-down + cloud-up SVG icons (LiaCloudDownloadAltSolid / LiaCloudUploadAltSolid) painted in the right-side wpageinfo slot. - i18n catalog updated for new strings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(koplugin/library): split libraryitem into focused modules libraryitem.lua had grown to 1018 lines mixing five unrelated concerns. Split along the natural seams: cloud_covers — readest-cloud:// URI scheme, on-disk <hash>.png cache, single-slot async download queue, visible-page filter group_covers — readest-group:// URI scheme, 2x2 mosaic composer with content-derived cache key (first-N hashes), cell layout table cloud_icons — bundled cloud-up/cloud-down SVG loader, IconWidget cache, paint-overlay positioning list_strip — list-mode group row builder (4-cover wider strip replacing ListMenu's square cover slot) bim_patch — BookInfoManager:getBookInfo router (cloud / group / local) + ListMenuItem update + paintTo patches; owns the _library_local_paths set and orig BIM reference libraryitem.lua is now 141 lines: just the entry-table constructors (entry_from_row, entry_from_group, entry_back) plus thin install / set_visible_hashes delegates. Each new module is 88-216 lines. No behavior change — same 113 specs pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore(koplugin): co-locate dev tooling, ship-zip exclusions, CI job split - apps/readest.koplugin/scripts/build-koplugin.mjs: local sideloading build with the same exclusions the release workflow uses. - Move lint-koplugin + test-koplugin from apps/readest-app/scripts/ to apps/readest.koplugin/scripts/. All koplugin dev tooling now lives with the koplugin and is excluded from the published release zip. - Rename to .mjs so Node treats them as ESM without the reparse warning (the i18n CommonJS scripts stay .js). - Release workflow: zip -r exclusions for scripts/, docs/, spec/, .busted so dev artifacts don't ship to end users. - PR workflow: split build_web_app into build_web_app + test_web_app for parallelism. The test job installs luarocks + busted + lsqlite3complete and runs pnpm test:lua. test-koplugin.mjs now hard-fails (instead of soft-skipping) when CI=true and a tool is missing — a broken CI toolchain previously exited 0 silently. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
113 lines
3.7 KiB
JavaScript
113 lines
3.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Run busted unit tests against apps/readest.koplugin under LuaJIT (the
|
|
* runtime KOReader uses). Spec files live in `apps/readest.koplugin/spec/`
|
|
* and are auto-discovered via `.busted` config.
|
|
*
|
|
* Invoked from `pnpm test:lua`. Soft-skips with a notice when busted or
|
|
* luajit is not installed; CI installs both and runs unconditionally.
|
|
*
|
|
* Required toolchain (one-time):
|
|
* brew install luajit luarocks (or apt-get install …)
|
|
* luarocks --lua-version=5.1 install busted
|
|
* luarocks --lua-version=5.1 install lsqlite3complete
|
|
*/
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
// Script lives at apps/readest.koplugin/scripts/; one parent up is the
|
|
// koplugin root.
|
|
const KOPLUGIN_DIR = path.resolve(__dirname, '..');
|
|
|
|
if (!fs.existsSync(KOPLUGIN_DIR)) {
|
|
console.error(`koplugin directory not found at ${KOPLUGIN_DIR}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!fs.existsSync(path.join(KOPLUGIN_DIR, 'spec'))) {
|
|
console.log('No spec/ directory under apps/readest.koplugin — nothing to test.');
|
|
process.exit(0);
|
|
}
|
|
|
|
const which = (cmd, env = process.env) =>
|
|
spawnSync(process.platform === 'win32' ? 'where' : 'which', [cmd], { env });
|
|
|
|
// In CI a missing toolchain is a hard failure (exit 1); locally it's a
|
|
// soft skip (exit 0) so devs without busted installed don't get blocked.
|
|
// GitHub Actions sets CI=true; respect any other CI's convention too.
|
|
const HARD_FAIL = !!process.env.CI;
|
|
const onMissing = (tool, install_hint) => {
|
|
const msg =
|
|
`test:lua: ${tool} not found. ` +
|
|
`Install via ${install_hint}.` +
|
|
(HARD_FAIL ? '' : ' Skipping (set CI=1 to make this an error).');
|
|
if (HARD_FAIL) {
|
|
console.error(msg);
|
|
process.exit(1);
|
|
} else {
|
|
console.warn(msg);
|
|
process.exit(0);
|
|
}
|
|
};
|
|
|
|
if (which('luajit').status !== 0) {
|
|
onMissing(
|
|
'luajit',
|
|
'`brew install luajit` on macOS, `apt-get install luajit` on Linux',
|
|
);
|
|
}
|
|
|
|
if (which('luarocks').status !== 0) {
|
|
onMissing('luarocks', '`brew install luarocks` (or `apt-get install luarocks`)');
|
|
}
|
|
|
|
// `luarocks --lua-version=5.1 path` emits export lines for PATH, LUA_PATH,
|
|
// LUA_CPATH that point at the user's 5.1 rocks tree. pnpm's spawned shells
|
|
// don't source the user's rc files, so ~/.luarocks/bin is usually missing
|
|
// from PATH and `which busted` fails even when busted is installed. We
|
|
// re-inject these vars into the spawn env here so subsequent lookups +
|
|
// busted's own `require('busted.runner')` both succeed.
|
|
const lrPath = spawnSync('luarocks', ['--lua-version=5.1', 'path'], { encoding: 'utf8' });
|
|
if (lrPath.status !== 0) {
|
|
if (HARD_FAIL) {
|
|
console.error('test:lua: `luarocks --lua-version=5.1 path` failed.');
|
|
process.exit(1);
|
|
}
|
|
console.warn('test:lua: `luarocks --lua-version=5.1 path` failed.');
|
|
process.exit(0);
|
|
}
|
|
const env = { ...process.env };
|
|
for (const line of lrPath.stdout.split('\n')) {
|
|
const m = line.match(/^export (LUA_PATH|LUA_CPATH|PATH)='(.*)'$/);
|
|
if (m) {
|
|
if (m[1] === 'PATH') {
|
|
// luarocks's PATH already includes the rest of the user's PATH (it
|
|
// re-emits the value it inherited), so an outright assignment is
|
|
// safe and avoids a double-prepend.
|
|
env.PATH = m[2];
|
|
} else {
|
|
env[m[1]] = m[2];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (which('busted', env).status !== 0) {
|
|
onMissing(
|
|
'busted',
|
|
'`luarocks --lua-version=5.1 install busted` ' +
|
|
'(and `lsqlite3complete` for SQLite tests)',
|
|
);
|
|
}
|
|
|
|
const luajitPath = which('luajit', env).stdout.toString().trim();
|
|
const r = spawnSync('busted', [`--lua=${luajitPath}`], {
|
|
cwd: KOPLUGIN_DIR,
|
|
stdio: 'inherit',
|
|
env,
|
|
});
|
|
process.exit(r.status === null ? 1 : r.status);
|