|
| 1 | +"""Tests for Epic 1 — Release Artifact Consistency. |
| 2 | +
|
| 3 | +Validates that the release workflow, sample-release-bundle docs, and |
| 4 | +release-artifacts.json are all consistent with each other. |
| 5 | +""" |
| 6 | + |
| 7 | +import json |
| 8 | +import re |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +import yaml |
| 12 | + |
| 13 | +REPO_ROOT = Path(__file__).parent.parent |
| 14 | +RELEASE_YML = REPO_ROOT / ".github" / "workflows" / "release.yml" |
| 15 | +ARTIFACTS_JSON = REPO_ROOT / "docs" / "release-artifacts.json" |
| 16 | +SAMPLE_BUNDLE = REPO_ROOT / "docs" / "sample-release-bundle.md" |
| 17 | +VERIFY_RELEASE = REPO_ROOT / "files" / "scripts" / "verify-release.sh" |
| 18 | + |
| 19 | + |
| 20 | +def _load_artifacts_json(): |
| 21 | + return json.loads(ARTIFACTS_JSON.read_text(encoding="utf-8")) |
| 22 | + |
| 23 | + |
| 24 | +def _read_release_yml(): |
| 25 | + return RELEASE_YML.read_text(encoding="utf-8") |
| 26 | + |
| 27 | + |
| 28 | +class TestReleaseArtifactsJson: |
| 29 | + def test_file_exists(self): |
| 30 | + assert ARTIFACTS_JSON.exists() |
| 31 | + |
| 32 | + def test_valid_json(self): |
| 33 | + data = _load_artifacts_json() |
| 34 | + assert "schema_version" in data |
| 35 | + |
| 36 | + def test_canonical_image_ref(self): |
| 37 | + data = _load_artifacts_json() |
| 38 | + assert data["canonical_image_ref"] == "ghcr.io/secai-hub/secai_os" |
| 39 | + |
| 40 | + def test_go_services_match_release_matrix(self): |
| 41 | + """Go services in artifacts.json must match release.yml matrix.""" |
| 42 | + data = _load_artifacts_json() |
| 43 | + release_content = _read_release_yml() |
| 44 | + |
| 45 | + # Extract matrix services from release.yml |
| 46 | + match = re.search(r"service: \[([^\]]+)\]", release_content) |
| 47 | + assert match, "Cannot find service matrix in release.yml" |
| 48 | + release_services = sorted(s.strip() for s in match.group(1).split(",")) |
| 49 | + artifact_services = sorted(data["go_services"]) |
| 50 | + |
| 51 | + assert release_services == artifact_services, ( |
| 52 | + f"Mismatch: release.yml has {release_services}, " |
| 53 | + f"artifacts.json has {artifact_services}" |
| 54 | + ) |
| 55 | + |
| 56 | + def test_all_nine_go_services(self): |
| 57 | + data = _load_artifacts_json() |
| 58 | + assert len(data["go_services"]) == 9 |
| 59 | + |
| 60 | + def test_all_six_python_services(self): |
| 61 | + data = _load_artifacts_json() |
| 62 | + assert len(data["python_services"]) == 6 |
| 63 | + |
| 64 | + def test_both_architectures(self): |
| 65 | + data = _load_artifacts_json() |
| 66 | + assert "linux-amd64" in data["architectures"] |
| 67 | + assert "linux-arm64" in data["architectures"] |
| 68 | + |
| 69 | + |
| 70 | +class TestReleaseWorkflowStructure: |
| 71 | + def test_has_build_iso_job(self): |
| 72 | + content = _read_release_yml() |
| 73 | + assert "build-iso:" in content |
| 74 | + |
| 75 | + def test_has_build_vm_images_job(self): |
| 76 | + content = _read_release_yml() |
| 77 | + assert "build-vm-images:" in content |
| 78 | + |
| 79 | + def test_vm_images_gated_on_kvm_runner(self): |
| 80 | + content = _read_release_yml() |
| 81 | + assert "HAS_KVM_RUNNER" in content |
| 82 | + |
| 83 | + def test_provenance_needs_build_iso(self): |
| 84 | + content = _read_release_yml() |
| 85 | + # Provenance job should depend on build-iso |
| 86 | + assert "build-iso" in content |
| 87 | + |
| 88 | + def test_release_files_include_iso(self): |
| 89 | + content = _read_release_yml() |
| 90 | + assert "secai-os-*.iso" in content |
| 91 | + |
| 92 | + def test_release_files_include_vm(self): |
| 93 | + content = _read_release_yml() |
| 94 | + assert "secai-os-*.qcow2" in content |
| 95 | + assert "secai-os-*.ova" in content |
| 96 | + |
| 97 | + def test_release_files_include_signatures(self): |
| 98 | + content = _read_release_yml() |
| 99 | + assert "*.iso.sig" in content |
| 100 | + |
| 101 | + def test_manifest_includes_install_artifacts(self): |
| 102 | + content = _read_release_yml() |
| 103 | + assert "install_artifacts" in content |
| 104 | + |
| 105 | + |
| 106 | +class TestSampleReleaseBundle: |
| 107 | + def test_mentions_iso(self): |
| 108 | + content = SAMPLE_BUNDLE.read_text(encoding="utf-8") |
| 109 | + assert ".iso" in content |
| 110 | + |
| 111 | + def test_mentions_qcow2(self): |
| 112 | + content = SAMPLE_BUNDLE.read_text(encoding="utf-8") |
| 113 | + assert ".qcow2" in content |
| 114 | + |
| 115 | + def test_mentions_ova(self): |
| 116 | + content = SAMPLE_BUNDLE.read_text(encoding="utf-8") |
| 117 | + assert ".ova" in content |
| 118 | + |
| 119 | + def test_mentions_optional_vm_artifacts(self): |
| 120 | + """Docs must note that QCOW2/OVA may be absent.""" |
| 121 | + content = SAMPLE_BUNDLE.read_text(encoding="utf-8") |
| 122 | + assert "absent" in content.lower() or "optional" in content.lower() |
| 123 | + |
| 124 | + def test_references_artifacts_json(self): |
| 125 | + content = SAMPLE_BUNDLE.read_text(encoding="utf-8") |
| 126 | + assert "release-artifacts.json" in content |
| 127 | + |
| 128 | + |
| 129 | +class TestVerifyReleaseScript: |
| 130 | + def test_has_step5_install_artifacts(self): |
| 131 | + content = VERIFY_RELEASE.read_text(encoding="utf-8") |
| 132 | + assert "Step 5" in content |
| 133 | + assert "install artifact" in content.lower() |
| 134 | + |
| 135 | + def test_handles_missing_artifacts_gracefully(self): |
| 136 | + content = VERIFY_RELEASE.read_text(encoding="utf-8") |
| 137 | + # Must skip gracefully when no install artifacts present |
| 138 | + assert "SKIP" in content or "skipping" in content.lower() |
| 139 | + |
| 140 | + def test_verifies_cosign_blob(self): |
| 141 | + content = VERIFY_RELEASE.read_text(encoding="utf-8") |
| 142 | + # Step 5 should use cosign verify-blob for install artifacts |
| 143 | + assert "cosign verify-blob" in content |
| 144 | + |
| 145 | + |
| 146 | +class TestBuildQcow2Script: |
| 147 | + def test_supports_ci_flag(self): |
| 148 | + content = (REPO_ROOT / "scripts" / "vm" / "build-qcow2.sh").read_text( |
| 149 | + encoding="utf-8" |
| 150 | + ) |
| 151 | + assert "--ci" in content |
| 152 | + |
| 153 | + def test_supports_image_ref_flag(self): |
| 154 | + content = (REPO_ROOT / "scripts" / "vm" / "build-qcow2.sh").read_text( |
| 155 | + encoding="utf-8" |
| 156 | + ) |
| 157 | + assert "--image-ref" in content |
0 commit comments