Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

feat: fail pull requests when coverage or a platform job drops (#115)

fx-kurumi9bc2058c6c0e
diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml
index c6043a9c..31c0a55c 100644
--- a/.github/workflows/platform.yml
+++ b/.github/workflows/platform.yml
@@ -34,10 +34,21 @@ jobs:
--user-data-dir="$RUNNER_TEMP/chromium-warmup" --dump-dom about:blank >/dev/null
# Real-Chromium tests run on their own: alongside the rest of the suite
# the browser can miss its DevTools liveness check on a loaded runner.
- - run: go test -p=2 ./... -count=1 -timeout=600s -skip "$REAL_BROWSER_TESTS"
- - run: go test -p=1 ./internal/httpapi ./internal/runner ./internal/runtime -count=1 -timeout=300s -run "$REAL_BROWSER_TESTS" -v
+ # Collect both isolated runs with identical instrumentation, then gate
+ # their union without rerunning the suite or counting a statement twice.
+ - name: Non-browser Go tests
+ run: go test -p=2 ./... -count=1 -timeout=600s -skip "$REAL_BROWSER_TESTS" -covermode=set -coverpkg=agentflow/internal/... -coverprofile="${{ runner.temp }}/go.cover"
+ - name: Real-browser Go tests
+ run: go test -p=1 ./internal/httpapi ./internal/runner ./internal/runtime -count=1 -timeout=300s -run "$REAL_BROWSER_TESTS" -v -covermode=set -coverpkg=agentflow/internal/... -coverprofile="${{ runner.temp }}/go-browser.cover"
+ - name: Coverage gate regression tests
+ run: python3 scripts/test-coverage-go.py -v
+ - name: Go statement coverage gate
+ run: |
+ min=$(tr -d '[:space:]' < scripts/coverage-go.min)
+ test -n "$min"
+ bash scripts/coverage-go.sh --profile "${{ runner.temp }}/go.cover" --profile "${{ runner.temp }}/go-browser.cover" --min "$min"
- name: Browser-free UI tests for the platform console
- run: npm ci --no-audit --no-fund && npm test
+ run: npm ci --no-audit --no-fund && npm run coverage
working-directory: webtest
- name: Install pinned CLIs for local protocol acceptance
run: npm install --global @openai/[email protected] @anthropic-ai/[email protected]
@@ -112,6 +123,12 @@ jobs:
LOOPFORGE_UNCONFIGURED_USER: e2e-no-key
LOOPFORGE_UNCONFIGURED_PASSWORD_FILE: ${{ github.workspace }}/.local/no-key-password
working-directory: e2e
+ # Separate steps so a failing suite stays failed: these are skipped
+ # unless every suite above succeeded, and a low hit rate fails the job.
+ - name: Export registered HTTP routes
+ run: AGENTFLOW_ROUTES_OUT="${{ runner.temp }}/routes.json" go test ./internal/httpapi -run '^TestRouteInventoryExport$' -count=1
+ - name: Require registered routes to be hit at least 85%
+ run: node e2e/coverage/route-coverage.mjs --routes "${{ runner.temp }}/routes.json" --log /tmp/loopforge.log --min 85
- uses: actions/upload-artifact@v7
if: always()
with:
@@ -166,3 +183,18 @@ jobs:
name: first-run-results
path: e2e/test-results/
if-no-files-found: ignore
+ platform-required:
+ # Stable check name for branch protection. An admin marks this required
+ # in GitHub; the workflow does not change repository settings.
+ name: platform-required
+ if: always()
+ needs: [core, browser, first-run]
+ runs-on: ubuntu-latest
+ steps:
+ - name: Require every platform job to pass
+ working-directory: ${{ runner.temp }}
+ run: |
+ if [[ "${{ needs.core.result }}" != "success" || "${{ needs.browser.result }}" != "success" || "${{ needs.first-run.result }}" != "success" ]]; then
+ echo "core=${{ needs.core.result }} browser=${{ needs.browser.result }} first-run=${{ needs.first-run.result }}" >&2
+ exit 1
+ fi
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index df88b458..8dc144c3 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -53,6 +53,19 @@ jobs:
working-directory: local/tools/tcmcp/web
run: npm ci && npm run build
+ curl-install:
+ # Once per workflow, outside the Python 3.8/3.12 matrix. The script
+ # installs Classic and Portable from a local fake release and does not
+ # contact github.com.
+ runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: local
+ steps:
+ - uses: actions/[email protected]
+ - name: Smoke-test curl install against a local fake release
+ run: bash scripts/smoke-curl-install.sh
+
secrets:
runs-on: ubuntu-latest
steps:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a06a896e..44bae788 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -18,6 +18,8 @@ Community contributions do not require private source manifests or hash updates.
Run the [public browser acceptance suite](e2e/public/README.md) for authentication, preferences or execution changes. Paid model and external knowledge tests require explicit operator configuration; state passed, failed, skipped and not-run checks accurately.
+Platform pull requests run the `core`, `browser`, and `first-run` jobs. The stable check `platform-required` fails unless all three succeed. A repository administrator has to mark `platform-required` as a required status check in GitHub branch protection. This repository does not change that GitHub setting.
+
For LoopForge Local, work inside `local/` and follow [local agent instructions](local/AGENTS.md). Identify whether a change affects Classic, Portable or shared behavior contracts. Keep these workflow assets independent from the platform and each other. Change Portable assets in `local/skills/`; rebuild generated Classic Cursor/Claude bundles with `python3 scripts/build-classic-hosts.py --write` from `local/`. Keep workflow templates generic; optional tools under `local/tools/` are distributed separately.
Run local checks from `local/`:
diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md
index 9cbccb39..81923150 100644
--- a/CONTRIBUTING.zh-CN.md
+++ b/CONTRIBUTING.zh-CN.md
@@ -15,6 +15,8 @@ bash scripts/scan-secrets.sh
登录、语言/主题或执行链路的改动需要跑[公共浏览器验收](e2e/public/README.md)。真实模型与外部知识库测试需显式配置;请区分通过、失败、跳过与未运行。
+平台的 pull request 会跑 `core`、`browser` 和 `first-run` 三个作业。稳定检查名 `platform-required` 只有三者都成功时才通过。仓库管理员需要在 GitHub 分支保护里把 `platform-required` 手动勾成必须通过的检查。这次代码改动不会修改 GitHub 上的分支保护设置。
+
LoopForge Local 请在 `local/` 内修改,遵循[本地开发约定](local/AGENTS.md)。先明确改动属于 Classic、Portable 或共享行为合同;三者与平台运行资产保持清晰边界。Portable 修改 `local/skills/`;Classic 的 Cursor/Claude 包在 `local/` 内运行 `python3 scripts/build-classic-hosts.py --write` 生成。工作流模板保持通用,可选工具放在 `local/tools/`,单独分发。
在 `local/` 内执行本地版检查:
diff --git a/docs/testing/acceptance-matrix.md b/docs/testing/acceptance-matrix.md
index c603cd17..68ae2e27 100644
--- a/docs/testing/acceptance-matrix.md
+++ b/docs/testing/acceptance-matrix.md
@@ -5,14 +5,16 @@ Which automated cases protect each user-facing capability, and what they need. "
| Capability | Automated coverage | Needs |
| --- | --- | --- |
| One-command install, first administrator in the browser | `e2e/public/00-first-run.spec.mjs`, CI job `first-run` | Docker · Fresh |
-| Self sign-up, signup switch, password rules, duplicate names | `internal/httpapi/auth_register_test.go`, `00-first-run.spec.mjs` | — |
+| Self sign-up, signup switch, password rules, duplicate names | `internal/httpapi/auth_register_test.go`, `e2e/public/00-first-run.spec.mjs` | — |
| Password sign-in, origin checks, session cookie, sign-out | `internal/httpapi/auth_password_test.go`, `e2e/public/platform.spec.mjs`, `e2e/api/00-smoke.test.mjs` | — |
-| Getting-started checklist, missing-key notice | `00-first-run.spec.mjs`, `e2e/public/composer.spec.mjs` | Fresh |
-| Expanded onboarding, persistent dismissal, capability question, optional GitHub, responsive composer | `e2e/public/welcome.spec.mjs`, `references.spec.mjs` | Model for the real capability reply |
+| Getting-started checklist, missing-key notice | `e2e/public/00-first-run.spec.mjs`, `e2e/public/composer.spec.mjs` | Fresh |
+| Expanded onboarding, persistent dismissal, capability question, optional GitHub, responsive composer | `e2e/public/welcome.spec.mjs`, `e2e/public/references.spec.mjs` | Model for the real capability reply |
| Main Bot executor/model selection and per-role SOP credential readiness | `e2e/public/executors.spec.mjs`, `internal/httpapi/assistant_provider_test.go` | Native CLI gateway fixtures are opt-in; no paid service |
| Tasks without GitHub: script/approval and document Agent | `e2e/public/without-github.spec.mjs` | Model for document Agent |
| Language and theme preferences | `e2e/public/platform.spec.mjs` | — |
| Every navigation view renders without runtime/CSP errors | `e2e/ui/01-views.spec.mjs` | — |
+| AI workbench conversations, credential wizard, notification bots, and domain admin | `e2e/ui/03-workbench-settings.spec.mjs` | No model or WeCom call |
+| SkillHub market browsing | `e2e/ui/04-skillhub-market.spec.mjs` | SkillHub proxy is mocked; nothing is installed |
| Projects, rules, Skills, MCP servers, agents, workflows (CRUD) | `e2e/api/10-catalog.test.mjs` | — |
| Requirements: create, search, edit, comments, clarification gate, dispatch, close/reopen, delete | `e2e/api/20-issues.test.mjs`, `e2e/ui/02-interactions.spec.mjs` | — |
| AI requirement analysis | `e2e/ui/02-interactions.spec.mjs` | Model |
@@ -24,17 +26,24 @@ Which automated cases protect each user-facing capability, and what they need. "
| Agent node with a real executor, AI run evaluation | `e2e/api/40-model.test.mjs` | Model |
| End-to-end delivery SOP: plan, fix, review, test, approve, summarize | `e2e/api/45-delivery-model.test.mjs` | Model |
| Workspace: git history, protected files, conflicts, shell, IDE | `e2e/api/55-workspace.test.mjs`, `e2e/ui/03-workspace.spec.mjs` | — |
+| Human takeover and compare-and-swap edits in a run workspace | `e2e/api/68-workspace-edit.test.mjs` | Repository fixture; does not push |
| Permission boundaries between accounts | `e2e/api/58-permissions.test.mjs` | — |
+| Authentication boundaries and project role permissions | `e2e/api/64-auth-permissions.test.mjs` | Optional second user for the role walk |
| Main Bot conversations, attachments, scheduled prompts | `e2e/api/60-assistant-lifecycle.test.mjs`, `e2e/public/composer.spec.mjs` | Model (reply cases) |
-| Task groups and multi-role collaboration | `e2e/api/65-task-groups.test.mjs` | Model |
-| Durable group-to-SOP handoff and context retention | `e2e/api/66-sop-handoff.test.mjs`, `internal/httpapi/sop_handoff_jobs_test.go`, `internal/repo/sop_handoff_mysql_test.go` | Model; lease recovery also tested on disposable MySQL |
+| Assistant conversations without a model: transcript, rename, archive, branch, and sharing | `e2e/api/69-assistant-sessions.test.mjs` | — |
+| Requirement spaces: CRUD, timeline, threads, artifacts, and members | `e2e/api/60-spaces.test.mjs` | — |
+| Task groups and multi-role collaboration | `internal/httpapi/rooms_test.go`, `internal/repo/group_run_view_test.go`, `internal/runtime/workspace_preparation_test.go`, `webtest/tests/collaboration-groups.test.mjs` | No model |
+| Group SOP handoff artifact inheritance | `internal/engine/state_helpers_cases_test.go`, `internal/engine/ops_validation_cases_test.go` | Engine `GroupSOPHandoff` only. `migrations/015_sop_handoff_jobs.sql` creates `sop_handoff_jobs` and `migrations/017_bot_sop_controls.sql` alters it, but no Go service reads or writes that table, so the job table is outside automatic coverage |
| Script views isolated from agent instructions | `internal/runtime/sandbox_script_test.go`, `internal/scriptview/` | Linux/Docker cases as supported by the host |
| Data persists across container recreation | `e2e/container-persistence.mjs` via `scripts/test-container.sh` | Docker |
| Rooms, scheduled dispatch, platform MCP tools, credential flags never leaking | `e2e/api/50-platform.test.mjs` | — |
+| Project integrations: notification bots, insight sources, business domains, and WeCom identity bindings | `e2e/api/62-integrations.test.mjs` | No outbound WeCom or insight call |
| Knowledge search and review queue | `e2e/api/50-platform.test.mjs`, `e2e/ui/02-interactions.spec.mjs` | Knowledge service |
| GitHub issue import, PR discovery and merge | `internal/tracker/github_test.go`, `internal/tracker/merge_mr_test.go`, `internal/runtime/github_mcp_test.go`, live: `internal/tracker/github_live_test.go` | Live: `AGENTFLOW_GITHUB_LIVE_WRITE=1`, a disposable repository and token file |
+| GitHub credential row and the separate manual path | `e2e/public/github-setup.spec.mjs` | No live GitHub write |
| Repository write permissions | `internal/httpapi/repository_authz_test.go` | — |
| Invocation cleanup preserves unrelated active runs | `e2e/api/05-cleanup-scope.test.mjs` | — |
+| Deterministic route edges: validation, unknown resources, and missing credentials | `e2e/api/90-route-sweep.test.mjs` | No model, knowledge write, or external ticket |
| LoopForge Local workflows, installers, dashboard | `local/tests/e2e/` | Python · CodeBuddy for live host runs |
## Not covered automatically
diff --git a/e2e/coverage/report.sh b/e2e/coverage/report.sh
index 547a1a92..c540c9b3 100755
--- a/e2e/coverage/report.sh
+++ b/e2e/coverage/report.sh
@@ -9,7 +9,8 @@
# 3. route coverage = routes hit in the platform access log / all routes;
# 4. web/ coverage = webtest/ unit coverage merged with the e2e browser coverage.
# Thresholds: AGENTFLOW_E2E_ROUTE_MIN and AGENTFLOW_E2E_WEB_MIN (default 85).
-# e2e is not part of CI; this only reports.
+# The pull-request route gate runs in the platform browser job against that
+# job's access log. This script still reruns the full local suite.
set -uo pipefail
cd "$(dirname "$0")/.."
E2E_DIR=$(pwd)
diff --git a/local/scripts/scan-secrets.sh b/local/scripts/scan-secrets.sh
index 2ed8e814..9aa1c3da 100755
--- a/local/scripts/scan-secrets.sh
+++ b/local/scripts/scan-secrets.sh
@@ -22,6 +22,7 @@ if ! curl -fsSL --retry 4 --retry-delay 2 --retry-max-time 120 \
"https://github.com/gitleaks/gitleaks/releases/download/v${VERSION}/gitleaks_${VERSION}_linux_x64.tar.gz" \
-o "$ARCHIVE"; then
# Authenticate the API request when available to avoid the anonymous rate limit.
+ # The API redirects to the same pinned asset when the release edge is down.
{
printf '%s\n' 'Accept: application/octet-stream'
if [[ -n "${LOOPFORGE_GITLEAKS_TOKEN:-}" ]]; then
diff --git a/scripts/coverage-go.min b/scripts/coverage-go.min
new file mode 100644
index 00000000..da5ec714
--- /dev/null
+++ b/scripts/coverage-go.min
@@ -0,0 +1 @@
+84.8
diff --git a/scripts/coverage-go.sh b/scripts/coverage-go.sh
index 50d887f2..18fa123b 100755
--- a/scripts/coverage-go.sh
+++ b/scripts/coverage-go.sh
@@ -1,17 +1,20 @@
#!/usr/bin/env bash
# Go statement coverage with agentflow/cmd/ and agentflow/deploy/ excluded.
#
-# scripts/coverage-go.sh [--min PCT] [--profile FILE] [--out FILE] [-p N] [--timeout D] [--coverpkg PATTERN]
+# scripts/coverage-go.sh [--min PCT] [--profile FILE]... [--out FILE] [-p N] [--timeout D] [--coverpkg PATTERN]
#
# Without --profile it runs `go test ./... -coverprofile` first, instrumenting
# every internal package in every test binary (-coverpkg), so a statement run by
# any package's tests counts. --coverpkg '' measures each package by its own
# tests only. The per-package table and the total are computed from the merged
# profile; a block covered by any test binary counts as covered once.
+# Repeat --profile to combine isolated test runs with the same instrumentation.
+# CI passes scripts/coverage-go.min with --min and both the non-browser and real
+# browser profiles; this script does not read the threshold file itself.
set -euo pipefail
min=""
-profile=""
+profiles=()
out="${COVERAGE_OUT:-coverage/go.out}"
par="${GO_TEST_P:-4}"
timeout="${GO_TEST_TIMEOUT:-4m}"
@@ -19,7 +22,7 @@ coverpkg="${GO_COVERPKG-agentflow/internal/...}"
while [ $# -gt 0 ]; do
case "$1" in
--min) min="$2"; shift 2 ;;
- --profile) profile="$2"; shift 2 ;;
+ --profile) profiles+=("$2"); shift 2 ;;
--out) out="$2"; shift 2 ;;
-p) par="$2"; shift 2 ;;
--timeout) timeout="$2"; shift 2 ;;
@@ -29,12 +32,12 @@ while [ $# -gt 0 ]; do
done
root="$(cd "$(dirname "$0")/.." && pwd)"
-cd "$root"
-if [ -z "$profile" ]; then
+if [ "${#profiles[@]}" -eq 0 ]; then
+ cd "$root"
mkdir -p "$(dirname "$out")"
- profile="$out"
- args=(-p="$par" -count=1 -timeout="$timeout" -covermode=set -coverprofile="$profile")
+ profiles=("$out")
+ args=(-p="$par" -count=1 -timeout="$timeout" -covermode=set -coverprofile="$out")
[ -z "$coverpkg" ] || args+=(-coverpkg="$coverpkg")
status=0
go test "${args[@]}" ./... || status=$?
@@ -44,13 +47,32 @@ if [ -z "$profile" ]; then
fi
fi
-test -s "$profile" || { echo "empty coverage profile: $profile" >&2; exit 1; }
+for profile in "${profiles[@]}"; do
+ test -s "$profile" || { echo "empty coverage profile: $profile" >&2; exit 1; }
+done
+
+filtered="${profiles[0]%.out}.filtered.out"
+while :; do
+ collides=0
+ for profile in "${profiles[@]}"; do
+ if [ "$filtered" = "$profile" ] || [ "$filtered" -ef "$profile" ]; then
+ collides=1
+ break
+ fi
+ done
+ [ "$collides" -eq 0 ] && break
+ filtered="${filtered%.out}.filtered.out"
+done
-filtered="${profile%.out}.filtered.out"
+tmp_filtered="$(mktemp "${filtered}.XXXXXX")"
+trap 'rm -f "$tmp_filtered"' EXIT
{
echo "mode: set"
- grep -v '^mode:' "$profile" | grep -Ev '^agentflow/(cmd|deploy)/' || true
-} >"$filtered"
+ for profile in "${profiles[@]}"; do
+ grep -v '^mode:' "$profile" | grep -Ev '^agentflow/(cmd|deploy)/' || true
+ done
+} >"$tmp_filtered"
+mv -f "$tmp_filtered" "$filtered"
awk -v min="$min" '
NR == 1 { next }
@@ -81,11 +103,11 @@ awk -v min="$min" '
printf "%-44s %8d %8d %8d %6.1f%%\n", p, total[p], cov[p], total[p] - cov[p], 100 * cov[p] / total[p]
}
pct = all ? 100 * allCov / all : 0
- printf "%-44s %8d %8d %8d %6.1f%%\n", "total", all, allCov, all - allCov, pct
+ printf "%-44s %8d %8d %8d %6.4f%%\n", "total", all, allCov, all - allCov, pct
if (min != "" && pct + 1e-9 < min + 0) {
- printf "FAIL: Go coverage %.1f%% is below the %s%% threshold\n", pct, min > "/dev/stderr"
+ printf "FAIL: Go coverage %.4f%% (%d/%d statements) is below the %s%% threshold\n", pct, allCov, all, min > "/dev/stderr"
exit 1
}
- if (min != "") printf "OK: Go coverage %.1f%% >= %s%%\n", pct, min
+ if (min != "") printf "OK: Go coverage %.4f%% >= %s%%\n", pct, min
}
' "$filtered"
diff --git a/scripts/scan-secrets.sh b/scripts/scan-secrets.sh
index 5242173f..b4d41a97 100644
--- a/scripts/scan-secrets.sh
+++ b/scripts/scan-secrets.sh
@@ -12,6 +12,7 @@ if ! curl -fsSL --retry 4 --retry-delay 2 --retry-max-time 120 \
--connect-timeout 15 --max-time 60 \
"https://github.com/gitleaks/gitleaks/releases/download/v${version}/gitleaks_${version}_linux_x64.tar.gz" -o "$scan_dir/gitleaks.tar.gz"; then
# Authenticate the API request when available to avoid the anonymous rate limit.
+ # The API redirects to the same pinned asset when the release edge is down.
{
printf '%s\n' 'Accept: application/octet-stream'
if [[ -n "${LOOPFORGE_GITLEAKS_TOKEN:-}" ]]; then
diff --git a/scripts/test-coverage-go.py b/scripts/test-coverage-go.py
new file mode 100644
index 00000000..0f727d93
--- /dev/null
+++ b/scripts/test-coverage-go.py
@@ -0,0 +1,101 @@
+from pathlib import Path
+import subprocess
+import tempfile
+import unittest
+
+
+SCRIPT = Path(__file__).resolve().with_name('coverage-go.sh')
+
+
+class CoverageGateTests(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.root = Path(self.temp.name)
+
+ def profile(self, name, blocks):
+ profile = self.root / name
+ profile.write_text('mode: set\n' + blocks)
+ return profile
+
+ def gate(self, *profiles, minimum='86.0'):
+ args = ['bash', str(SCRIPT), '--min', minimum]
+ for profile in profiles:
+ args.extend(['--profile', str(profile)])
+ return subprocess.run(args, capture_output=True, text=True, timeout=10)
+
+ def test_combines_hits_across_profiles_without_counting_blocks_twice(self):
+ core = self.profile('core.out', (
+ 'agentflow/internal/runtime/browser.go:1.1,2.2 6 1\n'
+ 'agentflow/internal/runtime/browser.go:3.1,4.2 3 0\n'
+ 'agentflow/internal/runtime/browser.go:5.1,6.2 1 0\n'
+ 'agentflow/cmd/main.go:1.1,2.2 100 0\n'
+ ))
+ browser = self.profile('browser.out', (
+ 'agentflow/internal/runtime/browser.go:1.1,2.2 6 0\n'
+ 'agentflow/internal/runtime/browser.go:3.1,4.2 3 1\n'
+ 'agentflow/internal/runtime/browser.go:5.1,6.2 1 0\n'
+ 'agentflow/deploy/main.go:1.1,2.2 100 0\n'
+ ))
+ self.assertEqual(self.gate(core).returncode, 1)
+ for profiles in ((core, browser), (browser, core), (core, browser, core)):
+ with self.subTest(profiles=profiles):
+ result = self.gate(*profiles)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertRegex(result.stdout, r'total\s+10\s+9\s+1\s+90\.0000%')
+
+ def test_rejects_ci_measurement_below_threshold_despite_rounding(self):
+ profile = self.profile('ci.out', (
+ 'agentflow/internal/engine/run.go:1.1,2.2 48051 1\n'
+ 'agentflow/internal/engine/run.go:3.1,4.2 7834 0\n'
+ ))
+ result = self.gate(profile)
+ self.assertEqual(result.returncode, 1)
+ self.assertIn('85.9819% (48051/55885 statements)', result.stderr)
+
+ def test_accepts_exact_threshold(self):
+ profile = self.profile('exact.out', (
+ 'agentflow/internal/engine/run.go:1.1,2.2 86 1\n'
+ 'agentflow/internal/engine/run.go:3.1,4.2 14 0\n'
+ ))
+ result = self.gate(profile)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+
+ def test_requires_every_supplied_profile(self):
+ profile = self.profile('complete.out', 'agentflow/internal/auth/auth.go:1.1,2.2 1 1\n')
+ empty = self.root / 'empty.out'
+ empty.write_text('')
+ for extra in (self.root / 'missing.out', empty):
+ with self.subTest(profile=extra):
+ result = self.gate(profile, extra)
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn('empty coverage profile:', result.stderr)
+
+ def test_preserves_input_profile_named_like_default_filtered_output(self):
+ core = self.profile('core.out', (
+ 'agentflow/internal/runtime/browser.go:1.1,2.2 6 1\n'
+ 'agentflow/internal/runtime/browser.go:3.1,4.2 4 0\n'
+ ))
+ second = self.profile('core.filtered.out', (
+ 'agentflow/internal/runtime/browser.go:1.1,2.2 6 0\n'
+ 'agentflow/internal/runtime/browser.go:3.1,4.2 4 1\n'
+ ))
+ core_before = core.read_text()
+ second_before = second.read_text()
+
+ result = subprocess.run(
+ ['bash', str(SCRIPT), '--profile', 'core.out', '--profile', 'core.filtered.out', '--min', '86'],
+ cwd=self.root,
+ capture_output=True,
+ text=True,
+ timeout=10,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertRegex(result.stdout, r'total\s+10\s+10\s+0\s+100\.0000%')
+ self.assertEqual(core.read_text(), core_before)
+ self.assertEqual(second.read_text(), second_before)
+ self.assertTrue((self.root / 'core.filtered.filtered.out').is_file())
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/webtest/tests/collaboration-groups.test.mjs b/webtest/tests/collaboration-groups.test.mjs
new file mode 100644
index 00000000..649c42e8
--- /dev/null
+++ b/webtest/tests/collaboration-groups.test.mjs
@@ -0,0 +1,103 @@
+// Collaboration rooms and group-mode run detail, without a model.
+// rooms.js is not on index.html, so this loads that script after a minimal
+// host exists. The copy and the create request come from createRoom.
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import path from 'node:path';
+import vm from 'node:vm';
+import { loadApp, settle, WEB_ROOT } from '../lib/load-app.mjs';
+
+async function loadRooms(app) {
+ app.evaluate(`
+ const host = document.createElement('div');
+ host.innerHTML = [
+ '<button type="button" id="newRoom"></button>',
+ '<button type="button" id="renameRoom" hidden></button>',
+ '<button type="button" id="roomModeChat"></button>',
+ '<button type="button" id="roomModeIssue"></button>',
+ '<form id="roomComposer">',
+ '<input id="roomInput">',
+ '<button type="button" id="roomDispatch"></button>',
+ '<select id="roomSOP"></select>',
+ '</form>',
+ '<div id="roomList"></div>',
+ '<div id="roomLog"></div>',
+ '<div id="roomResources"></div>',
+ '<h2 id="roomTitle"></h2>',
+ '<p id="roomSubtitle"></p>',
+ ].join('');
+ document.body.appendChild(host);
+ state.projectFilter = 'project-1';
+ state.currentView = 'home';
+ `);
+ const source = await readFile(path.join(WEB_ROOT, 'rooms.js'), 'utf8');
+ new vm.Script(source, { filename: path.join(WEB_ROOT, 'rooms.js') }).runInContext(app.context);
+}
+
+test('creating a collaboration room uses the existing prompt and posts the room', async (t) => {
+ const app = await loadApp();
+ t.after(() => {
+ app.evaluate('clearTimeout(roomsPollTimer)');
+ return app.close();
+ });
+ app.router.post('/api/rooms', (call) => ({
+ id: 'room-1', name: call.body.name, projectId: call.body.projectId, members: [],
+ }));
+ app.router.get(/^\/api\/rooms\?/, [{
+ id: 'room-1', name: '需求值班群', projectId: 'project-1', members: [],
+ }]);
+ app.router.get(/^\/api\/rooms\/room-1\/messages/, []);
+ await loadRooms(app);
+
+ app.document.querySelector('#newRoom').click();
+ await settle(4);
+ assert.equal(app.document.querySelector('#confirmTitle').textContent, '新建协作群');
+ assert.equal(app.document.querySelector('#confirmMessage').textContent, '群名称会显示在当前项目的群列表里。');
+ assert.equal(app.document.querySelector('#confirmPromptLabel').textContent, '群名称');
+ assert.equal(app.document.querySelector('#confirmPromptInput').placeholder, '例如:需求值班群');
+ assert.equal(app.document.querySelector('#confirmOkBtn').textContent, '创建');
+
+ app.document.querySelector('#confirmPromptInput').value = ' 需求值班群 ';
+ app.document.querySelector('#confirmOkBtn').click();
+ await settle(8);
+
+ const created = app.router.calls.filter((call) => call.method === 'POST' && call.path === '/api/rooms');
+ assert.equal(created.length, 1);
+ assert.deepEqual(created[0].body, { projectId: 'project-1', name: '需求值班群' });
+ assert.match(app.document.body.textContent, /已创建协作群/);
+});
+
+test('a group-mode run detail shows the existing collaboration copy', async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ const workflow = app.evaluate('structuredClone(state.data.workflows[0])');
+ workflow.collaborationMode = 'group';
+ workflow.version = 3;
+ workflow.nodes = [
+ { id: 'node-1', type: 'agent', name: 'Implement' },
+ { id: 'task-1', type: 'agent', name: 'Room task', requestId: 'req-1' },
+ ];
+ const run = {
+ ...app.evaluate('structuredClone(state.data.runs[0])'),
+ status: 'succeeded',
+ kind: 'sop',
+ finishedAt: '2026-10-21T10:05:00Z',
+ workflowSnapshot: workflow,
+ nodes: { 'node-1': { status: 'succeeded', attempt: 1 } },
+ };
+ app.router.get('/api/runs/run-1', run);
+ app.evaluate(`state.data.runs=[${JSON.stringify(run)}];state.selectedRun='run-1';state.activeRun=state.data.runs[0]`);
+ app.evaluate(`switchView('runs');showRunDetail('run-1')`);
+ await settle(6);
+ app.evaluate('renderRunDetail(state.activeRun)');
+
+ const detail = app.document.querySelector('#runDetail').textContent;
+ assert.match(detail, /协作模式/);
+ assert.match(detail, /历史协作记录/);
+ assert.match(detail, /SOP 主干已冷冻/);
+ assert.match(detail, /1 步可展开/);
+ assert.match(detail, /群内任务 1 个/);
+ assert.match(detail, /冷冻 SOP v3/);
+ assert.doesNotMatch(app.evaluate(`document.querySelector('#runDetail .run-progress-cell span').textContent`), /执行进度/);
+});