The projection lists both tar.gz and zip for platform-independent library releases; .zip must map to the archive asset kind so the website can offer it as a download format. Add coverage in the independent-release projection test.
601 lines
25 KiB
Python
601 lines
25 KiB
Python
#!/usr/bin/env python3
|
|
"""Tests for the public release projection (`scripts/project-release.py`)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SCRIPT = ROOT / "scripts" / "project-release.py"
|
|
CLI_SHA = "1" * 40
|
|
STD_SHA = "2" * 40
|
|
TARGET = "x86_64-unknown-linux-gnu"
|
|
VERSION = "3.0.0-rc.7"
|
|
ARCHIVE = f"marqdo-{VERSION}-{TARGET}.tar.gz"
|
|
INDEX_DIGEST = "a" * 64
|
|
ARCHIVE_DIGEST = "b" * 64
|
|
CHECKSUM_DIGEST = "c" * 64
|
|
EVIDENCE_DIGEST = "d" * 64
|
|
APP_SHA = "3" * 40
|
|
APP_VERSION = "0.1.0-beta.1"
|
|
APP_TAG = f"mqdh-v{APP_VERSION}"
|
|
APP_ARCHIVE = f"marqdo-harness-{APP_VERSION}-{TARGET}.tar.gz"
|
|
APP_INDEX_DIGEST = "f" * 64
|
|
APP_ARCHIVE_DIGEST = "1" * 64
|
|
APP_MANIFEST_DIGEST = "2" * 64
|
|
|
|
|
|
def git(repo: Path, *args: str) -> str:
|
|
return subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True,
|
|
text=True).stdout.strip()
|
|
|
|
|
|
def commit_file(repo: Path, name: str, content: str) -> str:
|
|
(repo / name).write_text(content, encoding="utf-8")
|
|
git(repo, "add", name)
|
|
git(repo, "-c", "user.name=test", "-c", "user.email=test@example.com", "commit", "-q", "-m", name)
|
|
return git(repo, "rev-parse", "HEAD")
|
|
|
|
|
|
def nested_commit(directory: Path) -> str:
|
|
directory.mkdir(parents=True)
|
|
git(directory, "init", "-q")
|
|
return commit_file(directory, "payload.txt", "payload\n")
|
|
|
|
|
|
def catalog() -> str:
|
|
return """\
|
|
[[component]]
|
|
id = "cli"
|
|
path = "cli"
|
|
kind = "core"
|
|
state = "active"
|
|
owner = "cflmy"
|
|
scope = "language and runtime"
|
|
requires = []
|
|
checks_with = ["conformance"]
|
|
release = "base"
|
|
entry = "tools/release/smoke.py"
|
|
|
|
[[component]]
|
|
id = "conformance"
|
|
path = "tests/conformance"
|
|
kind = "test"
|
|
state = "active"
|
|
owner = "cflmy"
|
|
scope = "public contract tests"
|
|
requires = ["cli"]
|
|
checks_with = []
|
|
release = "none"
|
|
entry = "scripts/build_all.sh"
|
|
|
|
[[component]]
|
|
id = "std-data"
|
|
path = "stdlib/data"
|
|
kind = "stdlib"
|
|
state = "active"
|
|
owner = "cflmy"
|
|
scope = "data modules"
|
|
requires = ["cli"]
|
|
checks_with = []
|
|
release = "base"
|
|
entry = "scripts/ci.sh"
|
|
"""
|
|
|
|
|
|
def gitmodules() -> str:
|
|
return """\
|
|
[submodule "cli"]
|
|
path = cli
|
|
url = https://git.cflmy.cn/cflmy/marqdo-cli.git
|
|
[submodule "tests/conformance"]
|
|
path = tests/conformance
|
|
url = https://git.cflmy.cn/cflmy/marqdo-extension-conformance.git
|
|
[submodule "stdlib/data"]
|
|
path = stdlib/data
|
|
url = https://git.cflmy.cn/cflmy/marqdo-std-data.git
|
|
"""
|
|
|
|
|
|
def app_catalog() -> str:
|
|
return catalog() + """
|
|
[[component]]
|
|
id = "app-harness"
|
|
path = "apps/harness"
|
|
kind = "app"
|
|
state = "active"
|
|
owner = "cflmy"
|
|
scope = "single-user application"
|
|
requires = ["cli"]
|
|
checks_with = []
|
|
release = "optional"
|
|
entry = "scripts/ci.sh"
|
|
"""
|
|
|
|
|
|
def app_gitmodules() -> str:
|
|
return gitmodules() + """\
|
|
[submodule "apps/harness"]
|
|
path = apps/harness
|
|
url = https://git.cflmy.cn/cflmy/marqdo-app-harness.git
|
|
"""
|
|
|
|
|
|
def app_release_entry(**overrides) -> dict:
|
|
entry = {
|
|
"component": "app-harness",
|
|
"path": "apps/harness",
|
|
"repository": "cflmy/marqdo-app-harness",
|
|
"tag": APP_TAG,
|
|
"published_at": "2026-12-02T08:00:00+00:00",
|
|
"accepted_sha": APP_SHA,
|
|
"component_state": "active",
|
|
"status": "pending",
|
|
"source_sha": APP_SHA,
|
|
"index_sha256": APP_INDEX_DIGEST,
|
|
"ci": {
|
|
"pipeline_number": 49,
|
|
"url": "https://ci.cflmy.cn/repos/21/pipeline/49",
|
|
"source_sha": APP_SHA,
|
|
},
|
|
"assets": [
|
|
{"name": APP_ARCHIVE, "size": 782584384, "target": TARGET, "sha256": APP_ARCHIVE_DIGEST},
|
|
{"name": APP_ARCHIVE + ".sha256", "size": 130, "target": TARGET, "sha256": CHECKSUM_DIGEST},
|
|
{"name": "mqdh-release.json", "size": 1000, "target": TARGET, "sha256": APP_MANIFEST_DIGEST},
|
|
{"name": "release-evidence.json", "size": 1400, "target": TARGET, "sha256": EVIDENCE_DIGEST},
|
|
],
|
|
"dependencies": [{"id": "cli", "source_sha": CLI_SHA}],
|
|
}
|
|
entry.update(overrides)
|
|
return entry
|
|
|
|
|
|
def app_acceptance(**overrides) -> dict:
|
|
record = {
|
|
"schema": "marqdo.release-acceptance",
|
|
"schema_version": 1,
|
|
"product": "mqdh",
|
|
"channel": "beta",
|
|
"version": APP_VERSION,
|
|
"platform": {
|
|
"target": TARGET,
|
|
"os": "linux",
|
|
"arch": "x86_64",
|
|
"minimum_runtime": "glibc 2.39",
|
|
},
|
|
"root_base_sha": "0" * 40,
|
|
"acceptance_url": f"https://git.cflmy.cn/cflmy/marqdo/releases/download/v3.0.0-beta.2/release-acceptance-mqdh.json",
|
|
"root_release_url": "https://git.cflmy.cn/cflmy/marqdo/releases/tag/v3.0.0-beta.2",
|
|
"install_guide_url": "https://git.cflmy.cn/cflmy/marqdo-app-harness/src/tag/mqdh-v0.1.0-beta.1/docs/mqdh/DISTRIBUTION.md",
|
|
"components": [
|
|
{
|
|
"id": "app-harness",
|
|
"release": {
|
|
"repository": "cflmy/marqdo-app-harness",
|
|
"tag": APP_TAG,
|
|
"source_sha": APP_SHA,
|
|
"index_sha256": APP_INDEX_DIGEST,
|
|
},
|
|
},
|
|
{
|
|
"id": "cli",
|
|
"release": {
|
|
"repository": "cflmy/marqdo-cli",
|
|
"tag": f"v{VERSION}",
|
|
"version": VERSION,
|
|
"source_sha": CLI_SHA,
|
|
"index_sha256": INDEX_DIGEST,
|
|
},
|
|
},
|
|
],
|
|
"enabled_capabilities": ["workbench", "bootstrap", "document-execution"],
|
|
"excluded_capabilities": ["native desktop shell", "automatic installation"],
|
|
"required_gates": {"linux": "PASS", "cold_install": "PASS"},
|
|
"deferred": [{
|
|
"item": "native-desktop-shell",
|
|
"state": "UNVERIFIED",
|
|
"scope": "linux-x86_64",
|
|
"tracker": "https://git.cflmy.cn/cflmy/marqdo-app-harness/issues/2",
|
|
"reason": "the beta package ships the portable workbench tree",
|
|
"risk": "no native window integration",
|
|
"revisit": "desktop shell milestone",
|
|
}],
|
|
"decision": "accepted",
|
|
"reviewer": "cflmy",
|
|
"accepted_at": "2026-12-02T08:10:00Z",
|
|
}
|
|
record.update(overrides)
|
|
return record
|
|
|
|
|
|
def release_entry(**overrides) -> dict:
|
|
entry = {
|
|
"component": "cli",
|
|
"path": "cli",
|
|
"repository": "cflmy/marqdo-cli",
|
|
"tag": f"v{VERSION}",
|
|
"published_at": "2026-12-02T05:00:00+00:00",
|
|
"accepted_sha": CLI_SHA,
|
|
"component_state": "active",
|
|
"status": "pending",
|
|
"source_sha": CLI_SHA,
|
|
"index_sha256": INDEX_DIGEST,
|
|
"ci": {
|
|
"pipeline_number": 176,
|
|
"url": "https://ci.cflmy.cn/repos/1/pipeline/176",
|
|
"source_sha": CLI_SHA,
|
|
},
|
|
"assets": [
|
|
{"name": ARCHIVE, "size": 4927204, "target": TARGET, "sha256": ARCHIVE_DIGEST},
|
|
{"name": ARCHIVE + ".sha256", "size": 116, "target": TARGET, "sha256": CHECKSUM_DIGEST},
|
|
{"name": "release-evidence.json", "size": 1200, "target": TARGET, "sha256": EVIDENCE_DIGEST},
|
|
],
|
|
"dependencies": [{"id": "std-data", "source_sha": STD_SHA}],
|
|
}
|
|
entry.update(overrides)
|
|
return entry
|
|
|
|
|
|
def loaded_assets() -> list[dict]:
|
|
return json.loads(json.dumps(release_entry()["assets"]))
|
|
|
|
|
|
def acceptance(**overrides) -> dict:
|
|
record = {
|
|
"schema": "marqdo.release-acceptance",
|
|
"schema_version": 1,
|
|
"product": "marqdo",
|
|
"channel": "rc",
|
|
"version": VERSION,
|
|
"platform": {
|
|
"target": TARGET,
|
|
"os": "linux",
|
|
"arch": "x86_64",
|
|
"minimum_runtime": "glibc 2.39",
|
|
},
|
|
"root_base_sha": "0" * 40,
|
|
"acceptance_url": f"https://git.cflmy.cn/cflmy/marqdo/releases/download/v{VERSION}/release-acceptance.json",
|
|
"root_release_url": f"https://git.cflmy.cn/cflmy/marqdo/releases/tag/v{VERSION}",
|
|
"install_guide_url": f"https://git.cflmy.cn/cflmy/marqdo-cli/src/tag/v{VERSION}/docs/developers/quickstart.md",
|
|
"components": [{
|
|
"id": "cli",
|
|
"release": {
|
|
"repository": "cflmy/marqdo-cli",
|
|
"tag": f"v{VERSION}",
|
|
"source_sha": CLI_SHA,
|
|
"index_sha256": INDEX_DIGEST,
|
|
},
|
|
"assets": loaded_assets(),
|
|
}],
|
|
"enabled_capabilities": ["check", "run", "call", "inspect", "stdlib-bundle"],
|
|
"excluded_capabilities": ["Windows/macOS native support", "strict L1 isolation"],
|
|
"required_gates": {
|
|
"linux": "PASS",
|
|
"strict_vm": "UNSUPPORTED",
|
|
"extension": "PASS",
|
|
"clean_install": "PASS",
|
|
},
|
|
"deferred": [{
|
|
"item": "windows-runtime-verification",
|
|
"state": "UNVERIFIED",
|
|
"scope": "windows-x86_64",
|
|
"tracker": "https://git.cflmy.cn/cflmy/marqdo-cli/issues/26",
|
|
"reason": "no native Windows runner in this release environment",
|
|
"risk": "not reachable from the accepted Linux asset",
|
|
"revisit": "next candidate",
|
|
}],
|
|
"decision": "accepted",
|
|
"reviewer": "cflmy",
|
|
"accepted_at": "2026-12-02T06:00:00Z",
|
|
}
|
|
record.update(overrides)
|
|
return record
|
|
|
|
|
|
class Fixture:
|
|
"""A tiny committed governance tree with real gitlinks."""
|
|
|
|
def __init__(self, root: Path, catalog_text: str | None = None,
|
|
modules_text: str | None = None, extra_gitlinks: dict[str, str] | None = None):
|
|
self.root = root
|
|
root.mkdir(parents=True, exist_ok=True)
|
|
git(root, "init", "-q")
|
|
commit_file(root, "components.toml", catalog_text if catalog_text is not None else catalog())
|
|
commit_file(root, ".gitmodules", modules_text if modules_text is not None else gitmodules())
|
|
for path, sha in (extra_gitlinks or {}).items():
|
|
subprocess.run(["git", "-C", str(root), "update-index", "--add", "--cacheinfo",
|
|
f"160000,{sha},{path}"], check=True)
|
|
subprocess.run(["git", "-C", str(root), "update-index", "--add", "--cacheinfo",
|
|
f"160000,{CLI_SHA},cli"], check=True)
|
|
subprocess.run(["git", "-C", str(root), "update-index", "--add", "--cacheinfo",
|
|
f"160000,{STD_SHA},stdlib/data"], check=True)
|
|
git(root, "-c", "user.name=test", "-c", "user.email=test@example.com",
|
|
"commit", "-q", "-m", "fixture gitlinks")
|
|
self.base = git(root, "rev-parse", "HEAD~1")
|
|
self.head = git(root, "rev-parse", "HEAD")
|
|
|
|
def write(self, name: str, value: dict) -> Path:
|
|
path = self.root.parent / name
|
|
path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
return path
|
|
|
|
|
|
def run_projection(tmp: Path, fixture: Fixture, record, report: dict,
|
|
revision: int = 0, out_name: str = "out",
|
|
generated_at: str = "2026-12-02T06:30:00Z", extra_args: list[str] | None = None):
|
|
records = record if isinstance(record, list) else [record]
|
|
acceptance_args: list[str] = []
|
|
for index, item in enumerate(records):
|
|
acceptance_path = fixture.write(f"acceptance-{index}.json", item)
|
|
acceptance_args.extend(["--acceptance", str(acceptance_path)])
|
|
report_path = fixture.write("reconcile.json", report)
|
|
out = tmp / out_name
|
|
result = subprocess.run([
|
|
sys.executable, str(SCRIPT),
|
|
"--root", str(fixture.root),
|
|
"--root-sha", fixture.head,
|
|
"--reconcile-report", str(report_path),
|
|
*acceptance_args,
|
|
"--generated-at", generated_at,
|
|
"--revision", str(revision),
|
|
"--out-dir", str(out),
|
|
*(extra_args or []),
|
|
], capture_output=True, text=True)
|
|
return result, out
|
|
|
|
|
|
class ProjectReleaseTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
base = ROOT / ".build" / "test-project-release"
|
|
base.mkdir(parents=True, exist_ok=True)
|
|
self._tmp = tempfile.TemporaryDirectory(dir=base)
|
|
self.tmp = Path(self._tmp.name)
|
|
self.fixture = Fixture(self.tmp / "repo")
|
|
|
|
def tearDown(self) -> None:
|
|
self._tmp.cleanup()
|
|
|
|
def report(self, **entry_overrides) -> dict:
|
|
return {
|
|
"schema": "marqdo.release-reconcile.v1",
|
|
"schema_version": 1,
|
|
"root_repository": "cflmy/marqdo",
|
|
"root_sha": self.fixture.head,
|
|
"scan_complete": True,
|
|
"results": [release_entry(**entry_overrides)],
|
|
}
|
|
|
|
def acceptance(self, **overrides) -> dict:
|
|
return acceptance(root_base_sha=self.fixture.base, **overrides)
|
|
|
|
def test_happy_path_emits_pointer_and_immutable_snapshot(self) -> None:
|
|
result, out = run_projection(self.tmp, self.fixture, self.acceptance(), self.report())
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
pointer = json.loads((out / "current.json").read_text(encoding="utf-8"))
|
|
self.assertEqual(pointer["revision"], 0)
|
|
self.assertEqual(pointer["schema_version"], 1)
|
|
snapshot_bytes = (out / pointer["snapshot"].removeprefix("/data/")).read_bytes()
|
|
self.assertEqual(hashlib.sha256(snapshot_bytes).hexdigest(), pointer["sha256"])
|
|
snapshot = json.loads(snapshot_bytes)
|
|
self.assertEqual(snapshot["snapshot_revision"], 0)
|
|
self.assertEqual(snapshot["root_source_sha"], self.fixture.head)
|
|
self.assertEqual([row["id"] for row in snapshot["components"]],
|
|
["cli", "conformance", "std-data"])
|
|
release = snapshot["releases"][0]
|
|
self.assertEqual(release["integration_state"], "accepted")
|
|
self.assertEqual(release["source_sha"], CLI_SHA)
|
|
self.assertEqual(snapshot["recommendations"][0]["channel"], "rc")
|
|
self.assertEqual(snapshot["offers"][0]["primary_asset_ids"],
|
|
[release["assets"][0]["asset_id"]])
|
|
asset = release["assets"][0]
|
|
self.assertEqual(asset["platform_status"], "supported")
|
|
self.assertEqual(asset["kind"], "archive")
|
|
self.assertEqual([row["platform_status"] for row in release["assets"][1:]],
|
|
["not-applicable", "not-applicable"])
|
|
# The acceptance URL and the verified release are traceable facts.
|
|
self.assertIn(self.acceptance()["acceptance_url"], snapshot["source_evidence_refs"])
|
|
self.assertIn(release["evidence_url"], snapshot["source_evidence_refs"])
|
|
|
|
def test_projection_is_deterministic_for_the_same_facts(self) -> None:
|
|
first, out_a = run_projection(self.tmp, self.fixture, self.acceptance(), self.report(),
|
|
out_name="a")
|
|
second, out_b = run_projection(self.tmp, self.fixture, self.acceptance(), self.report(),
|
|
out_name="b")
|
|
self.assertEqual(first.returncode, 0, first.stderr)
|
|
self.assertEqual(second.returncode, 0, second.stderr)
|
|
pointer = json.loads((out_a / "current.json").read_text(encoding="utf-8"))
|
|
digest = pointer["sha256"]
|
|
self.assertEqual((out_b / f"snapshots/{digest}.json").read_bytes(),
|
|
(out_a / f"snapshots/{digest}.json").read_bytes())
|
|
self.assertEqual((out_b / "current.json").read_bytes(),
|
|
(out_a / "current.json").read_bytes())
|
|
|
|
def test_projects_verified_independent_release_as_pending(self) -> None:
|
|
independent_sha = "4" * 40
|
|
independent = release_entry(
|
|
component="std-data", path="stdlib/data", repository="cflmy/marqdo-std-data",
|
|
tag="v0.1.1", source_sha=independent_sha, accepted_sha=independent_sha,
|
|
index_sha256="e" * 64,
|
|
ci={"pipeline_number": 27, "url": "https://ci.cflmy.cn/repos/10/pipeline/27",
|
|
"source_sha": independent_sha},
|
|
assets=[{"name": "marqdo-std-data-0.1.1-source.tar.gz", "size": 6763,
|
|
"target": "source", "sha256": "9" * 64},
|
|
{"name": "marqdo-std-data-0.1.1-source.zip", "size": 7000,
|
|
"target": "source", "sha256": "8" * 64}],
|
|
dependencies=[],
|
|
published_at="2026-12-03T00:20:00+00:00",
|
|
)
|
|
report = self.report()
|
|
report["results"].append(independent)
|
|
result, out = run_projection(
|
|
self.tmp, self.fixture, self.acceptance(), report,
|
|
extra_args=["--include-independent-releases",
|
|
"--independent-repository", "cflmy/marqdo-std-data"])
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
pointer = json.loads((out / "current.json").read_text(encoding="utf-8"))
|
|
snapshot = json.loads((out / pointer["snapshot"].removeprefix("/data/")).read_text(encoding="utf-8"))
|
|
rows = {row["release_id"]: row for row in snapshot["releases"]}
|
|
self.assertIn("std-data-0.1.1", rows)
|
|
pending = rows["std-data-0.1.1"]
|
|
self.assertEqual(pending["integration_state"], "pending")
|
|
self.assertEqual(pending["distribution_state"], "available")
|
|
self.assertEqual(pending["channel"], "stable")
|
|
self.assertEqual([asset["kind"] for asset in pending["assets"]],
|
|
["archive", "archive"])
|
|
self.assertEqual([offer["product"] for offer in snapshot["offers"]], ["marqdo"])
|
|
self.assertEqual([item["offer_id"] for item in snapshot["recommendations"]],
|
|
[snapshot["offers"][0]["offer_id"]])
|
|
|
|
def test_rejects_source_sha_not_pinned_by_root(self) -> None:
|
|
record = self.acceptance()
|
|
record["components"][0]["release"]["source_sha"] = "9" * 40
|
|
result, _ = run_projection(self.tmp, self.fixture, record, self.report())
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("!= root gitlink", result.stderr)
|
|
|
|
def test_rejects_bundle_dependency_not_pinned_by_root(self) -> None:
|
|
result, _ = run_projection(
|
|
self.tmp, self.fixture, self.acceptance(),
|
|
self.report(dependencies=[{"id": "std-data", "source_sha": "9" * 40}]))
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("Bundle dependency std-data", result.stderr)
|
|
|
|
def test_rejects_unverified_release(self) -> None:
|
|
result, _ = run_projection(self.tmp, self.fixture, self.acceptance(),
|
|
self.report(status="blocked", error="asset digest mismatch"))
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("not a verified release", result.stderr)
|
|
|
|
def test_rejects_blocked_scan(self) -> None:
|
|
report = self.report()
|
|
report["scan_complete"] = False
|
|
result, _ = run_projection(self.tmp, self.fixture, self.acceptance(), report)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("scan is not complete", result.stderr)
|
|
|
|
def test_rejects_channel_version_mismatch(self) -> None:
|
|
result, _ = run_projection(self.tmp, self.fixture,
|
|
self.acceptance(channel="beta"), self.report())
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("does not match version", result.stderr)
|
|
|
|
def test_rejects_asset_digest_mismatch_between_acceptance_and_release(self) -> None:
|
|
record = self.acceptance()
|
|
record["components"][0]["assets"][0]["sha256"] = "e" * 64
|
|
result, _ = run_projection(self.tmp, self.fixture, record, self.report())
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("accepted assets do not match", result.stderr)
|
|
|
|
def test_rejects_rejected_decision(self) -> None:
|
|
result, _ = run_projection(self.tmp, self.fixture,
|
|
self.acceptance(decision="rejected"), self.report())
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("only an accepted record", result.stderr)
|
|
|
|
def test_rejects_non_advancing_revision(self) -> None:
|
|
result, out = run_projection(self.tmp, self.fixture, self.acceptance(), self.report())
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
again, _ = run_projection(self.tmp, self.fixture, self.acceptance(), self.report(),
|
|
revision=0, out_name="out")
|
|
self.assertNotEqual(again.returncode, 0)
|
|
self.assertIn("requires revision 1", again.stderr)
|
|
|
|
def test_rejects_unverified_domain_checkout(self) -> None:
|
|
# An active domain without a checkout must fail closed instead of
|
|
# silently projecting an incomplete catalog.
|
|
fixture = Fixture(self.tmp / "repo2")
|
|
with (fixture.root / "components.toml").open("a", encoding="utf-8") as handle:
|
|
handle.write("""
|
|
[[component]]
|
|
id = "web"
|
|
path = "extensions/web"
|
|
kind = "domain"
|
|
state = "active"
|
|
owner = "cflmy"
|
|
scope = "web authoring"
|
|
requires = []
|
|
checks_with = []
|
|
release = "none"
|
|
entry = ""
|
|
""")
|
|
with (fixture.root / ".gitmodules").open("a", encoding="utf-8") as handle:
|
|
handle.write("""[submodule "extensions/web"]
|
|
\tpath = extensions/web
|
|
\turl = https://git.cflmy.cn/cflmy/marqdo-ext-web.git
|
|
""")
|
|
web_sha = nested_commit(fixture.root.parent / "objects-web")
|
|
subprocess.run(["git", "-C", str(fixture.root), "update-index", "--add", "--cacheinfo",
|
|
f"160000,{web_sha},extensions/web"], check=True)
|
|
git(fixture.root, "add", "components.toml", ".gitmodules")
|
|
git(fixture.root, "-c", "user.name=test", "-c", "user.email=test@example.com",
|
|
"commit", "-q", "-m", "add domain without checkout")
|
|
fixture.base = git(fixture.root, "rev-parse", "HEAD~1")
|
|
fixture.head = git(fixture.root, "rev-parse", "HEAD")
|
|
report = {
|
|
"schema": "marqdo.release-reconcile.v1", "schema_version": 1,
|
|
"root_sha": fixture.head, "scan_complete": True,
|
|
"results": [release_entry()],
|
|
}
|
|
result, _ = run_projection(self.tmp, fixture,
|
|
acceptance(root_base_sha=fixture.base), report, out_name="domain")
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("cannot be expanded", result.stderr)
|
|
|
|
|
|
def test_projects_an_application_offer_with_a_managed_runtime(self) -> None:
|
|
fixture = Fixture(self.tmp / "repo-app", catalog_text=app_catalog(),
|
|
modules_text=app_gitmodules(), extra_gitlinks={"apps/harness": APP_SHA})
|
|
report = {
|
|
"schema": "marqdo.release-reconcile.v1", "schema_version": 1,
|
|
"root_sha": fixture.head, "scan_complete": True, "results": [
|
|
release_entry(), app_release_entry(),
|
|
],
|
|
}
|
|
records = [acceptance(root_base_sha=fixture.base),
|
|
app_acceptance(root_base_sha=fixture.base)]
|
|
result, out = run_projection(self.tmp, fixture, records, report, out_name="app")
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
pointer = json.loads((out / "current.json").read_text(encoding="utf-8"))
|
|
snapshot = json.loads((out / pointer["snapshot"].removeprefix("/data/")).read_text(encoding="utf-8"))
|
|
offers = {offer["offer_id"]: offer for offer in snapshot["offers"]}
|
|
mqdh = offers[f"mqdh-{APP_VERSION}-{TARGET}"]
|
|
self.assertEqual(mqdh["channel"], "beta")
|
|
self.assertEqual(mqdh["primary_asset_ids"],
|
|
[f"app-harness-{APP_VERSION}-{APP_ARCHIVE}"])
|
|
installations = {member["release_id"]: member["installation"] for member in mqdh["components"]}
|
|
self.assertEqual(installations, {
|
|
f"app-harness-{APP_VERSION}": "included",
|
|
f"cli-{VERSION}": "managed",
|
|
})
|
|
channels = {release["release_id"]: release["channel"] for release in snapshot["releases"]}
|
|
self.assertEqual(channels, {
|
|
f"app-harness-{APP_VERSION}": "beta",
|
|
f"cli-{VERSION}": "rc",
|
|
})
|
|
self.assertEqual(len(snapshot["recommendations"]), 2)
|
|
|
|
def test_rejects_application_tag_without_the_mqdh_prefix(self) -> None:
|
|
fixture = Fixture(self.tmp / "repo-app-bad", catalog_text=app_catalog(),
|
|
modules_text=app_gitmodules(), extra_gitlinks={"apps/harness": APP_SHA})
|
|
report = {
|
|
"schema": "marqdo.release-reconcile.v1", "schema_version": 1,
|
|
"root_sha": fixture.head, "scan_complete": True, "results": [
|
|
release_entry(), app_release_entry(tag=f"v{APP_VERSION}"),
|
|
],
|
|
}
|
|
record = app_acceptance(root_base_sha=fixture.base)
|
|
record["components"][0]["release"]["tag"] = f"v{APP_VERSION}"
|
|
result, _ = run_projection(self.tmp, fixture, record, report, out_name="app-bad")
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("app release tag", result.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|