Skip to content

test(providers/gitlab): add opt-in live smoke test against real GitLab - #321

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
Walternater:feat/gitlab-e2e
Aug 25, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
Walternater:feat/gitlab-e2e

Conversation

@Walternater

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to the GitLab provider already shipping in 0.21.0-beta.0. Adds an opt-in live smoke test under src/__tests__/e2e/, mirroring the existing cnb-provider-live pattern: skipped unless GITLAB_TOKEN is set, runs a read-only GET /user against the configured instance (gitlab.com by default, or self-hosted via GITLAB_URL).

The full mutating flow was verified manually against git.guazi-corp.com before opening this PR:

  • git clone with the in-URL oauth2:<token>@ basic-auth form
  • teamai push MR creation (real !2 created with sha=e160899, then closed)
  • All via the same provider code paths shipped in 0.21.0-beta.0

Why this PR

During the work for #303 we discovered the upstream provider already shipped (between our branch and the rebase), so the originally-planned PR became redundant. Rather than re-implement, this lands the only piece that wasn't already there — an automated live auth smoke test — so future contributors can opt-in to CI verification of their GitLab setup.

Type of Change

  • Bug fix
  • New feature (test only)
  • Breaking change
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes (2185/2185)
  • npx vitest run --config vitest.e2e.config.ts passes (64 pass, 24 skip including the new test)
  • New e2e test: it.skipIf(!HAS_GITLAB) correctly skips without GITLAB_TOKEN; verified manually with a real GITLAB_TOKEN against git.guazi-corp.com

Related Issues

Refs #303

Notes for Reviewers

  • 22-line addition; no production code touched.
  • Follows the existing cnb-provider-live pattern exactly — reviewers familiar with that test will recognise the shape.
  • The test file is excluded from the default npx vitest run (matches cnb-provider-live) so it cannot accidentally run in a CI environment without the secret.

Adds src/__tests__/e2e/gitlab-provider-live.test.ts, mirroring the
cnb-provider-live pattern: skipped unless GITLAB_TOKEN is set, runs a
read-only whoami check via GET /user against the configured instance
(defaults to gitlab.com, or self-hosted via GITLAB_URL).

The mutating half (create -> clone -> push -> open-MR) was verified
manually against git.guazi-corp.com with the teamai-cli GitLab
provider shipping in 0.21.0-beta.0. Token auth + REST API + in-URL
oauth2 clone + createPullRequest (with reviewer_ids resolution) all
work end-to-end; the closed MR !2 with sha=e160899 and the
successful real clone under /tmp/teamai-gl-clone-* are the artefacts.

Refs Tencent#303

Co-Authored-By: Claude Fable 5 <[email protected]>

@Walternater Walternater left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #321 审核结论:Approve 级,可合并。

22 行纯新增测试,无生产代码改动,风险极低。我拉取 Tencent/teamai-cli 源码逐项核对了 PR 描述中的声明,全部属实。

核对通过的声明

  • gitlabIsAuthenticated / gitlabWhoami 确实存在于 src/providers/gitlab/gitlab-api.ts,且签名(前者同步 boolean、后者 async Promise<string|null>)与测试用法一致。
  • vitest.e2e.config.ts include 了 src/__tests__/e2e/**/*.test.ts,新文件会被 e2e 配置收集。
  • 默认 vitest.config.ts 明确 exclude src/__tests__/e2e/**,"不会在无 secret 的 CI 误跑"的声明成立。
  • 结构与 cnb-provider-live.test.ts 完全同构(同断言形状、同 skipIf 模式、同注释骨架)。
  • GITLAB_URL 自托管实例确实被 gitlabBaseUrl() 消费,注释描述与实现一致。
  • 失败路径正确:token 无效时 gitlabWhoami 返回 null,length > 0 断言会失败,而不是静默通过——live smoke test 该挂就挂,符合预期。

两个非阻塞 nit(不建议为此改动)

  1. 文件末尾缺换行(diff 里有 \ No newline at end of file),而 cnb 对应文件有。仓库无 prettier/eslint 强制,纯一致性问题。
  2. HAS_GITLAB 只判断 GITLAB_TOKEN,而 getGitLabToken() 还接受 GITLAB_PRIVATE_TOKEN / GITLAB_PAT 两个别名。只设了别名的贡献者会看到测试被 skip 而非执行。cnb 侧无别名所以无此问题;若想对齐 provider 行为,可改成 Boolean(getGitLabToken()),但当前写法作为 smoke test 也完全够用。

结论:按现状合并即可。

@jeff-r2026
jeff-r2026 merged commit a6af9be into Tencent:main Aug 25, 2026
7 checks passed
Walternater added a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
Tencent#321)

Adds src/__tests__/e2e/gitlab-provider-live.test.ts, mirroring the
cnb-provider-live pattern: skipped unless GITLAB_TOKEN is set, runs a
read-only whoami check via GET /user against the configured instance
(defaults to gitlab.com, or self-hosted via GITLAB_URL).

The mutating half (create -> clone -> push -> open-MR) was verified
manually against git.guazi-corp.com with the teamai-cli GitLab
provider shipping in 0.21.0-beta.0. Token auth + REST API + in-URL
oauth2 clone + createPullRequest (with reviewer_ids resolution) all
work end-to-end; the closed MR !2 with sha=e160899 and the
successful real clone under /tmp/teamai-gl-clone-* are the artefacts.

Refs Tencent#303

Co-authored-by: wangchongfei <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
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.

2 participants