Skip to content

feat(input): accept alphanumeric CNPJ in OceanInputType (OR-98)#1088

Merged
FabioRolin merged 4 commits into
masterfrom
feature/OR-98-alphanumeric-cnpj-input
Jun 2, 2026
Merged

feat(input): accept alphanumeric CNPJ in OceanInputType (OR-98)#1088
FabioRolin merged 4 commits into
masterfrom
feature/OR-98-alphanumeric-cnpj-input

Conversation

@FabioRolin

Copy link
Copy Markdown
Collaborator

Summary

  • OceanInputType.CNPJ and OceanInputType.CpfCnpj now accept the alphanumeric CNPJ format defined by Receita Federal NT 49/2024 ([A-Z] allowed in positions 1..12, DVs stay numeric).
  • Keyboard switches from KeyboardType.Number to KeyboardType.Ascii so the user can actually type letters. On POS hosts that disable the numeric virtual keyboard via OceanDS.disabledKeyboards, the Ascii keyboard still opens normally (only Number is disabled).
  • New helper sanitizeWithAlphanumeric on the base OceanInputType interface — keeps [A-Z0-9], upper-cases letters, drops separators.
  • CPF stays untouched (digits-only + numeric keyboard).
  • Backward compatible: every numeric CNPJ that worked before keeps working.

Refs spec Pagnet/blu-mobile-android#3650 (OR-98) — delivers task T2 of the execution plan (Ocean DS Android is the first project in the queue, blocks consumer migrations T6/T7).

Test plan

  • ./gradlew :ocean-components:testDebugUnitTest — new OceanInputTypeTest (10+ cases) + existing suite green.
  • ./gradlew :ocean-components:ktlintCheck — no violations.
  • Manual smoke on POS device — confirm Ascii virtual keyboard opens for CNPJ field even with N960KInputSetup active (covered by T8 in the spec).

Reviewers: @Pagnet/plataformas and mobile devs.

🤖 Generated with Claude Code

Receita Federal NT 49/2024 introduces alphanumeric CNPJs (letters A-Z
in positions 1..12, DVs stay numeric). OceanInputType.CNPJ and
CpfCnpj previously filtered to digits-only and forced a numeric
keyboard, blocking the new format entirely.

Changes:
- New helper `sanitizeWithAlphanumeric` on the base interface — keeps
  `[A-Z0-9]`, upper-cases letters, drops separators.
- `CNPJ` now uses `KeyboardType.Ascii` and the alphanumeric sanitiser.
  Legacy numeric CNPJs keep working unchanged.
- `CpfCnpj` switches to `Ascii` and selects between numeric/alpha
  sanitisation by the presence of letters or length > 11.
- POS-friendly: only `KeyboardType.Number` is in
  `OceanDS.disabledKeyboards`, so the Ascii keyboard is allowed to
  open even when the numeric virtual keyboard is disabled.

CPF remains untouched — still digits-only with the numeric keyboard.

Refs: spec Pagnet/blu-mobile-android#3650 (OR-98).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gustavoalens

Copy link
Copy Markdown
Collaborator

Code Review

Resumo

PR implementa suporte ao formato alfanumérico de CNPJ (Receita Federal NT 49/2024) no OceanInputType, afetando CNPJ e CpfCnpj. A mudança é backward compatible, bem coberta por testes (10+ casos) e a lógica está correta. Dois arquivos modificados (+145/-7).


Apontamentos

🔴 Blockers

Nenhum.

🟡 Warnings

  • UX degradation no campo CpfCnpj em modo CPF

    • Arquivo: OceanInputType.kt:231
    • Problema: CpfCnpj agora sempre abre teclado Ascii, mesmo quando o usuário está digitando um CPF (11 dígitos, sem letras). Teclados Ascii não têm layout numérico por padrão — usuários que digitam apenas CPF (maioria) vão encontrar um teclado menos conveniente.
    • Sugestão: Considerar retornar o tipo de teclado dinamicamente com base no estado atual do campo, ou aceitar o tradeoff e documentar claramente nos release notes. Vale validar com UX antes do merge nos consumidores.
  • Lógica de detecção de letras divergente entre isCnpj e sanitize

    • Arquivo: OceanInputType.kt:258, 270
    • Problema: isCnpj usa currentValue.any { it in 'A'..'Z' } (valor já sanitizado, sempre uppercase). Já sanitize usa text.any { it.uppercaseChar() in 'A'..'Z' } (input bruto). Funcionalmente correto por conta da pipeline de sanitização, mas a inconsistência pode confundir mantenedores.
    • Sugestão: Centralizar a detecção de letras num único helper privado para garantir consistência.

🟢 Suggestions

  • Comentários multi-linha em produção podem ser condensadosOceanInputType.kt:234-239, 251-253, 265-268: os blocos de 3-4 linhas de // explicam contexto não óbvio (POS, NT 49/2024), o que é válido, mas cabem em 2 linhas cada.

  • KDoc no arquivo de teste é verbosoOceanInputTypeTest.kt:1-10: o KDoc de classe explica o contexto em 4 linhas; para teste, uma linha bastaria, pois os nomes dos testes já são autoexplicativos.

  • CPF_LENGTH = 11 não compartilhado — existe apenas dentro de CpfCnpj. Se CPF precisar desse valor no futuro, haverá duplicação. Baixo risco agora, mas vale o registro.


Cobertura de Testes

  • Sanitização — uppercase, separadores, símbolos
  • Tipo de teclado (CNPJ → Ascii, CPF → Number)
  • Max length e truncation
  • Backward compatibility — CNPJ numérico continua funcionando
  • CpfCnpj com letras roteado corretamente para CNPJ alfanumérico
  • CPF permanece digits-only
  • Edge case ausente: CpfCnpj com exatamente 11 dígitos (transformForInput("12345678909")) confirmando que permanece em modo CPF e não transborda para CNPJ — vale um teste explícito no boundary.

Veredito

APPROVED — lógica correta, backward compatible, bem testado. O warning de UX do teclado Ascii em modo CPF é o ponto mais relevante para validar com produto/UX antes do merge nos consumidores (T6/T7).

@FabioRolin FabioRolin marked this pull request as ready for review May 26, 2026 20:21
@FabioRolin FabioRolin requested a review from gustavoalens May 26, 2026 20:32
@FabioRolin FabioRolin self-assigned this May 26, 2026
FabioRolin and others added 2 commits June 2, 2026 12:08
Per @gustavoalens' review on PR #1088: code changes do not need
explanatory comments — keep them only for genuinely complex logic or
accepted temporary solutions. Removes the change-explaining comments
from OceanInputType (CNPJ/CpfCnpj) and the verbose class KDoc from
OceanInputTypeTest. Behaviour and tests unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI `build` was failing on `:app:compileReleaseArtProfile` with
`Java heap space`. The baseline-profile ART compilation in the release
build needs more than the previous 2 GB. Bumps the daemon heap to 4 GB
(+1 GB metaspace), well within the GitHub-hosted runner's memory.

Unrelated to the OR-98 input change — pre-existing heap fragility that
surfaced on this PR's release build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

@FabioRolin FabioRolin merged commit ce7cc36 into master Jun 2, 2026
3 checks passed
@FabioRolin FabioRolin deleted the feature/OR-98-alphanumeric-cnpj-input branch June 2, 2026 17:23
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.

2 participants