test(edge-api): 3792 行/121 Test 的 handlers_test.go 按域归位——包内生产代码与另 13 个测试文件早已按域切分,它是唯一没归位的 leftovers;拆成 10 个域测试文件后只剩 184 行/3 个 handlers.go 级 Test + 一份共享夹具(测试名集合与 helper 集合逐个相同、=== RUN 413=413、0 SKIP,净 +113 行是拆文件固有成本) - #2288
Merged
Conversation
…to 域 95 个 Test 按生产文件归位(纯搬家,Test 总数 303 守恒,含共享夹具与单测私有夹具归属整理) Co-authored-by: Cursor <cursor@vectorcontrol.tech>
…l 域 23 个 Test 归位,handlers_test.go 只留 3 个 handlers.go 级测试与共享夹具 Co-authored-by: Cursor <cursor@vectorcontrol.tech>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
做了什么
edge-server/internal/api/handlers_test.go是全仓最大的 Go 测试文件:3792 行 / 121 个func Test,而它所在的包生产代码早已按域切分(handlers_runs.go、handlers_projects.go、handlers_settings.go、handlers_artifacts.go、handlers_instances.go、handlers_agents.go、handlers_approvals.go、handlers_events.go、handlers_delivery_journal.go、model_catalog*.go、response_dto.go),测试也早已按域命名(handlers_settings_test.go、handlers_runtime_sessions_test.go、handlers_approvals_ownership_test.go、deploy_*_test.go×5、diff_apply_*_test.go×3 …)。这个巨型文件是这套约定下唯一没归位的 leftovers。本 PR 是纯搬家:121 个 Test 按被测生产文件归位,
handlers_test.go从 3792 行/121 Test 变成 184 行/3 Test(只留真正属于handlers.go的TestErrorResponseFormat、TestMuxUnknownPath、TestEnsureStoreNilRepoCreatesInMemory+ 一份共享夹具newTestHandler/fakeRunExecutor/allowTestWorkspace/drainEvents/assertNextEvent/assertErrorCode/unwrapSuccess/fakeCallbackJournal)。新建/扩充(Test 数):
handlers_runs_test.go53|handlers_projects_test.go30|handlers_approvals_test.go10|handlers_artifacts_test.go4|handlers_events_test.go4|handlers_delivery_journal_test.go2|handlers_agents_test.go2|response_dto_test.go2|model_catalog_test.go1|handlers_instances_test.go1|handlers_settings_test.go+9(原有 2 个保留)。守恒证明(主机独立复跑,比「数量对得上」更强)
即:既没有测试被删/被改名,也没有夹具被复制成两份。
证据
暗卷(主机自己做的一发,证明搬走的测试仍然会咬人):把
internal/api/handlers_projects.go:188的role := strings.TrimSpace(req.Role)改成role := "user",已搬到新文件的TestPostThreadMessageUsesRequestedRole立刻红:git checkout还原后复跑ok 0.013s。(车道自己另做了 2 发:GetDeliveryJournal跳过 entries、GetThreadPins跨线程过滤,均红→revert 复绿。)诚实记账
LEAK_GUARD_SKIP=1:本机 pre-commit leak-guard 对既有测试夹具const testCapSecret = "my-secret-key-for-capability-test-32"(master 的handlers_test.go:3141,随 Test 搬到handlers_runs_test.go:1132)报假阳性。主机复核:git grep -hoE "\"[A-Za-z0-9_-]*(secret|token|password|apikey|api_key)[A-Za-z0-9_-]*\""在 master 与 branch 两侧的字面量集合逐字相同(各 4 条,diff rc=0),且 CI 的check-secrets.sh --range通过 ⇒ 没有引入任何新敏感串。TestErrorResponseFormat测的是errcode.ErrorBody形状,留在handlers_test.go(handlers.go级);TestArtifactDiffPreviewReadOnlyRoutes…横跨 diff/artifacts/previews,按名归到 artifacts,可再议。scripts/verify/**与各基线 json 未动(已核:test-sleep-budget.json无internal/api条目,handlers_test.go的time.Sleep= 0,全部scripts/verify/*.jsongrephandlers_test.go= 0 命中 ⇒ 拆分不踩任何 per-file ratchet)。