Skip to content

fix: preserve unknown wrangler config fields on save#8

Merged
paoloanzn merged 2 commits intomainfrom
codex/preserve-wrangler-config
Mar 23, 2026
Merged

fix: preserve unknown wrangler config fields on save#8
paoloanzn merged 2 commits intomainfrom
codex/preserve-wrangler-config

Conversation

@paoloanzn
Copy link
Copy Markdown
Contributor

Summary

  • preserve unknown top-level and env-level fields when wrangler.jsonc is loaded and saved by the CLI
  • stop CLI save paths from silently dropping unsupported Wrangler config sections
  • add regression tests for config round-tripping and cleared known fields

Problem

Users reported that configuration sections were being "stripped away" from wrangler.jsonc, including reports involving the Workers AI binding and other Wrangler-managed settings.

At first glance this can look like a linter or editor-save race, but the actual failure mode is inside flare-edge-cli itself.

Root Cause

The CLI currently loads wrangler.jsonc into a narrow typed Go struct and then writes it back through JSON marshaling.

That means any field not explicitly modeled in internal/domain/config/wrangler.go is lost on save.

So whenever a command rewrites Wrangler config, unsupported sections can disappear, including custom or newer Wrangler keys. The effect is especially visible in projects where users or other tools add fields that flare-edge-cli does not yet know about.

Fix

This PR updates the Wrangler config model to preserve unknown fields during JSON unmarshal and marshal:

  • WranglerConfig now stores unknown top-level fields in an internal raw map
  • WranglerEnvConfig now stores unknown env-level fields in an internal raw map
  • known fields are still written from the typed model
  • unknown fields are merged back into the serialized output instead of being discarded
  • cleared known fields do not reappear from preserved extras

This keeps the CLI’s typed behavior for the fields it owns while avoiding destructive rewrites for fields it does not model.

Scope

This fix benefits every command path that saves wrangler.jsonc, not just one command. That includes flows such as:

  • AI binding updates
  • deploy-time config mutation
  • route attach/domain/detach
  • KV, D1, and R2 binding updates
  • teardown cleanup writes

Testing

  • go test ./internal/domain/config
  • go test ./...

Added regression tests to verify that:

  • unknown top-level fields survive round-trip serialization
  • unknown env-level fields survive round-trip serialization
  • known field updates still apply correctly
  • cleared known fields do not come back from preserved extras

Important Note

This PR preserves unknown fields, but it does not preserve comments or original formatting/order. The file is still rewritten as normalized JSON output. That is a separate follow-up if we want true JSONC comment-preserving edits.

@paoloanzn paoloanzn merged commit 07abec1 into main Mar 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant