Commit 9d34fbe
authored
refactor(utils): consolidate duplicated helpers onto @sim/utils (#5509)
* refactor(utils): consolidate duplicated helpers onto @sim/utils
Replaces ~90 hand-rolled reimplementations of error-message extraction,
postgres error-code checks, sleep, Math.random, retry/backoff, object
filtering/omission, noop, string truncation, date/time formatting, email
normalization, and plain-object type guards with the shared @sim/utils
exports. Wires check:utils into CI (test-build.yml) so these patterns
don't regress.
* fix(test): mock @sim/utils/random instead of Math.random in schedule-execute tests
The schedules/execute route previously used Math.random() for jitter delay;
this consolidation PR switched it to randomInt() from @sim/utils/random,
which is backed by crypto.getRandomValues() rather than Math.random(). The
route.test.ts spies on Math.random() no longer had any effect, so jitter
became real random delay instead of the deterministic 0ms the tests expect,
causing intermittent 10s timeouts in CI.
* fix(retry): preserve uncapped Retry-After comparison in tools/index.ts
parseRetryAfter() caps its return value at 30s by default. tools/index.ts
compares the parsed Retry-After against a caller-configured maxDelayMs to
decide whether to skip a retry entirely -- capping before that comparison
silently defeats the skip check whenever maxDelayMs is configured above
30s, since a Retry-After between 30s and maxDelayMs would incorrectly look
"within limits" and get retried instead of skipped (caught by Cursor
Bugbot). Added an optional maxMs param (default unchanged) so tools/index.ts
can request the raw, uncapped value for its own comparison while
backoffWithJitter still clamps the actual sleep duration to maxDelayMs.
Added a regression test covering maxDelayMs > 30s.
* fix(utils): fall back to Intl-resolved abbreviation for unmapped timezones
getTimezoneAbbreviation only covered 9 hardcoded IANA zones and returned
the raw IANA string for everything else, degrading schedule descriptions
for zones like Europe/Berlin or America/Toronto (caught by Greptile). The
deleted local implementation in schedules/utils.ts resolved any valid IANA
timezone generically via Intl.DateTimeFormat's short timeZoneName. Restore
that as a fallback so only genuinely invalid timezone strings return
themselves unchanged.1 parent 099f525 commit 9d34fbe
98 files changed
Lines changed: 310 additions & 327 deletions
File tree
- .github/workflows
- apps/sim
- app
- (auth)/login
- (interfaces)/resume/[workflowId]/[executionId]
- (landing)/changelog/components/changelog-timeline
- api
- auth/oauth
- billing/invoices
- cron/renew-subscriptions
- files/public/[token]
- otp
- sso
- function/execute
- logs/export
- mcp/servers/test-connection
- memory
- mothership/execute
- organizations/[id]
- invitations
- members
- schedules/execute
- table/import-csv
- v1
- admin/credits
- knowledge/[id]/documents
- webhooks/poll/[provider]
- workspace-events/poll
- f/[token]
- workspace/[workspaceId]
- components/resource/components/resource-chrome-fallback
- files/components/file-viewer/rich-markdown-editor
- home
- components
- chat-surface-context
- suggested-actions
- hooks/stream
- knowledge/[id]
- [documentId]
- components/document-tags-modal
- logs
- settings/components
- billing
- mothership
- team-management/components/organization-member-lists
- teammates
- tables
- [tableId]
- components/import-csv-dialog
- w
- [workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat
- components/sidebar/hooks
- blocks/blocks
- connectors/x
- ee/access-control/components
- executor/handlers/agent
- hooks/queries
- lib
- api/contracts/tools/aws
- billing/validation
- copilot
- chat
- tools/server
- files
- knowledge
- core
- rate-limiter/hosted-key
- security
- utils
- events
- execution
- file-parsers
- knowledge/connectors
- logs/execution
- messaging/sms
- monitoring
- table
- tokenization
- webhooks
- workflows
- schedules
- subblocks
- workspaces/organization
- providers
- stores/chat
- tools
- amplitude
- github
- incidentio
- notion
- packages
- logger
- src
- utils/src
- workflow-persistence/src
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
280 | | - | |
| 281 | + | |
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
Lines changed: 4 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
| |||
133 | 126 | | |
134 | 127 | | |
135 | 128 | | |
136 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
137 | 132 | | |
138 | 133 | | |
139 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
1021 | 1022 | | |
1022 | 1023 | | |
1023 | 1024 | | |
1024 | | - | |
| 1025 | + | |
1025 | 1026 | | |
1026 | 1027 | | |
1027 | 1028 | | |
| |||
1165 | 1166 | | |
1166 | 1167 | | |
1167 | 1168 | | |
1168 | | - | |
| 1169 | + | |
1169 | 1170 | | |
1170 | 1171 | | |
1171 | 1172 | | |
| |||
1220 | 1221 | | |
1221 | 1222 | | |
1222 | 1223 | | |
1223 | | - | |
| 1224 | + | |
1224 | 1225 | | |
1225 | 1226 | | |
1226 | 1227 | | |
| |||
0 commit comments