Merge authoritative main into the task branch

Why: include the current integration baseline before verification.

Evidence: fetched origin/main=6479eb5c38636e758b7e44a36fdc7ce6883ad1c9.

Impact: integrate upstream changes without rewriting task history.

Refs: task-sync
This commit is contained in:
2026-10-11 04:43:06 +00:00
4 changed files with 465 additions and 2 deletions
+199
View File
@@ -174,3 +174,202 @@ jobs:
run: make test
- name: Build the single binary
run: make build
# 协作存储方案 U2:真实 PostgreSQL + pgvector + Redis 门禁。
# 缺服务时失败而非跳过(make test-backend-pg 硬校验环境变量);
# 组件版本随 job 输出固定,供验收记录对齐(方案 KTD12/U2)。
test-pg:
runs-on: ubuntu-latest
env:
GOPROXY: https://goproxy.cn,direct
steps:
- name: Checkout
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
SUBMODULE_TOKEN: ${{ secrets.SUBMODULE_TOKEN }}
run: |
set -euo pipefail
# Credential handling stays inline: no file from the candidate is executed.
# Workflow provenance and runner isolation still require platform controls.
python3 - <<'PY_CHECKOUT'
import os
from pathlib import Path
import re
import subprocess
import sys
from urllib.parse import urlsplit
# 服务端基址取运行器注入的 GITHUB_SERVER_URL(平台控制、候选 PR 不可影响)。
# 2026-10-05 修复(run 948/949 实测):注入值为内网直连形态
# 'http://172.17.0.1:3000'(docker 网关 → 宿主 Gitea),与公网拼写不同且为
# http——此前硬编码常量严格比对会拒绝合法检出。校验收宽为「http(s) + 非空
# netloc」;凭据仍只附着于「该基址 + 下方仓库白名单」构造的 URL。
SERVER = os.environ.get("GITHUB_SERVER_URL", "").rstrip("/")
parsed_server = urlsplit(SERVER)
if parsed_server.scheme not in {"http", "https"} or not parsed_server.netloc:
sys.exit("Checkout server must be the platform-injected http(s) URL")
SSH = "ssh://git@git-ssh.u1680832.nyat.app:31411/weichen/"
# Reviewed allowlist, independent of candidate .gitmodules. Add repositories
# here only with an explicit review of the checkout credential's scope.
REPOSITORIES = {
"modules/core": "Agent-System-Core",
"modules/backend": "Agent-System-Backend",
"modules/frontend": "Agent-System-Frontend",
"modules/ui": "Agent-System-UI",
"modules/documents": "Agent-System-Documents",
"deps/agent-system-core": "Agent-System-Core",
"deps/development-guidelines": "Development-Guidelines",
"deps/agent-native": "Agent-Native",
"deps/agent-squad": "Agent-Squad",
"deps/agent-intent": "Agent-Intent",
"deps/agent-command": "Agent-Command",
"deps/error-code-system": "Error-Code-System",
"deps/logging-system": "Logging-System",
}
root_token = os.environ.pop("TOKEN", "")
component_token = os.environ.pop("SUBMODULE_TOKEN", "")
if not root_token or not component_token:
sys.exit("Checkout requires TOKEN and SUBMODULE_TOKEN")
if os.environ.get("GITHUB_REPOSITORY") != "weichen/Agent-System-Dev":
sys.exit("Checkout repository is outside the reviewed allowlist")
sha = os.environ.get("GITHUB_SHA", "")
if not re.fullmatch(r"[0-9a-fA-F]{40}", sha):
sys.exit("Checkout requires a fixed commit SHA")
# Discard inherited Git tracing/config/SSH hooks. Auth lives only in one
# Git process tree, in an exact URL-scoped header, never in a URL or file.
clean_env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
clean_env.update(GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_SYSTEM="/dev/null",
GIT_CONFIG_GLOBAL="/dev/null", GIT_TERMINAL_PROMPT="0")
config = {
"core.hooksPath": "/dev/null", "core.fsmonitor": "false",
"init.templateDir": "", "credential.helper": "",
"fetch.recurseSubmodules": "false", "submodule.recurse": "false",
"http.followRedirects": "false", "protocol.allow": "never",
"protocol." + urlsplit(SERVER).scheme + ".allow": "always",
}
def git(repo, *args, extra=None):
values = config | (extra or {})
env = clean_env | {"GIT_CONFIG_COUNT": str(len(values))}
for index, (key, value) in enumerate(values.items()):
env[f"GIT_CONFIG_KEY_{index}"] = key
env[f"GIT_CONFIG_VALUE_{index}"] = value
return subprocess.run(["git", "-C", str(repo), *args], env=env,
check=True, stdout=subprocess.PIPE).stdout
def materialize(repo, depth=0):
if depth > 16:
raise ValueError("Submodule depth exceeds the reviewed checkout limit")
links = {}
for entry in git(repo, "ls-tree", "-rz", "HEAD").split(b"\0"):
if not entry:
continue
metadata, path = entry.split(b"\t", 1)
mode, kind, commit = metadata.decode().split()
if mode == "160000":
links[path.decode()] = commit
if not links:
return
raw = git(repo, "config", "--no-includes", "--blob", "HEAD:.gitmodules", "--null", "--list")
entries = {}
for item in raw.split(b"\0"):
if not item:
continue
key, value = item.decode().split("\n", 1)
match = re.fullmatch(r"submodule\.(.+)\.(path|url)", key)
if not match:
raise ValueError("Unsupported candidate .gitmodules setting")
name, field = match.groups()
if field in entries.setdefault(name, {}):
raise ValueError("Duplicate candidate .gitmodules setting")
entries[name][field] = value
if set(entries) != set(links):
raise ValueError("Submodule names must match the fixed gitlink paths")
# Validate the entire level before any authenticated component fetch.
for name, fields in entries.items():
repository = REPOSITORIES.get(name)
if not repository or fields.get("path") != name:
raise ValueError("Submodule path is outside the reviewed allowlist")
trusted_url = f"{SERVER}/weichen/{repository}.git"
if fields.get("url") not in {SSH + repository + ".git", trusted_url}:
raise ValueError("Submodule URL is outside the reviewed allowlist")
for name in entries:
url = f"{SERVER}/weichen/{REPOSITORIES[name]}.git"
# Persist only the reviewed public URL so Git recognizes the
# initialized submodule after process-scoped config is gone.
git(repo, "config", f"submodule.{name}.url", url)
git(repo, "submodule", "update", "--init", "--checkout", "--", name,
extra={f"submodule.{name}.url": url,
f"submodule.{name}.update": "checkout",
f"http.{url}.extraheader": "AUTHORIZATION: token " + component_token})
child = repo / name
if git(child, "rev-parse", "HEAD").decode().strip() != links[name]:
raise ValueError("Materialized submodule does not match the fixed SHA")
materialize(child, depth + 1)
try:
root = Path.cwd()
# An ephemeral clean checkout is required; do not reuse prior Git state.
if (root / ".git").exists():
raise ValueError("Checkout requires a fresh workspace")
git(root, "init", "-q")
url = SERVER + "/weichen/Agent-System-Dev.git"
git(root, "remote", "add", "origin", url)
git(root, "fetch", "--depth=1", "origin", sha,
extra={f"http.{url}.extraheader": "AUTHORIZATION: token " + root_token})
git(root, "checkout", "-q", "--detach", "FETCH_HEAD")
materialize(root)
except (ValueError, OSError, subprocess.CalledProcessError) as error:
sys.exit(f"Checkout refused: {error}")
print("Checkout complete; credentials were not persisted in Git configuration")
PY_CHECKOUT
unset TOKEN SUBMODULE_TOKEN
- name: Install Go 1.27.1
run: |
set -euo pipefail
curl -fsSL -o "$RUNNER_TEMP/go.tgz" https://mirrors.aliyun.com/golang/go1.27.1.linux-amd64.tar.gz
tar -C /usr/local -xzf "$RUNNER_TEMP/go.tgz"
ln -sfn /usr/local/go/bin/go /usr/local/bin/go
ln -sfn /usr/local/go/bin/gofmt /usr/local/bin/gofmt
- name: Install house-style Python packages
run: python3 -m pip install --break-system-packages -i https://pypi.tuna.tsinghua.edu.cn/simple python-docx python-pptx openpyxl
- name: Install PostgreSQL, pgvector and Redis
run: |
set -euo pipefail
SUDO=""
if command -v sudo >/dev/null 2>&1 && [ "$(id -u)" != 0 ]; then SUDO=sudo; fi
$SUDO apt-get update -y
$SUDO apt-get install -y postgresql postgresql-contrib postgresql-16-pgvector redis-server
# 固定组件/扩展版本输出(随日志归档,作为验收对齐依据)。
psql --version
redis-server --version
- name: Start PostgreSQL and Redis
run: |
set -euo pipefail
SUDO=""
if command -v sudo >/dev/null 2>&1 && [ "$(id -u)" != 0 ]; then SUDO=sudo; fi
# 运行器容器以 root 运行且无 sudo:以 postgres 身份执行用 runuser/su
# (实测 $SUDO -u 在 root 容器展开成裸 "-u" → exit 127)。
pg_as_postgres() {
if command -v runuser >/dev/null 2>&1; then runuser -u postgres -- "$@";
else su postgres -s /bin/bash -c "$*"; fi
}
$SUDO service postgresql start || $SUDO pg_ctlcluster 16 main start
# 预装 pg_trgm 到 public:与测试辅助的幂等预装一致,锁定的组件契约;
# pgvector 版本一并输出(随日志归档,作为验收对齐依据)。
pg_as_postgres psql -tAc "CREATE EXTENSION IF NOT EXISTS vector"
pg_as_postgres psql -tAc "SELECT extname || '=' || extversion FROM pg_extension WHERE extname IN ('vector','pg_trgm')"
pg_as_postgres psql -c "CREATE USER ci_agent PASSWORD 'ci_job_local_only' CREATEDB"
pg_as_postgres psql -c "CREATE DATABASE agent_test OWNER ci_agent"
pg_as_postgres psql -d agent_test -c "CREATE EXTENSION IF NOT EXISTS pg_trgm"
redis-server --daemonize yes --port 6399 --save '' --appendonly no
redis-cli -p 6399 ping
- name: Backend tests against real PostgreSQL and Redis (required, no silent skip)
env:
AGENT_PG_TEST_DSN: postgres://ci_agent:ci_job_local_only@127.0.0.1:5432/agent_test?sslmode=disable
AGENT_REDIS_TEST_ADDR: 127.0.0.1:6399
run: make test-backend-pg
File diff suppressed because one or more lines are too long
+9 -1
View File
@@ -13,7 +13,7 @@ PLUGINS := plugins
COMBO := core=$(shell git -C $(CORE) rev-parse --short HEAD 2>/dev/null)+backend=$(shell git -C $(BACKEND) rev-parse --short HEAD 2>/dev/null)+frontend=$(shell git -C $(FRONTEND) rev-parse --short HEAD 2>/dev/null)+ui=$(shell git -C $(UI) rev-parse --short HEAD 2>/dev/null)+agentcmd=$(shell git -C deps/agent-command rev-parse --short HEAD 2>/dev/null)+documents=$(shell git -C modules/documents rev-parse --short HEAD 2>/dev/null)+native=$(shell git -C deps/agent-native rev-parse --short HEAD 2>/dev/null)+squad=$(shell git -C deps/agent-squad rev-parse --short HEAD 2>/dev/null)+intent=$(shell git -C deps/agent-intent rev-parse --short HEAD 2>/dev/null)
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null)+$(COMBO)
.PHONY: help sync status build frontend svc svc-list svc-info svc-commits svc-history svc-update test-backend test-frontend test-ui test-core test-agentcmd test-pins test-libs dev pin clean setup precheck task-start task-sync task-close task-finish facts-verify evidence version
.PHONY: help sync status build frontend svc svc-list svc-info svc-commits svc-history svc-update test-backend test-backend-pg test-frontend test-ui test-core test-agentcmd test-pins test-libs dev pin clean setup precheck task-start task-sync task-close task-finish facts-verify evidence version
version:
@echo "agent-system $(VERSION)"
@@ -101,6 +101,14 @@ test-core:
test-backend:
cd $(BACKEND) && go test ./...
# 真实 PG/Redis 门禁(协作存储方案 U2):缺环境直接失败而非静默跳过。
# CI 的必跑 job 提供原生服务;本地用 scripts/svc.sh db create <名> --port 8897
# 与 redis-server --port 6399 起隔离实例(见 docs/guides/team-storage.md)。
test-backend-pg:
@test -n "$${AGENT_PG_TEST_DSN}" || { echo "test-backend-pg: AGENT_PG_TEST_DSN 未设置(真实 PostgreSQL 必需,不静默跳过)"; exit 1; }
@test -n "$${AGENT_REDIS_TEST_ADDR}" || { echo "test-backend-pg: AGENT_REDIS_TEST_ADDR 未设置(真实 Redis 必需,不静默跳过)"; exit 1; }
cd $(BACKEND) && go test -count=1 ./...
eval-deliverables:
cd $(BACKEND) && go test ./eval/ ./internal/quality/ -count=1