fix(service-settings): env door enforces declared pattern — the last one-door family (#6580) - #6626
Merged
Merged
Conversation
…one-door family (#6580) The write gate's pattern judgment is hoisted into shared helpers (declaredPattern / firstPatternMiss) called by BOTH doors, in the firstRejectedOption / firstRangeViolation / firstRejectedDomainMember idiom. An OS_* override whose value misses the declared pattern is loudly reported via reportRejectedEnvOverride (once per var+value), ignored, and pins nothing — the #5204 contract. Family ordering agrees between doors: options -> pattern -> valueDomain -> bounds. Write-door behavior is unchanged byte-for-byte, including the invalid-RegExp declaration tolerance (nothing to enforce, never a refusal), now shared by construction. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01USNUyHEr7uaU6MoEWXitei
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 7 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
os-project-manager
marked this pull request as ready for review
August 8, 2026 08:45
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.
Closes #6580
问题
settings 的 env 门(
effectiveEnvOverride)逐族核对声明约束——option 表(#5131/#5204)、值窗/步进(#5932/#6199)、valueDomain(#5712)——唯独漏了pattern:它只在写入门validatePatch执行(invalid_format)。后果是 #5204 的原始形状在最后一族上复现:PUT /api/settings/:ns拒绝的形状非法值,经OS_*覆盖照样生效并置顶 cascade(locked: true)。修法
按本面既有惯例(
firstRejectedOption/firstRangeViolation/firstRejectedDomainMember),把写入门的 pattern 判定提为共享判定点:declaredPattern:声明的pattern编译为可执行形式;编译失败 = 无可执行(写入门一贯的宽容,原话 "invalid manifest pattern — don't block writes"),两门经同一函数取得声明,宽容不可能再漂移。编译一次,注册时预存入RegisteredManifest.patterns(与optionTables/bounds/valueDomains同理:get()是最热路径,缺席键 = 无可执行)。firstPatternMiss:唯一的比较点,两门同调。非字符串值不判(shape 决定适用性,与写入门历来行为及firstRangeViolation的长度窗同款姿态)。reportRejectedEnvOverride:响亮 error(每 var+值 去重一次)+ 回落 cascade 下一层,键不置顶(env 来源的 settings 值绕过 manifest 的 options 表校验 —— #5094 在写入 API 上堵住的洞,在 OS_* 覆盖这一侧原样敞开 #5204 契约,与其余三族逐字一致)。注册时auditEnvOverrides也把 pattern 键纳入巡查,启动即上报。门间次序(binding 要求,明示如下)
两门判族次序一致:options(无 domain 时)→ pattern → valueDomain → bounds/step。写入门本来就是这个次序(options 分支在前,pattern 其后,#5712 的 domain 分支再后,#5932 的值窗最后);env 门本 PR 重排为同序——同一个值破多族时,两门报同一族,而不只是都拒。为此 env 门的 domain 判定从 options 的 if/else 对位移到 pattern 之后(与 options 互斥关系不变,行为仅在 pattern+domain 双破值上按写入门次序收敛)。
写入门逐字保持
invalid_format+constraint: { pattern }措辞、码、无value回显,均不变(新测试钉住);无效 RegExp 声明两门同宽容(钉住);ai.temperature等既有各族行为不动(全套 330 测试绿)。测试(新文件
settings-env-pattern.test.ts,12 例)全部用合成 manifest(#6579 正在并行改
company.manifest.ts,本 PR 不触任何 manifest 文件,fixture 对其落地次序鲁棒):invalid_format+constraint.pattern拒,信封逐字不变。反向验证(先预测后运行)
摘除 env 门的 pattern 调用(
if (pattern && false)),预测:env 各例红(响亮忽略、注册上报、不锁键、两个双破次序例的 env 半边),写入门/宽容钉/合法覆盖/落后族例绿。实测:5 红 7 绿,与预测逐条一致,恢复后 330/330 绿。迁移面核查(triage 的 escalation 条款)
未发现任何真实部署依赖「env 值绕过 pattern」:在库 pattern 键为
ai.gateway_model、ai.cloudflare_model、company.country、localization.default_country;全仓(含 docker/examples/docs)无OS_COMPANY_COUNTRY设值点;OS_AI_GATEWAY_MODEL仅见于部署文档,其记载用途(gateway model id,provider/model形)本身合 pattern;OS_LOCALIZATION_DEFAULT_COUNTRY仅测试内出现且值合 pattern。未触发 escalation。验证数字
pnpm --filter @objectstack/service-settings test:17 files, 330 passed, 0 failed。tsc --noEmit:13 errors,与 debt ledger 记录持平(所触两文件 0 错)。node scripts/check-nul-bytes.mjs:OK。🤖 Generated with Claude Code
https://claude.ai/code/session_01USNUyHEr7uaU6MoEWXitei
Generated by Claude Code