Repository navigation
test: let e2e scenarios move the local date through a test clock file - #5570
Conversation
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Port upstream f94b9a2: KIMI_CODE_CLOCK_FILE drives HostClockService.now(). The fork keeps the host/ path while upstream uses node-local/; the source blob matches the upstream post-image. The unit test covers the ISO file, invalid input and the wall-clock fallback. The upstream e2e scenario and support files are test-only and remain unported; the source status is present. Ledger MoonshotAI#5570 pending -> ported. Verified: host clock 3 pass; agent-core-v2 typecheck clean; check:no-comments clean.
Requirement or Bug
这是
tests/e2e/scenarios/cache专题(#5526)清单里的 E5:会话进行到一半,用户机器上的日期变了,比如跨过了午夜。产品的承诺是保持缓存前缀:日期只在提醒里告诉模型,system 里不写日期,所以日期变化不该改写前缀。之前只有引擎测试覆盖这一项,E2E 没办法让产品看到的时间往前走,清单里记着缺口「需要一个产品经IHostClock读取的测试时钟」。这个 PR 加上这个测试时钟,并补上 E5 的 E2E 场景。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:引擎的
IHostClock是日期提醒取时间的唯一来源。设置了测试开关KIMI_CODE_CLOCK_FILE时,它从这个变量指向的文件里读当前时间;每次调用都重新读,所以测试改写文件,就相当于用户机器上的时间过去了。E2E 驱动只在场景给了clock选项时才写这个文件、设这个变量,其他场景启动产品的环境和原来一样。flowchart LR S["场景:clock 选项给起点<br/>clock(时间) 改写时钟"] -->|写| F["测试 home 里的 clock.txt"] D["E2E 驱动 productEnv"] -->|文件存在时设置<br/>KIMI_CODE_CLOCK_FILE| P["产品进程<br/>TUI / ACP / Web / Desktop"] P --> C["IHostClock.now()<br/>每次调用都读文件"] F -.读.-> C C --> R["日期提醒<br/>今天的日期 / 日期变了"] R --> M["发给假模型的请求"]IHostClock只被日期提醒用到,它只决定告诉模型的本地日期。引擎里其他直接调用Date.now()、new Date()的地方(超时、时间戳等)不受影响,仍然是真实时间。IHostClockIHostClock只喂日期提醒,换掉它不会碰到超时和时间戳这些逻辑context provider failed日志,这次请求不带日期,断言日期的场景一定失败clock选项、时钟文件存在时E5 场景
date-change-keeps-the-prefix:起点2030-01-01T12:00:00Z,第一回合之后把时钟拨到第二天,再聊一回合,重启,再聊一回合。断言:toLocaleDateString('en-CA')算,不写死,因为不同时区的日期不同;两个时刻在任何时区下都正好差一天。阅读顺序:
packages/agent-core-v2/src/os/backends/node-local/hostClockService.ts和它的单测;tests/e2e/surfaces/environment.ts:什么时候把变量交给产品;tests/e2e/support/scenario.ts:clock选项和clock(时间);tests/e2e/scenarios/cache/date-change-keeps-the-prefix.spec.ts。可以略读:
scripts/checks/e2e-boundary.json里testSwitches的登记、清单 E5 的覆盖更新、tests/e2e/AGENTS.md「写场景」表新增的一行、步骤标题。Behavior Changes and Affected Users
KIMI_CODE_CLOCK_FILEkimi web、ACP、SDKKIMI_CODE_CLOCK_FILEscripts/checks/e2e-boundary.json的testSwitches,不进用户文档clock选项时设置,否则不变clock选项时环境不变受影响模块和覆盖:
hostClockService.test.ts3 条,分别是不设变量时读真实时间、每次调用都重读文件、内容无效时抛错;日期提醒原有的dateChange单测继续通过。productEnv是所有面启动产品的入口,改了它,所以重启相关的驱动自测也要跟着跑,交给本 PR 的 E2E 作业。changeset:不带。引擎只多了一个测试开关,用户不设它时行为完全不变,维护者决定不写。
验证:见折叠块。E2E 没有在本地跑,交给本 PR 的 CI。
运行的命令和结果
基线是 main
d5263af02,在 macOS 上跑。pnpm lint:通过,e2e-cache-catalog报 39 项、10 个 cache 场景都已登记、18 项写明了缺口(E5 的缺口去掉了)。pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit、pnpm exec tsc -p tests/e2e/tsconfig.json --noEmit:通过。pnpm exec vitest run packages/agent-core-v2/test/os/backends/node-local/hostClockService.test.ts packages/agent-core-v2/test/features/dateChange:18 条通过。node --test 'scripts/checks/*.test.mjs':130 条通过。pnpm run check:duplication d5263af02:没有新增重复。path.join和readFileSync,内容先trim(),CRLF 和 BOM 都会被去掉。只在 macOS 上核对过,Linux 和 Windows 交给 CI。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.