test: 实时 API 测试仅在 integration build tag 下编译 - #60
Merged
Merged
Conversation
HoneyBBQ
added this pull request to stack #62
September 28, 2026 10:10
HoneyBBQ
marked this pull request as ready for review
September 28, 2026 12:45
Live provider tests ran whenever an API key was present in the environment or a .env file, so a plain `go test -short ./...` could send billed requests. Move every live test, its helpers and the .env-loading TestMain into *_integration_test.go files guarded by `//go:build integration`, matching the existing Edge TTS test. The default build no longer reads any credential variables; the Copilot unit tests use a fixed token for their local server. Run live tests with: go test -tags integration -run '^TestIntegration_' ./...
Run the test job against the Go version declared in go.mod and the current stable release, fail when go mod tidy changes go.mod or go.sum, vet the integration-tagged tests on every run, and select live tests in the integration job with -tags integration.
HoneyBBQ
force-pushed
the
ci/test-isolation
branch
from
September 29, 2026 21:35
a5b37a1 to
ee97ab3
Compare
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.
问题
调用真实 provider API 的测试写在普通的
_test.go文件里,只要环境中有凭据就会执行。这些包大多在TestMain里加载.env。开发者本地有.env时,每次go test ./...都会发出计费请求,加-short也拦不住。Copilot 的单元测试还会读取GITHUB_COPILOT_TOKEN,并把它发给本地测试服务器。CI 只测一个 Go 版本,也不检查
go.mod和go.sum是否 tidy。改动
.env的TestMain,都移到带//go:build integration的*_integration_test.go文件里。涉及六个包:alibabacloud/images、anthropic/messages、github/copilot、google/generativeai、openai/completions、openai/responses。其中alibabacloud/images的TestMain是新加的。opencode/go的实时测试原本就在单独的文件里,只补上 tag 并按同样的规则改名。Edge TTS 包原本就用这个 tag。不加 tag 时,读取凭据的代码不会编译进测试二进制。DASHSCOPE_IMAGE_LIVE=1开关。go.mod声明的 Go 版本和最新稳定版上分别跑 build、vet 和单元测试,并跑go vet -tags integration,保证带 tag 的文件能编译。go mod tidy改动了go.mod或go.sum时,lint job 失败。集成测试 job 加上-tags integration,触发条件和 secrets 不变。mise.toml和docs/getting-started.md写明新的命令:go test -tags integration -count=1 -run '^TestIntegration_' ./...。验证
go build、go vet、go vet -tags integration、go test ./... -short -count=1 -race和go test ./... -count=1均通过。golangci-lint run加不加--build-tags integration都没有告警。actionlint通过。.env里写同样的值,再把HTTPS_PROXY/HTTP_PROXY指向一个关闭的端口。此时go test ./...加不加-short都通过。同样设置下加-tags integration,实时测试会执行并在代理上失败。这说明它们默认是被编译排除的,不是碰巧跳过。