From 6b18c76df703a1ecf34137baf786e66efd375697 Mon Sep 17 00:00:00 2001 From: Offending Commit Date: Mon, 21 Sep 2026 16:28:44 -0500 Subject: [PATCH] fix(tests): assert the packaging manifest, not whatever is in dist/ The wheel-membership assertion read dist/ and so depended on ambient state. dist/ is gitignored, so CI had none and the test skipped, while a stale local artifact failed it -- the precise local/CI asymmetry this work set out to remove, reintroduced by the test meant to guard it. mtime cannot fix it either. The artifact that exposed this was *newer* than the source and still wrong: it was built during a mutation test from a deliberately broken tree. Freshness and correctness are different questions, and only one of them is visible from a timestamp. So assert the actual trap where it is deterministic. pyproject lists packages explicitly, so a new package directory is dropped from the wheel silently; comparing that list against the package directories on disk catches it from source, with no build and nothing ambient. The test now runs everywhere instead of skipping in the one environment that matters. End-to-end proof stays in just check-install, which builds, installs and imports, and already runs in the package job. Mutation-tested against the real trap: an undeclared subpackage fails this test, and twine check passes on the same tree -- confirming again that metadata validation cannot see archive contents. --- tests/test_release_contract.py | 54 ++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/tests/test_release_contract.py b/tests/test_release_contract.py index 34441a0..4b64527 100644 --- a/tests/test_release_contract.py +++ b/tests/test_release_contract.py @@ -6,6 +6,7 @@ import tarfile import tempfile import re +import tomllib import unittest import zipfile from pathlib import Path @@ -795,12 +796,47 @@ def test_known_drift_baseline_exists_and_is_parseable(self) -> None: test_id, _, fingerprint = entry.partition(" ") self.assertTrue(test_id.strip() and fingerprint.strip()) - def test_built_wheel_contains_the_harness_module(self) -> None: - # `twine check` reads metadata and never opens the archive, so it passes - # on a wheel missing a module entirely. Proven by probe during U4. - wheels = sorted((ROOT / "dist").glob("*.whl")) if (ROOT / "dist").exists() else [] - if not wheels: - self.skipTest("no built wheel in dist/; `just build` first") - with zipfile.ZipFile(wheels[-1]) as archive: - names = archive.namelist() - self.assertIn("hermes_plugin_kit/testing.py", names) + def test_packaging_manifest_covers_every_package_directory(self) -> None: + """The trap this guards is a subpackage silently dropped from the wheel. + + `pyproject.toml` lists packages explicitly, so a new package directory + is omitted from the build with no warning and `twine check` -- which + reads metadata, never the archive -- passes on the result. + + This asserts the manifest against the source tree rather than against + a built wheel. An earlier version inspected `dist/`, which made it + depend on whatever happened to be lying there: it passed in CI, where + `dist/` is absent and the test skipped, and failed locally against a + stale artifact. Worse, mtime could not distinguish stale from wrong -- + the wheel that caught this was *newer* than the source and still built + from a mutated tree. End-to-end proof belongs in `just check-install`, + which builds, installs and imports; this is the fast, deterministic + half. + """ + manifest = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8")) + declared = set(manifest["tool"]["setuptools"]["packages"]) + + package_root = ROOT / "hermes_plugin_kit" + on_disk = {"hermes_plugin_kit"} | { + ".".join(child.relative_to(ROOT).parts) + for child in package_root.rglob("*") + if child.is_dir() and (child / "__init__.py").exists() + } + + missing = sorted(on_disk - declared) + self.assertEqual( + [], missing, + "package directories absent from pyproject's explicit packages list " + "are dropped from the wheel silently; twine check will not notice", + ) + + def test_the_harness_module_is_inside_a_declared_package(self) -> None: + manifest = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8")) + declared = set(manifest["tool"]["setuptools"]["packages"]) + + self.assertTrue((ROOT / "hermes_plugin_kit" / "testing.py").is_file()) + self.assertIn( + "hermes_plugin_kit", declared, + "the harness ships as a flat module inside this package; if it ever " + "becomes a subpackage it needs its own entry here", + )