feat(sandbox): 支持 github 注入与 GitHub 仓库资源挂载,升级 go-sdk 到 v7.26.12#449
Conversation
附带修复其内部 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
There was a problem hiding this comment.
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.
回应 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 可省略。
- 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 例外,方便后续提交示例配置。
|
@fennoai review |
|
/gemini review |
|
No issues found in the changed code. Checked the diff against Validation:
Residual risk: GitHub repository mount and sandbox-side injection still need maintainer-run integration coverage with real credentials, which this review did not execute. |
There was a problem hiding this comment.
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.
在 buildSandboxResources 解引用 GitRepositoryResource.AuthorizationToken 前补充 nil 检查,避免未来内部构造路径绕过 parser 时触发 panic。
|
[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 DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary
Commands.Connect重复关闭 channel 引发的 panic,并接入GitRepositoryResource必填字段校验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 仓库:透传到 SDKCreateParams.Resources,沙箱启动前由平台拉取仓库快照并挂载到指定路径。格式type=github_repository,url=<url>,mount-path=<absPath>,token=<token>,type可省略,mount-path也可写作mounturl、绝对mount-path(用path.IsAbs适配 POSIX)、必填token,检查同一沙箱内多个 GitHub 仓库资源必须共用同一 token,并在mount-path与mount同时给出且不一致时报错2.19.7变更范围
github.com/qiniu/go-sdk/v7到v7.26.12github类型支持(token 必填,禁用 base-url/headers)sandbox create增加--resource参数,支持 GitHub repository resourcegithubInjectionTarget常量集中描述固定目标域名docs/sandbox_create.md、injection rule 文档与CHANGELOG.md已知边界
--resourcetoken 与--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 时由维护者跑备注
--resource的token必填约束来自 go-sdkv7.26.12对GitRepositoryResource.AuthorizationToken的校验;即使同时配置了--inline-injection type=github,api-key=...,资源项仍需要显式传入token。