Skip to content

wrangler] fix: validate types output file at the target path#14583

Open
Partha-Shankar wants to merge 3 commits into
cloudflare:mainfrom
Partha-Shankar:fix/migration-audit
Open

wrangler] fix: validate types output file at the target path#14583
Partha-Shankar wants to merge 3 commits into
cloudflare:mainfrom
Partha-Shankar:fix/migration-audit

Conversation

@Partha-Shankar

@Partha-Shankar Partha-Shankar commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes a false-positive validation error in wrangler types when generating types from a subdirectory.

Details

Previously, validateTypesFile() searched parent directories for an existing worker-configuration.d.ts. As a result, running wrangler types from a subdirectory could incorrectly fail if an unrelated custom worker-configuration.d.ts existed in a parent directory, even though no such file existed at the target output path.

This change validates only the target output path, ensuring the validation matches the actual output location.

Adds a regression test covering this scenario.


  • Tests

    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation

    • Cloudflare docs PR(s):
    • Documentation not necessary because: This fixes an internal validation bug without changing the public API or documented behavior.

Open in Devin Review

…onfig fields

Add optional string validation checks for database_name, migrations_dir, migrations_table, and database_internal_env inside validateD1Binding. This aligns D1's validation behavior with other bindings (like KV, R2, and Durable Objects) that typecheck all optional parameters.
… database fields

Also add changeset for type validation of optional D1 configuration fields.
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08ae23f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@cloudflare/workers-utils Patch
wrangler Patch
@cloudflare/autoconfig Patch
@cloudflare/cli-shared-helpers Patch
@cloudflare/deploy-helpers Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
@cloudflare/workers-auth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 7, 2026
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team July 7, 2026 06:03
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/d1-binding-config-validation.md: [@cloudflare/wrangler]
  • .changeset/types-ignore-parent-directory-dts.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/type-generation.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/type-generation/index.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

Open in Devin Review

Comment on lines +3434 to +3468
it("should ignore a non-Wrangler types file in a parent directory", async ({
expect,
}) => {
const parentDir = path.resolve("..");
const parentTypesPath = path.join(
parentDir,
"worker-configuration.d.ts"
);

fs.writeFileSync(parentTypesPath, "export interface CustomEnv {}");

try {
fs.writeFileSync(
"./index.ts",
"export default { async fetch() {} };"
);
fs.writeFileSync(
"./wrangler.jsonc",
JSON.stringify({
compatibility_date: "2022-01-12",
name: "test-name",
main: "./index.ts",
}),
"utf-8"
);

await runWrangler("types");

expect(fs.existsSync("./worker-configuration.d.ts")).toBe(true);
} finally {
try {
fs.unlinkSync(parentTypesPath);
} catch {}
}
});

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.

🔍 Test writes to parent of temp directory, potential parallel test interference

The new test at line 3434 writes worker-configuration.d.ts into path.resolve("..") — the parent of the runInTempDir() sandbox. If multiple test shards or parallel runs use sibling temp directories under the same parent (e.g., /tmp/), this file could collide with another test's parent directory check. The finally block cleans it up, but a crash before cleanup or a parallel read could cause flakiness. Consider using a dedicated isolated directory instead of .., or at minimum using a unique filename.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14583

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14583

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14583

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14583

miniflare

npm i https://pkg.pr.new/miniflare@14583

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14583

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14583

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14583

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14583

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14583

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14583

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14583

wrangler

npm i https://pkg.pr.new/wrangler@14583

commit: 08ae23f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants