ci: scope native acceptance and bind release candidate artifacts (#6378)
* ci: scope native acceptance and bind release candidate artifacts * ci: isolate Windows installers and use portable Git tree fixtures * test: preserve installer subprocess diagnostics on timeout
This commit is contained in:
1 parent
4dc695ca76
commit
67fc220c8a
15 files changed
+1222
-288
No files matched your search
@@ -0,0 +1,65 @@
|
||||
"""Protect the required-check contract when GitHub skips conditional jobs."""
|
||||
|
||||
import pytest
|
||||
|
||||
from scripts.ci_gate import check_results
|
||||
|
||||
|
||||
def results(*domains):
|
||||
return {
|
||||
"changes": {"result": "success", "outputs": {
|
||||
f"{domain}_required": str(domain in domains).lower()
|
||||
for domain in ("python", "webui", "tui", "docker", "native")
|
||||
}},
|
||||
**{job: {"result": "skipped"} for job in (
|
||||
"test", "windows_process", "windows_installers", "webui_checks", "webui_browser", "webui", "tui", "docker", "native",
|
||||
)},
|
||||
}
|
||||
|
||||
|
||||
def test_documentation_needs_no_product_jobs():
|
||||
assert check_results(results(), "pull_request") == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("result", ["failure", "cancelled", "skipped"])
|
||||
def test_selected_job_must_succeed(result):
|
||||
needs = results("webui")
|
||||
for job in ("webui_checks", "webui_browser", "webui"):
|
||||
needs[job]["result"] = "success"
|
||||
needs["webui_browser"]["result"] = result
|
||||
assert check_results(needs, "pull_request")
|
||||
|
||||
|
||||
def test_native_runs_on_high_risk_pr_but_not_main_push():
|
||||
needs = results("native")
|
||||
assert check_results(needs, "pull_request")
|
||||
assert check_results(needs, "push") == []
|
||||
needs["native"]["result"] = "success"
|
||||
assert check_results(needs, "pull_request") == []
|
||||
|
||||
|
||||
def test_failed_or_incomplete_selection_is_not_documentation_only():
|
||||
needs = results()
|
||||
needs["changes"]["result"] = "failure"
|
||||
assert check_results(needs, "pull_request")
|
||||
needs["changes"]["result"] = "success"
|
||||
del needs["changes"]["outputs"]["native_required"]
|
||||
assert check_results(needs, "pull_request")
|
||||
|
||||
|
||||
def test_unexpected_failure_is_not_ignored():
|
||||
needs = results()
|
||||
needs["native"]["result"] = "cancelled"
|
||||
assert check_results(needs, "push")
|
||||
|
||||
|
||||
def test_selected_windows_installers_are_required_independently_of_process_tests():
|
||||
needs = results("python", "native")
|
||||
for job in ("test", "windows_process", "native"):
|
||||
needs[job]["result"] = "success"
|
||||
assert check_results(needs, "pull_request") == ["windows_installers: required, got skipped"]
|
||||
needs["windows_installers"]["result"] = "success"
|
||||
assert check_results(needs, "pull_request") == []
|
||||
needs["windows_installers"]["result"] = "skipped"
|
||||
needs["native"]["result"] = "skipped"
|
||||
assert check_results(needs, "push") == []
|
||||
@@ -0,0 +1,205 @@
|
||||
"""Path policy and real git range regressions for the CI selector."""
|
||||
|
||||
import html
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
|
||||
from scripts.ci_scope import JOBS, classify_paths, select_scope
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def selected(result):
|
||||
return {name.removesuffix("_required") for name, value in result["outputs"].items() if value}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("path", "expected"),
|
||||
[
|
||||
("docs/releasing.md", set()),
|
||||
("webui/README.md", set()),
|
||||
("README.md", {"docker"}),
|
||||
("Dockerfile", {"docker"}),
|
||||
("entrypoint.sh", {"docker"}),
|
||||
("tests/test_docker_config.py", {"python", "docker"}),
|
||||
("tests/test_docker_smoke.py", {"python", "docker"}),
|
||||
("webui/package.json", {"webui", "docker"}),
|
||||
("nanobot/channels/discord/webui/index.ts", {"webui", "docker"}),
|
||||
("tui/package.json", {"tui", "native"}),
|
||||
("tui/scripts/build.ts", {"tui", "native"}),
|
||||
("tui/src/composer/textarea.ts", {"tui"}),
|
||||
("nanobot/channels/websocket/runtime.py", {"python", "webui", "tui", "docker", "native"}),
|
||||
("nanobot/providers/registry.py", {"python", "docker"}),
|
||||
("nanobot/webui/native_file_picker.py", {"python", "webui", "docker"}),
|
||||
("nanobot/webui/client_contract.py", {"python", "webui", "tui", "docker"}),
|
||||
("nanobot/webui/forking.py", {"python", "webui", "tui", "docker"}),
|
||||
("nanobot/cli/webui.py", {"python", "docker", "native"}),
|
||||
("nanobot/webui/ws_http.py", {"python", "webui", "tui", "docker"}),
|
||||
("nanobot/session/session_messages.py", {"python", "webui", "tui", "docker"}),
|
||||
("packages/client-events/notifications.ts", {"webui", "tui", "docker"}),
|
||||
("nanobot/update_recovery.py", {"python", "docker", "native"}),
|
||||
("nanobot/release_trust.py", {"python", "docker", "native"}),
|
||||
("nanobot/gateway/runtime.py", {"python", "docker", "native"}),
|
||||
("nanobot/process_runtime.py", {"python", "docker", "native"}),
|
||||
("nanobot/cli/entry.py", {"python", "docker", "native"}),
|
||||
("nanobot/utils/atomic_file.py", {"python", "docker", "native"}),
|
||||
("tests/test_update_backup.py", {"python", "native"}),
|
||||
("tests/test_install_scripts.py", {"python", "native"}),
|
||||
("tests/providers/test_cached_tokens.py", {"python"}),
|
||||
("scripts/pytest_timing.py", {"python"}),
|
||||
("tests/scripts/test_pytest_timing.py", {"python"}),
|
||||
("scripts/verify_packaged_update.py", {"python", "native"}),
|
||||
("scripts/check_client_import_boundaries.mjs", {"webui", "tui"}),
|
||||
(".github/workflows/release-candidate.yml", {"python", "native"}),
|
||||
(".github/workflows/release-approve.yml", {"python", "native"}),
|
||||
(".github/workflows/tui-release.yml", {"python", "tui", "native"}),
|
||||
("pyproject.toml", {"python", "webui", "tui", "docker", "native"}),
|
||||
("hatch_build.py", {"python", "webui", "tui", "docker", "native"}),
|
||||
("scripts/install_channel_dependencies.py", {"python", "webui", "tui", "docker", "native"}),
|
||||
(".github/workflows/ci.yml", {"python", "webui", "tui", "docker", "native"}),
|
||||
("scripts/ci_scope.py", {"python", "webui", "tui", "docker", "native"}),
|
||||
("nanobot/webui/build.py", {"python", "webui", "tui", "docker", "native"}),
|
||||
("nanobot/webui/local_client_assets.py", {"python", "webui", "docker", "native"}),
|
||||
],
|
||||
)
|
||||
def test_existing_path_policy(path, expected):
|
||||
# These are reachable repository inputs, not merely invented glob matches.
|
||||
assert (ROOT / path).is_file()
|
||||
result = classify_paths([path])
|
||||
assert selected(result) == expected
|
||||
assert result["paths"][0]["reason"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["new-domain/source.txt", ".github/workflows/publish-index.yml", "uv.lock"])
|
||||
def test_new_or_cross_domain_paths_require_every_job(path):
|
||||
assert all(classify_paths([path])["outputs"].values())
|
||||
|
||||
|
||||
def test_union_preserves_each_reason():
|
||||
result = classify_paths(["docs/releasing.md", "tui/package.json", "nanobot/providers/registry.py"])
|
||||
assert selected(result) == {"python", "docker", "tui", "native"}
|
||||
assert len(result["paths"]) == 3
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repo(tmp_path):
|
||||
def git(*args, input=None):
|
||||
return subprocess.run(
|
||||
["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True, input=input,
|
||||
).stdout.strip()
|
||||
|
||||
git("init", "-b", "main")
|
||||
git("config", "user.name", "CI scope test")
|
||||
git("config", "user.email", "ci-scope@example.invalid")
|
||||
|
||||
def commit(path, text):
|
||||
target = tmp_path / path
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(text, encoding="utf-8")
|
||||
git("add", "--all")
|
||||
git("commit", "-m", "fixture change")
|
||||
return git("rev-parse", "HEAD")
|
||||
|
||||
return tmp_path, git, commit
|
||||
|
||||
|
||||
def test_push_includes_all_commits_not_only_last(repo):
|
||||
cwd, _, commit = repo
|
||||
base = commit("docs/guide.md", "initial")
|
||||
commit("nanobot/providers/new.py", "production")
|
||||
head = commit("webui/src/new.ts", "frontend")
|
||||
result = select_scope("push", base, head, cwd=cwd)
|
||||
assert selected(result) == {"python", "webui", "docker"}
|
||||
assert result["diff_range"] == f"{base}..{head}"
|
||||
|
||||
|
||||
def test_pr_uses_merge_base_not_base_tip(repo):
|
||||
cwd, git, commit = repo
|
||||
commit("docs/guide.md", "initial")
|
||||
git("checkout", "-b", "feature")
|
||||
head = commit("webui/src/new.ts", "frontend")
|
||||
git("checkout", "main")
|
||||
base = commit("tui/src/base-only.ts", "base branch only")
|
||||
assert selected(select_scope("pull_request", base, head, cwd=cwd)) == {"webui", "docker"}
|
||||
assert selected(select_scope("push", base, head, cwd=cwd)) == {"webui", "docker", "tui"}
|
||||
|
||||
|
||||
def test_rename_and_delete_keep_old_domain(repo):
|
||||
cwd, git, commit = repo
|
||||
commit("nanobot/providers/old.py", "production")
|
||||
base = commit("tui/src/removed.ts", "native package")
|
||||
target = cwd / "docs" / "renamed file.md"
|
||||
target.parent.mkdir()
|
||||
(cwd / "nanobot/providers/old.py").rename(target)
|
||||
(cwd / "tui/src/removed.ts").unlink()
|
||||
git("add", "--all")
|
||||
git("commit", "-m", "rename and delete")
|
||||
result = select_scope("push", base, git("rev-parse", "HEAD"), cwd=cwd)
|
||||
assert selected(result) == {"python", "docker", "tui"}
|
||||
assert {item["path"] for item in result["paths"]} == {
|
||||
"nanobot/providers/old.py", "tui/src/removed.ts", "docs/renamed file.md",
|
||||
}
|
||||
|
||||
|
||||
def test_empty_missing_and_invalid_diff_are_full(repo):
|
||||
cwd, _, commit = repo
|
||||
head = commit("docs/guide.md", "initial")
|
||||
for base, expected in [(head, "empty diff"), ("0" * 40, "git diff unavailable"), ("--help", "invalid")]:
|
||||
result = select_scope("push", base, head, cwd=cwd)
|
||||
assert all(result["outputs"].values())
|
||||
assert expected in result["reason"]
|
||||
|
||||
|
||||
def test_non_repository_and_dispatch_are_full(tmp_path):
|
||||
result = select_scope("pull_request", "1" * 40, "2" * 40, cwd=tmp_path)
|
||||
assert all(result["outputs"].values())
|
||||
assert "git diff unavailable" in result["reason"]
|
||||
result = select_scope("workflow_dispatch", "", "", cwd=tmp_path)
|
||||
assert all(result["outputs"].values())
|
||||
assert "manual dispatch" in result["reason"]
|
||||
|
||||
|
||||
def test_cli_emits_only_fixed_boolean_outputs_and_escaped_summary(repo):
|
||||
cwd, git, commit = repo
|
||||
base = commit("docs/guide.md", "initial")
|
||||
# A PR authored on Unix can contain names Windows cannot check out or add
|
||||
# to its index. Build the actual Git tree directly, without materializing it.
|
||||
blob = git("rev-parse", "HEAD:docs/guide.md")
|
||||
subtree = git("mktree", "-z", input=f"100644 blob {blob}\t```\npython_required=false<script>.ts\0")
|
||||
tree = git("mktree", "-z", input=f"040000 tree {subtree}\twebui\0")
|
||||
head = git("commit-tree", tree, "-p", base, "-m", "untrusted filename")
|
||||
output, summary = cwd / "output", cwd / "summary"
|
||||
proc = subprocess.run(
|
||||
[sys.executable, str(ROOT / "scripts/ci_scope.py"), "--event", "push", "--base", base, "--head", head],
|
||||
cwd=cwd, check=True, capture_output=True, text=True,
|
||||
env={**os.environ, "GITHUB_OUTPUT": str(output), "GITHUB_STEP_SUMMARY": str(summary)},
|
||||
)
|
||||
result = json.loads(proc.stdout)
|
||||
assert selected(result) == {"webui", "docker"}
|
||||
assert output.read_text().splitlines() == [
|
||||
f"{job}={str(result['outputs'][job]).lower()}" for job in JOBS
|
||||
]
|
||||
assert "<script>" in summary.read_text()
|
||||
assert "\\npython_required=false" in summary.read_text()
|
||||
summary_json = summary.read_text().split("<pre>", 1)[1].removesuffix("</pre>\n")
|
||||
assert json.loads(html.unescape(summary_json)) == result
|
||||
|
||||
|
||||
def test_every_frozen_worker_source_selects_native_acceptance(tmp_path):
|
||||
from nanobot.update_jobs import _worker_archive
|
||||
|
||||
archive = tmp_path / "worker.pyz"
|
||||
_worker_archive(archive)
|
||||
with ZipFile(archive) as bundle:
|
||||
sources = ["nanobot/" + name.removeprefix("_nanobot_update/")
|
||||
for name in bundle.namelist()
|
||||
if name.startswith("_nanobot_update/") and not name.endswith("__init__.py")]
|
||||
assert sources
|
||||
for path in sources:
|
||||
assert classify_paths([path])["outputs"]["native_required"], path
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Producer/consumer artifact wiring must survive failed-jobs-only retries."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
WORKFLOWS = Path(__file__).resolve().parents[2] / ".github/workflows"
|
||||
|
||||
|
||||
def workflow(name):
|
||||
return yaml.load((WORKFLOWS / name).read_text(encoding="utf-8"), Loader=yaml.BaseLoader)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform,step", [("linux", "linux_input"), ("windows", "windows_input")])
|
||||
def test_native_consumers_receive_immutable_producer_ids(platform, step):
|
||||
jobs = workflow("release-candidate.yml")["jobs"]
|
||||
key = f"{platform}_artifact_id"
|
||||
producer = jobs["candidate"]
|
||||
assert producer["outputs"][key] == "${{ steps." + step + ".outputs.artifact-id }}"
|
||||
upload = next(item for item in producer["steps"] if item.get("id") == step)
|
||||
assert upload["uses"] == "actions/upload-artifact@v4"
|
||||
assert jobs["native"]["with"][key] == "${{ needs.candidate.outputs." + key + " }}"
|
||||
consumer = workflow("native-acceptance.yml")["jobs"]["native"]
|
||||
download = next(item for item in consumer["steps"] if item.get("uses") == "actions/download-artifact@v4")
|
||||
assert "inputs." + key in download["with"]["artifact-ids"]
|
||||
assert "name" not in download["with"]
|
||||
assert download["with"]["merge-multiple"] == "true"
|
||||
|
||||
|
||||
def test_accepted_handoff_uses_the_producer_id_and_requires_native_success():
|
||||
jobs = workflow("release-candidate.yml")["jobs"]
|
||||
assert jobs["candidate"]["outputs"]["prepared_artifact_id"] == "${{ steps.prepared.outputs.artifact-id }}"
|
||||
verified = jobs["verified"]
|
||||
assert set(verified["needs"]) == {"candidate", "native"}
|
||||
gate = verified["steps"][0]
|
||||
assert gate["env"]["NATIVE_RESULT"] == "${{ needs.native.result }}"
|
||||
assert gate["run"] == 'test "$BUILD_RESULT" = success && test "$NATIVE_RESULT" = success'
|
||||
download = next(item for item in verified["steps"] if item.get("uses") == "actions/download-artifact@v4")
|
||||
assert download["with"]["artifact-ids"] == "${{ needs.candidate.outputs.prepared_artifact_id }}"
|
||||
assert download["with"]["merge-multiple"] == "true"
|
||||
assert "name" not in download["with"]
|
||||
|
||||
|
||||
def test_windows_installer_matrix_has_an_independent_required_job():
|
||||
jobs = workflow("ci.yml")["jobs"]
|
||||
installer = jobs["windows_installers"]
|
||||
assert installer["runs-on"] == "windows-latest"
|
||||
assert "native_required" in installer["if"] and "python_required" in installer["if"]
|
||||
assert "github.event_name != 'push'" in installer["if"]
|
||||
commands = [step.get("run", "") for step in installer["steps"]]
|
||||
assert any("tests/test_install_scripts.py" in command and "-n 4" in command for command in commands)
|
||||
assert not any("tests/test_install_scripts.py" in step.get("run", "")
|
||||
for step in jobs["windows_process"]["steps"])
|
||||
assert "windows_installers" in jobs["required"]["needs"]
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Acceptance must use the built candidate bytes, not a rebuilt substitute."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
|
||||
from scripts.native_acceptance_input import acceptance_input
|
||||
|
||||
COMMIT = "a" * 40
|
||||
TAG = "win_amd64"
|
||||
|
||||
|
||||
def candidate(tmp_path):
|
||||
wheel = tmp_path / "nanobot_ai-0.3.6.dev42-py3-none-win_amd64.whl"
|
||||
with ZipFile(wheel, "w") as archive:
|
||||
archive.writestr("nanobot/_build_commit.txt", COMMIT + "\n")
|
||||
manifest = {"candidate_commit": COMMIT, "version": "0.3.6.dev42", "artifacts": [{
|
||||
"filename": wheel.name, "size": wheel.stat().st_size,
|
||||
"sha256": hashlib.sha256(wheel.read_bytes()).hexdigest(),
|
||||
}]}
|
||||
payload = json.dumps(manifest).encode()
|
||||
(tmp_path / "release-manifest.json").write_bytes(payload)
|
||||
return wheel, hashlib.sha256(payload).hexdigest()
|
||||
|
||||
|
||||
def test_select_exact_candidate_wheel(tmp_path):
|
||||
wheel, digest = candidate(tmp_path)
|
||||
result = acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)
|
||||
assert result["wheel"] == str(wheel)
|
||||
assert result["version"] == "0.3.6.dev42"
|
||||
assert result["manifest_sha256"] == digest
|
||||
|
||||
|
||||
def test_reject_replaced_wheel(tmp_path):
|
||||
wheel, digest = candidate(tmp_path)
|
||||
wheel.write_bytes(wheel.read_bytes() + b"changed")
|
||||
with pytest.raises(ValueError, match="wheel differs"):
|
||||
acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)
|
||||
|
||||
|
||||
def test_reject_replaced_manifest(tmp_path):
|
||||
_, digest = candidate(tmp_path)
|
||||
path = tmp_path / "release-manifest.json"
|
||||
path.write_bytes(path.read_bytes() + b" ")
|
||||
with pytest.raises(ValueError, match="manifest differs"):
|
||||
acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)
|
||||
|
||||
|
||||
def test_reject_wrong_candidate_commit(tmp_path):
|
||||
_, digest = candidate(tmp_path)
|
||||
with pytest.raises(ValueError, match="Candidate commit differs"):
|
||||
acceptance_input(tmp_path, tag=TAG, commit="b" * 40, manifest_sha256=digest)
|
||||
|
||||
|
||||
def test_pr_package_must_embed_checked_out_commit(tmp_path):
|
||||
wheel, _ = candidate(tmp_path)
|
||||
result = acceptance_input(tmp_path, tag=TAG, commit=COMMIT, version="0.3.6.dev42")
|
||||
assert result["wheel_sha256"] == hashlib.sha256(wheel.read_bytes()).hexdigest()
|
||||
with pytest.raises(ValueError, match="Wheel build commit differs"):
|
||||
acceptance_input(tmp_path, tag=TAG, commit="b" * 40, version="0.3.6.dev42")
|
||||
Reference in new issue
Block a user