Skip to content

fix: correct +09:00 timezone integration test assertion#329

Merged
tianzhou merged 2 commits into
mainfrom
fix/mysql-timezone-test-and-cleanup
Jun 7, 2026
Merged

fix: correct +09:00 timezone integration test assertion#329
tianzhou merged 2 commits into
mainfrom
fix/mysql-timezone-test-and-cleanup

Conversation

@tianzhou

@tianzhou tianzhou commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #321 (timezone source option for MySQL/MariaDB). The main fix is a wrong test assertion; the validation code is left functionally unchanged.

The bug

The MySQL integration test asserted the wrong UTC instant. KST is UTC+9, so the naive DATETIME 2025-09-29 02:31:23 interpreted as +09:00 is 2025-09-28T17:31:23Z (the previous day), not 2025-09-29T17:31:23Z.

mysql2's parseDateTime does new Date(\${str}${timezone}`)`, which yields the previous-day instant:

'2025-09-29 02:31:23' + '+09:00'  →  2025-09-28T17:31:23.000Z

Because the old expected value is never producible by the driver, the test would have failed against a real container — indicating the Testcontainers integration suite was not run before #321 merged. The same off-by-one-day miscalculation appears in #321's description table (immutable history, nothing to fix there). The "Z" test was already correct and is unchanged.

Validation hardening

While here, the timezone validation in toml-loader.ts is left intact but gains:

  • A comment explaining why the typeof source.timezone !== "string" guard is required — TOML can yield non-strings, and RegExp.test() coerces a single-element array like ["local"] to a passing string, which would otherwise reach the driver as a non-string.
  • A regression test for that ["local"] array case.

(An earlier revision of this PR briefly dropped the guard; review correctly flagged the resulting hole, so it was restored. The net diff to the validation logic is therefore zero — only the comment and the new test are added.)

Testing

  • pnpm test src/config/__tests__/toml-loader.test.ts — 109 pass, including the new array-rejection case and the existing invalid-format (Asia/Seoul) case.
  • The corrected +09:00 assertion was verified against mysql2's exact parseDateTime logic. The full integration test still requires Docker to run.

🤖 Generated with Claude Code

The MySQL integration test for the new `timezone` source option (#321)
asserted the wrong UTC instant. KST is UTC+9, so the naive DATETIME
`2025-09-29 02:31:23` interpreted as `+09:00` is `2025-09-28T17:31:23Z`
(the previous day), not `2025-09-29T17:31:23Z`. mysql2's parseDateTime
does `new Date(`${str}${timezone}`)`, which produces the previous-day
instant — so the assertion would have failed against a real container,
indicating the integration suite was not run before merge. Fix the
expected value and the explanatory comment.

Also drop the redundant `typeof source.timezone !== "string"` guard in
the TOML timezone validation: the field is already narrowed to a string,
and RegExp.test() coerces safely, so the guard can never be the sole
cause of a throw (unlike search_path's guard, which is load-bearing for
its .trim() call).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 7, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR corrects the expected UTC instant in the MySQL timezone integration test for timezone = "+09:00" and simplifies TOML timezone validation logic.

Changes:

  • Fixes the MySQL integration test assertion to expect the correct previous-day UTC timestamp for +09:00.
  • Updates the test comment to accurately explain the date rollover when converting KST → UTC.
  • Removes the typeof source.timezone !== "string" check from TOML timezone validation (note: this introduces a validation hole; see review comment).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/connectors/tests/mysql.integration.test.ts Updates the +09:00 DATETIME→UTC expectation and clarifies the reasoning in comments.
src/config/toml-loader.ts Simplifies timezone validation condition for MySQL/MariaDB sources.

Comment thread src/config/toml-loader.ts Outdated
Removing the typeof check opened a validation hole flagged in review: a
single-element TOML array such as timezone = ["local"] coerces via
RegExp.test() to the passing string "local", so the array would reach
the driver as a non-string. Restore the typeof guard and add a
regression test for the array case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/config/toml-loader.ts
Comment on lines +460 to 466
// Accepted by mysql2/mariadb drivers: "local", "Z", or "±HH:MM" (e.g., "+09:00").
// The typeof guard is required: TOML can yield non-strings (e.g. arrays), and
// RegExp.test() would coerce a single-element array like ["local"] to a passing
// string before it reaches the driver as a non-string value.
if (
typeof source.timezone !== "string" ||
!/^(?:local|Z|[+-]\d\d:\d\d)$/.test(source.timezone)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct — the guard was dropped then restored after the earlier comment, so the net validation diff is now zero (only an explanatory comment + regression test remain). Updated the PR title and description to match: the change set is now the +09:00 test-assertion fix plus the array-case hardening, with no guard removal.

@tianzhou tianzhou changed the title fix: correct +09:00 timezone test assertion and drop redundant guard fix: correct +09:00 timezone integration test assertion Jun 7, 2026
@tianzhou tianzhou merged commit af08b7a into main Jun 7, 2026
3 checks passed
@tianzhou tianzhou deleted the fix/mysql-timezone-test-and-cleanup branch June 9, 2026 10:42
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