Skip to content

fix(weread): fix API endpoints, arg access, and include tests in CI#433

Merged
jackwener merged 1 commit intojackwener:mainfrom
Conn-Ho:feat/weread-adapter
Mar 25, 2026
Merged

fix(weread): fix API endpoints, arg access, and include tests in CI#433
jackwener merged 1 commit intojackwener:mainfrom
Conn-Ho:feat/weread-adapter

Conversation

@Conn-Ho
Copy link
Copy Markdown
Contributor

@Conn-Ho Conn-Ho commented Mar 25, 2026

Summary

The weread adapter (added in #89) had several bugs that prevented authenticated commands from working. This PR fixes all of them and verifies all 7 weread commands working end-to-end.

Bugs Fixed

  • args['book-id'] access — positional args are stored under their original kebab-case name, not camelCase. book.ts, highlights.ts, and notes.ts were all accessing args.bookId (undefined), causing every book-specific API call to send bookId=undefined → server rejected with errCode -2003.

  • API base URL — authenticated endpoints are on weread.qq.com/web/ and weread.qq.com/api/, not i.weread.qq.com. Cross-origin fetches to i.weread.qq.com from a weread.qq.com page context fail at the browser level despite CORS headers.

  • notebooks endpoint path — was /user/notebooks (404), correct path is /api/user/notebook.

  • syncKey casing — WeRead API uses syncKey (capital K), not synckey.

  • Error code handlingweread.qq.com/web/ endpoints return errCode/errMsg (camelCase) while i.weread.qq.com uses errcode/errmsg. Added fallback to handle both.

  • Tests not running in CIsrc/clis/weread/**/*.test.ts was missing from vitest.config.ts adapter project, so 15 existing util tests were silently skipped.

Verified Working

Command Type Status
weread search <query> PUBLIC
weread ranking PUBLIC
weread shelf COOKIE
weread notebooks COOKIE
weread book <id> COOKIE
weread notes <id> COOKIE
weread highlights <id> COOKIE

Test plan

  • npx vitest run --project adapter — all 18 tests pass
  • npm run typecheck — no type errors
  • opencli weread search "三体" — returns book list
  • opencli weread shelf — returns your bookshelf (requires Chrome login)
  • opencli weread notebooks — returns books with notes
  • opencli weread book <bookId> — returns book details
  • opencli weread notes <bookId> — returns your notes on a book

🤖 Generated with Claude Code

@Astro-Han
Copy link
Copy Markdown
Contributor

Solid bug fix PR. All 5 fixes are correct and well-targeted:

  • args['book-id'] kebab-case access ✅
  • weread.qq.com same-origin for cookie auth ✅
  • /api/user/notebook endpoint path ✅
  • syncKey casing ✅
  • errcode/errCode dual format handling ✅

Appreciate the thorough verification table covering all 7 commands. Clean diff, no regressions spotted. LGTM 👍

Minor suggestions (non-blocking):

  • Could add a couple of test cases for the errCode (camelCase) format to cover the new dual handling
  • syncKey: "0" uses double quotes while the rest of the file uses single quotes

@jackwener jackwener force-pushed the feat/weread-adapter branch from 9ab7586 to 8dbea4e Compare March 25, 2026 15:56
@jackwener jackwener merged commit 824dc38 into jackwener:main Mar 25, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants