fix(tablewrap): corrige validação de caption — usa presença de <title> em vez de conteúdo textual#1212
Open
Rossi-Luciano wants to merge 5 commits intoscieloorg:masterfrom
Open
Conversation
…title em vez de bool(caption)
… dos testes do modelo
…title e adiciona casos isolados de caption sem label
Contributor
There was a problem hiding this comment.
Pull request overview
Este PR corrige a validação “label or caption” de <table-wrap> para seguir a regra SPS de forma estrutural: considerar válida a presença de <caption><title> mesmo quando <title/> está vazio, e rejeitar <caption> sem <title>.
Changes:
- Adiciona
caption_has_titleao modeloTableWrape expõe a chave emTableWrap.data. - Atualiza
validate_label_or_captionpara usarcaption_has_titleem vez debool(caption_text). - Ajusta/expande testes para cobrir os casos isolados de
<caption><title/>(OK) e<caption>sem<title>(CRITICAL).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packtools/sps/models/tablewrap.py |
Introduz caption_has_title e adiciona o campo ao payload data. |
packtools/sps/validation/tablewrap.py |
Troca a regra de validação para checar a presença estrutural de <title> em <caption>. |
tests/sps/validation/test_tablewrap.py |
Corrige docstring e adiciona testes cobrindo os cenários de <caption> com/sem <title>. |
tests/sps/models/test_tablewrap.py |
Atualiza os dicionários esperados para incluir caption_has_title. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Returns: | ||
| bool: True if <caption><title> exists (even if empty), False otherwise. | ||
| """ | ||
| caption_element = self.element.find(".//caption") |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Descrição
Problema
validate_label_or_captionavaliavabool(caption), ondecaptioné o texto extraído porET.tostring(..., method="text"). Isso produzia dois comportamentos incorretos:<caption><title/></caption>(título vazio, mas estruturalmente válido per SPS) retornava""e era tratado como ausente — a validação falhava indevidamente.<caption>texto livre</caption>(sem<title>) retornava o texto e era aceito como válido — a validação passava indevidamente.O problema foi identificado na revisão do Copilot do PR #1130.
Solução
models/tablewrap.pycaption_has_title: verifica a presença do elemento<title>dentro de<caption>viacaption_element.find("title") is not None, independente do seu conteúdo.caption_has_titleexposta emTableWrap.data.validation/tablewrap.pyvalidate_label_or_captionsubstituibool(caption)porbool(caption_has_title).get_default_paramsregistrando que as chaveslabel_error_levelecaption_error_levelforam descontinuadas em favor delabel_or_caption_error_level.tests/sps/validation/test_tablewrap.pytest_valid_table_wrap_with_empty_title: o teste passava por causa do<label>, não do<caption><title/>— o docstring anterior era enganoso.test_label_or_caption_only_caption_with_empty_title: isola o cenário em que apenas<caption><title/>está presente (sem<label>) — deve retornarOK.test_label_or_caption_only_caption_without_title_fails:<caption>sem<title>e sem<label>— deve retornarCRITICAL.tests/sps/models/test_tablewrap.pycaption_has_title: Truenos 9 dictsexpecteddos testes do modelo, sincronizando-os com o contrato atual deTableWrap.data.Testes