fix: ship loc_additions thresholds so the new batch metric takes effect - #7
Merged
Conversation
`loc_additions` was added as the preferred batch-size metric, but no config example carried it, so `init` read `undefined` from every template and the metric never activated. Users had to hand-edit YAML to enable it — with no example to copy from. Why the metric matters: `loc_changes` sums additions and deletions, so a refactor that nets 3,000 lines removed (3,000 added, 6,000 deleted, 9,000 combined) rates the same as a 9,000-line feature batch. Batch risk is about how much new code shipped, not how much churn there was. Added to all six shipped configs — the three presets plus the root example and both files under `examples/gitlab-configs/`, since those are what people actually copy. Thresholds reuse each file's existing `loc_changes` values rather than inventing a ratio. Additions are always ≤ additions + deletions, so the same numbers applied to additions alone can only relax a rating, never tighten it: no existing project gets downgraded by upgrading. The numbers can be tuned against real distributions later. The test reads the shipped files from disk and pushes them through `ThresholdsSchema`, which catches both ways this can regress: someone removing the field from a config, and someone changing the schema so zod strips it on load. That second case has precedent here — `release_interval_days` and `code_freeze_days` are present in every config, absent from the schema, and silently discarded, while freeze-period assessment reads hardcoded constants instead (#6). Passing validation does not prove a field is live, so the acceptance check was `release:analyze --show-config` actually printing the "in effect" section for all six configs. Closes #2 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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 #2。
#1引入了loc_additions(以「新增行數」評估批量,優先於loc_changes),但沒有任何設定檔範例帶這個欄位,所以init.ts:298從每個 template 讀到的都是undefined,這個判準在預設安裝下永遠不生效。使用者要自己手改 YAML 才能啟用,而 YAML 裡沒有範例可抄。加到全部六份出貨設定檔——三個 preset 加上根目錄的
.gitlab-analysis.example.yml與examples/gitlab-configs/下的兩份,因為後三份才是使用者實際會拿去抄的。另補src/presets/README.md的說明。閾值數字沿用各檔既有的
loc_changes不發明新比例。
additions ≤ additions + deletions恆成立,所以同一組數字套在「只算新增」上只會讓評級變寬鬆、不會變嚴格——既有專案升級後不會突然被降級。數字之後可依實際分佈再調。安全性檢查清單
.env管理所有配置資訊./scripts/check-secrets.sh並通過檢查npm testcheck-secrets.sh的檔案內容掃描 ✅ 通過。所有數字為設定閾值,無真實團隊資料。測試計畫
驗收條件不是「YAML 有那幾行」,而是它真的被讀進去並生效。 這個 repo 有反例:
release_interval_days與code_freeze_days出現在每一份設定檔、卻不在ThresholdsSchema內,載入時被 zod 靜默 strip,而凍結期評估其實讀的是硬編碼常數(見 #6)。驗證通過不代表欄位有生效,所以實測了六份設定檔:六份全部印出「生效中」,且
loc_changes被正確標記為已被取代。自動化驗證:
新增
tests/unit/presets/shipped-config-thresholds.test.ts(18 個測試)。它從磁碟讀真實的出貨設定檔再過ThresholdsSchema,所以兩種退化都抓得到:loc_additions第 2 種特別重要,因為
safeParse在欄位被 strip 時仍然回傳 success——測試斷言的是result.data.loc_additions存在,不只是驗證通過。突變測試(兩種退化各驗一次):
mobile-app.example.yml移除loc_additionsThresholdsSchema移除loc_additions第三組測試釘住「
loc_additions的閾值不得比loc_changes嚴格」,作為上述「升級不應讓既有專案降級」這個承諾的迴歸保護。相關 Issue
Closes #2