Pin exact diagnostic message assertions for invalid requirement IDs and basenames in specvalidation tests

未关闭 适合新手
#596 5 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
testing

调研方向

先阅读 validator/internal/specvalidation/schema_test.go 中现有的 wantMessages 模式以了解约定,然后打开 identifiers_test.go(TestValidateRequirementIDs)和 basenames_test.go(TestValidateRequirementBasename)。为无效用例 REQ-CORE--00001、REQ---00001 和 notes.yaml 添加精确消息断言,使用 issue 中引用的字符串,这些字符串来自 identifiers.go:34 和 basenames.go:38。使用 go test ./validator/internal/specvalidation/... 进行确认,然后修改源文件中的一条消息,检查测试是否确实因 diff 而失败。

由索引模型根据 Issue 内容生成。

描述

bug component:validator triaged

What happened

In PR #593 (commit d5fb98fbad98de7d3bf5fef397c55c9c937d2965), diagnostic messages in validator/internal/specvalidation/identifiers.go:34 and validator/internal/specvalidation/basenames.go:38 were updated to specify "hyphen-separated alphanumeric segments":
"Requirement ID %q is invalid. Use REQ-<SCOPE>-<NNNNN> with an uppercase scope of hyphen-separated alphanumeric segments and a five-digit sequence."
"Requirement file basename %q is invalid. Use REQ-<SCOPE>-<NNNNN>.yaml with an uppercase scope of hyphen-separated alphanumeric segments and a five-digit sequence."

However, in validator/internal/specvalidation/identifiers_test.go (TestValidateRequirementIDs), test assertions only verify diag.Code == CodeInvalidID, diag.Field == "id", and substring identifiesID(diag.Message, tc.wantIDs[i]) (which only checks that the ID string appears in the message). In validator/internal/specvalidation/basenames_test.go (TestValidateRequirementBasename), assertions only check for substring containment of "notes" and "REQ-<SCOPE>-<NNNNN>.yaml". Neither suite asserts the full diagnostic message or the newly added guidance "hyphen-separated alphanumeric segments".

Maintainer @JohnStrunk noted in PR #593 review (https://github.com/redhat-et/ProtoBot/pull/593#pullrequestreview-3504313264):
"3. No test pins the new message text. A search for hyphen-separated finds only the two source lines. Optional: add the exact-message test from the triage proposal."

During triage of Issue #501, the triage agent (fullsend-ai-triage) had proposed a dedicated test function (TestRequirementIDDiagnosticMessage) asserting the exact updated diagnostic text, but it was not included in PR #593 because Issue #501 did not make it a mandatory criterion.

What could go better

In validator/internal/specvalidation/schema_test.go, previous issues #539, #575, and #576 systematically replaced partial substring matching with exact wantMessages assertions across all error cases to prevent diagnostic wording regressions and ensure user-facing guidance remains stable.

Leaving identifiers_test.go and basenames_test.go with only code and substring checks leaves the newly clarified diagnostic wording unpinned. If a future edit or refactor inadvertently alters the message format or removes the hyphen-separated segment explanation, no test in the test suite will fail. Adding exact message pinning aligns identifiers_test.go and basenames_test.go with the testing conventions established in schema_test.go.

Proposed change

  1. In validator/internal/specvalidation/identifiers_test.go:
    • Add a unit test function TestRequirementIDDiagnosticMessage(t *testing.T) (matching the test proposed by the triage agent on #501) or add exact message assertions to TestValidateRequirementIDs verifying that invalid requirement IDs (such as REQ-CORE--00001 and REQ---00001) produce the exact expected message:
      Requirement ID "REQ-CORE--00001" is invalid. Use REQ-<SCOPE>-<NNNNN> with an uppercase scope of hyphen-separated alphanumeric segments and a five-digit sequence.
  2. In validator/internal/specvalidation/basenames_test.go:
    • Update TestValidateRequirementBasename for the malformed requirement basename test case to assert the exact diagnostic message:
      Requirement file basename "notes.yaml" is invalid. Use REQ-<SCOPE>-<NNNNN>.yaml with an uppercase scope of hyphen-separated alphanumeric segments and a five-digit sequence.

Validation criteria

  1. go test ./validator/internal/specvalidation/... verifies exact diagnostic message strings for both CodeInvalidID and CodeRequirementInvalidBasename.
  2. Altering the diagnostic message string in identifiers.go or basenames.go causes go test to fail with a mismatch diff.
  3. All pre-commit hooks (python scripts/lint.py --all-files) and Go foundation checks pass cleanly.

Related issues checked

Searched: pin diagnostic message identifiers basenames; wantMessages identifiers_test CodeInvalidID; diagnostic message assertions test; CodeRequirementInvalidBasename identifiers_test basenames_test
Considered: #501, fullsend-ai/agents#2067, fullsend-ai/agents#2097, fullsend-ai/agents#2065, #511, #499, #539, #519, #531, #576, #479, #575, #456, #465, #506

  • #501: Closed; updated diagnostic strings in PR #593 but omitted adding exact message test assertions.
  • fullsend-ai/agents#2067: Open; review correctness check for assertion weakening in PR diffs; does not add tests to ProtoBot.
  • fullsend-ai/agents#2097: Open; code agent prompt guidance for updating pre-existing table tests; does not modify ProtoBot tests.
  • fullsend-ai/agents#2065: Open; style conventions check for diagnostic field paths; does not add test assertions.
  • #511, #519, #531, #539, #575, #576: Closed; hardened and enforced exact diagnostic message assertions (wantMessages) specifically within schema_test.go, leaving identifiers_test.go and basenames_test.go unpinned.
  • #499, #479: Closed; hardened cycle diagnostic assertions in relationships_test.go.
  • #456, #465, #506: Closed; addressed test tag scanning, schema blank validation, and os.DevNull linting; unrelated to identifier message tests.

Generated by retro agent from https://github.com/redhat-et/ProtoBot/pull/593

主要语言
Go
星标
7
派生
9
平均合并
22 小时 37 分钟
30 天内合并 PR
118

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

redhat-et/ProtoBot 的其他 Issue

查看 redhat-et/ProtoBot 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。