test(sdk-ts): make setInputFiles historical-mtime expectation portable to Windows

DZ
2d ago
+8-2

Summary

The sdk-ts test packages/sdk-ts/tests/objectWrapper.test.ts > normalizes files and payloads and routes locator.setInputFiles fails on Windows hosts at current main.

The test writes historical.txt and sets a pre-epoch mtime with utimes(path, new Date(0), new Date(-1_000)), expecting the upload payload to omit lastModified (the SDK's nodeBrowserApiPlatform.readInputFile omits the field when the reported mtime is negative — a correct guard, not the thing being fixed here). On Windows that fixture cannot exist: libuv's utimes wraps pre-epoch seconds through an unsigned 32-bit conversion, so a file given mtime = -1000 ms reports mtimeMs = 4294967295000 (~2106-02-07) back through fs.stat. The upload therefore carries a positive lastModified and the strict toStrictEqual fails:

- Expected
+ Received
  files: [
    {
      "data": "b2xk",
+     "lastModified": 4294967295000,
      "name": "historical.txt",

The production code is already correct on both platforms — the omission branch simply cannot be exercised through a real filesystem on Windows. So this is a test-side portability fix, in the same spirit as #3458 (this exact failure was also catalogued as pre-existing on Windows in the validation notes of that PR).

The change derives the expected payload from what the filesystem actually reports, keeping the test green and meaningful everywhere:

  • on POSIX (CI), stat reports the negative mtime, so the expectation remains files: [{ name, data }] — the pre-epoch omission branch stays covered;
  • on Windows, the expectation becomes lastModified: <reported mtimeMs> — which additionally covers the positive-mtime passthrough for path uploads, previously untested.

No production code changes, no changeset (CONTRIBUTING.md: tests do not need a Changeset).

Validation

All on a Windows 11 host (the affected platform), at base 3bedd82 (current main):

  • packages/sdk-ts/tests/objectWrapper.test.ts before the change: 102 passed / 1 failed (... routes locator.setInputFiles, AssertionError ... "lastModified": 4294967295000 vs omitted, test line 2222). After the change: 103/103 pass. Red/green logs attached to the contribution package.
  • Full sdk-ts unit suite: 651 passed / 12 failed at base → 652 passed / 11 failed with this change. The failure-set diff is exactly the objectWrapper test above; the remaining 11 are pre-existing on Windows and unrelated: 5 in factories.test.ts (addressed by open #3458), 1 in localBrowser.test.ts (addressed by open #3506), 1 in browserbaseTransport.test.ts (undici cross-test timer pollution, previously diagnosed), 1 in packageContract.test.ts (spawn pnpm ENOENT for .cmd shims), and 3 new cdpClient.test.ts service-worker symlink cases from #3502 that require symlink privileges on Windows.
  • node:fs/promises round-trip probe confirming the platform behavior: utimes(f, new Date(0), new Date(-1000)) then stat → mtimeMs === 4294967295000 on Windows.
  • oxfmt --check — clean; oxlint — 0 errors (9 pre-existing no-deprecated warnings on untouched lines); tsc --noEmit -p packages/sdk-ts — clean; git diff --check — clean.

AI assistance

Prepared with an AI coding agent (ZCode) from a maintainer-diagnosed failure; the analysis, fix, and validation were verified locally as described above.


Summary by cubic

Fixes the sdk-ts setInputFiles test so it passes on Windows as well as POSIX.

The test writes a file with a pre-epoch mtime and expects the upload payload to omit lastModified. On Windows, libuv wraps pre-epoch mtimes into positive values, so the filesystem reports a positive mtime and the strict assertion fails.

The expected payload is now derived from what stat actually reports instead of being hardcoded:

  • POSIX keeps reporting the negative mtime, so the pre-epoch omission branch stays covered.
  • Windows now asserts the wrapped positive mtime, which also covers positive-mtime passthrough.

No production code changes.