Validate Workers deploy config - #647
Conversation
Greptile SummaryThis PR adds input validation for the Cloudflare Workers deploy config, ensuring
Confidence Score: 4/5Safe to merge; validation guards run before any CLI or filesystem work and tests cover every new rejection path. The validation logic is correct and idempotent. normalizedConfig is invoked in every helper as well as at the public entry points, causing repeated validation on already-valid config — currently harmless but worth cleaning up. The compatibilityDate regex accepts logically impossible dates like 2026-13-45, which would surface as a Wrangler error rather than an early validation failure. packages/targets/deploy-workers/src/index.ts — the redundant normalizedConfig calls in the helper functions. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["build / ship"] --> B["normalizedConfig"]
B --> C{"requireSegment: name"}
C -->|invalid| ERR1["throw: requires name / URL-safe"]
C -->|valid| D{"requireSegment: accountId"}
D -->|invalid| ERR2["throw: URL-safe segment"]
D -->|valid| E{"routes map requireText"}
E -->|"blank route"| ERR3["throw: requires routes[i]"]
E -->|valid| F{"optionalText fields"}
F -->|"blank string"| ERR4["throw: requires field"]
F -->|valid| G{"compatibilityDate regex"}
G -->|"bad format"| ERR5["throw: YYYY-MM-DD"]
G -->|valid| H{"workerVars key regex"}
H -->|"bad key"| ERR6["throw: valid env var name"]
H -->|valid| I["normalized Config"]
I --> J["renderPlan / deployArgs / exec"]
Reviews (1): Last reviewed commit: "Validate Workers deploy config" | Re-trigger Greptile |
| @@ -43,6 +104,7 @@ function deployArgs(ctx: { channel: string; projectDir: string }, config: Config | |||
| } | |||
|
|
|||
| function renderPlan(ctx: { channel: string; projectDir: string; version: string }, config: Config): string { | |||
| config = normalizedConfig(config); | |||
There was a problem hiding this comment.
Redundant
normalizedConfig calls throughout helpers
normalizedConfig is called in both the top-level entry points (build, ship) and again inside every helper (workerEntry, wranglerConfig, deployEnv, deployArgs, renderPlan). A single build invocation triggers roughly 9 normalizations. While idempotent today, this pattern obscures where validation actually occurs and makes the helpers harder to test in isolation. Consider removing the normalizedConfig call from the helpers and ensuring callers always pass an already-normalized config, or keeping validation only at the public build/ship entry points.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if (date && !/^\d{4}-\d{2}-\d{2}$/.test(date)) { | ||
| throw new Error('deploy-workers compatibilityDate must use YYYY-MM-DD'); | ||
| } |
There was a problem hiding this comment.
^\d{4}-\d{2}-\d{2}$ only validates the format, not calendar validity. A value like '2026-13-45' satisfies the regex but is not a real date, and Wrangler would reject it at deploy time. Adding isNaN(Date.parse(date)) as a secondary guard would catch logically invalid dates early.
| if (date && !/^\d{4}-\d{2}-\d{2}$/.test(date)) { | |
| throw new Error('deploy-workers compatibilityDate must use YYYY-MM-DD'); | |
| } | |
| if (date && (!/^\d{4}-\d{2}-\d{2}$/.test(date) || isNaN(Date.parse(date)))) { | |
| throw new Error('deploy-workers compatibilityDate must use YYYY-MM-DD'); | |
| } |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
15 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Fixes #646.
Changes:
Validation: