Skip to content

fix: lk upload usa content type pela extensão e timeout no envio ao storage - #77

Merged
cirdes merged 1 commit into
mainfrom
djalma1/lin-8122-upload
Oct 27, 2026
Merged

cirdes merged 1 commit into
mainfrom
djalma1/lin-8122-upload

Conversation

@djalmaaraujo

Copy link
Copy Markdown
Collaborator

Issue relacionada

Parte A da LIN-8122

Descrição

lk upload de .docx, .xlsx e .pptx subia como application/zip, porque o content type saía dos bytes. O backend recusa zip nos anexos de documento: o arquivo subia e o update seguinte falhava com 422. Agora o tipo vem da extensão, e sem extensão conhecida cai no sniff de antes. --content-type explícito continua ganhando.

O Go não traz os tipos do Office nem .csv sem o mime db do sistema, então coloquei uma tabelinha em internal/commands/upload.go copiada do app/models/uploads/allowed_content_types.rb do linkana. O preço é manter as duas iguais na mão.

O PUT no storage usava http.DefaultClient, sem timeout. Agora tem --timeout (default 5m): estourou, sai com exit 1 dizendo o arquivo e quanto esperou. O SURFACE.txt fica igual, ele só lista comandos.

A parte B (manifest dos comandos novos e release) vai em outro PR, depois da LIN-8114 e da LIN-8116.

Instruções de teste

  1. make test, make lint e make cover (95.5%).
  2. Com o linkana local: make build, ./lk config set base_url http://localhost:3000, ./lk impersonate <usuário>, ./lk upload --file x.docx devolve content_type application/vnd.openxmlformats-officedocument.wordprocessingml.document. O binário da main devolve application/zip pro mesmo arquivo.
  3. ./lk upload --file grande.pdf --timeout 1ms sai com exit 1 e upload de grande.pdf sem resposta do storage após 1ms (--timeout).
E2E contra o linkana local (arquivos fictícios)
# LIN-8122 part A e2e — real local linkana (http://localhost:3000, linkana@a768af642d), fictitious files
# branch binary: cli@3579a03; main binary: cli@50cb246
# 2026-10-26T18:39:35-03:00
$ lk[branch] config
{
  "base_url": "http://localhost:3000",
}
[exit 0]
$ lk[branch] impersonate operador.e2e8114@example.com --format json
{
  "target_email": "operador.e2e8114@example.com",
}
[exit 0]
$ lk[branch] upload --file contrato-ficticio.docx --format json
{
  "byte_size": 269,
  "content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "filename": "contrato-ficticio.docx",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[branch] upload --file planilha-ficticia.xlsx --format json
{
  "byte_size": 265,
  "content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  "filename": "planilha-ficticia.xlsx",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[branch] upload --file certidao-ficticia.pdf --format json
{
  "byte_size": 45,
  "content_type": "application/pdf",
  "filename": "certidao-ficticia.pdf",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[branch] upload --file contrato-ficticio.docx --content-type application/zip --format json
{
  "byte_size": 269,
  "content_type": "application/zip",
  "filename": "contrato-ficticio.docx",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[main] upload --file contrato-ficticio.docx --format json
{
  "byte_size": 269,
  "content_type": "application/zip",
  "filename": "contrato-ficticio.docx",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[main] upload --file planilha-ficticia.xlsx --format json
{
  "byte_size": 265,
  "content_type": "application/zip",
  "filename": "planilha-ficticia.xlsx",
  "id": "eyJfcmFp…",
  "signed_id": "eyJfcmFp…"
}
[exit 0]
$ lk[branch] impersonate stop
{
  "stopped": true,
  "target_email": "operador.e2e8114@example.com"
}
[exit 0]
### blob content_type no banco local x allowlist DEFAULT (bin/rails runner)
contrato-ficticio.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document | allowed
planilha-ficticia.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | allowed
certidao-ficticia.pdf | application/pdf | allowed
contrato-ficticio.docx | application/zip | REJECTED
contrato-ficticio.docx | application/zip | REJECTED
planilha-ficticia.xlsx | application/zip | REJECTED
### timeout contra o storage local real
$ lk[branch] upload --file grande-ficticio.pdf --timeout 1ms
error: upload de grande-ficticio.pdf sem resposta do storage após 1ms (--timeout)
[exit 1]
$ lk[branch] upload --file certidao-ficticia.pdf --timeout 0s
error: --timeout precisa ser maior que zero
[exit 1]
$ lk[branch] impersonate stop
{
  "stopped": true,
  "target_email": "operador.e2e8114@example.com"
}
[exit 0]

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Requires human review: Corrige o content type do upload por extensão (docx/xlsx/pptx etc.) e adiciona --timeout (default 5m) no PUT ao storage, com testes. O default de 5m é um tradeoff operacional que precisa de validação.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

Turn on auto-fix | Re-trigger cubic

@djalmaaraujo
djalmaaraujo requested a review from cirdes October 26, 2026 21:53
@cirdes
cirdes merged commit a31b542 into main Oct 27, 2026
4 checks passed
@cirdes
cirdes deleted the djalma1/lin-8122-upload branch October 27, 2026 13:01
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