test(config): 令牌门禁改用不变量测试,不再靠枚举例子 - #27
Merged
Merged
Conversation
is_loopback_host 是 ensure_bindable 唯一的判据,而它连续两次出问题都说明同一件事: 缺陷不在"哪几个例子"里,而在"按什么判定"里(拿字符串前缀当网段、拿库函数当版本 无关的真相)。逐例枚举的用例天生抓不住这类错误,所以改成四条不变量: - 语料由生成得到,不是手写清单:127/8 的写法交叉相乘,'像回环'的名字由 127.<a>.<b>.<c>.example 生成,另有 RFC1918/CGNAT/link-local/云元数据端点。 - 判为对外的东西,拼写怎么改(空白、方括号、大小写)都不能翻回来。 - ::ffff:A.B.C.D 与 A.B.C.D 的判定必须一致:这条与解释器版本无关,而它盯住的 bug 恰恰是版本相关的(3.11 的 IPv6Address.is_loopback 不认 v4-mapped),于是 CI 的 3.11 腿就能盯住它。 - 我们放行的写法,系统真绑一次后选中的必须是回环地址(localhost 走本机解析器,与 我们的字符串逻辑无关);只覆盖系统确实肯绑的写法,OSError 跳过而不是假装通过。 - 开箱默认值(DEFAULT_BIND_HOST / ServeConfig().host)必须免令牌。 验证:把实现换回未归一化版本并模拟 3.11 语义时三条用例失败(含新加的那条); 同一语义配当前实现则全套照过,没有误报。 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
上一轮修
is_loopback_host时,我加的用例是手写清单(127.corp.example之类)。这次换成不变量——因为连着两次出问题的都是"按什么判定",而不是"哪几个例子":startswith("127.")当网段用,于是放行了127.corp.example这类主机名;IPv6Address.is_loopback上,而它对 v4-mapped 形式的支持是随 Python 版本加的——同一个地址,3.11 要令牌、3.12 不要。枚举式的用例天生抓不住这两类:改判定依据不会让旧例子失效。所以这里改成四条不变量。
语料由生成得到
127.{a}.{b}.{c}由交叉相乘得到(125 项),"像回环"的名字由127.<a>.<b>.<c>.example生成,另加上 RFC1918 / CGNAT100.64/10/ link-local169.254(含云厂商元数据端点)/ 未指定地址 / NAT64 / 文档网段。要加新的"像不像"形状,改生成器而不是补一行例子。四条不变量
ensure_bindable一律拒绝。任何依赖字符串形状的判定都会在这里露出来。::ffff:A.B.C.D与A.B.C.D判定一致:这条本身与解释器版本无关,而它盯住的 bug 是版本相关的——所以它把"3.11 与 3.12 不一致"翻译成了一个在任何版本上都成立的要求,CI 的 3.11 腿就能盯住它。localhost尤其重要——它走的是本机解析器,与我们的字符串逻辑无关。只覆盖系统确实肯绑的写法(macOS 只为lo配了127.0.0.1,绑127.1.2.3会被拒,那属于"能不能用"而非"判得对不对"),遇到OSError跳过而不是假装通过。DEFAULT_BIND_HOST与ServeConfig().host都要过ensure_bindable(..., ""),否则ponte serve默认就起不来。验证
pytest413 passed,覆盖率 86.75%;ruff、mypy(本机与--platform linux)、_smoke_test.py全过。is_loopback语义后,三条用例失败(含新加的::ffff:那条);同一 3.11 语义配当前实现则全套照过——所以这些不变量在旧版本上也不是误报。补充一句边界:不变量测试能盯住"判定与要求不一致",但盯不住解释器行为差异本身——v4-mapped 那类差异最终仍要靠版本矩阵来暴露。这条测试做的是把它变成本地可复现、且在任何版本上都该成立的要求。