Skip to content

fix: ship loc_additions thresholds so the new batch metric takes effect - #7

Merged
lis186 merged 1 commit into
mainfrom
fix/preset-loc-additions
Jul 30, 2026
Merged

fix: ship loc_additions thresholds so the new batch metric takes effect#7
lis186 merged 1 commit into
mainfrom
fix/preset-loc-additions

Conversation

@lis186

@lis186 lis186 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

變更說明

Closes #2

#1 引入了 loc_additions(以「新增行數」評估批量,優先於 loc_changes),但沒有任何設定檔範例帶這個欄位,所以 init.ts:298 從每個 template 讀到的都是 undefined,這個判準在預設安裝下永遠不生效。使用者要自己手改 YAML 才能啟用,而 YAML 裡沒有範例可抄。

加到全部六份出貨設定檔——三個 preset 加上根目錄的 .gitlab-analysis.example.ymlexamples/gitlab-configs/ 下的兩份,因為後三份才是使用者實際會拿去抄的。另補 src/presets/README.md 的說明。

閾值數字沿用各檔既有的 loc_changes

不發明新比例。additions ≤ additions + deletions 恆成立,所以同一組數字套在「只算新增」上只會讓評級變寬鬆、不會變嚴格——既有專案升級後不會突然被降級。數字之後可依實際分佈再調。

安全性檢查清單

  • 我已確認沒有提交任何敏感資訊(tokens, passwords, 內部 URLs)
  • 我已確認沒有包含真實的公司/專案名稱
  • 我已使用 .env 管理所有配置資訊
  • 我已執行 ./scripts/check-secrets.sh 並通過檢查
  • 我已執行測試並通過:npm test

check-secrets.sh 的檔案內容掃描 ✅ 通過。所有數字為設定閾值,無真實團隊資料。

測試計畫

驗收條件不是「YAML 有那幾行」,而是它真的被讀進去並生效。 這個 repo 有反例:release_interval_dayscode_freeze_days 出現在每一份設定檔、卻不在 ThresholdsSchema 內,載入時被 zod 靜默 strip,而凍結期評估其實讀的是硬編碼常數(見 #6)。驗證通過不代表欄位有生效,所以實測了六份設定檔:

$ ./bin/run.js release:analyze -p group/project --config <每一份> --show-config
閾值設定:
  MR 數量:
    健康: < 50
    警告: <= 100
    危險: > 100

新增行數(生效中,優先於 LOC 變更):     ← 這一段以前永遠不會印
    健康: < 5000
    警告: <= 10000
    危險: > 10000

LOC 變更(未使用:已由新增行數取代):
    健康: < 5000
    警告: <= 10000
    危險: > 10000

六份全部印出「生效中」,且 loc_changes 被正確標記為已被取代。

自動化驗證:

npx tsc --noEmit                          # 0 錯誤
npx vitest run --no-file-parallelism      # 81 檔 / 1192 passed / 16 skipped(原 1174)

新增 tests/unit/presets/shipped-config-thresholds.test.ts(18 個測試)。它從磁碟讀真實的出貨設定檔再過 ThresholdsSchema,所以兩種退化都抓得到:

  1. 有人從設定檔移除 loc_additions
  2. 有人動了 schema 使它在載入時被 zod strip

第 2 種特別重要,因為 safeParse 在欄位被 strip 時仍然回傳 success——測試斷言的是 result.data.loc_additions 存在,不只是驗證通過。

突變測試(兩種退化各驗一次):

突變 結果
mobile-app.example.yml 移除 loc_additions 3 紅(該檔的 3 條測試)
ThresholdsSchema 移除 loc_additions 6 紅(六份檔案的 schema 保存測試)

第三組測試釘住「loc_additions 的閾值不得比 loc_changes 嚴格」,作為上述「升級不應讓既有專案降級」這個承諾的迴歸保護。

相關 Issue

Closes #2

`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>
@lis186
lis186 merged commit e893357 into main Jul 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loc_additions 閾值沒有任何設定檔範例帶,新的批量判準預設不生效

1 participant