Skip to content

fix(cli): materialize CSV redirects into the KV decofile snapshot - #548

Open
JonasJesus42 wants to merge 1 commit into
mainfrom
fix/csv-redirects-kv-snapshot
Open

JonasJesus42 wants to merge 1 commit into
mainfrom
fix/csv-redirects-kv-snapshot

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problema

readDecofileFromDir diz produzir um decofile "byte-identical to the bundled blocks.gen snapshot". Não produz: generate-blocks injeta blocos sintéticos __csv_redirects__* via buildCsvRedirectBlocks (scripts/generate-blocks.ts:183,288) e os escritores de KV liam os .deco/blocks/*.json crus. Logo decofile:<sha> nunca teve os redirects vindos de CSV.

Hoje isso está mascarado — o blocks.gen bundlado continua residente e os redirects resolvem da memória. No momento em que o bundle deixa de ser o fallback (decoVitePlugin({ fastDeploy }) stuba pra {}), todo redirect de CSV some e os 301 de migração viram 404 silencioso. Justamente os sites com dezenas de milhares de regras são os que optam por fast-deploy pelo ganho de memória.

Correção

Uma chamada a buildCsvRedirectBlocks dentro de readDecofileFromDir, não em cada caller — assim sync-blocks-to-kv e migrate-blocks-to-kv ficam cobertos de uma vez e a invariante declarada passa a valer de fato. Mesma precedência do gerador ({ ...csv, ...blocks }): redirect curado no CMS ganha de linha de CSV.

Testes

3 casos novos em fast-deploy-kv.test.ts: loader de CSV aninhado em site.routes[] (a forma que quebrou em produção — invisível para loadRedirects, que só varre o topo), colisão de chave com bloco real, e no-op quando não há CSV. O primeiro falha sem a correção.

Primeiro de uma pilha; pré-requisito para ligar o stub do blocks.gen.

🤖 Generated with Claude Code


Summary by cubic

Fixes readDecofileFromDir so the KV decofile snapshot includes CSV-backed __csv_redirects__* blocks, matching the bundled blocks.gen snapshot. Previously those redirects were missing, so fast-deploy sites lost them once the bundled snapshot stopped being the fallback, turning migration 301s into silent 404s.

Notes

  • The fix lives in the shared read path, so both sync-blocks-to-kv and migrate-blocks-to-kv are covered.
  • On key collisions, a curated CMS redirect wins over the synthetic CSV block.
  • Adds tests for nested CSV loaders, key collisions, and the no-CSV no-op case.

Written for commit 82e78d0. Summary will update on new commits.

Review in cubic

`readDecofileFromDir` promises a decofile "byte-identical to the bundled
blocks.gen snapshot", but `generate-blocks` also injects synthetic
`__csv_redirects__*` blocks via `buildCsvRedirectBlocks` and the KV writers
did not. So `decofile:<sha>` never carried CSV-backed redirects.

Today that is masked: the bundled snapshot is still resident, so the
redirects resolve from memory. The moment the bundle stops being the
fallback — `decoVitePlugin({ fastDeploy })` stubs it to `{}` — every
CSV-backed redirect disappears and bulk-migration 301s turn into silent
404s. Sites with tens of thousands of rules are exactly the ones that opt
into fast-deploy for the memory win.

Fixed in `readDecofileFromDir` rather than in each caller, so both
`sync-blocks-to-kv` and `migrate-blocks-to-kv` are covered and the stated
byte-identical invariant actually holds. Same precedence as the generator:
a curated CMS redirect wins over a CSV row.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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