Repository navigation
control_plane/projects: single-source the safe project-id grammar - #8666
psychologister wants to merge 1 commit into
Conversation
repository_identity._SAFE_PROJECT_ID is the canonical stable-identifier grammar
(^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$); resolve_project_identity uses it to validate
the loopx:<id> fallback when a checkout has no origin remote. The projects registry
restated the identical pattern as its own _SAFE_ID and used it in _identifier to
reject unsafe project/goal ids. The registry already imports
normalize_repository_identity from repository_identity, so borrowing one more
owner object adds no import edge and cannot cycle. _SAFE_ID is retired and
_identifier now fullmatches against the owner; the sole remaining use of the re
module in this file was that definition, so its import is dropped too.
presentation/static_site.py keeps a same-named _SAFE_ID with a genuinely different
grammar (no colon, 63-character cap) and is left untouched -- it is a neighbour,
not a copy.
The by-name semantic inventory cannot see this: both bindings are private
_-names it does not catalogue, and they carried different names, so a name-keyed
match would not pair them even if it looked. The new guard keys on the compiled
pattern value -- a whole-tree census of re.compile sites, identity for the
consumer, retirement, the distinct static-site neighbour, and behavioural parity
through registry._identifier over the owner's grammar (including the 256/257
length boundary) plus the resolve_project_identity fallback.
Refs loopx-project#4447.
Signed-off-by: psychologister <230141834+psychologister@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.1-sol · OpenAI · runtime_reported · reasoning_effort=max
Reviewed commit: 278555ddf396ad6c0a6b08fd9dd9f0d8c120fcad
[P2] 这项改动已合入主干。 对当前 main 执行 git merge-tree,输出树与 main 自身完全一致;每个改动文件在核验的 main 的 Git blob 也与本 PR 相同。对应实现已由 #8637 合入。 见 已合入的 #8637。请将本 PR 标为 #8637 的重复提交;若原改动之外还有缺口,请从最新 main 提交可复现的新差异。
动机 / Motivation
用项目 ID 查找项目的调用方,以及需要为无 origin 的 Git 仓库生成稳定标识的调用方,依赖同一套 ID 字符规则。 旧版在两处各维护一份相同的字符规则。若以后只改其中一处,像 qa:beta 这样的 ID 可能在注册表可用,却无法生成稳定标识;共用规则消除了这个维护点。 复用现有规则后,两个入口对合法和非法 ID 的判断保持一致;例如 256 字符合法而 257 字符非法。 这份改动只涉及项目标识的字符校验;站点 ID 和有 origin 时的仓库身份识别沿用各自规则。
改动思路 / Approach
以已进入主干的仓库身份模块为字符规则的唯一来源。注册表原来就导入这个模块,因此增加符号引用没有引入新的模块依赖。 显式传入项目 ID 时,注册表先去掉首尾空白,再用共享规则检查字符,接着按 ID 查找记录。仓库身份入口先读 origin;缺少可用 origin 时才检查给定 ID,并生成 loopx: 前缀的标识。两条路径沿用各自的成功、未找到和报错方式。 保留主干已交付的实现与回归测试;若还有新缺口,应在最新主干上给出独立、可复现的例子。
具体改动 / Changes
收敛跟踪项 #4447 要求核对实际重定义。按已接受的 语义词表 RFC(版本 6f563c0e43a923e2e757b23027bad69ec5f9391a)评判:I1 的登记要求不适用于这个未登记的本地正则;这里沿用单一来源的设计。I6 的配套登记条件在本案不触发,输入的含义没有改动。2 个文件;生产 +5/-4,测试 +187/-0。相对于上述核验的 main,净差异为零。
关键代码讲解
- _identifier:去掉首尾空白,对整个 ID 做校验。旧版在本文件编译规则;该提交改用现有的共享规则。
- resolve_project:项目查询先验证显式 ID,再从注册表找对应记录。合法但不存在的 ID 仍返回 unresolved。
- resolve_project_identity:读取真实 Git origin;失败时才用已存在的正则验证项目 ID 并返回 loopx: 标识。此次没有更改这个顺序。
将站点 ID 的规则同注册表区别开来;原有入口在测试中既验证了合法 ID 的查询,又验证了拒绝路径。按字面值查找重复声明仅是局部防回退,不能证明整个代码库没有语义等价的规则。
对主干的风险 / Risks
如果日后两个调用方对同一字符作出不同判断,用户会遇到能注册却无法生成稳定身份的情况。这里在分叉基线、PR 提交和用于测试的主干分别执行注册表查询与真实 Git 身份回退,观察到相同接受集合、相同错误和一致的查找结果。现有静态站点 ID 的正则依然独立,且并未增加新配置、权限或迁移负担。 257 字符、非 ASCII、斜杠和非法首字符被拒绝;合法但未登记的 ID 返回 unresolved,临时注册表内容保持不变。
PASS:PR 提交和用于测试的主干 dd44cdc 各通过 60 项相关用例;原分叉基线通过 24 项现有入口用例。 PASS:在 核验的 main 上跑 git merge-tree --write-tree,两端树都是 771ec26f038bc63d0db9494a1e06237157d058b6,所有改动文件也分别与已合并版本逐个相同。这次只验证了相关本地用例和 Git 合并结果;未核验托管 CI,也未运行完整预合入套件。
语义与 CI 对齐
复用现有规则,没有新增或扩展词表,也没有将某种输入变成新的权限或执行义务。相应架构和行为测试在主干已存在,并在本轮本地通过。
我的整体评价 / Verdict
分叉以来是生产代码 +5/-4、测试 +187;主要机制只有一个共享正则。现有正式入口与架构测试已在主干跑通,重复提交只会增加评审和合入记录。 长期维护和调用体验都已由原合并保全。loopx project resolve --project-id=… / resolve_project_identity 未更改任何可视界面,核验范围为原有程序入口和输出。 请将本 PR 标为 #8637 的重复提交;若原改动之外还有缺口,请从最新 main 提交可复现的新差异。 若补交实质差异,再以新的精确提交和仍缺失的案例复审。
English verdict: REQUEST_CHANGES — This exact proposal adds no changes to the verified main revision; the implementation and its tests already shipped in #8637.
repository_identity.SAFE_PROJECT_ID is the canonical stable-identifier grammar
(^[A-Za-z0-9][A-Za-z0-9.:-]{0,255}$); resolve_project_identity uses it to validate
the loopx: fallback when a checkout has no origin remote. The projects registry
restated the identical pattern as its own _SAFE_ID and used it in _identifier to
reject unsafe project/goal ids. The registry already imports
normalize_repository_identity from repository_identity, so borrowing one more
owner object adds no import edge and cannot cycle. _SAFE_ID is retired and
_identifier now fullmatches against the owner; the sole remaining use of the re
module in this file was that definition, so its import is dropped too.
presentation/static_site.py keeps a same-named _SAFE_ID with a genuinely different
grammar (no colon, 63-character cap) and is left untouched -- it is a neighbour,
not a copy.
The by-name semantic inventory cannot see this: both bindings are private
_-names it does not catalogue, and they carried different names, so a name-keyed
match would not pair them even if it looked. The new guard keys on the compiled
pattern value -- a whole-tree census of re.compile sites, identity for the
consumer, retirement, the distinct static-site neighbour, and behavioural parity
through registry._identifier over the owner's grammar (including the 256/257
length boundary) plus the resolve_project_identity fallback.
Refs #4447.
Signed-off-by: psychologister 230141834+psychologister@users.noreply.github.com