Skip to content

Follow-up to #61: address the review suggestions - #62

Merged
MyPrototypeWhat merged 3 commits into
MiniMax-AI:mainfrom
LiuChen19960902:fix/timezone-guard-review
Oct 23, 2026
Merged

MyPrototypeWhat merged 3 commits into
MiniMax-AI:mainfrom
LiuChen19960902:fix/timezone-guard-review

Conversation

@LiuChen19960902

@LiuChen19960902 LiuChen19960902 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #61: the review suggestions

Thanks for the review on #61. That PR was squashed into 4e1856a while I was still working on these
fixes, 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.mjs forwarder. You're right that the repository
    suite enforces the repo-wide Mini App rules; the plugin's tests stay in the plugin.

  • npm test in the package now runs node --test with no path argument. You suggested
    node --test test/, but on newer Node a bare directory is no longer accepted as a positional
    argument — it fails with Cannot find module '.../test'. The no-argument form auto-discovers the
    test files:

    form Node 24.13.1 (measured here) Node 20
    node --test "test/**/*.test.mjs" (was) ✓ 11/11 ✗ per your report: no glob support
    node --test test/ ✗ MODULE_NOT_FOUND ✓ per your report
    node --test (now) ✓ 11/11 not measured here

    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, while
    v22 and later describe only globs.

  • formatDiff returns plain text now. No leading space; app.js adds the separator where it
    joins the strings — the whole-hour form keeps its own 约, non-integral offsets get a space. The
    tests no longer hard-code a space.

The four suggestions from #61

  1. plugin.json description — it named another vendor's product. It now reads "跟对方聊天"
    (chat with the other person), which is the neutral phrasing you asked for.

  2. Pure functions extracted and unit-tested — the time calculations (resolveZone / bandOf
    / parseOffset / formatDiff / dayDelta / periodOf) move to a new
    miniapp/client/time.js, and the browser and Node run the same file, so there is no
    second copy to keep in sync. bandOf returns a band key there; app.js wraps it to put the
    copy back, so no call site changed.
    The tests ship with the package at test/time.test.mjs and run from the package directory with
    npm test. They cover the band thresholds landing exactly on the hour, offset parsing including
    non-integral zones such as GMT+05:45, the time-difference wording (including that it carries no
    padding), and the calendar-day difference behind "still yesterday".

  3. 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 简体中文.

  4. The two inline scripts in index.html overlapped with app.js — all three now go through
    the same implementation in time.js:

    • the saved preferences are parsed once (in head, handed to body through window.TZ_PREFS)
      instead of being read and parsed twice;
    • "is this the same city" had two different answers (the inline script compared canonical zone
      IDs, app.js compared raw strings) — both now compare the canonical result of
      resolveZone.

    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.js is 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

  • MiniMax Code 3.1.4 on Windows 11 Home (10.0.26300, x64).
  • npm run validate reports no errors and no warnings for this package. Repository-wide it
    reports repository: OK with 14 warnings that all belong to other packages and pre-date this
    PR: README_HEADING_MISSING in amszuidas/mcode-token-usage-board and
    yanhy2000/mcode-usage-monitor, README_MIN_VERSION_MISSING in yujiachen-y/xinyu-daily and
    zch0227/anatomy-gallery, and ENTRY_STDOUT in stevenjj33/workflow-console,
    webguhui/minimax-photo and webguhui/minimax-video. None of them is in a file this PR
    touches.
  • The repository suite is back to 69 tests, the same count as on main — the forwarder is gone and
    nothing was added to the repo-wide suite.
  • The package's own npm test runs 11 tests, all passing.
  • In Chromium 155 against the package's own files, the time-difference line renders correctly for
    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 use context.dataDir. Makes no
network request. Spawns no process. Declares no agentAccess and starts no Agent turn. The
browser's localStorage holds interface preferences only, under timezone-guard.prefs.v1.

…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 MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json description: "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.js and both inline scripts use it. test/time.test.mjs covers 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 duplicated canonZone and the second localStorage parse are gone. Both inline scripts now use TZ_TIME.resolveZone / TZ_PREFS ✅
  • Version 1.0.1 → 1.0.2 matches in plugin.json and both READMEs ✅
  • server.mjs: the only whitelist change is adding time.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 in plugins/liuchen19960902/timezone-guard/test/ and run them locally.

Optional suggestions

  1. "别在对方睡着的时区跟克聊天" — the 「克」 reads like what was left after deleting "Claude", and the sentence doesn't make sense. Something like 「别在对方睡着的时候发消息」 would work.
  2. The package's "test": "node --test \"test/**/*.test.mjs\"" fails on Node 20 with Could not find '.../test/**/*.test.mjs', because --test glob support only arrived in Node 21. The README tells users to run npm test, so node --test test/ would be safer.
  3. For non-whole-hour offsets, formatDiff returns 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 where app.js joins the strings.

Comment thread test/timezone-guard.test.mjs Outdated
//
// 覆盖的是 miniapp/client/time.js:档位判定的整点边界、偏移解析
// (含 +05:45 这类非整小时时区)、时差文案、跨日的日历日差。
import '../plugins/liuchen19960902/timezone-guard/test/time.test.mjs';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/时差保安实时对照对方当地时间:绿了正常聊,黄了短聊,红了先睡。",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: 「跟克聊天」 reads like what was left after deleting "Claude". Maybe something like 「别在对方睡着的时候发消息」?

"miniApp": "./miniapp/miniapp.json"
},
"scripts": {
"test": "node --test \"test/**/*.test.mjs\""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + ' 分钟';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@LiuChen19960902

Copy link
Copy Markdown
Contributor Author

三条都处理了,集中在 d9c6974。

必修 —— 已删除根目录的 test/timezone-guard.test.mjs。 你说得对,仓库 CI 执行的是仓库级 Mini App 规则,插件专属测试应该留在插件里。删掉后根 test/ 与 main 完全一致,仓库测试项数从 79 回到 69(= main 的基线),没有被加进仓库套件。

可选 2 —— 用了 node --test,但没照搬 node --test test/。 你那条建议在 Node 24 上会红:

Error: Cannot find module '...\timezone-guard\test'
code: 'MODULE_NOT_FOUND'

裸目录从某个版本起不再被当作位置参数接受。三种写法的实测情况:

写法 Node 24.13.1(我这里实测) Node 20
node --test "test/**/*.test.mjs"(原来) ✓ 11/11 ✗ 按你说的,不支持 glob
node --test test/ ✗ MODULE_NOT_FOUND ✓ 按你说的
node --test(现在) ✓ 11/11 我这里没有 Node 20,未实测

说明一下证据边界:Node 24 那列是本机实测,Node 20 那列是引用你的报告,我无法复现(这台机器只有 Node 24)。Node 官方文档与这个分野相符 —— v20 还写着 node --test custom_test_dir/ 这种目录用法,v22 之后只讲 glob。所以选了无参数形式:靠自动发现,不需要任何版本特定的语法。代价是它会把 test/ 下的文件都当测试,以后往那儿放非测试 JS 要注意。

可选 3 —— formatDiff 现在只回纯文本。 前导空格挪到 app.js 真正拼接的地方:整小时那个「约」自带分词,非整小时才补空格。测试里不再硬编码空格,改成断言任何输入都不带首尾空白。

顺带说明一个我原本担心的点,实测是安全的:app.js 的判据用的是带符号的 diffMinutes % 60,而 formatDiff 内部用 Math.abs。JS 里 -900 % 60 得到 -0,而 -0 === 0 为 true,所以负的整小时倍数仍然走「不补空格」分支,与内部分支一致。穷举 -1440…1440 共 2881 个取值,0 处不一致。若当初写成 Object.is(d % 60, 0) 就会翻车。

浏览器实读的时差文案(Chromium 155,直接跑包内文件):

场景 渲染结果
上海 / 洛杉矶(+15) 上海比洛杉矶快约 15 小时
上海 / 孟买(+05:30) 上海比孟买快 2 小时 30 分钟
上海 / 加德满都(+05:45) 上海比加德满都快 2 小时 15 分钟
查塔姆 / 上海(当日 +13:45,夏令时) 查塔姆比上海快 5 小时 45 分钟
加德满都 / 卡拉奇(45 分钟) 加德满都比卡拉奇快 45 分钟
洛杉矶 → 上海(负向 −900) 上海比洛杉矶快约 15 小时

另外两个分支也确认没有被波及:同城走「两边同一时区,时间完全一致」,异时区同偏移走「当前时差 0 小时(此刻同步)」,都不会进到补空格那行。

校验:npm run validate 本包 0 error 0 warning、全仓 repository: OK,14 条 warning 全在其他包;仓库 npm test 69 项(其中 2 个 symlink 用例在 Windows 上 EPERM,main 上同样失败);包内 npm test 11 项全过。

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • formatDiff now returns plain text, with the spacing decided in app.js where 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 the node --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).

@MyPrototypeWhat
MyPrototypeWhat merged commit 3f53eae into MiniMax-AI:main Oct 23, 2026
1 check 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.

2 participants