Repository navigation
test(cmd): 测试与本机真实家目录隔离,避免读到真实登录态 - #185
Merged
Merged
Conversation
cmd 包新增 TestMain:HOME 指向临时目录并清空 FEISHU_USER_ACCESS_TOKEN / FEISHU_PROFILE / FEISHU_APP_* 等环境变量。 此前本机已登录时,读类命令的测试会把真实 User Token 发给测试服务器;token 过期时还会向测试服务器发起刷新, 导致 TestDocMediaPreview 等结果随本机登录状态变化(CI 无登录态复现不了)。
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
问题
合并 #184 后,在 main 上跑发版前检查时,
TestDocMediaPreview在本机失败:请求记录里多出一次POST /open-apis/authen/v2/oauth/token。原因是
cmd包的测试没有和本机真实家目录隔离。本机已登录时,读类命令的测试会读取真实的~/.feishu-cli/token.json:CI 环境没有登录态,所以复现不了。
修复
新增
cmd/main_test.go的TestMain:HOME、USERPROFILE指向临时目录;FEISHU_USER_ACCESS_TOKEN、FEISHU_PROFILE、FEISHU_APP_ID/SECRET、FEISHU_CLI_SKILLS_DIR。这里只改环境变量,不替换
profile.homeFunc。部分测试会再用t.Setenv("HOME", ...)指定自己的家目录,替换后这些测试会失败。改动只涉及测试,不影响二进制行为。
验证
main_test.go后,TestDocMediaPreview在本机失败;恢复后通过。token.json的 mtime 在测试前后不变。go vet ./...、go test ./...(22 个包全部 ok)、go test -race ./...、make check-skills、make check-privacy全部通过。