Repository navigation
Follow-up to #61: address the review suggestions - #62
Conversation
…ts, Chinese-only note - plugin.json: the description no longer names another vendor product. - The time calculations (resolveZone / bandOf / parseOffset / formatDiff / dayDelta / periodOf) move to miniapp/client/time.js, which the browser and Node run as the same file. That makes them unit-testable, and it gives index.html and app.js one single implementation of "is this the same city" instead of two that could drift apart. - The package ships test/time.test.mjs; the repository CI runs it through test/timezone-guard.test.mjs. - Both READMEs now state that the interface is Chinese only. Five static files are served now instead of four, so the Data & access sections and the PR description are updated to match. Version 1.0.1 -> 1.0.2.
MyPrototypeWhat
left a comment
There was a problem hiding this comment.
Thanks for the quick follow-up on the #61 suggestions! Everything important is addressed. There's one thing I need changed before merge (below); the rest are optional suggestions. Here is what I checked against 4d284fb:
plugin.jsondescription: "Claude" is gone ✅. One wording issue is left, see suggestion 1.- The time logic now lives in
miniapp/client/time.js(UMD), so the browser and Node run the same source.app.jsand both inline scripts use it.test/time.test.mjscovers the 06/09/18/22 on-the-hour boundaries, the +05:45 / +12:45 / −03:30 offsets, and day deltas across month and year ✅ - Both READMEs now say the UI is Chinese-only ✅
index.html: the duplicatedcanonZoneand the secondlocalStorageparse are gone. Both inline scripts now useTZ_TIME.resolveZone/TZ_PREFS✅- Version 1.0.1 → 1.0.2 matches in
plugin.jsonand both READMEs ✅ server.mjs: the only whitelist change is addingtime.js. It still accepts only GET/HEAD and looks files up by basename in the whitelist, so there's no traversal ✅- No credentials, host DB, other plugins' data, or network access ✅. DST still comes from Intl/tzdata, and the band and day-delta logic didn't change.
Local runs: node scripts/validate.mjs passes; node --test test/*.test.mjs passes; in the package, node --test test/*.test.mjs 10/10 passes.
Must fix
- Please remove the root forwarder
test/timezone-guard.test.mjs. Repo CI only enforces repo-wide miniapp rules, and plugin-specific tests must not be wired into it. Keep the package's own tests inplugins/liuchen19960902/timezone-guard/test/and run them locally.
Optional suggestions
- "别在对方睡着的时区跟克聊天" — the 「克」 reads like what was left after deleting "Claude", and the sentence doesn't make sense. Something like 「别在对方睡着的时候发消息」 would work.
- The package's
"test": "node --test \"test/**/*.test.mjs\""fails on Node 20 withCould not find '.../test/**/*.test.mjs', because--testglob support only arrived in Node 21. The README tells users to runnpm test, sonode --test test/would be safer. - For non-whole-hour offsets,
formatDiffreturns a leading space (' 5 小时 45 分钟'). That's caller-side formatting inside a pure function, and the tests have to hard-code the space. I'd return plain text and add the space whereapp.jsjoins the strings.
| // | ||
| // 覆盖的是 miniapp/client/time.js:档位判定的整点边界、偏移解析 | ||
| // (含 +05:45 这类非整小时时区)、时差文案、跨日的日历日差。 | ||
| import '../plugins/liuchen19960902/timezone-guard/test/time.test.mjs'; |
There was a problem hiding this comment.
Must fix: please remove this root forwarder. Repo CI only enforces repo-wide miniapp rules, and plugin-specific tests must not be wired into it. Keep the tests in plugins/liuchen19960902/timezone-guard/test/ and run them locally.
| "version": "1.0.1", | ||
| "description": "别在对方睡着的时区跟 Claude 聊天。A/时差保安实时对照对方当地时间:绿了正常聊,黄了短聊,红了先睡。", | ||
| "version": "1.0.2", | ||
| "description": "别在对方睡着的时区跟克聊天。A/时差保安实时对照对方当地时间:绿了正常聊,黄了短聊,红了先睡。", |
There was a problem hiding this comment.
Optional: 「跟克聊天」 reads like what was left after deleting "Claude". Maybe something like 「别在对方睡着的时候发消息」?
| "miniApp": "./miniapp/miniapp.json" | ||
| }, | ||
| "scripts": { | ||
| "test": "node --test \"test/**/*.test.mjs\"" |
There was a problem hiding this comment.
Optional: On Node 20 this fails with Could not find 'test/**/*.test.mjs', because --test only gained glob support in Node 21. node --test test/ works on both.
| var minutes = abs % 60; | ||
| if (minutes === 0) return '约 ' + hours + ' 小时'; | ||
| // 非整小时时带一个前导空格,拼到「快/慢」后面才不会连成一团。 | ||
| return hours > 0 ? ' ' + hours + ' 小时 ' + minutes + ' 分钟' : ' ' + minutes + ' 分钟'; |
There was a problem hiding this comment.
Optional: The leading space is caller-side formatting. I'd return plain text here and add the space where app.js joins the strings.
The previous revision replaced the vendor name with a bare "克", which read as an unfinished sentence next to the "对方" used later in the same line. It now says "跟对方聊天", matching what the review asked for.
…helper Review follow-up, three items: - Remove the root test/timezone-guard.test.mjs forwarder. The repository suite enforces the repo-wide Mini App rules; plugin-specific tests stay with the plugin. The root test/ directory is now identical to main again. - Run the package tests with bare `node --test` instead of a glob. On Node 20 the glob form fails because --test gained glob support only in 21; the suggested `node --test test/` fails on Node 22+ with MODULE_NOT_FOUND because a bare directory is no longer accepted as a positional argument. The no-argument form auto-discovers and needs no version-specific syntax. - formatDiff now returns plain text. The leading space moved to app.js, where the strings are actually joined: the whole-hour form carries its own "约", non-integral offsets get a space. The tests no longer hard-code padding; they assert no padding at all.
|
三条都处理了,集中在 必修 —— 已删除根目录的 可选 2 —— 用了 裸目录从某个版本起不再被当作位置参数接受。三种写法的实测情况:
说明一下证据边界:Node 24 那列是本机实测,Node 20 那列是引用你的报告,我无法复现(这台机器只有 Node 24)。Node 官方文档与这个分野相符 —— v20 还写着 可选 3 —— 顺带说明一个我原本担心的点,实测是安全的: 浏览器实读的时差文案(Chromium 155,直接跑包内文件):
另外两个分支也确认没有被波及:同城走「两边同一时区,时间完全一致」,异时区同偏移走「当前时差 0 小时(此刻同步)」,都不会进到补空格那行。 校验: |
MyPrototypeWhat
left a comment
There was a problem hiding this comment.
Thanks for the quick and thorough follow-up in d9c6974.
The must-fix is done: the root forwarder test/timezone-guard.test.mjs is gone, and root test/, scripts/, CI config and the root package.json are now identical to main. Repo npm run check passes on Node 22 (69/69, back to the main baseline).
The optional items are handled well too:
formatDiffnow returns plain text, with the spacing decided inapp.jswhere the string is actually assembled; the new test asserting no leading/trailing whitespace is a nice touch.- The test script is now a bare
node --test. Thanks for flagging thenode --test test/problem on Node 24 — the no-argument form is the better choice.
On the Node 20 question you couldn't check locally: I ran npm test from the plugin directory with Node 20 and Node 22. Both discover only test/time.test.mjs and run 11/11 tests passing, with nothing stray picked up (the package has no node_modules).
Follow-up to #61: the review suggestions
Thanks for the review on #61. That PR was squashed into
4e1856awhile I was still working on thesefixes, so they landed a moment too late to make it into it. This PR carries them, based on the
current
main.From the review of this PR
Removed the root
test/timezone-guard.test.mjsforwarder. You're right that the repositorysuite enforces the repo-wide Mini App rules; the plugin's tests stay in the plugin.
npm testin the package now runsnode --testwith no path argument. You suggestednode --test test/, but on newer Node a bare directory is no longer accepted as a positionalargument — it fails with
Cannot find module '.../test'. The no-argument form auto-discovers thetest files:
node --test "test/**/*.test.mjs"(was)node --test test/MODULE_NOT_FOUNDnode --test(now)To be precise about what I actually verified: the Node 24 column is measured on this machine; the
Node 20 column is your report, which I could not reproduce (no Node 20 available here). The Node
docs back the split — v20 still documents
node --test custom_test_dir/as a directory, whilev22 and later describe only globs.
formatDiffreturns plain text now. No leading space;app.jsadds the separator where itjoins the strings — the whole-hour form keeps its own
约, non-integral offsets get a space. Thetests no longer hard-code a space.
The four suggestions from #61
plugin.jsondescription — it named another vendor's product. It now reads "跟对方聊天"(chat with the other person), which is the neutral phrasing you asked for.
Pure functions extracted and unit-tested — the time calculations (
resolveZone/bandOf/
parseOffset/formatDiff/dayDelta/periodOf) move to a newminiapp/client/time.js, and the browser and Node run the same file, so there is nosecond copy to keep in sync.
bandOfreturns a band key there;app.jswraps it to put thecopy back, so no call site changed.
The tests ship with the package at
test/time.test.mjsand run from the package directory withnpm test. They cover the band thresholds landing exactly on the hour, offset parsing includingnon-integral zones such as
GMT+05:45, the time-difference wording (including that it carries nopadding), and the calendar-day difference behind "still yesterday".
The interface is Chinese only — both READMEs now say so up front: the plugin name, the
verdict, the city names, the time periods and the date format are all Chinese, the page has
no language switch, and the READMEs ship in English and 简体中文.
The two inline scripts in
index.htmloverlapped withapp.js— all three now go throughthe same implementation in
time.js:head, handed tobodythroughwindow.TZ_PREFS)instead of being read and parsed twice;
IDs,
app.jscompared raw strings) — both now compare the canonical result ofresolveZone.Checked in a real browser: with one city on both sides the second name and the ⇄ button are
hidden; the same name in a different zone keeps them; a corrupted preferences blob still
renders the page.
Knock-on change: five static files are served now instead of four (
time.jsis the new one),so the "Data & access" sections in both READMEs and in this description say five. Version
1.0.1 → 1.0.2.
Tested environment
npm run validatereports no errors and no warnings for this package. Repository-wide itreports
repository: OKwith 14 warnings that all belong to other packages and pre-date thisPR:
README_HEADING_MISSINGinamszuidas/mcode-token-usage-boardandyanhy2000/mcode-usage-monitor,README_MIN_VERSION_MISSINGinyujiachen-y/xinyu-dailyandzch0227/anatomy-gallery, andENTRY_STDOUTinstevenjj33/workflow-console,webguhui/minimax-photoandwebguhui/minimax-video. None of them is in a file this PRtouches.
main— the forwarder is gone andnothing was added to the repo-wide suite.
npm testruns 11 tests, all passing.whole-hour and non-integral zones:
快约 15 小时(Los Angeles),快 2 小时 30 分钟(Mumbai,+05:30),
快 2 小时 15 分钟(Kathmandu, +05:45),快 5 小时 45 分钟(Chatham — +12:45 standard,+13:45 under daylight saving, and the run was in the latter).
Data & access
Reads only the five static files inside its own package directory:
index.html,styles.css,cities.js,time.js,app.js. Writes no files and does not usecontext.dataDir. Makes nonetwork request. Spawns no process. Declares no
agentAccessand starts no Agent turn. Thebrowser's
localStorageholds interface preferences only, undertimezone-guard.prefs.v1.