Skip to content

fix: aceitar version inteiro no envelope de evento - #1

Merged
Bulletdev merged 1 commit into
mainfrom
fix/version-integer-envelope
Aug 23, 2026
Merged

fix: aceitar version inteiro no envelope de evento#1
Bulletdev merged 1 commit into
mainfrom
fix/version-integer-envelope

Conversation

@Bulletdev

Copy link
Copy Markdown
Owner

O que esta PR faz?

O Rails serializa version como número JSON, então o Jason.decode/1 entrega o inteiro 1 aos
dois consumidores. Os dois comparavam contra a lista de strings ["1"], que nunca casa. Esta PR
passa a aceitar as duas formas.

Nada quebra hoje, porque o publisher ainda não envia o campo. No dia em que enviar, a entrega cai a
zero sem erro em nenhuma das duas pontas - o mesmo sintoma de "não implementado". O mecanismo que
existe justamente para proteger contra incompatibilidade de schema seria o que causaria a queda.

Tipo da PR

Bugfix.

O que esta PR adiciona, remove ou atualiza?

  • redis_subscriber.ex e events_controller.ex: @supported_versions passa de ["1"] para
    [1, "1"].
  • Comentário nos dois arquivos explicando por que a lista não pode ser estreitada de volta. Sem
    isso, é o tipo de coisa que alguém "limpa" numa refatoração futura.
  • Dois testes cobrindo o caminho do inteiro, aceito e rejeitado. Os quatro testes de version que
    já existiam usam string e passam dos dois lados do bug.

Como testar?

mix test test/prostaff_events/redis_subscriber_test.exs

Os dois testes novos falham no commit anterior:

1) test resolve_topics/1 aceita version inteiro (ProstaffEvents.RedisSubscriberTest)
   Assertion with in failed
   code:  assert "org_events:org-1" in topics
   left:  "org_events:org-1"
   right: []

O right: [] é o bug: envelope completo, com todos os campos obrigatórios, e nenhum tópico.

Medição anterior contra Redis real e Phoenix.PubSub real, publicando o envelope que o
build_envelope do Rails realmente gera:

Envelope Entregues ao cliente
sem version (comportamento de hoje) 2
version: 1 inteiro 0
version: "1" string 2

Resultado esperado

mix test em 55 testes, 0 falhas. Portões de qualidade verdes: format, compile --warnings-as-errors, credo --strict, sobelow --config --exit e dialyzer.

Ordem de deploy

Esta PR precisa chegar em produção antes de o prostaff-api começar a enviar version.
Inverter a ordem derruba a entrega de eventos pela janela inteira de deploy, sem alarme.

É retrocompatível por construção - inteiro, string e ausência continuam funcionando - então pode ir
sozinha, sem coordenação.

Fora de escopo

Ficam para as próximas: separar os dois motivos pelos quais resolve_topics/1 devolve [] (hoje o
log diz "missing required fields" para os dois), subir o ramo não roteado de Logger.debug para
warning, e dar destino assinável aos tipos que hoje só chegam em org_events.

Rails serializes `version` as a JSON number, so Jason.decode/1 hands the
consumers the integer 1. Both consumers compared it against the string list
["1"], which never matched:

  - RedisSubscriber.resolve_topics/1 returned [], so the event reached no
    topic at all, not even org_events. The only trace was a Logger.warning
    that says "missing required fields" while printing an event that has
    them all.
  - EventsController rejected the request as an unsupported version.

Nothing breaks today because the publisher does not send the field yet. The
day it does, delivery drops to zero with no error on either side - the same
symptom as "not implemented". The mechanism that exists to protect against
schema incompatibility would be the one causing the outage.

Measured against a real Redis and a real Phoenix.PubSub, publishing the
envelope build_envelope/0 actually generates: 2 messages delivered with no
`version`, 0 with `version: 1`, 2 with `version: "1"`.

The four existing version tests all use strings, so they pass on both sides
of this bug. The two added here fail before the fix.

  - accept both forms in redis_subscriber.ex and events_controller.ex
  - comment why the list must not be narrowed back
  - cover the integer path, accepted and rejected

Deploy order matters: this must reach production before prostaff-api starts
sending the field. It is backwards compatible (integer, string and absent all
work), so it can ship on its own.
@Bulletdev Bulletdev self-assigned this Aug 23, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Bulletdev
Bulletdev merged commit f9171ac into main Aug 23, 2026
5 checks passed
@Bulletdev
Bulletdev deleted the fix/version-integer-envelope branch August 23, 2026 16:33
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