Skip to content

feat(sandbox): 支持 github 注入与 GitHub 仓库资源挂载,升级 go-sdk 到 v7.26.12#449

Merged
qiniu-prow[bot] merged 11 commits into
qiniu:masterfrom
miclle:sandbox/sdk-v7.26.11-github-resource
May 12, 2026
Merged

feat(sandbox): 支持 github 注入与 GitHub 仓库资源挂载,升级 go-sdk 到 v7.26.12#449
qiniu-prow[bot] merged 11 commits into
qiniu:masterfrom
miclle:sandbox/sdk-v7.26.11-github-resource

Conversation

@miclle
Copy link
Copy Markdown
Contributor

@miclle miclle commented May 12, 2026

Summary

  • 升级 go-sdk 到 v7.26.12:附带修复 SDK 内部 Commands.Connect 重复关闭 channel 引发的 panic,并接入 GitRepositoryResource 必填字段校验
  • github 注入类型injection-rule create / update 以及 sandbox create --inline-injection 接入 SDK 的 GithubInjection,通过 --api-key / api-key= 传入 GitHub Token;平台克隆仓库与匹配 github.com / api.github.com 出站请求时自动注入,沙箱内不可见明文。CLI 层显式拒绝 base-url / headers,且 token 必填非空,避免 typo 静默成功
  • sandbox create --resource 挂载 GitHub 仓库:透传到 SDK CreateParams.Resources,沙箱启动前由平台拉取仓库快照并挂载到指定路径。格式 type=github_repository,url=<url>,mount-path=<absPath>,token=<token>type 可省略,mount-path 也可写作 mount
  • CLI 层提前校验资源参数:校验 url、绝对 mount-path(用 path.IsAbs 适配 POSIX)、必填 token,检查同一沙箱内多个 GitHub 仓库资源必须共用同一 token,并在 mount-pathmount 同时给出且不一致时报错
  • CHANGELOG 记录为 2.19.7

变更范围

  • 升级 github.com/qiniu/go-sdk/v7v7.26.12
  • 为 sandbox injection rule 和 inline injection 增加 github 类型支持(token 必填,禁用 base-url/headers)
  • sandbox create 增加 --resource 参数,支持 GitHub repository resource
  • 抽出 githubInjectionTarget 常量集中描述固定目标域名
  • 同步更新命令帮助、docs/sandbox_create.md、injection rule 文档与 CHANGELOG.md
  • 补充资源解析、GitHub injection、文档输出、mount/mount-path 冲突、token 一致性等单测

已知边界

  • --resource token 与 --inline-injection type=github 或已存在的 github --injection-rule 之间的一致性,CLI 不做跨参数比较,由平台侧校验
  • url 推荐使用 HTTPS 形式;SSH URL 含 , / : 等保留字符无法被解析

Test plan

  • make test 全部通过(包含 cmd_test/ 文档断言更新)
  • make test-sandbox-unit 通过
  • gofmt -s -l . 无输出
  • staticcheck ./iqshell/sandbox/... ./cmd/... 无新增告警
  • go build ./main/ 通过
  • go test ./iqshell/sandbox/... ./cmd_test/... 通过
  • go test ./... 通过
  • git diff --check 通过
  • make lint 当前仍会因仓库既有 staticcheck 历史问题失败,失败项不在本 PR 新增/修改文件中
  • 待集成验证:make test-sandbox-integration 需要凭据,依赖 PR review 时由维护者跑

备注

--resourcetoken 必填约束来自 go-sdk v7.26.12GitRepositoryResource.AuthorizationToken 的校验;即使同时配置了 --inline-injection type=github,api-key=...,资源项仍需要显式传入 token

miclle added 4 commits May 12, 2026 11:52
附带修复其内部 Commands.Connect 重复关闭 pidCh 引发的 panic(qshell 当前仅使用 sandbox 级 Connect,不直接触发,但升级后未来扩展更安全)。
- BuildInjectionParts / InjectionParts 新增 github 分支,通过 --api-key / api-key= 承载 GitHub Token
- injection-rule create / update / list / get 与 sandbox create --inline-injection 全链路打通 github 类型
- 平台克隆仓库与匹配 github.com / api.github.com 出站请求时自动注入 token,沙箱内不可见明文
- 补充单测、CLI 帮助与文档示例
- CreateInfo.Resources 透传到 SDK 的 CreateParams.Resources,沙箱启动前由平台克隆并挂载仓库快照
- 解析格式:type=github_repository,url=<url>,mount-path=<absPath>[,token=<token>],type 缺省按 github_repository 处理,mount-path 也接受 mount 别名
- 资源 token 与已配置的 github 注入凭证可共用,二者均可承载克隆所需 token
- 复用 sbClient.ParseMetadataMap 解析键值串,避免新增解析器重复
- 补充 buildSandboxResources 单测、CLI 帮助与文档示例
- 新增 github 注入类型
- 新增 sandbox create --resource 挂载 GitHub 仓库
- 升级 go-sdk 到 v7.26.11
@qiniu-prow qiniu-prow Bot added the size/L label May 12, 2026
Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

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

Reviewed in four passes (code quality, performance, security, documentation). I found a few user-visible correctness/documentation gaps worth tightening before merge.

Comment thread iqshell/sandbox/sandbox/operations/create.go
Comment thread iqshell/sandbox/utils.go
Comment thread docs/sandbox_create.md Outdated
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for GitHub-related features in the sandbox environment, including a new github injection type for credentials and a --resource flag for mounting GitHub repositories during sandbox creation. The changes include updates to CLI commands, documentation, and unit tests, alongside an upgrade of the go-sdk dependency to version v7.26.11. I have no feedback to provide.

miclle added 4 commits May 12, 2026 12:10
回应 PR review 反馈:

- BuildInjectionParts 的 github 分支显式拒绝 --base-url / --headers,
  避免 typo 看起来配置成功却被静默丢弃(github 目标固定为
  github.com / api.github.com,无可配置项)
- parseSandboxResource 在 mount-path 非空后追加 path.IsAbs 校验,
  让 CLI 直接报错而不是把相对路径传到后端再失败;用 path.IsAbs 而非
  filepath.IsAbs,避免 Windows 主机上把 /workspace 误判为相对路径
- sandbox_create.md 仓库挂载示例对齐 SDK 用语(拉取仓库快照)
- 新增三个回归用例覆盖以上校验
回应 PR review [P3]:同一沙箱内多个 GitHub 仓库资源必须共用同一 token
(go-sdk 注释明示约束)。当前实现仅逐条解析后交给后端,遇到不一致
token 时由平台克隆阶段返回较难理解的错误。

- buildSandboxResources 累计已见非空 token,发现冲突即报 CLI 错误
- 部分资源省略 token(继承沙箱级 github 注入)仍允许
- 新增 3 个回归用例覆盖一致/冲突/混合空非空场景
Adds `.env` and `.env.*` patterns to `.gitignore` to prevent environment variable files from being accidentally committed.
对齐 go-sdk v7.26.12 的 GitRepositoryResource 必填字段校验,将 sandbox create --resource 的 token 改为必填并提前返回 CLI 错误。

同步更新命令帮助、sandbox_create 文档、CHANGELOG 与资源解析测试,避免文档继续暗示资源 token 可省略。
@miclle miclle changed the title feat(sandbox): 支持 github 注入与 GitHub 仓库资源挂载,升级 go-sdk 到 v7.26.11 feat(sandbox): 支持 github 注入与 GitHub 仓库资源挂载,升级 go-sdk 到 v7.26.12 May 12, 2026
miclle added 2 commits May 12, 2026 16:51
- BuildInjectionParts(github) 在 token 为空 / 仅空白时直接报错,避免 typo 看起来配置成功却构造出无效注入
- parseSandboxResource 当 mount-path 与 mount 同时给出且不一致时报错,不再静默优先 mount-path
- --resource flag 帮助文本补充 CLI 历史泄漏警告,与 --api-key 描述保持一致
- 抽出 githubInjectionTarget 常量,集中描述 GitHub 注入的固定目标域名,方便后续 SDK 扩展时同步
- 文档:澄清 --resource 推荐 HTTPS URL、mount-path 绝对路径、同沙箱内 token 一致性以及与 --inline-injection 之间 token 一致性由平台校验
- CHANGELOG 2.19.7 文案微调,拆分自动注入与明文不可见的描述

补充配套单测:
- TestBuildInjectionParts_GithubEmptyToken 改为期望失败
- TestBuildInjectionSpecGithubRequiresToken 新增
- TestBuildSandboxResources_RejectsConflictingMountAliases / AcceptsAgreeingMountAliases 新增
澄清 --resource URL 中逗号才会影响键值串解析,并明确 github injection 的 --api-key 必填约束。

为 .env.* 忽略规则保留 .env.example 例外,方便后续提交示例配置。
@miclle
Copy link
Copy Markdown
Contributor Author

miclle commented May 12, 2026

@fennoai review

@miclle
Copy link
Copy Markdown
Contributor Author

miclle commented May 12, 2026

/gemini review

@fennoai
Copy link
Copy Markdown

fennoai Bot commented May 12, 2026

No issues found in the changed code.

Checked the diff against origin/master, reviewed the sandbox resource parsing and GitHub injection paths, and verified the updated test/doc surface.

Validation:

  • go test ./iqshell/sandbox/... ./cmd_test/...
  • git diff --check origin/master...HEAD

Residual risk: GitHub repository mount and sandbox-side injection still need maintainer-run integration coverage with real credentials, which this review did not execute.

View job run

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces GitHub integration for the sandbox environment, enabling GitHub credential injection and the mounting of GitHub repositories as resources. It adds the --resource flag to the sandbox creation command, supports the github injection type, and upgrades the Qiniu Go SDK to version 7.26.12. Review feedback recommended adding a defensive nil check for authorization tokens during resource parsing to enhance code robustness and prevent potential panics.

Comment thread iqshell/sandbox/sandbox/operations/create.go
在 buildSandboxResources 解引用 GitRepositoryResource.AuthorizationToken 前补充 nil 检查,避免未来内部构造路径绕过 parser 时触发 panic。
@qiniu-prow
Copy link
Copy Markdown
Contributor

qiniu-prow Bot commented May 12, 2026

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: miclle

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@qiniu-prow qiniu-prow Bot merged commit 593556b into qiniu:master May 12, 2026
5 checks passed
@miclle miclle deleted the sandbox/sdk-v7.26.11-github-resource branch May 12, 2026 09:24
@miclle miclle mentioned this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant