René's URL Explorer Experiment


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: escape hatch was unusable for multi-line templates. It only inspected the line above the interpolated expression, which for a multi-line template sits inside the SQL string — the marker would be sent to Postgres as junk. This is the shape of the actual outage site (cleanup-stale-executions/route.ts's CASE…END block), so the escape hatch did not work where it was most needed. The annotation is now also accepted above the enclosing TaggedTemplateExpression or its enclosing statement. An empty reason is still rejected at every anchor. 5. Coverage hole: SCAN_DIRS was [apps, packages]; the root scripts/ directory was never scanned. Added (12,899 → 12,977 files). False negatives closed (free, from fix 1) Aliased imports (import { sql as raw }), namespace imports (d.sql\…`), and the matching d.sql.param(...)` member form are now detected. All were previously invisible. Verification Each fix has a test that is red before the change and green after — verified by reverting each fix individually and watching the specific test fail (6 reverts, 6 targeted failures). End-to-end on the full repo: Exits 0 across 12,977 files. Still catches the original outage: reverting sql.param(now, asyncJobs.startedAt) at cleanup-stale-executions/route.ts:250 is reported at line 254. Does not flag a Date injected into the postgres-js templates in apps/sim/app/api/tools/postgresql/utils.ts or scripts/setup/probes.ts. Does not flag a cross-function now shadow or an interface { start: Date } file. Injecting both into the real apps/sim/background/cleanup-logs.ts: the old detector reports 2 violations, the new one reports 0. Runtime: 5.46s → 4.07s over a larger file set (12,899 → 12,977 files). Skipping files with no drizzle-orm import before the scope pass more than pays for the extra analysis. Known limitations (unchanged or accepted) These are not covered — this PR does not claim full coverage: Cross-file imported Date constants (import { CUTOFF } from './constants'). Function-call returns: ${getCutoff()}. Array/member access: ${dates[0]}, ${row.startedAt}, ${this.now}. Dates flowing through object properties or array elements. Class property bindings, which the old pass collected. Since isDateExpression only resolves bare identifiers and class fields are read as this.x, collecting them could only ever produce false positives, never a catch — so they are dropped deliberately. Block-level scoping is approximated at function level. That direction only over-approximates within a single function, which was already the case. Follow-up in this PR: script unit tests removed Per review discussion, the repo does not carry unit tests for scripts/ — only 3 of 34 scripts had them. This PR now also removes all three, so the convention is consistent: Deletes scripts/check-sql-date-binding.test.ts, scripts/check-migrations-safety.test.ts, and scripts/check-tool-request-boundary.test.ts Drops the bun test … half of the check:sql-date-binding and check:tool-request-boundary gates in package.json — both invoked files this PR deletes, so CI would fail otherwise. check:migrations never referenced its test Removes findSqlDateBindingViolations (a pure test wrapper) and un-exports analyzeSource, SCAN_DIRS, lintSql, and findToolRequestBoundaryViolations — every one had zero references outside its own script and existed only so the tests could reach them All three gates verified running and passing standalone afterwards: check:sql-date-binding ✓ 12974 files bind every sql-template Date through a column encoder check:tool-request-boundary ✓ production tool requests are materialized only by the shared transport check:migrations ✓ No new migrations to check. The detector still reports the original outage site when its sql.param is reverted, and no YAML/JSON/script reference to any deleted file remains. Supersedes #6343, which is closed.

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

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:be350748-b993-ee8a-e6f5-0881b2fae1c2
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idADD6:303206:92785D:CEF938:6AFB506E
html-safe-nonce8f669cd61226600f04fdfb853ebc41b4890374129ac0f3b67323166f473b31fb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREQ2OjMwMzIwNjo5Mjc4NUQ6Q0VGOTM4OjZBRkI1MDZFIiwidmlzaXRvcl9pZCI6IjMzMjYzNzE5MjUzNzc4OTY1NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5b03b83038c1ca9beec863d118789aec8d63ec9f10fc5681c471278788cd84f7
hovercard-subject-tagpull_request:4223738574
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6340/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altscripts/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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecbf66c024bb6d10e6955baa7413c54cf13a201bb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6340/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6340%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6340%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/6340/files
Reloadhttps://github.com/simstudioai/sim/pull/6340/files
Reloadhttps://github.com/simstudioai/sim/pull/6340/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests197 (197)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
fix/sql-date-binding-precisionhttps://github.com/simstudioai/sim/tree/fix/sql-date-binding-precision
Conversation 20 https://github.com/simstudioai/sim/pull/6340
Commits 5 https://github.com/simstudioai/sim/pull/6340/commits
Checks 28 https://github.com/simstudioai/sim/pull/6340/checks
Files changed https://github.com/simstudioai/sim/pull/6340/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
fix(scripts): make the sql Date-binding audit precise and crash-proof https://github.com/simstudioai/sim/pull/6340/files#top
Show all changes 5 commits https://github.com/simstudioai/sim/pull/6340/files
6d0a971 fix(scripts): make the sql Date-binding audit precise and crash-proof waleedlatif1 Aug 6, 2026 https://github.com/simstudioai/sim/pull/6340/commits/6d0a9716a626232897140ec860741fd5666dc3f2
d828a11 fix(scripts): honor shadowed bindings and defaulted destructured Dates waleedlatif1 Aug 6, 2026 https://github.com/simstudioai/sim/pull/6340/commits/d828a1151d8ab3b66b9657aadd0c54ad15bc14ac
78cea08 fix(scripts): audit drizzle sql tags bound through a dynamic import waleedlatif1 Aug 6, 2026 https://github.com/simstudioai/sim/pull/6340/commits/78cea089e8511a352bee763820672772bd815ca5
789e313 chore(scripts): drop the sql Date-binding unit tests and the exports … waleedlatif1 Aug 6, 2026 https://github.com/simstudioai/sim/pull/6340/commits/789e313aa114d6fa1d92b580e75002a133b41434
7d05018 chore(scripts): drop the script unit tests and the exports that serve… waleedlatif1 Aug 6, 2026 https://github.com/simstudioai/sim/pull/6340/commits/7d05018bf845ba821dc2bb5250ad39025e6264a5
Clear filters https://github.com/simstudioai/sim/pull/6340/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
package.json https://github.com/simstudioai/sim/pull/6340/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
check-migrations-safety.test.ts https://github.com/simstudioai/sim/pull/6340/files#diff-46d6287301fbad5fdb174d71c845a33c73cf30de52c7ae27a0169df384497dbe
check-migrations-safety.ts https://github.com/simstudioai/sim/pull/6340/files#diff-865af4a4f714acde64e1c454597c6426e4779e4927b66c876b03d546447e82ab
check-sql-date-binding.test.ts https://github.com/simstudioai/sim/pull/6340/files#diff-88963c4df32eb1015cec9a56a9b2fd2604cf93a8956a28e92d576be448c03575
check-sql-date-binding.ts https://github.com/simstudioai/sim/pull/6340/files#diff-6668fd030519fad23bb491783297ab0d994322ae2b1c5713bec0c81cdef70707
check-tool-request-boundary.test.ts https://github.com/simstudioai/sim/pull/6340/files#diff-32bb310c027078982bc70891dd7d6356ad0b6221a183d631047bc687c2982a76
check-tool-request-boundary.ts https://github.com/simstudioai/sim/pull/6340/files#diff-85664b8fd67ebd33ce6a55ff54e33ea03fd6b0aa6bf8097a34edc4064ec70a59
https://github.com/simstudioai/sim/blob/staging/.github/CODEOWNERS#L36
package.jsonhttps://github.com/simstudioai/sim/pull/6340/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
View file https://github.com/simstudioai/sim/blob/7d05018bf845ba821dc2bb5250ad39025e6264a5/package.json
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6340/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6340/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
https://github.com/simstudioai/sim/pull/6340/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
scripts/check-migrations-safety.test.tshttps://github.com/simstudioai/sim/pull/6340/files#diff-46d6287301fbad5fdb174d71c845a33c73cf30de52c7ae27a0169df384497dbe
View file https://github.com/simstudioai/sim/blob/0ae09c1518f048f4a82481c2cccb801f4fc2b59c/scripts/check-migrations-safety.test.ts
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
scripts/check-migrations-safety.tshttps://github.com/simstudioai/sim/pull/6340/files#diff-865af4a4f714acde64e1c454597c6426e4779e4927b66c876b03d546447e82ab
View file https://github.com/simstudioai/sim/blob/7d05018bf845ba821dc2bb5250ad39025e6264a5/scripts/check-migrations-safety.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6340/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6340/files#diff-865af4a4f714acde64e1c454597c6426e4779e4927b66c876b03d546447e82ab
https://github.com/simstudioai/sim/pull/6340/files#diff-865af4a4f714acde64e1c454597c6426e4779e4927b66c876b03d546447e82ab
scripts/check-sql-date-binding.test.tshttps://github.com/simstudioai/sim/pull/6340/files#diff-88963c4df32eb1015cec9a56a9b2fd2604cf93a8956a28e92d576be448c03575
View file https://github.com/simstudioai/sim/blob/0ae09c1518f048f4a82481c2cccb801f4fc2b59c/scripts/check-sql-date-binding.test.ts
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6340/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.