Skip to content

feat(git): support tokens for generic HTTP repositories - #1279

Merged
crispinhu27 merged 21 commits into
mainfrom
feature/generic-http-git
Nov 24, 2026
Merged

crispinhu27 merged 21 commits into
mainfrom
feature/generic-http-git

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Self-hosted Git repositories can use their http:// clone URLs with personal Git tokens over standard Git HTTP transport.

  • Authorize an HTTP instance by entering its hostname or IP address and optional port under Git Host Trust.
  • Let users choose an authorized instance and enter a token plus a Git authentication username when required by the server. The repository access check runs git ls-remote against a clone URL at that endpoint.
  • Preserve managed repository web links and their hosting provider. Pasting git clone http://host/team/repo.git explicitly selects HTTP transport when the host is also managed.
  • Match credentials by scheme, host, and port. Git uses the execution environment's network and DNS. Git disables redirects for the authorized HTTP origin it actually accesses, including equivalent IPv6 spellings.

Scope

  • Platform core / API / runner

Compatibility

HTTP authorizations use a separate table and an additive credential field. Existing HTTPS credentials resolve using their original host keys. HTTP transmits Git Basic credentials in cleartext. HTTP repositories and plaintext credentials on execution machines require Runner 0.12.1 or later. Task claims, workspace preparation, and terminals filter plaintext credentials by Runner capability. PR and MR APIs are handled by provider integrations.

Validation

  • Re-ran the four failing platform/core regressions with Go and Node available, the complete Web Go package, and the Quick Access suite. Added coverage for managed links and explicit HTTP, Runner version gating, revoked authorizations, and equivalent IPv6 spellings.
  • Re-ran the domain, gitwork, and repo Go suites, with targeted tests in HTTP API, runtime, runner, engine, tracker, and OpenAPI. The HTTP authorization regression verifies that a member can save and use a token after a platform administrator authorizes the host, and that revocation stops subsequent credential issuance.
  • Exercised ls-remote, clone, push, and fetch with Basic authentication against the native git-http-backend in Docker using ordinary hostname resolution.
  • Re-ran 14 platform Web tests covering Git credentials, SSH keys, admin authorization, and the project wizard.
  • The initial feature implementation passed the chatbot production build and all 484 tests on rerun.
  • Tested workspace preparation and terminal credential delivery on Runner 0.12.0 and 0.12.1. Exercised authenticated IPv6 listing, clone, push, and fetch against the native Git HTTP backend and verified that an unrelated host on the same port could still follow redirects.
  • Ran go vet on the affected packages, git diff --check, python3 scripts/check-public.py, and bash scripts/scan-secrets.sh.

Safety

  • Checked the published diff for credentials, internal endpoints, production data, and private infrastructure.
  • Preserved user files and unrelated changes.

@Robert0622

Copy link
Copy Markdown
Collaborator

I reviewed acd9cdd and tested a disposable private repository served by git-http-backend with Basic authentication. The updated helper completed ls-remote, clone, push, and fetch. The base Runner helper failed authentication against the same repository.

  • [P1] Restore the required platform check. TestExplainGitAuthFailure, TestProjectAdminLayout, and TestProjectWizard still assert the previous copy. TestRepositoryFormUsesSingleURL also caught the managed-link behavior change below. All four passed locally on 4ff0e73 and failed on this PR. platform/core job
  • [P2] Preserve managed repository links. HTTP links to the configured Gongfeng host previously resolved to the managed project identity and an HTTPS clone URL. The early return and catalog API now save these as transport-only repositories, so reusing those links loses existing HTTPS authorization and provider-backed sync. Please preserve the existing managed link format and make literal HTTP an explicit choice when the hostname overlaps. Web parser
  • [P2] Detect Runners that support plaintext Git. The base and PR Runners both report 0.11.2 and pass SupportsGitHTTP(). In the private-repository smoke test, the base helper failed with could not read Username and the updated helper cloned successfully. Please advertise a separate plaintext HTTP capability or version and show the upgrade requirement before dispatch. Workspace gate
  • [P2] Show revoked HTTP credentials as unavailable. A saved token with an empty authorized-host list still renders Git HTTP 已配置 in Quick Access. Credential issuance requires an active authorization. Please factor that authorization into the readiness state. Quick Access
  • [P2] Apply the no-redirect policy consistently to IPv6 endpoints. The helper canonicalizes IPv6 for credential lookup. Git's URL-scoped configuration can miss the no-redirect rule when the same address has a different valid spelling. Please cover the same endpoint spellings on both paths. Workspace Git configuration

@Robert0622

Copy link
Copy Markdown
Collaborator

Re-reviewed 6e1cc30. The four previously failing regressions passed locally, along with the managed-link and revoked-credential tests. A private IPv6 Git fixture passed ls-remote, clone, push, and fetch using the expanded address spelling. Platform CI

  • [P2] Apply the Runner capability check to workspace preparation and terminals. Task claims and chat turns filter plaintext Git credentials for Runner 0.11.2. The direct workspace request still copies them into both PreparationInvocation.GitHTTPCredentials and TerminalGitHTTPCredentials. A local request test on an unbound workspace reproduced all three cases: prepare, terminal-open preparation, and terminal credentials. Please apply the same filter to these requests so older Runners still get HTTPS credentials and only capable Runners receive credentials for plaintext Git. Workspace request
  • [P2] Preserve redirects for unrelated repositories on the same port. The IPv6 fallback sets a wildcard rule that also matches unrelated HTTP hosts with single-label names. Against an anonymous local Git fixture, ls-remote followed its normal redirect before workspace binding and failed with HTTP 301 after binding an IPv6 credential on the same port. Please scope redirect suppression to authenticated operations for the approved endpoint. Redirect rule

@Robert0622

Copy link
Copy Markdown
Collaborator

Re-reviewed 15a19e6. The workspace credential matrix for Runner 0.12.0 and 0.12.1 and the regression for redirect scope both pass. A native git-http-backend fixture on IPv6 passed ls-remote, clone, push, and fetch through the ordinary workspace shell. Platform CI

  • [P2] Keep standard Git helper scripts working with HTTP credentials. The wrapper replaces GIT_EXEC_PATH with a directory containing only git-remote-http. On Git 2.43.5, git submodule status in a local repository passed with HTTPS credentials and failed as soon as an HTTP host was added to the workspace binding. Git's shell setup loads git-sh-i18n relative to git --exec-path, so adding the system directory to PATH leaves that lookup broken. Please preserve Git's support-file lookup when wrapping the HTTP transport. Git wrapper
  • [P2] Apply the HTTP transport to native Git commands launched directly. The credential binding prepends the shim to the child PATH. localSandbox.command resolves Argv[0] against the parent PATH before it sets that environment. In the same private-repository fixture, direct ExecuteLocalCommand with git ls-remote failed with could not read Username. The workspace shell invocation succeeded. Please apply the bound executable search path to direct Git commands as well. Git binding · Native command launch

@Robert0622

Copy link
Copy Markdown
Collaborator

Re-reviewed 7f51e70. Both prior regressions pass. I also tested direct invocation and shell invocation against a private IPv6 Git fixture, including a recursive clone of a private submodule, push, and fetch. Platform CI

Please keep the Git helper directory used by credential-bound commands under Runner control across shared workspace turns. Build it from the installed Git distribution for the invocation or use a Runner-owned copy that workspace processes cannot modify. This needs to preserve the existing per-speaker credential isolation.

@Robert0622

Copy link
Copy Markdown
Collaborator

Re-reviewed 72709d1. On Docker, the Git helper mount is read-only and separate speakers successfully used their own credentials in the same workspace. The Git redirect, submodule, and terminal credential-scope checks also passed.

[P2] Preserve existing Docker workspace state when installing Git helpers. A Docker workspace that starts without Git credentials has no helper mount. The first credential-bound command invalidates the running sandbox, and the mount mismatch makes startup remove and recreate its container. I reproduced this in a disposable Docker workspace by running a credential-bound git --version. The command succeeded, the container ID changed, and the file I wrote under /tmp disappeared. The bind-mounted project file survived. Dependencies or running services in the container can be lost in the middle of a shared session. Can we provision the read-only mount before preparing new workspaces and give existing workspaces an explicit migration that restores preparation before accepting another command? Container replacement

@crispinhu27

Copy link
Copy Markdown
Collaborator Author

I reverted 59b3e026 to remove the separate IDE/API migration. In 6c76e717, new Docker workspaces get the Runner-owned, read-only Git helper mount when the container is created. This also covers workspaces that start without credentials and receive their first token later. Docker workspace review

A graceful personal Runner update already closes its managed shared sandboxes. Platform workers can retain containers across deploys. If a retained container lacks the mount, credential binding reports it and leaves the running container in place. Its normal recreation installs the mount and uses the existing preparation flow.

I verified both paths with disposable Docker workspaces. The first token preserved the new workspace's container ID and /tmp marker. The retained container kept its state when binding was refused, and normal recreation reused the project directory and replayed preparation.

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

指定提交已在专用 Compose 环境部署,平台和 MySQL 均健康。实测发现两处需要修复。

  • [P2] 浏览器无法完成 HTTP 仓库访问检查。 保存 HTTP 令牌后,在凭据弹窗点击「检查仓库访问」。预期可输入克隆地址并确认。Chromium 实测中,地址提示框位于仍打开的原生模态弹窗下方,输入框无法获得焦点,确认按钮也收不到点击。同一仓库直接调用验证 API 返回 repositoryReadable=true。凭据弹窗
  • [P2] 保存 HTTP 令牌会阻止纯脚本 Docker SOP 启动。 用未安装 Git 的 node:22-bookworm-slim 运行仅含 printf 的 SOP,再为同一账号保存该 SOP 用不到的 HTTP Git 令牌并重跑。预期脚本照常执行,实际在启动前报 copy Git helpers from sandbox image: exit status 127。保存前和撤销授权并删除令牌后,同一 SOP 均执行成功。命令启动 · Git 助手准备

实测

  • 核对 HEAD 与提供的 base,三点 diff 检查通过。首次 Compose 构建因默认客户端缓存只读退出,改用任务临时目录后构建并启动成功。容器标签和镜像内提交号均与 HEAD 一致。
  • 使用提供的 GitHub 测试凭据请求账号和测试仓库 API,均返回 200。对该仓库执行 git ls-remote HEAD 成功。
  • Chromium 实测管理员授权和撤销 HTTP 主机、普通成员保存令牌。普通成员尝试授权和在授权前保存令牌均返回 403。仓库访问检查弹窗无法交互,直接调用 API 可读取私有测试仓库。换端口或撤销授权后,验证均被拒绝。
  • 平台 Docker 和实际注册的个人 Runner 0.12.1 均对专用 Basic Auth Git 仓库完成 ls-remote、克隆、fetch、子模块状态检查和 push dry-run。两端工作区终端执行 ls-remote 均退出 0。
  • 同一 Node slim SOP 依次在保存令牌前、保存后、撤销授权并删除令牌后执行,结果为成功、启动失败、成功。
  • 旧 Docker 工作区迁移、活动会话保留、Runner 0.12.0/0.12.1 能力及凭据筛选测试通过。原生隔离子用例因本机不支持而跳过。Web 和 Quick Access 定向测试各通过 12 项。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] 保存 HTTP Git 令牌后,Docker SOP 无法通过 PATH 使用运行中安装的 Git。 使用未预装 Git 的 node:22-bookworm-slim,为执行账号保存已授权的 HTTP Git 令牌,再在 SOP 中将 Git 安装到 /usr/local/bin。/usr/local/bin/git --version 返回 2.39.5,紧接着的 git --version 预期也能执行,实际报 git: executable not found: /run/loopforge-git/distribution/git 并退出 127。撤销授权并删除令牌后,同一 SOP 成功。Git 包装器固定从基础镜像的 Git 快照启动,该快照在镜像未预装 Git 时为空。快照准备 · Git 启动入口

实测

  • 核对 HEAD、指定 base 的三点 diff 和 git diff --check。在 loopforge-crispin-review 中完成 Compose 源码构建,容器标签和镜像内提交号均匹配 HEAD,平台和 MySQL 健康。
  • 使用提供的 GitHub 测试凭据请求账号和测试仓库 API,均返回 200。对测试仓库执行 git ls-remote HEAD 成功。
  • Chromium 实测管理员授权和撤销 HTTP 主机、普通成员保存令牌、输入克隆地址并完成访问检查。普通成员尝试授权或在授权前保存令牌均返回 403。错误端口和撤销后的验证均被拒绝,撤销后重新执行 Git 读取也被拒绝。仓库 API 保存了通用 HTTP 协议和克隆地址。
  • 平台 Docker 和个人 Runner 0.12.1 均对专用 Basic Auth 仓库完成 ls-remote、克隆、fetch、子模块状态检查和 push --dry-run。审批等待期间,两个工作区终端执行 ls-remote 均退出 0。
  • Node slim 纯脚本 SOP 在保存令牌前、保存后和删除后均成功。运行中安装 Git 的 SOP 在有令牌时因 git --version 退出 127 而失败,移除令牌后的对照运行成功。
  • Go 的 domain、gitwork、repo、Web 和 OpenAPI 测试通过。HTTP API、Docker 迁移、凭据隔离和 Runner 版本筛选的定向测试通过。原生沙箱子用例因测试机不支持而跳过。
  • Web 定向测试 12 项和 Quick Access 定向测试 12 项通过,chatbot 生产构建通过。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] 原生 Runner 上 Git 辅助目录固定在 /tmp,/tmp 挂 noexec 的机器上 HTTPS 的 Git 凭据也会失效。 main 上原生执行把 agentflow-helper 放在工作区的 .agentflow/runtime/bin,这个 PR 改成 nativeGitToolsRoot() 返回 /tmp/.loopforge-git-helpers-<uid>,原生路径的 helper 和 http-bin/git 都从那里执行。服务器把 /tmp 挂成 noexec 是常见加固,此时即使只配置 HTTPS 主机,Git 也会因 helper 无法执行而失败。在本机(/tmp 为 noexec)执行 /tmp/.loopforge-git-helpers-991/runner-*/credential/bin/agentflow-helper git-credential get 得到 Permission denied(126);同一容器里 go test ./internal/runtime 比 main 多 6 个失败,包括 TestSOPGitCredentialsUseAnEphemeralHostScopedRelay、TestBindGitWorkspaceFetchesTokenPerHost、TestRunSandboxBindsHostCredentialHelperForVerification、TestWithSandboxCredentialsRefreshesExplicitBindings、TestWorkspaceTerminalSandboxUsesOverlayAndPrivateCredentials、TestWorkspaceGitScopesHTTPRedirectsToAuthorizedOrigin,把该路径换到可执行盘后 6 个全过。建议回到工作区内的目录,或把 <workspace>/.loopforge-git-helpers 同级的可执行位置作为原生根。git_workspace_tools.go

[P3] 原生环境没有安装 Git 时,只绑定明文 HTTP 主机的非 Git 脚本也会启动失败。 prepareNativeGitDistribution 里 exec.LookPath("git") 失败直接报错 prepare Runner Git helpers: exec: "git": executable file not found in $PATH。只绑 HTTPS 主机时同一脚本正常。宿主一般都有 Git,影响面小,但与 edcf507 处理的 Docker 情况属于同一类。git_workspace_tools.go

实测

  • 复核 fafdb4f 提出的 P2:导出新旧两版 Docker 启动脚本,在宿主上模拟一个没有 Git 的镜像(/run/loopforge-git 挂载换成 /build/sim1279/root,distribution 为空,PATH 里没有 git)。fafdb4ff 版在运行中安装 Git 前后执行 git --version 都报 git: executable not found: .../distribution/git(127),与本 PR 描述一致;ce6dc80 版安装前报 git: not found(127),安装后 command -v git 指向 /usr/local/bin/git,git --version 输出 2.47.3,退出 0。该 P2 已修复。
  • 镜像自带 Git 时(用 copyGitDistribution 把宿主 Git 复制成快照),http-bin/git 仍排 PATH 最前,git --exec-path 指向 distribution/exec,git submodule status 退出 0,此前修过的子模块脚本问题没有回退。
  • 运行中安装的 Git 拿不到明文 HTTP 令牌:AGENTFLOW_GIT_HTTP_ORIGIN 为空时直接调用 agentflow-helper git-credential get 无输出、不访问网关;设置后才请求网关。失败方向是安全的。
  • 令牌不进日志:在 18179 环境保存 SEKRET-p1279-zzz 后在平台日志里检索不到;凭据列表接口不返回 token,并带 Cache-Control: no-store。
  • 授权:主机未授权时保存令牌 403,授权(201)后保存 200。Repo 级 TestWorkspaceGitScopesHTTPRedirectsToAuthorizedOrigin、TestPlainHTTP* 与 gitwork 包通过。
  • Runner 版本门槛从 0.12.0 升到 0.12.1,FilterGitHTTPCredentials、runner_dispatch、assistant_process 中的检查一致,engine/httpapi/domain 相关测试通过。
  • 本机没有 Docker,TestDockerScriptWithGitCredentialOnImageWithoutGit 一类用例无法运行,上述结论来自宿主上运行 PR 自身的启动脚本。原生隔离沙箱缺 bwrap,与本次改动无关。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

指定提交已部署,平台和 MySQL 均健康。实测确认 5 处需要修复的问题。

  1. [P2] Runner 无法重新打开保留旧 Docker 容器的凭据终端。 使用升级前的挂载布局,关闭终端并确认容器空闲后重新准备工作区。预期补齐只读挂载并打开终端,实际准备返回 ready,随后带有效 HTTPS 凭据的终端返回 HTTP 409,提示缺少挂载。同一夹具在 base 上可以打开终端。 workspace_preparation.go:150
  2. [P2] Docker 中运行时安装的 Git 无法使用已授权的 HTTP 令牌。 用未预装 Git 的 node:22-bookworm-slim 运行 SOP,在脚本内安装 Git 后读取私库。git --version 返回 2.39.5,同一令牌在平台校验中返回「仓库可读」,但 SOP 中的 git ls-remote 因无法读取用户名而退出 128。 sandbox_docker.go:241
  3. [P2] 原生执行环境缺少 Git 时,保存 HTTP 令牌会阻止纯 shell 脚本启动。 将 PATH 限定为只有 sh,运行仅含 printf 的脚本。无令牌及仅配置 HTTPS 凭据时均成功。配置 HTTP 令牌后,同一脚本在启动前报 exec: "git": executable file not found in $PATH。 git_workspace_tools.go:153
  4. [P2] 仓库路径级配置会覆盖 HTTP 跳转禁用规则。 仓库本地已有路径级 http.followRedirects=true 时,授权 HTTP 仓库的有效配置应为 false。直连 Git 和工作区 transport 的配置查询均返回 true。 https_host.go:49
  5. [P3] 个人配置列表显示了错误的协议。 在 Chromium 保存 http://host:port 的凭据后,列表将地址显示为 https://http://host:port,应显示实际保存的 HTTP 地址。 workbench.js:788

实测

  • 核对 HEAD、指定 base 的三点 diff 和 git diff --check。在同一 Compose 项目完成源码构建,平台和 MySQL 均健康,容器标签及镜像内提交号与 HEAD 一致。
  • 使用提供的 GitHub 测试凭据查询账号和私库列表,均返回 200。对该账号下的私有测试库执行 git ls-remote HEAD,退出 0。
  • Chromium 实测管理员授权和撤销 HTTP 主机、普通成员保存令牌及检查私库访问。普通成员授权和授权前保存均返回 403。正确令牌可读,错误令牌、不同端口和撤销后均被拒绝。留空令牌改名后仍可读,旧 ETag 撤销返回 412。
  • 显式 HTTP 仓库保存后,仅修改分支字段再重载,协议和克隆地址保持正确。模拟工蜂链接及显式 HTTP 克隆地址的 API 用例通过。
  • 平台 Docker 和实际注册的 Runner 0.12.1 均完成私库 ls-remote、克隆、fetch、子模块状态检查和 push --dry-run。两个工作区终端的 ls-remote 均退出 0。撤销主机授权后,新运行的私库读取被拒绝。
  • 实际注册 base Runner 0.12.0。普通 SOP 脚本成功,绑定 HTTP 仓库的请求在分发前返回 HTTP 400,并提示升级到 0.12.1。
  • 使用真实 Docker 容器对照旧挂载布局。平台本地迁移、活动终端保留和共享工作区凭据隔离用例通过。个人 Runner 的旧容器重开终端用例在 base 通过,在 head 失败。
  • 无 Git 镜像中的纯 shell SOP 在保存 HTTP 令牌前后均成功。将 Debian Git 安装到同类镜像的运行环境后,Git 可执行,使用已保存凭据读取私库失败。
  • 执行原生无 Git 的脚本绑定测试,以及直连和工作区的路径级跳转配置查询。分别复现脚本启动失败和有效配置仍为 true。
  • Go 的 domain、gitwork、repo、Web 和 OpenAPI 套件通过。HTTP API、engine、runner 和 runtime 的相关回归用例通过,原生隔离沙箱子用例因环境不支持而跳过。Web 和 Quick Access 定向测试各通过 12 项,chatbot 生产构建通过。

Robert0622
Robert0622 previously approved these changes Nov 24, 2026

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复测 c3379b0,对照上一轮评审的 6bcb0eb,期间新增 bf0a857 和 c3379b0 两个提交。上一轮的 5 个问题都已处理,没有发现新的阻塞问题,通过。

上一轮问题的处理

  • [P2] 仓库路径级配置会覆盖 HTTP 跳转禁用:已修复。现在 followRedirects=false 写在完整的仓库 URL 上(GIT_CONFIG_COUNT)。Git 按路径最长匹配,长度相同时命令行配置后读取,所以这条规则会生效。实测方法:起一个返回 302 的 HTTP 源,由跳转目标记录收到的请求;然后在仓库本地分别写入 http.<host>/team/app.git.followRedirects=true、.../team/app.git/、.../team/ 三种路径级配置。
    • 6bcb0eb:有效配置是 true,三种情况下 Git 都跟着跳到了另一个端口(跳转目标收到 /team/app.git/info/refs)。
    • c3379b0:有效配置都是 false,Git 停在 302(The requested URL returned error: 302),跳转目标一个请求都没收到。不写本地配置、只写主机级配置时,两个提交都是 false。
  • [P2] 原生执行环境没有 Git 时,保存 HTTP 令牌会让纯 shell 脚本无法启动:已修复。PATH 里只有 sh、绑定了 HTTP 令牌,运行 printf:
    • 6bcb0eb:报 prepare Runner Git helpers: exec: "git": executable file not found in $PATH
    • c3379b0:输出 script ran,新用例 TestNativeScriptWithGitCredentialOnHostWithoutGit 通过。
    • 有 Git 的情况没有受影响:私库由本机带 Basic 认证的 git-http-backend 提供,经 shell 和直接调用 git 执行 ls-remote 都能读到 refs/heads/main;令牌错误时返回 Authentication failed。
  • [P3] 个人配置列表把 HTTP 地址显示成 https://http://…:已修复。在 Chromium 里,个人配置的 Git 列表显示 其他 Git · http://172.18.0.4:18480(截图 1)。webtest/tests/git-http-credentials.test.mjs 3/3 通过。
  • [P2] Runner 无法重新打开旧 Docker 容器的凭据终端:现在工作区准备阶段会调用 RefreshWorkspaceGitTools。只有在容器没有活动终端、并且 docker inspect 显示没有正在执行的 exec 时才重建容器,补上只读挂载。conversation、preparation、terminal 三个调用点都在拿到工作区独占锁之后才调用,逻辑上没问题。
  • [P2] Docker 中运行时安装的 Git 用不了 HTTP 令牌:c3379b0 已修复。镜像里没有 Git 时,沙箱会去掉 http-bin 并设置 AGENTFLOW_GIT_HTTP_SYSTEM_GIT=1,凭据 helper 不再要求 origin 一致。即便如此,也只会为已授权、且本轮确有凭据的 HTTP 主机返回令牌,跳转到其他主机时拿不到令牌。原生路径把这个变量设为空,行为和之前一样(上面的原生实测就是在 c3379b0 上跑的)。文档里也写明了:运行时安装的 Git 使用它自己的跳转设置。

本机没法实测的部分:上面两项 Docker 修复,我只做了代码审查。容器里不能运行 Docker,TestRunnerWorkspacePreparationRefreshesLegacyDockerGitMount、TestDockerGitToolsRefreshAfterLegacyContainerBecomesIdle、TestDockerScriptWithGitCredentialOnImageWithoutGit 在本机都被跳过了。建议合入前在有 Docker 的环境里,加上 AGENTFLOW_TEST_GIT_HELPERS_DOCKER=1 把这三个用例跑一遍。

部署实测(c3379b0)

  • 环境:原生部署 PR head(Go 1.26.11,MySQL 8.4.7 新建的库,按 PR 重新构建 chatbot),建了 admin 和 bob 两个本地账号。私库由本机带 Basic 认证的 git-http-backend 提供(http://172.18.0.4:18480/team/app.git)。
  • 授权:普通成员授权 HTTP 主机返回 403。管理员授权之前保存令牌,返回 403「请联系平台管理员先授权该 HTTP Git 主机」。管理员授权返回 201,之后 bob 保存令牌返回 200。
  • 检查仓库访问:令牌正确时返回 repositoryReadable: true(截图 2)。仓库不存在或令牌错误时,都提示无法读取;换一个端口,提示「仓库地址必须与此令牌的 HTTP 主机和端口一致」。git 服务端日志确认请求带的是 git-user 的 Basic 认证。

测试

  • ./internal/gitwork 全部通过;go vet(gitwork、runtime、runner)通过。CI 15 项检查全绿(包括 core)。
  • ./internal/runtime 里与 Git、HTTP、Credential、Binding 相关的用例全部通过,只有 TestEnvironmentIdentityGitAndMCPHeaders 失败,原因是本机没有容器网络,在 6bcb0eb 上同样失败。
  • ./internal/repo 和 ./web 通过。./internal/runtime、./internal/runner、./internal/engine 其余的失败都是本机缺 bwrap 或 Docker 引起的(报错 bwrap sandbox unavailable)。runner 的 25 个失败用例和 6bcb0eb、main 完全一致,engine 的 80 个失败用例和 main 完全一致,都不是这个 PR 引入的。TestBrowserViewCapturesLighterFramesWhileScrolling 只在并发跑时偶尔失败,单独重跑能通过。

截图 1:个人配置的 Git 列表正确显示 HTTP 地址
1279-01

截图 2:检查 HTTP 私库的访问权限,结果为「仓库可读」
1279-02

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复测 3efd8f8(Merge main into generic HTTP Git branch)。上一轮在 c3379b0 上已经 approve,这次只有合并 main 这一个提交,部署实测和测试都正常。但合并后 Runner 的版本门槛和 main 撞了,HTTP 仓库的版本检查对 main 构建的 Runner 失效了。建议改完再合,这次先不 approve。

[P2] 合并后 RunnerVersionGitPlainHTTP 和 main 已有的 RunnerVersionProjectCredentials 都是 0.12.1,Runner 版本没有再往上升

  • internal/domain/runner.go:159 RunnerVersionGitPlainHTTP = "0.12.1",:182 RunnerVersionProjectCredentials = "0.12.1"(#1295 已经合进 main)。冲突解决时 internal/runner/daemon.go:1462 保留了 main 的 runnerVersion = domain.RunnerVersionProjectCredentials,所以本 PR 的 Runner 仍然上报 0.12.1。对比合并前后本 PR 相对 main 的改动,唯一的差别就是不再修改 runnerVersion 这一行。
  • 问题在于:用当前 main 构建的 Runner 也上报 0.12.1,但它没有本 PR 的 HTTP 支持。main 的 internal/gitwork/http_credentials.go:45 只处理 https,:78 的凭据 helper 是 test "$protocol" = https || exit 0。
  • 实测:把 main(177d881)构建的 Runner 接到本 PR 的平台上,GET /api/runners 显示 runnerVersion: "0.12.1"。在本 PR 代码里,Runner{RunnerVersion: "0.12.1"} 的 SupportsGitPlainHTTP() 返回 true,FilterGitHTTPCredentials 会保留 http:// 凭据。
  • 后果:如果在本 PR 合入之前从 main 发版,那个版本的 Runner 连到合入本 PR 后的平台时,requireRunnerRepositoryCapabilities(internal/engine/runner_dispatch.go:129)、assistant_process.go:563 等处的检查都会放行 HTTP 仓库,并把 http:// 凭据发给它。但 Runner 自己的 helper 不会提供这个凭据,结果会是 Git 认证失败。这一步是按代码推断的,没有在 main 构建的 Runner 上跑完整的 SOP;作为参照,本机不带凭据用 git 访问同一个私库,报错是 could not read Username ... terminal prompts disabled。用户看不到本 PR 设计的「Git HTTP 仓库需要 Runner … 请先升级执行机器」提示。
  • 建议:和 #1284 合并 main 后的处理(0.12.2 → 0.12.3)一样,把 RunnerVersionGitPlainHTTP 升到合入时 main 上还没被占用的下一个版本(现在是 0.12.2;#1284 已经用了 0.12.3,如果它先合入,这里就要用 0.12.4),runnerVersion 改成指向它,同时更新 docs/deployment.md:151 里的 “HTTP repositories on an execution machine require Runner 0.12.1 or later”。docs/deployment.md:104 那处 0.12.1 是项目凭据的,保持不变。

合并冲突的其他部分没有问题

  • internal/runtime/sandbox_docker.go 的 execOnce:先调用 #1295 的 projectCommandEnvironment,再调用本 PR 的 prepareCommandGitTools(ctx, command.environment),两个错误都包成 errProcessNotStarted,顺序合理。
  • internal/domain/runner.go 的两段常量和方法都保留了,没有残留冲突标记。

部署实测(3efd8f8)

  • 原生部署 head(Go 1.26.11,MySQL 8.4.7 全新库,按 PR 重新构建 chatbot),健康检查 200。私库是本机起的一个带 Basic 认证的 git-http-backend(http://172.18.0.2:18480/team/app.git),没有用 Tencent/LoopForge 测。
  • 普通用户 bob 在管理员授权前保存令牌,返回 403「请联系平台管理员先授权该 HTTP Git 主机」;bob 自己去授权主机,返回 403;管理员授权返回 201;之后 bob 保存令牌返回 200。
  • 「检查仓库访问」:正确的仓库返回 repositoryReadable: true;仓库不存在时提示「无法读取仓库…」,服务端日志显示请求带了认证、返回 404;换一个端口,提示「仓库地址必须与此令牌的 HTTP 主机和端口一致」。

测试

  • go vet ./... 通过。chatbot 488 个用例里,message-queue-hook.test.jsx 的一个用例在 5 个分支并发构建时超时(2200ms),单独重跑 24/24 通过,main 上同样 24/24 通过。
  • ./internal/domain、./internal/gitwork、./internal/repo 全部通过。./internal/httpapi、./internal/runtime、./internal/runner、./internal/engine 的失败用例是 main(177d881)的子集,没有新增失败,都是本机缺 bwrap、Docker 导致的。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复测 ef0d723(Require a distinct Runner version for plain HTTP Git)。上一轮提的版本号问题已经改好。但这次用真实 CLI 在执行机器上实测时,发现用 CodeBuddy 的对话克隆 http:// 私库会认证失败,所以这次先评论,不 approve。

上一轮的 P2 已修复

  • RunnerVersionGitPlainHTTP 改成 0.12.2,internal/runner/daemon.go:1462 的 runnerVersion 也指向它,docs/deployment.md:151 同步改成 0.12.2。两个测试的基线版本也改成了 main 现有的 RunnerVersionProjectCredentials(0.12.1)。
  • 实测:同一个平台上接了两台执行机器。main(c3dd1b4)构建的 Runner 上报 0.12.1,本 PR 构建的 Runner 上报 0.12.2。在 main 那台上的对话里,平台日志记录了 git.plain_http_unavailable: Git HTTP 仓库需要 Runner 0.12.2 或更新版本,请先升级执行机器,没有把 http:// 凭据发给它。版本门槛按预期生效。
  • 合入顺序提醒:#1284 也改了 daemon.go 的同一行(升到 0.12.3),两个 PR 互相有冲突。本 PR 先合没问题;如果 #1284 先合,main 构建的 Runner 会上报 0.12.3 却没有 HTTP 支持,这里就要再升到 0.12.4。

[P2] 用 CodeBuddy 的对话克隆 http:// 仓库时认证失败:CLI 的 Bash 是登录 shell,PATH 被重置,http-bin/git 包装脚本失效

  • 环境:Debian/Ubuntu 上的原生沙箱执行机器,本 PR 构建的 Runner 0.12.2。私库是本机起的一个带 Basic 认证的 git-http-backend,管理员已授权这个 HTTP 主机,用户的令牌已保存,「检查仓库访问」返回 repositoryReadable: true。

  • 复现:在这台执行机器上开对话,用 CodeBuddy(iOA,deepseek-v4.1-flash)执行 git clone http://<host>/team/app.git。结果是 fatal: could not read Username for 'http://<host>': terminal prompts disabled,git 服务端日志里只有不带认证的请求。

  • 原因:

    • internal/runtime/command_binding.go:390 只是把 http-bin:bin 加到 CLI 进程的 PATH 前面。CodeBuddy 的 Bash 工具起的是登录 shell,会执行 /etc/profile。Debian 的 /etc/profile 会把非 root 用户的 PATH 直接改写成 /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games,所以 shell 里的 git 就成了 /usr/bin/git。在对话里看到的是 command -v git → /usr/bin/git,而 AGENTFLOW_WORKSPACE_GIT_BINS 这个环境变量还在。
    • 绕开包装脚本后,git_credential_helper.go:81-85 拿不到 AGENTFLOW_GIT_HTTP_ORIGIN,AGENTFLOW_GIT_HTTP_SYSTEM_GIT 也是空的,于是对 protocol=http 什么都不返回。GIT_TRACE 显示 git 调用了 agentflow-helper git-credential get,但没拿到用户名。
  • 对照(同一台机器、同一个工作区):

    • 在 CodeBuddy 里手动执行 PATH="$AGENTFLOW_WORKSPACE_GIT_BINS:$PATH" git clone …,克隆成功,服务端日志显示请求带了认证。说明令牌、会话网关和 helper 这条链路本身是通的。
    • 换成 Claude Code(DeepSeek deepseek-flash)执行同一条命令,command -v git 是 …/http-bin/git,克隆成功。
  • 影响:CodeBuddy 是默认执行器。在 Linux 原生执行机器上,用 CodeBuddy 的对话没法使用 http:// 仓库。按 path_helper 的规则推断,macOS 也会把 /usr/bin 排在前面。HTTPS 不受影响,因为它不依赖 PATH:GIT_CONFIG_* 里的 helper 直接回答 https。SOP 里的 CodeBuddy 节点用的是同一套环境绑定,估计也有这个问题,这次没单独测。

  • 建议:原生沙箱也要让包装脚本在登录 shell 之后依然生效。Docker 那边是在 dockerMCPCallLaunch 里把 $AGENTFLOW_WORKSPACE_GIT_BINS 重新加回 PATH。原生沙箱可以考虑两种做法:

    • 在对话 HOME 里写一个 .profile 或 .bash_profile,做同样的事。
    • 不依赖 PATH,比如把 GIT_EXEC_PATH 指向已经带 git-remote-http 包装的 distribution。

    另外建议加一个回归用例:先用登录 shell(sh -lc)重置 PATH,再跑 git ls-remote http://…。

测试

  • 本 PR 构建通过,go vet ./... 通过,chatbot 测试 488/488 通过。
  • ./internal/domain、./internal/gitwork 全部通过,TestGitHTTPRepositoryRequiresCompatibleRunner 通过。
  • ./internal/repo、./internal/runner、./internal/engine、./internal/httpapi、./internal/runtime 里的失败用例,main(c3dd1b4)上同样失败,没有新增失败。原因是本机没有 Chromium 和 Docker,测试进程还继承了外层环境的 Git 身份变量。
  • 部署方式:本机原生部署(Go 1.26.11,MySQL 8.4.7 全新库)。容器不允许创建 user namespace,用一个只处理 --chdir 和 bind 映射的 bwrap 替身跑原生沙箱。上面的 PATH 问题和 bwrap 无关:真 bwrap 用的是 --ro-bind / /,看到的是同一个 /etc/profile,环境变量也原样传进去。没有用 Tencent/LoopForge 当测试仓库。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复测 ca5b574(Merge main and preserve HTTP Git helpers in login shells)。上一轮的 P2(CodeBuddy 的登录 shell 重置 PATH 后,克隆 http:// 私库认证失败)已修好,合并 main 的冲突处理也没问题。这次真实部署实测通过,Approve。

登录 shell 修复(P2 已解决)

  • 原生沙箱:internal/runtime/command_binding.go:386-389 在有 http-bin 时把 GIT_EXEC_PATH 指向 distribution/exec。即使登录 shell 把 PATH 改回 /usr/bin,/usr/bin/git 也会通过这个目录里的 git-remote-http 包装去拿凭据。不依赖 PATH,比在 HOME 里写 profile 更稳。
  • Docker:sandbox_docker.go:254-269 在镜像带 Git 时同样导出 GIT_EXEC_PATH。镜像不带 Git 时仍去掉 http-bin 并设置 AGENTFLOW_GIT_HTTP_SYSTEM_GIT=1,和原来的行为一致。
  • 回归用例:TestWorkspaceGitScopesHTTPRedirectsToAuthorizedOrigin 新增了 login shell 子用例,本 PR 通过。我把 command_binding.go 里新加的 4 行去掉后,这个子用例失败,报错 could not read Username for 'http://[::1]:…': terminal prompts disabled,和上一轮实测看到的现象一样,所以这个用例能拦住回归。

合并 main

  • RunnerVersionGitPlainHTTP 升到 0.12.4,避开了 main 上 #1284 已占用的 0.12.3(RunnerVersionConversationSOPWorkspace)。daemon.go:1455 和 docs/deployment.md 都同步改了;两个测试的基线版本也改成了 RunnerVersionConversationSOPWorkspace。
  • runner_dispatch.go 冲突处理正确:保留了 main 的「复用对话检出需要 0.12.3」检查,requireWorkBranchCapabilities 换成了 PR 里改名后的 requireRunnerRepositoryCapabilities。后者包含 SSH、HTTP 和新建分支、继续分支的检查,没有漏掉。
  • 和当前 main(f3d4f41)合并没有冲突。GitHub 上的 CI 全部通过。

部署实测(本机原生部署,本 PR 构建)

  • 环境:Go 1.26.11 编译平台和 Runner,MySQL 8.4.7 全新库。Runner 上报 0.12.4,登记为普通成员 bob 的执行机器,共享给测试项目,使用原生沙箱。私库是本机起的一个带 Basic 认证的 git-http-backend(http://localhost:43380/team/app.git)。管理员授权了这个 HTTP 主机,bob 保存了自己的令牌。没有用 Tencent/LoopForge 当测试仓库。
  • CodeBuddy(iOA,deepseek-v4.1-flash)对话:上一轮在这里失败。
    • 这次对话里 PATH 仍被重置为 /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games,command -v git 是 /usr/bin/git,GIT_EXEC_PATH 指向 …/git-helpers/…/distribution/exec。
    • git clone http://localhost:43380/team/app.git 成功,修改后 git push origin HEAD:main 也成功。服务端日志里,首次不带认证的请求返回 401 之后,upload-pack 和 receive-pack 都带上了正确的认证。
    • 第二轮里:git --exec-path、git status、git log、git submodule status 都正常;显式执行 bash -lc 'git ls-remote http://localhost:43380/…' 也成功。
    • 越权检查:同一端口换成没有授权的 http://127.0.0.1:43380,返回 could not read Username … terminal prompts disabled,服务端只收到不带认证的请求。令牌没有发给未授权的主机。
  • Claude Code(DeepSeek deepseek-flash)对话:git 解析到 http-bin/git,GIT_EXEC_PATH 也已设置。clone、push、ls-remote 都成功,服务端日志显示请求带了认证。

测试

  • go vet ./... 通过。./internal/domain、./internal/gitwork 全部通过。./internal/engine 和 ./internal/httpapi 里 Git HTTP 和 Runner 相关的用例都通过,包括 TestGitHTTPRepositoryRequiresCompatibleRunner 和 TestSOPGitCredentialsAreHydratedOnlyOnAuthenticatedRunnerClaim。
  • chatbot 测试 494/494 通过。webtest 286/286 通过。
  • ./internal/runtime 里的 Docker 和 Chromium 用例在 main(f3d4f41)上同样失败,原因是本机没有 Docker 和 Chromium。TestSharedWorkspaceGitHelpersReadOnly/native 在 exit 12(往 exec 目录写探针文件成功)这一步失败,原因是容器不允许 user namespace,我用的是一个不做 --ro-bind 的 bwrap 替身,和本次改动无关。Docker 版的 login shell 用例需要显式开启,本机跑不了。

@crispinhu27
crispinhu27 merged commit 7bebfa5 into main Nov 24, 2026
16 checks passed
@crispinhu27
crispinhu27 deleted the feature/generic-http-git branch November 24, 2026 18:40
Robert0622 pushed a commit that referenced this pull request Nov 24, 2026
Conflicts take main's text with this PR's rule applied: user-facing SOP
wording becomes LOOP. The same rule is applied to the messages, comments,
prompts and tests that #1284 and #1279 added since the previous merge.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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