ci: align release tooling with the upstream deterministic pipeline
- add tools/release/package.py: sorted, commit-timestamped, uid/gid-normalised deterministic archive; refuses dirty trees, source-SHA mismatch and stale versions; emits SOURCE_SHA, FILES.sha256 and RELEASE_INFO.json with binaries, protocol revisions, core baseline and manifest digest - add tools/release/smoke.py: verifies checksum/manifest/source/version then cold-installs the archive through a real core CLI into an isolated MARQDO_TOOL_HOME and exercises help/compile/query/check/remove, writing smoke evidence - add tools/ci/test_release_metadata.py: single CI gate for version/fact consistency across Cargo files, tool.json, spec, CHANGELOG, release notes, README and CI configuration - Woodpecker and GitHub pipelines now run the metadata gate and use the Python packager/smoke test in the tag-only release lane; shell release scripts are thin wrappers; docs/ci.md and docs/releasing.md document gates and non-gates
This commit is contained in:
1 parent
85458c1d93
commit
835f61dc01
13 files changed
+663
-122
No files matched your search
Binary file not shown.
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Metadata consistency gate for the beta release.
|
||||
|
||||
Checks that the tool version, Cargo files, tool manifest, public spec, changelog,
|
||||
release notes and CI configuration describe the same facts. This is a
|
||||
documentation/contract gate, not a functional test.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def fail(message: str) -> "NoReturn":
|
||||
print(f"release-metadata: FAIL: {message}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
cargo = (ROOT / "Cargo.toml").read_text(encoding="utf-8")
|
||||
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', cargo)
|
||||
if not match:
|
||||
fail("Cargo.toml has no version")
|
||||
version = match.group(1)
|
||||
if not re.fullmatch(r"\d+\.\d+\.\d+-beta\.\d+", version):
|
||||
fail(f"version {version} is not a beta semver (expected x.y.z-beta.N)")
|
||||
lock = (ROOT / "Cargo.lock").read_text(encoding="utf-8")
|
||||
if not re.search(
|
||||
r'\[\[package\]\]\nname = "marqdo-knowledge"\nversion = "' + re.escape(version) + r'"',
|
||||
lock,
|
||||
):
|
||||
fail("Cargo.lock version does not match Cargo.toml")
|
||||
|
||||
tool = json.loads((ROOT / "packaging/tool.json").read_text(encoding="utf-8"))
|
||||
expected = {
|
||||
"schema": "marqdo.cli-tool",
|
||||
"schema_version": 1,
|
||||
"name": "marqdo-knowledge",
|
||||
"version": version,
|
||||
"command": "knowledge",
|
||||
"entrypoint": "bin/marqdo-knowledge",
|
||||
"requires": {"api_revision": 1, "analysis": 3},
|
||||
}
|
||||
if tool != expected:
|
||||
fail(f"packaging/tool.json is not the current exact manifest: {tool}")
|
||||
|
||||
spec = (ROOT / "spec/knowledge.md").read_text(encoding="utf-8")
|
||||
if f'"version": "{version}"' not in spec:
|
||||
fail("spec/knowledge.md tool identity version is stale")
|
||||
if '"requires": {"api_revision": 1, "analysis": 3}' not in spec:
|
||||
fail("spec/knowledge.md requirements are stale")
|
||||
|
||||
changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
if f"## {version}" not in changelog:
|
||||
fail("CHANGELOG.md has no section for this version")
|
||||
notes = ROOT / "docs/releases" / f"{version}.md"
|
||||
if not notes.is_file():
|
||||
fail(f"missing docs/releases/{version}.md")
|
||||
body = notes.read_text(encoding="utf-8")
|
||||
for heading in ("What is complete in this beta", "What is NOT complete in this beta", "Compatibility and upgrade notes"):
|
||||
if heading not in body:
|
||||
fail(f"release notes are missing section `{heading}`")
|
||||
|
||||
readme = (ROOT / "README.md").read_text(encoding="utf-8")
|
||||
if version not in readme:
|
||||
fail("README.md does not mention the current version")
|
||||
|
||||
for configuration in (".woodpecker/main.yml", ".github/workflows/ci.yml"):
|
||||
text = (ROOT / configuration).read_text(encoding="utf-8")
|
||||
if "tools/release/package.py" not in text:
|
||||
fail(f"{configuration} does not use the deterministic packager")
|
||||
if "tools/release/smoke.py" not in text:
|
||||
fail(f"{configuration} does not run the archive smoke test")
|
||||
|
||||
ci_docs = (ROOT / "docs/ci.md").read_text(encoding="utf-8")
|
||||
if "NOT RUN" not in ci_docs:
|
||||
fail("docs/ci.md must state the non-gated items")
|
||||
print(f"release-metadata: OK (version {version})")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Binary file not shown.
Binary file not shown.
Executable
+309
@@ -0,0 +1,309 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the deterministic marqdo-knowledge beta release archive.
|
||||
|
||||
The archive is reproducible: sorted entries, commit timestamp for all mtimes,
|
||||
uid/gid 0, normalised modes, gzip without a timestamp. It refuses a dirty tree,
|
||||
a version that does not match `Cargo.toml`, or a HEAD that differs from
|
||||
`--source-sha`. It never publishes anything; tagging is a separate reviewed
|
||||
step.
|
||||
|
||||
Usage (from the repository root, after `cargo build --release --locked`):
|
||||
|
||||
python3 tools/release/package.py \
|
||||
--source-sha "$(git rev-parse HEAD)" \
|
||||
--version "$(sed -n 's/^version = \"\\(.*\\)\"/\\1/p' Cargo.toml | head -1)"
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
TARGET = "x86_64-unknown-linux-gnu"
|
||||
CORE_BASELINE = (
|
||||
"cflmy/marqdo-cli@4bbefc92449ee480c8a2c89b0308feb4cda8d0e7 (3.0.0-rc.4)"
|
||||
)
|
||||
COPY_FILES = (
|
||||
"tool.json",
|
||||
"README.md",
|
||||
"LICENSE-APACHE",
|
||||
"CHANGELOG.md",
|
||||
"docs/STATUS.md",
|
||||
"docs/ci.md",
|
||||
"docs/releasing.md",
|
||||
)
|
||||
COPY_TREES = (
|
||||
"docs/architecture",
|
||||
"docs/releases",
|
||||
"examples",
|
||||
"spec",
|
||||
)
|
||||
SKIP_TREE_PARTS = {".git", ".marqdo", "target", "dist", ".cargo-home", ".scratch"}
|
||||
SKIP_SUFFIXES = {".sqlite", ".sqlite-journal", ".sqlite-wal", ".sqlite-shm"}
|
||||
|
||||
|
||||
def fail(message: str) -> "NoReturn":
|
||||
print(f"package: error: {message}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def run(command: list[str], *, cwd: Path = ROOT, capture: bool = False) -> str:
|
||||
completed = subprocess.run(
|
||||
command,
|
||||
cwd=cwd,
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=capture,
|
||||
)
|
||||
return completed.stdout.strip() if capture else ""
|
||||
|
||||
|
||||
def git(*args: str) -> str:
|
||||
return run(["git", *args], capture=True)
|
||||
|
||||
|
||||
def sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as handle:
|
||||
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def cargo_version() -> str:
|
||||
text = (ROOT / "Cargo.toml").read_text(encoding="utf-8")
|
||||
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text)
|
||||
if not match:
|
||||
fail("Cargo.toml has no package version")
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def check_version_consistency(version: str) -> None:
|
||||
if cargo_version() != version:
|
||||
fail(f"--version {version} does not match Cargo.toml {cargo_version()}")
|
||||
lock = (ROOT / "Cargo.lock").read_text(encoding="utf-8")
|
||||
match = re.search(
|
||||
r'\[\[package\]\]\nname = "marqdo-knowledge"\nversion = "([^"]+)"', lock
|
||||
)
|
||||
if not match or match.group(1) != version:
|
||||
fail("Cargo.lock marqdo-knowledge version does not match Cargo.toml")
|
||||
tool = json.loads((ROOT / "packaging/tool.json").read_text(encoding="utf-8"))
|
||||
if tool.get("version") != version:
|
||||
fail("packaging/tool.json version does not match Cargo.toml")
|
||||
if tool.get("entrypoint") != "bin/marqdo-knowledge":
|
||||
fail("packaging/tool.json entrypoint must be bin/marqdo-knowledge")
|
||||
if tool.get("requires") != {"api_revision": 1, "analysis": 3}:
|
||||
fail("packaging/tool.json requires must be exactly api_revision 1 / analysis 3")
|
||||
spec = (ROOT / "spec/knowledge.md").read_text(encoding="utf-8")
|
||||
if f'"version": "{version}"' not in spec:
|
||||
fail("spec/knowledge.md tool identity version is stale")
|
||||
notes = ROOT / "docs/releases" / f"{version}.md"
|
||||
if not notes.is_file():
|
||||
fail(f"missing release notes {notes.relative_to(ROOT)}")
|
||||
|
||||
|
||||
def clean_tree() -> None:
|
||||
status = git("status", "--porcelain")
|
||||
if status:
|
||||
fail("working tree is dirty; commit before packaging")
|
||||
head = git("rev-parse", "HEAD")
|
||||
if not re.fullmatch(r"[a-f0-9]{40}", head):
|
||||
fail("HEAD is not a full commit sha")
|
||||
return head
|
||||
|
||||
|
||||
def collect_examples(stage: Path, version: str) -> None:
|
||||
examples = ROOT / "examples"
|
||||
if not examples.is_dir():
|
||||
fail("examples directory is missing")
|
||||
for path in sorted(examples.rglob("*")):
|
||||
relative = path.relative_to(ROOT)
|
||||
if any(part in SKIP_TREE_PARTS for part in relative.parts):
|
||||
continue
|
||||
if path.is_dir() or path.suffix in SKIP_SUFFIXES:
|
||||
continue
|
||||
destination = stage / relative
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(path, destination)
|
||||
# The compiled database is never shipped.
|
||||
for stale in stage.rglob(".marqdo"):
|
||||
if stale.is_dir():
|
||||
shutil.rmtree(stale)
|
||||
if not (stage / "examples/mixed/notes.md").is_file():
|
||||
fail("examples/mixed is missing from the staged archive")
|
||||
|
||||
|
||||
def build_stage(stage: Path, version: str, source_sha: str, commit_time: datetime.datetime) -> None:
|
||||
binary = ROOT / "target/release/marqdo-knowledge"
|
||||
if not binary.is_file():
|
||||
fail("target/release/marqdo-knowledge is missing; run cargo build --release --locked")
|
||||
(stage / "bin").mkdir(parents=True)
|
||||
shutil.copyfile(binary, stage / "bin/marqdo-knowledge")
|
||||
(stage / "bin/marqdo-knowledge").chmod(0o755)
|
||||
|
||||
for name in COPY_FILES:
|
||||
source = ROOT / name
|
||||
if not source.is_file():
|
||||
fail(f"missing required file {name}")
|
||||
shutil.copyfile(source, stage / name)
|
||||
shutil.copyfile(ROOT / "packaging/tool.json", stage / "tool.json")
|
||||
|
||||
for tree in COPY_TREES:
|
||||
source = ROOT / tree
|
||||
if not source.is_dir():
|
||||
fail(f"missing required directory {tree}")
|
||||
for path in sorted(source.rglob("*")):
|
||||
if path.is_dir() or path.suffix in SKIP_SUFFIXES:
|
||||
continue
|
||||
if any(part in SKIP_TREE_PARTS for part in path.relative_to(ROOT).parts):
|
||||
continue
|
||||
destination = stage / path.relative_to(ROOT)
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(path, destination)
|
||||
collect_examples(stage, version)
|
||||
|
||||
(stage / "SOURCE_SHA").write_text(source_sha + "\n", encoding="utf-8")
|
||||
|
||||
# Per-file manifest. FILES.sha256 and RELEASE_INFO.json are themselves not
|
||||
# listed, so the manifest stays independent of these metadata files.
|
||||
files = []
|
||||
for path in sorted(stage.rglob("*")):
|
||||
if not path.is_file():
|
||||
continue
|
||||
relative = path.relative_to(stage).as_posix()
|
||||
if relative in {"FILES.sha256", "RELEASE_INFO.json"}:
|
||||
continue
|
||||
files.append((relative, sha256_file(path), path.stat().st_size))
|
||||
manifest_lines = "".join(
|
||||
f"{digest} {relative}\n" for relative, digest, _size in files
|
||||
)
|
||||
(stage / "FILES.sha256").write_text(manifest_lines, encoding="utf-8")
|
||||
manifest_digest = sha256_file(stage / "FILES.sha256")
|
||||
|
||||
binary_info = {
|
||||
"sha256": sha256_file(stage / "bin/marqdo-knowledge"),
|
||||
"size": (stage / "bin/marqdo-knowledge").stat().st_size,
|
||||
}
|
||||
info = {
|
||||
"schema": "marqdo.knowledge.release-info",
|
||||
"schema_version": 1,
|
||||
"product": "marqdo-knowledge",
|
||||
"product_version": version,
|
||||
"channel": "beta",
|
||||
"target": TARGET,
|
||||
"build_profile": "release",
|
||||
"source_sha": source_sha,
|
||||
"commit_time_utc": commit_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||
"protocols": {
|
||||
"cli_tool": 1,
|
||||
"tool_api_revision": 1,
|
||||
"analysis": 3,
|
||||
"sqlite_schema": 1,
|
||||
"okf": "0.3",
|
||||
},
|
||||
"binaries": {"marqdo-knowledge": binary_info},
|
||||
"core_baseline": CORE_BASELINE,
|
||||
"files_manifest": "FILES.sha256",
|
||||
"files_manifest_sha256": manifest_digest,
|
||||
"file_count": len(files) + 2,
|
||||
"known_limitations": "docs/STATUS.md",
|
||||
"notes": [
|
||||
"Checksums prove content integrity only; they are not a publisher signature.",
|
||||
"Install through `marqdo tool install <this bundle>`; direct execution requires a compatible core CLI.",
|
||||
"Run `python3 tools/release/smoke.py --archive <tarball>` before publishing.",
|
||||
],
|
||||
}
|
||||
(stage / "RELEASE_INFO.json").write_text(
|
||||
json.dumps(info, indent=2, sort_keys=True, ensure_ascii=False) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def write_archive(stage: Path, commit_time: datetime.datetime, out_dir: Path, version: str) -> Path:
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
base = f"marqdo-knowledge-{version}-{TARGET}"
|
||||
archive = out_dir / f"{base}.tar.gz"
|
||||
if archive.exists():
|
||||
archive.unlink()
|
||||
with tempfile.NamedTemporaryFile(dir=out_dir, delete=False) as raw:
|
||||
raw_path = Path(raw.name)
|
||||
try:
|
||||
with raw_path.open("wb") as raw_file:
|
||||
with gzip.GzipFile(filename="", mode="wb", fileobj=raw_file, mtime=0, compresslevel=9) as compressed:
|
||||
with tarfile.open(fileobj=compressed, mode="w", format=tarfile.GNU_FORMAT) as tar:
|
||||
for path in sorted(stage.rglob("*")):
|
||||
relative = path.relative_to(stage).as_posix()
|
||||
info = tarfile.TarInfo(name=f"{base}/{relative}")
|
||||
info.uid = 0
|
||||
info.gid = 0
|
||||
info.uname = ""
|
||||
info.gname = ""
|
||||
info.mtime = int(commit_time.timestamp())
|
||||
if path.is_dir():
|
||||
info.type = tarfile.DIRTYPE
|
||||
info.mode = 0o755
|
||||
tar.addfile(info)
|
||||
else:
|
||||
info.type = tarfile.REGTYPE
|
||||
info.mode = 0o755 if relative.startswith("bin/") else 0o644
|
||||
info.size = path.stat().st_size
|
||||
with path.open("rb") as handle:
|
||||
tar.addfile(info, handle)
|
||||
shutil.move(raw_path, archive)
|
||||
finally:
|
||||
if raw_path.exists():
|
||||
raw_path.unlink()
|
||||
digest = sha256_file(archive)
|
||||
checksum = out_dir / f"{archive.name}.sha256"
|
||||
checksum.write_text(f"{digest} {archive.name}\n", encoding="utf-8")
|
||||
print(f"archive: {archive}")
|
||||
print(f"sha256: {digest}")
|
||||
print(f"manifest: {out_dir / 'RELEASE_INFO.json'}")
|
||||
return archive
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--source-sha", required=True)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument("--out-dir", default="dist")
|
||||
args = parser.parse_args()
|
||||
|
||||
head = clean_tree()
|
||||
if args.source_sha != head:
|
||||
fail(f"--source-sha {args.source_sha} does not match HEAD {head}")
|
||||
check_version_consistency(args.version)
|
||||
|
||||
version_output = run(
|
||||
[str(ROOT / "target/release/marqdo-knowledge"), "--version"], capture=True
|
||||
)
|
||||
if version_output != f"marqdo-knowledge {args.version}":
|
||||
fail(f"release binary reports `{version_output}`, expected version {args.version}")
|
||||
|
||||
commit_epoch = int(git("show", "-s", "--format=%ct", head))
|
||||
commit_time = datetime.datetime.fromtimestamp(commit_epoch, datetime.timezone.utc)
|
||||
out_dir = (ROOT / args.out_dir).resolve() if not Path(args.out_dir).is_absolute() else Path(args.out_dir)
|
||||
with tempfile.TemporaryDirectory(prefix="marqdo-knowledge-package-") as temporary:
|
||||
stage = Path(temporary)
|
||||
build_stage(stage, args.version, head, commit_time)
|
||||
archive = write_archive(stage, commit_time, out_dir, args.version)
|
||||
shutil.copyfile(stage / "RELEASE_INFO.json", out_dir / "RELEASE_INFO.json")
|
||||
shutil.copyfile(stage / "FILES.sha256", out_dir / "FILES.sha256")
|
||||
print(f"source_sha: {head}")
|
||||
print(f"target: {TARGET}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+209
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Cold-install smoke test for a built marqdo-knowledge release archive.
|
||||
|
||||
Extracts the archive into a fresh directory, verifies its checksum, source SHA,
|
||||
file manifest and version consistency, installs the bundle through the real
|
||||
core CLI into an isolated MARQDO_TOOL_HOME, then exercises the shipped tool:
|
||||
help, compile/query/check on the packaged examples, and removal. It never uses
|
||||
the development source tree.
|
||||
|
||||
Usage:
|
||||
MARQDO_BIN=/path/to/marqdo python3 tools/release/smoke.py \
|
||||
--archive dist/marqdo-knowledge-0.1.0-beta.2-x86_64-unknown-linux-gnu.tar.gz
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def fail(message: str) -> "NoReturn":
|
||||
print(f"smoke: FAIL: {message}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as handle:
|
||||
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def run(command: list[str], *, env: dict[str, str] | None = None) -> str:
|
||||
completed = subprocess.run(
|
||||
command,
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
env=env,
|
||||
)
|
||||
return completed.stdout.strip()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--archive", required=True)
|
||||
parser.add_argument("--marqdo-bin", default=os.environ.get("MARQDO_BIN", ""))
|
||||
parser.add_argument("--evidence-out", default="")
|
||||
args = parser.parse_args()
|
||||
|
||||
marqdo = Path(args.marqdo_bin)
|
||||
if not marqdo.is_file():
|
||||
fail("set --marqdo-bin or MARQDO_BIN to a real core CLI binary")
|
||||
archive = Path(args.archive).resolve()
|
||||
if not archive.is_file():
|
||||
fail(f"archive {archive} does not exist")
|
||||
checksum_path = archive.with_name(archive.name + ".sha256")
|
||||
if not checksum_path.is_file():
|
||||
fail(f"missing checksum {checksum_path.name}")
|
||||
expected = checksum_path.read_text(encoding="utf-8").split()[0]
|
||||
actual = sha256_file(archive)
|
||||
if expected != actual:
|
||||
fail(f"archive SHA-256 {actual} does not match checksum {expected}")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="marqdo-knowledge-smoke-") as work:
|
||||
work_path = Path(work)
|
||||
with tarfile.open(archive, "r:gz") as tar:
|
||||
members = tar.getnames()
|
||||
if any(name.startswith("/") or ".." in Path(name).parts for name in members):
|
||||
fail("archive contains an unsafe path")
|
||||
tar.extractall(work_path)
|
||||
roots = [path for path in work_path.iterdir() if path.is_dir()]
|
||||
if len(roots) != 1:
|
||||
fail("archive must contain exactly one top directory")
|
||||
package = roots[0]
|
||||
info = json.loads((package / "RELEASE_INFO.json").read_text(encoding="utf-8"))
|
||||
tool = json.loads((package / "tool.json").read_text(encoding="utf-8"))
|
||||
source_sha = (package / "SOURCE_SHA").read_text(encoding="utf-8").strip()
|
||||
if not re.fullmatch(r"[a-f0-9]{40}", source_sha):
|
||||
fail("SOURCE_SHA is not a full commit sha")
|
||||
if info.get("source_sha") != source_sha:
|
||||
fail("RELEASE_INFO source_sha does not match SOURCE_SHA")
|
||||
if info.get("product_version") != tool.get("version"):
|
||||
fail("RELEASE_INFO product_version does not match tool.json")
|
||||
if tool.get("entrypoint") != "bin/marqdo-knowledge":
|
||||
fail("tool.json entrypoint is not bin/marqdo-knowledge")
|
||||
binary = package / "bin/marqdo-knowledge"
|
||||
if not binary.is_file() or not os.access(binary, os.X_OK):
|
||||
fail("packaged entrypoint is missing or not executable")
|
||||
version_output = run([str(binary), "--version"])
|
||||
if version_output != f"marqdo-knowledge {tool.get('version')}":
|
||||
fail(f"packaged binary reports `{version_output}`")
|
||||
manifest = package / "FILES.sha256"
|
||||
listed: dict[str, str] = {}
|
||||
for line in manifest.read_text(encoding="utf-8").splitlines():
|
||||
parts = line.split(" ", 1)
|
||||
if len(parts) != 2:
|
||||
fail("FILES.sha256 has a malformed line")
|
||||
digest, relative = parts
|
||||
listed[relative] = digest
|
||||
manifest_digest = sha256_file(manifest)
|
||||
if info.get("files_manifest_sha256") != manifest_digest:
|
||||
fail("RELEASE_INFO files_manifest_sha256 does not match FILES.sha256")
|
||||
for relative, digest in listed.items():
|
||||
path = package / relative
|
||||
if not path.is_file():
|
||||
fail(f"manifest lists missing file {relative}")
|
||||
if sha256_file(path) != digest:
|
||||
fail(f"file digest mismatch for {relative}")
|
||||
|
||||
tool_home = work_path / "tool-home"
|
||||
tool_home.mkdir()
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_TOOL_HOME"] = str(tool_home)
|
||||
env.pop("MARQDO_API_REVISION", None)
|
||||
run([str(marqdo), "tool", "install", str(package)], env=env)
|
||||
try:
|
||||
listing = run([str(marqdo), "tool", "list"], env=env)
|
||||
if "knowledge" not in listing:
|
||||
fail("tool was not listed after install")
|
||||
run([str(marqdo), "knowledge", "--help"], env=env)
|
||||
compile_report = json.loads(
|
||||
run(
|
||||
[
|
||||
str(marqdo),
|
||||
"knowledge",
|
||||
"compile",
|
||||
str(package / "examples/mixed"),
|
||||
"--json",
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
)
|
||||
if not compile_report.get("success"):
|
||||
fail("compile did not succeed")
|
||||
if compile_report["payload"]["documents"] <= 0:
|
||||
fail("compile reported no documents")
|
||||
query_report = json.loads(
|
||||
run(
|
||||
[
|
||||
str(marqdo),
|
||||
"knowledge",
|
||||
"query",
|
||||
"归一化",
|
||||
"--root",
|
||||
str(package / "examples/mixed"),
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
)
|
||||
if not query_report.get("success") or not query_report.get("hits"):
|
||||
fail("query returned no hits")
|
||||
check_report = json.loads(
|
||||
run(
|
||||
[
|
||||
str(marqdo),
|
||||
"knowledge",
|
||||
"check",
|
||||
str(package / "examples/mixed"),
|
||||
"--json",
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
)
|
||||
if not check_report.get("success") or check_report["payload"]["errors"] != 0:
|
||||
fail("check failed")
|
||||
if check_report["payload"]["database"] != "current":
|
||||
fail("check did not report a current database")
|
||||
evidence = {
|
||||
"schema": "marqdo.knowledge.smoke",
|
||||
"schema_version": 1,
|
||||
"archive": archive.name,
|
||||
"archive_sha256": actual,
|
||||
"source_sha": source_sha,
|
||||
"version": tool["version"],
|
||||
"core": run([str(marqdo), "--version"]),
|
||||
"documents": compile_report["payload"]["documents"],
|
||||
"query_hits": len(query_report["hits"]),
|
||||
"database": check_report["payload"]["database"],
|
||||
}
|
||||
print(json.dumps(evidence, indent=2, sort_keys=True, ensure_ascii=False))
|
||||
if args.evidence_out:
|
||||
Path(args.evidence_out).write_text(
|
||||
json.dumps(evidence, indent=2, sort_keys=True, ensure_ascii=False) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
finally:
|
||||
run([str(marqdo), "tool", "remove", "knowledge"], env=env)
|
||||
remaining = run([str(marqdo), "tool", "list"], env=env)
|
||||
if "knowledge" in remaining:
|
||||
fail("tool was not removed")
|
||||
print("smoke: OK")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user