Title: fix(scripts): make the sql Date-binding audit precise and crash-proof by waleedlatif1 · Pull Request #6340 · simstudioai/sim · GitHub
Open Graph Title: fix(scripts): make the sql Date-binding audit precise and crash-proof by waleedlatif1 · Pull Request #6340 · simstudioai/sim
X Title: fix(scripts): make the sql Date-binding audit precise and crash-proof by waleedlatif1 · Pull Request #6340 · simstudioai/sim
Description: scripts/check-sql-date-binding.ts (shipped in #6337) catches a real production bug class — a bare Date interpolated into a drizzle raw sql template reaches the postgres driver unserialized and throws ERR_INVALID_ARG_TYPE. The detection goal is kept unchanged. This PR fixes five ways the detector could fail CI on correct code, plus three false negatives that fall out of the same fix.
False positives fixed
1. The tag was matched by the bare identifier name sql. That cannot tell drizzle's sql tag from postgres-js's own client tag (const sql = postgres(url)), which serializes Dates correctly. Two live call sites already sit in scanned directories:
apps/sim/app/api/tools/postgresql/utils.ts:20 — const sql = postgres({...}) with **6 live interpolating sql\`` templates** (~lines 233/241/255/268/280/307). Adding a Date` there is correct code the old detector would reject.
packages/db/scripts/reconcile-workspace-storage.ts:21 — same pattern; passed only by luck (its queries are literal-only).
scripts/setup/probes.ts:24 — a third, in the directory this PR newly scans.
The tag is now resolved to an actual import … from 'drizzle-orm' binding. A locally declared const sql = postgres(...) is no longer treated as the drizzle tag.
2. collectDateNames over-approximated scope file-wide. Two sub-problems:
TSPropertySignature fields typed Date were absorbed, so a single interface R { start: Date } marked the identifier start as a Date for the whole file.
Bindings crossed function boundaries, so const now = new Date() in one function made ${now} in another — where now is a number — a violation.
The audit found 97 of 179 (54%) files containing an interpolating sql template already bind at least one Date-typed name, across 282 distinct names dominated by exactly the collision-prone ones (now 335 bindings, timestamp 123, createdAt 83, date 75, updatedAt 70, start 24, expiresAt 24, end 22, cutoff 15). A drizzle-scoped re-measure on this branch gives 88/142 files. Either way this was a when-not-if CI break.
Bindings are now tracked in a lexical scope chain (function-level), with declaration-order-independent fix-point resolution retained for const b = a chains. Destructured Date params — function q({ since }: { since: Date }) — were previously caught via the TSPropertySignature path; that true positive is preserved by handling destructuring patterns explicitly, and now also resolves through a named interface (function q({ since }: Range)).
3. A parse failure crashed the run. errorRecovery: true does not cover missing Babel plugins, and main() had no try/catch, so a decorator, a class accessor, JSX in a .ts file, or any pre-existing syntax error failed CI with a stack trace. The per-file parse() is now wrapped; an unparseable file is reported as visibly skipped (printed to stderr with the parser message and a count), not silently swallowed. The decorators plugin is added.
4. The // sql-date-bound:
Open Graph Description: scripts/check-sql-date-binding.ts (shipped in #6337) catches a real production bug class — a bare Date interpolated into a drizzle raw sql template reaches the postgres driver unserialized and thro...
X Description: scripts/check-sql-date-binding.ts (shipped in #6337) catches a real production bug class — a bare Date interpolated into a drizzle raw sql template reaches the postgres driver unserialized and thro...
Opengraph URL: https://github.com/simstudioai/sim/pull/6340
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:be350748-b993-ee8a-e6f5-0881b2fae1c2 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ADD6:303206:92785D:CEF938:6AFB506E |
| html-safe-nonce | 8f669cd61226600f04fdfb853ebc41b4890374129ac0f3b67323166f473b31fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREQ2OjMwMzIwNjo5Mjc4NUQ6Q0VGOTM4OjZBRkI1MDZFIiwidmlzaXRvcl9pZCI6IjMzMjYzNzE5MjUzNzc4OTY1NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5b03b83038c1ca9beec863d118789aec8d63ec9f10fc5681c471278788cd84f7 |
| hovercard-subject-tag | pull_request:4223738574 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6340/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | scripts/check-sql-date-binding.ts (shipped in #6337) catches a real production bug class — a bare Date interpolated into a drizzle raw sql template reaches the postgres driver unserialized and thro... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width