From 4960eee3cecefe35afccf463036260de3dcdfc41 Mon Sep 17 00:00:00 2001 From: Tom Softreck Date: Thu, 12 Nov 2026 16:56:45 +0100 Subject: [PATCH 1/2] fix(release): qualify installed projection artifacts before publication (DEP-001) Co-authored-by: Koru Agent --- .github/workflows/publish.yml | 3 + .github/workflows/test-locked.yml | 4 + VERSION | 2 +- code2llm/__init__.py | 2 +- pyproject.toml | 2 +- scripts/verify_projection_distribution.py | 138 ++++++++++++++++++++++ setup.py | 2 +- uv.lock | 2 +- 8 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 scripts/verify_projection_distribution.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a7ad74f..9b7f67f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -60,6 +60,9 @@ jobs: - name: Install package run: pip install dist/*.whl + - name: Qualify installed projection exporter from wheel and sdist + run: python -I scripts/verify_projection_distribution.py --artifact-directory dist --expected-version "$(cat VERSION)" + - name: Verify installed analyzer wheel run: | python -I - <<'PY' diff --git a/.github/workflows/test-locked.yml b/.github/workflows/test-locked.yml index d42b802..05b86b6 100644 --- a/.github/workflows/test-locked.yml +++ b/.github/workflows/test-locked.yml @@ -28,3 +28,7 @@ jobs: run: uv sync --locked --extra dev --python "${{ matrix.python-version }}" - name: Test supported Python versions run: uv run --no-sync python -m pytest -q -n 2 + - name: Build and qualify projection distributions + run: | + uv build --out-dir dist + uv run --no-sync python -I scripts/verify_projection_distribution.py --artifact-directory dist --expected-version "$(cat VERSION)" diff --git a/VERSION b/VERSION index 1db40e7..b626e78 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.183 +0.5.184 diff --git a/code2llm/__init__.py b/code2llm/__init__.py index d621f8a..0834a25 100644 --- a/code2llm/__init__.py +++ b/code2llm/__init__.py @@ -8,7 +8,7 @@ and entity resolution with multilingual support. """ -__version__ = "0.5.183" +__version__ = "0.5.184" __author__ = "STTS Project" # Core analysis components (lightweight, always needed) diff --git a/pyproject.toml b/pyproject.toml index 1ea5ebc..48a30ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "code2llm" -version = "0.5.183" +version = "0.5.184" description = "High-performance Python code flow analysis with optimized TOON format - CFG, DFG, call graphs, and intelligent code queries" readme = "README.md" requires-python = ">=3.10" diff --git a/scripts/verify_projection_distribution.py b/scripts/verify_projection_distribution.py new file mode 100644 index 0000000..253e5be --- /dev/null +++ b/scripts/verify_projection_distribution.py @@ -0,0 +1,138 @@ +"""Qualify the public projection exporter in installed wheel and sdist artifacts. + +Run with ``python -I`` to exclude the checkout from import resolution. The +artifact mode creates a separate, empty venv for each distribution; neither +an editable checkout nor a manually copied exporter can satisfy this check. +This verifies the projection contract, not the bytes of its source inputs. +""" +from __future__ import annotations + +import argparse +import base64 +import hashlib +from importlib import metadata +import json +from pathlib import Path +import subprocess +import sys +import tempfile +from types import SimpleNamespace +import venv + + +def require(condition, message): + if not condition: + raise RuntimeError(message) + + +def digest(value): + data = json.dumps(value, sort_keys=True, ensure_ascii=False, separators=(",", ":")) + return "sha256:" + hashlib.sha256(data.encode("utf-8")).hexdigest() + + +def check_document(document, expected_version): + require(document["schema"] == "code2llm.projection/v1", "Unexpected projection schema") + require(document["producer"] == {"tool": "code2llm", "version": expected_version}, + "Missing or mismatched producer identity") + records = document["records"] + require(document["digest"] == digest(records), "Invalid projection digest") + for record in records: + content = {key: value for key, value in record.items() if key != "digest"} + require(record["digest"] == digest(content), "Invalid record digest") + + +def check_installed(expected_version): + import code2llm + from code2llm.exporters import ProjectionsExporter, build_projection, get_exporter + from code2llm.exporters import projections_exporter + + require(Path(code2llm.__file__).resolve().is_relative_to(Path(sys.prefix).resolve()), + "Imported checkout instead of the installed distribution") + distribution = metadata.distribution("code2llm") + require(code2llm.__version__ == distribution.version == expected_version, + "Distribution and producer versions differ from the release") + entry = next((entry for entry in distribution.files or () + if str(entry) == "code2llm/exporters/projections_exporter.py"), None) + require(entry is not None and entry.hash is not None, "Exporter missing from installed RECORD") + installed_path = Path(distribution.locate_file(entry)).resolve() + require(installed_path == Path(projections_exporter.__file__).resolve(), + "Exporter was loaded outside the distribution") + actual_hash = base64.urlsafe_b64encode(hashlib.sha256(installed_path.read_bytes()).digest()).rstrip(b"=").decode() + require(entry.hash.mode == "sha256" and entry.hash.value == actual_hash, + "Exporter differs from installed RECORD") + require(get_exporter("projections") is ProjectionsExporter, "Public registry lacks projections") + require(projections_exporter.MAX_RECORDS == 2048 and projections_exporter.FIELD_LIMIT == 200, + "Projection v1 bounds differ from the consumer contract") + + long_field = "ą" * (projections_exporter.FIELD_LIMIT + 10) + functions = [SimpleNamespace(name=f"f{i}", qualified_name=long_field + str(i), + file=long_field + ".py", line=i + 1) + for i in range(projections_exporter.MAX_RECORDS + 1)] + fixture = SimpleNamespace(modules=[], classes=[], functions=functions, + stats={"files": 1, "lines": len(functions)}, + project_path="projection-contract", analysis_mode="standard") + expected = build_projection(fixture) + check_document(expected, expected_version) + require(len(expected["records"]) == projections_exporter.MAX_RECORDS + and expected["stats"]["truncated"] is True, "Record bound was not reported") + require(all(len(record[key]) <= projections_exporter.FIELD_LIMIT + for record in expected["records"] for key in ("file", "symbol")), + "Fields exceed the public bound") + # Exercise the checker against deliberately invalid evidence as well. + for invalid in ({**expected, "digest": "sha256:" + "0" * 64}, + {**expected, "producer": {}}): + try: + check_document(invalid, expected_version) + except RuntimeError: + pass + else: + raise RuntimeError("Invalid projection was accepted") + with tempfile.TemporaryDirectory(prefix="projection-contract-") as directory: + first = Path(directory) / "first.json" + second = Path(directory) / "second.json" + exporter = ProjectionsExporter() + require(exporter.export(fixture, str(first)) == first, "Export path differs") + exporter.export(fixture, str(second)) + require(first.read_bytes() == second.read_bytes(), "Export bytes are nondeterministic") + observed = json.loads(first.read_text(encoding="utf-8")) + require(observed == expected, "Public builder and exporter differ") + check_document(observed, expected_version) + return {"status": "PASS", "version": expected_version, + "projection_digest": expected["digest"], "records": len(expected["records"]), + "source_bytes_verified": False} + + +def check_artifacts(directory, expected_version): + directory = directory.resolve() + wheels = sorted(directory.glob("code2llm-*.whl")) + sources = sorted(directory.glob("code2llm-*.tar.gz")) + require(len(wheels) == len(sources) == 1, "Exactly one wheel and one sdist are required") + results = [] + script = str(Path(__file__).resolve()) + for artifact in [*wheels, *sources]: + with tempfile.TemporaryDirectory(prefix="projection-install-") as temporary: + root = Path(temporary) + environment = root / "venv" + venv.EnvBuilder(with_pip=True).create(environment) + python = environment / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python") + subprocess.run([str(python), "-I", "-m", "pip", "install", str(artifact)], + cwd=root, check=True, timeout=300) + observed = subprocess.run([str(python), "-I", script, + "--expected-version", expected_version], + cwd=root, check=True, capture_output=True, text=True, timeout=60) + results.append({"artifact": artifact.name, + "sha256": hashlib.sha256(artifact.read_bytes()).hexdigest(), + "check": json.loads(observed.stdout)}) + require(results[0]["check"]["projection_digest"] == results[1]["check"]["projection_digest"], + "Wheel and sdist produce different projections") + return {"status": "PASS", "artifacts": results, "forge_consumer": "NOT_RUN"} + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--expected-version", required=True) + parser.add_argument("--artifact-directory", type=Path) + args = parser.parse_args() + result = (check_artifacts(args.artifact_directory, args.expected_version) + if args.artifact_directory else check_installed(args.expected_version)) + print(json.dumps(result, sort_keys=True)) diff --git a/setup.py b/setup.py index c152251..7604cf8 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ def read_readme(): setup( name="code2llm", - version="0.5.183", + version="0.5.184", description="Python code flow analysis tool - CFG, DFG, and call graph extraction", long_description=read_readme(), long_description_content_type="text/markdown", diff --git a/uv.lock b/uv.lock index 7f00caa..ea94eb7 100644 --- a/uv.lock +++ b/uv.lock @@ -647,7 +647,7 @@ source = { editable = "packages/code2graph" } [[package]] name = "code2llm" -version = "0.5.183" +version = "0.5.184" source = { editable = "." } dependencies = [ { name = "astroid" }, From 603f53d7f4e7509c3b4d90035232a29b3190099b Mon Sep 17 00:00:00 2001 From: Tom Softreck Date: Thu, 12 Nov 2026 17:05:36 +0100 Subject: [PATCH 2/2] fix(release): reuse uv for bounded isolated artifact installation Co-authored-by: Koru Agent --- .github/workflows/publish.yml | 2 +- scripts/verify_projection_distribution.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9b7f67f..7f254df 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -58,7 +58,7 @@ jobs: path: dist/ - name: Install package - run: pip install dist/*.whl + run: pip install uv dist/*.whl - name: Qualify installed projection exporter from wheel and sdist run: python -I scripts/verify_projection_distribution.py --artifact-directory dist --expected-version "$(cat VERSION)" diff --git a/scripts/verify_projection_distribution.py b/scripts/verify_projection_distribution.py index 253e5be..9b68809 100644 --- a/scripts/verify_projection_distribution.py +++ b/scripts/verify_projection_distribution.py @@ -13,6 +13,7 @@ from importlib import metadata import json from pathlib import Path +import shutil import subprocess import sys import tempfile @@ -107,15 +108,17 @@ def check_artifacts(directory, expected_version): wheels = sorted(directory.glob("code2llm-*.whl")) sources = sorted(directory.glob("code2llm-*.tar.gz")) require(len(wheels) == len(sources) == 1, "Exactly one wheel and one sdist are required") + installer = shutil.which("uv") + require(installer is not None, "Install uv to qualify isolated distributions") results = [] script = str(Path(__file__).resolve()) for artifact in [*wheels, *sources]: with tempfile.TemporaryDirectory(prefix="projection-install-") as temporary: root = Path(temporary) environment = root / "venv" - venv.EnvBuilder(with_pip=True).create(environment) + venv.EnvBuilder().create(environment) python = environment / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python") - subprocess.run([str(python), "-I", "-m", "pip", "install", str(artifact)], + subprocess.run([installer, "pip", "install", "--python", str(python), str(artifact)], cwd=root, check=True, timeout=300) observed = subprocess.run([str(python), "-I", script, "--expected-version", expected_version],