-
Notifications
You must be signed in to change notification settings - Fork 24
Implementa validações obrigatórias SPS 1.10 para elementos de fórmula #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Implementa validações obrigatórias SPS 1.10 para elementos de fórmula #1075
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Implementa validações obrigatórias da SPS 1.10 para <disp-formula> e <inline-formula>, adicionando checagens de prefixos de IDs e atributos obrigatórios (ex.: @id em <mml:math>), além de ajustar o formato de resposta para suportar i18n via build_response.
Changes:
- Adiciona validações de prefixo/obrigatoriedade de
@idpara fórmulas e para<mml:math>(disp e inline). - Estende o modelo de fórmula com
mml_math_idetex_math_id. - Atualiza regras (níveis CRITICAL/ERROR/WARNING) e amplia/ajusta testes unitários para as novas validações e campos i18n.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
packtools/sps/validation/formula.py |
Inclui novas validações SPS 1.10 (prefixos e @id em mml:math) e migra respostas para build_response com suporte a i18n. |
packtools/sps/models/formula.py |
Adiciona propriedades mml_math_id e tex_math_id ao modelo e expõe no data. |
packtools/sps/validation_rules/formula_rules.json |
Configura novos níveis de severidade para as validações adicionadas. |
tests/sps/validation/test_formula.py |
Atualiza testes para novo payload (msg/adv templates) e adiciona cenários para prefixos e @id em mml:math. |
tests/sps/models/test_formula.py |
Ajusta expectativas dos testes do modelo para incluir os novos campos mml_math_id/tex_math_id. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i, item in enumerate(expected): | ||
| with self.subTest(i): | ||
| self.assertDictEqual(item, obtained[i]) |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only asserts that obtained[0] matches the expected "@id" error and doesn’t verify that no additional non-OK validations were returned (new prefix validations can add extra ERROR items). Consider filtering obtained by title == "@id" (like the newer tests) and/or asserting there are no unexpected non-OK responses so the test fails if new mandatory validations start triggering.
| advice=_('The @id of <disp-formula> must start with prefix "e". Change {id} to e{id} in <disp-formula id="{id}">. Consult SPS documentation for more detail.').format(id=formula_id), | ||
| data=self.data, | ||
| error_level=self.rules["id_prefix_error_level"], | ||
| advice_text=_('The @id of <disp-formula> must start with prefix "e". Change {id} to e{id} in <disp-formula id="{id}">. Consult SPS documentation for more detail.'), |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix-fix suggestion in the advice will produce values like "ef10" for an ID "f10" (it prepends "e" rather than making the ID start with "e"). Update the advice template/params to suggest replacing the leading character or otherwise generating an example that results in a valid SPS-style ID (e.g., "e10").
| advice=_('The @id of <disp-formula> must start with prefix "e". Change {id} to e{id} in <disp-formula id="{id}">. Consult SPS documentation for more detail.').format(id=formula_id), | |
| data=self.data, | |
| error_level=self.rules["id_prefix_error_level"], | |
| advice_text=_('The @id of <disp-formula> must start with prefix "e". Change {id} to e{id} in <disp-formula id="{id}">. Consult SPS documentation for more detail.'), | |
| advice=_('The @id of <disp-formula> must start with prefix "e". Update the value of id in <disp-formula id="{id}"> so that it starts with "e" (for example, change "f10" to "e10"). Consult SPS documentation for more detail.').format(id=formula_id), | |
| data=self.data, | |
| error_level=self.rules["id_prefix_error_level"], | |
| advice_text=_('The @id of <disp-formula> must start with prefix "e". Update the value of id in <disp-formula id="{id}"> so that it starts with "e" (for example, change "f10" to "e10"). Consult SPS documentation for more detail.'), |
| advice=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.').format(mml_id=mml_math_id, formula_id=item_id), | ||
| data=self.data, | ||
| error_level=self.rules["mml_math_id_prefix_error_level"], | ||
| advice_text=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.'), |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advice suggests changing an ID like "e03" to "me03" (by prepending "m"), which still won’t match the expected "m"-prefixed pattern used elsewhere (e.g., "m03"). Adjust the advice template so the suggested change results in an ID that actually starts with "m" (replace the prefix rather than prepend).
| advice=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.').format(mml_id=mml_math_id, formula_id=item_id), | |
| data=self.data, | |
| error_level=self.rules["mml_math_id_prefix_error_level"], | |
| advice_text=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.'), | |
| advice=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} so that it starts with "m" (for example, "m03" instead of "e03") in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.').format(mml_id=mml_math_id, formula_id=item_id), | |
| data=self.data, | |
| error_level=self.rules["mml_math_id_prefix_error_level"], | |
| advice_text=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} so that it starts with "m" (for example, "m03" instead of "e03") in <mml:math id="{mml_id}"> inside <disp-formula id="{formula_id}">. Consult SPS documentation for more detail.'), |
| dict or None: A validation result dictionary if the validation fails; otherwise, None. | ||
| """ | ||
| # Só valida se houver mml:math | ||
| if not self.data.get("mml_math"): |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate_mml_math_id (and similarly validate_mml_math_id_prefix) uses if not self.data.get("mml_math") to decide whether a mml:math exists. If the element exists but its text serialization is an empty string, this check incorrectly skips required @id validations. Use an explicit is None check (since the model returns None when the element is absent) rather than relying on truthiness.
| if not self.data.get("mml_math"): | |
| if self.data.get("mml_math") is None: |
| # Só valida se houver mml:math | ||
| if not self.data.get("mml_math"): | ||
| return None | ||
|
|
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as in disp-formula: using if not self.data.get("mml_math") treats an empty-string MathML serialization as “no mml:math”, causing mml:math @id validations to be skipped. Prefer checking self.data.get("mml_math") is None to distinguish “absent element” from “present but empty content”.
| advice=_('The @id of <inline-formula> must start with prefix "e". Change {id} to e{id} in <inline-formula id="{id}">. Consult SPS documentation for more detail.').format(id=formula_id), | ||
| data=self.data, | ||
| error_level=self.rules["id_prefix_error_level"], | ||
| advice_text=_('The @id of <inline-formula> must start with prefix "e". Change {id} to e{id} in <inline-formula id="{id}">. Consult SPS documentation for more detail.'), |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix-fix suggestion in the advice will produce IDs like "ef10" for an existing "f10" (it prepends "e"). Update the advice template so the suggested change results in a valid "e"-prefixed ID (e.g., replace the leading character, or provide an example like "e10").
| advice=_('The @id of <inline-formula> must start with prefix "e". Change {id} to e{id} in <inline-formula id="{id}">. Consult SPS documentation for more detail.').format(id=formula_id), | |
| data=self.data, | |
| error_level=self.rules["id_prefix_error_level"], | |
| advice_text=_('The @id of <inline-formula> must start with prefix "e". Change {id} to e{id} in <inline-formula id="{id}">. Consult SPS documentation for more detail.'), | |
| advice=_('The @id of <inline-formula> must start with prefix "e". Change {id} to an ID starting with "e" (for example, "e10") in <inline-formula id="{id}">. Consult SPS documentation for more detail.').format(id=formula_id), | |
| data=self.data, | |
| error_level=self.rules["id_prefix_error_level"], | |
| advice_text=_('The @id of <inline-formula> must start with prefix "e". Change {id} to an ID starting with "e" (for example, "e10") in <inline-formula id="{id}">. Consult SPS documentation for more detail.'), |
| advice=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <inline-formula id="{formula_id}">. Consult SPS documentation for more detail.').format(mml_id=mml_math_id, formula_id=item_id), | ||
| data=self.data, | ||
| error_level=self.rules["mml_math_id_prefix_error_level"], | ||
| advice_text=_('The @id of <mml:math> must start with prefix "m". Change {mml_id} to m{mml_id} in <mml:math id="{mml_id}"> inside <inline-formula id="{formula_id}">. Consult SPS documentation for more detail.'), | ||
| advice_params={"mml_id": mml_math_id, "formula_id": item_id}, |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advice currently suggests changing an ID like "e03" to "me03" by prepending "m", which is unlikely to be the intended SPS pattern (commonly "m03"). Adjust the advice template/params so the recommended change yields an ID that actually starts with "m" (replace prefix rather than prepend).
Este PR implementa as validações obrigatórias da especificação SPS 1.10 para os elementos
<disp-formula>e<inline-formula>, incluindo validações de prefixos de IDs e atributos obrigatórios em elementos internos como<mml:math>.Principais adições:
format_responseparabuild_responsepara suporte completo a internacionalização (i18n)mml_math_idetex_math_idao modeloCobertura: 87,5% das regras obrigatórias SPS (7/8 implementadas)
Onde a revisão poderia começar?
Ordem sugerida de revisão:
packtools/sps/models/formula.py- Novas propriedadesmml_math_idetex_math_idpacktools/sps/validation/formula.py- 10 validações (linhas 121-700)packtools/sps/validation/formula_rules.json- Níveis de errotests/sps/validation/test_formula.py- 15 testes (7 novos)Pontos de atenção:
format_responseparabuild_response(breaking change)parent=self.dataem vez de parâmetros individuaisComo este poderia ser testado manualmente?
1. Executar suite de testes:
2. Testar validação de prefixo incorreto:
3. Testar ID ausente em mml:math:
Algum cenário de contexto que queira dar?
Contexto SPS:
A especificação SciELO Publishing Schema (SPS) 1.10 define regras obrigatórias para identificação de fórmulas matemáticas em artigos científicos. Essas regras garantem:
@idMotivação técnica:
A migração de
format_responseparabuild_responsefoi necessária porque:format_responseignora silenciosamente os parâmetrosadvice_texteadvice_paramsBreaking Change:
O campo retornado mudou de
obtainedparagot_value. Testes que verificam valores devem usarerror["got_value"]em vez deerror["obtained"].Screenshots
Não aplicável - validações de XML retornam estruturas de dados.
Quais são tickets relevantes?
N.A.
Referências
N.A.