Merge pull request #2431 from pikasTech/fix/2424-jd01-agentrun-gitea-repo

fix: allow JD01 Gitea mirror for AgentRun dispatch
This commit is contained in:
Lyon
2026-07-07 09:08:20 +08:00
committed by GitHub
2 changed files with 35 additions and 7 deletions
@@ -0,0 +1,23 @@
import { strict as assert } from "node:assert";
import { test } from "node:test";
import {
DEFAULT_AGENTRUN_REPO_URL,
GITEA_AGENTRUN_REPO_URL,
resolveAgentRunRepoUrl
} from "./code-agent-agentrun-profile.ts";
test("resolveAgentRunRepoUrl allows approved internal mirrors", () => {
assert.equal(resolveAgentRunRepoUrl({}), DEFAULT_AGENTRUN_REPO_URL);
assert.equal(
resolveAgentRunRepoUrl({ HWLAB_CODE_AGENT_AGENTRUN_REPO_URL: `${GITEA_AGENTRUN_REPO_URL}/?token=ignored#fragment` }),
GITEA_AGENTRUN_REPO_URL
);
});
test("resolveAgentRunRepoUrl rejects unapproved internal repo URLs", () => {
assert.throws(
() => resolveAgentRunRepoUrl({ HWLAB_CODE_AGENT_AGENTRUN_REPO_URL: "http://gitea-http.devops-infra.svc.cluster.local:3000/other/HWLAB.git" }),
(error) => error?.code === "agentrun_internal_repo_url_required"
);
});
+12 -7
View File
@@ -4,6 +4,7 @@
import { truthyFlag } from "./server-http-utils.ts";
export const DEFAULT_AGENTRUN_REPO_URL = "http://git-mirror-http.devops-infra.svc.cluster.local/pikasTech/HWLAB.git";
export const GITEA_AGENTRUN_REPO_URL = "http://gitea-http.devops-infra.svc.cluster.local:3000/mirrors/pikasTech-HWLAB.git";
const ADAPTER_ID = "agentrun-v01";
const AGENTRUN_BACKEND_PREFIX = ADAPTER_ID;
@@ -42,18 +43,22 @@ export function resolveAgentRunRepoUrl(env = process.env) {
const raw = firstNonEmpty(env.HWLAB_CODE_AGENT_AGENTRUN_REPO_URL, env.HWLAB_BOOT_READ_URL, DEFAULT_AGENTRUN_REPO_URL);
const url = new URL(raw);
const host = url.hostname.toLowerCase();
const allowedHost = "git-mirror-http.devops-infra.svc.cluster.local";
const allowedByTest = truthyFlag(env.HWLAB_CODE_AGENT_AGENTRUN_ALLOW_NON_K3S_URL) && ["127.0.0.1", "localhost"].includes(host);
if (url.protocol !== "http:" || (host !== allowedHost && !allowedByTest)) {
throw Object.assign(new Error(`HWLAB_CODE_AGENT_AGENTRUN_REPO_URL must use internal k3s git mirror ${DEFAULT_AGENTRUN_REPO_URL}; got ${redactUrl(raw)}`), {
url.pathname = url.pathname.replace(/\/+$/u, "");
url.search = "";
url.hash = "";
const normalized = url.toString().replace(/\/+$/u, "");
if (url.protocol !== "http:" || (!isAllowedAgentRunRepoUrl(normalized) && !allowedByTest)) {
throw Object.assign(new Error(`HWLAB_CODE_AGENT_AGENTRUN_REPO_URL must use an approved internal k3s git mirror (${DEFAULT_AGENTRUN_REPO_URL} or ${GITEA_AGENTRUN_REPO_URL}); got ${redactUrl(raw)}`), {
code: "agentrun_internal_repo_url_required",
statusCode: 500
});
}
url.pathname = url.pathname.replace(/\/+$/u, "");
url.search = "";
url.hash = "";
return url.toString().replace(/\/+$/u, "");
return normalized;
}
function isAllowedAgentRunRepoUrl(repoUrl) {
return repoUrl === DEFAULT_AGENTRUN_REPO_URL || repoUrl === GITEA_AGENTRUN_REPO_URL;
}
export function requireAgentRunSourceCommit(env) {