fix(zhihu): make question runtime-compatible#732
Conversation
- Build URL in Node.js, embed via JSON.stringify for safety-by-design - Remove unnecessary (page as any) cast — IPage already has evaluate - Simplify error message construction (no nested ternaries) - Replace implementation-detail test with numeric ID validation test
Astro-Han
left a comment
There was a problem hiding this comment.
Reviewed the runtime-compatibility change for zhihu question. I checked the string-based evaluate migration, the added numeric questionId guard, and the updated unit tests. I did not find blocking issues. I also ran npx vitest run src/clis/zhihu/question.test.ts locally on the PR branch, and all 5 tests passed.
Minor: error message formatting for fetch exceptionsWhen
Two consecutive "failed" without a separator reads awkwardly. Suggested fix in const detail = result?.status > 0
? `with HTTP ${result.status}`
: (result?.error ? `: ${result.error}` : '');This produces Otherwise the PR looks solid — runtime fix is correct, input validation and security hardening are well done. 👍 |
"request failed Failed to fetch" → "request failed: Failed to fetch"

Summary
Fix
zhihu questionso it works in the real browser runtime again.The command was using function-style
page.evaluate(...), but the runtime only supports string-basedevaluate. This PR switches it to the supported form, navigates to the question page first, and keeps the existing auth / fetch error mapping.Validation
npx vitest run src/clis/zhihu/question.test.tsnpm run buildnode dist/main.js zhihu question 2021881398772981878 --limit 2 -f jsonCloses #604