Skip to content

sync: mirror from thyn-ai/codna@b5154ec100489c998cd04b4ce82585415c5a40c3 - #74

Closed
0xamlab wants to merge 1 commit into
mainfrom
sync/b5154ec100489c998cd04b4ce82585415c5a40c3
Closed

0xamlab wants to merge 1 commit into
mainfrom
sync/b5154ec100489c998cd04b4ce82585415c5a40c3

Conversation

@0xamlab

@0xamlab 0xamlab commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Automated mirror of cli/ (flattened), the root allowlist (server.json, glama.json, LICENSE, .gitleaks.toml) and the public-root/ community tree from thyn-ai/codna at b5154ec100489c998cd04b4ce82585415c5a40c3. Merges itself via auto-merge once the mirror's required checks (codna review, Analyze (python)) pass and the codna-ai review approves; if a later sync lands first, this PR is closed as superseded -- every sync PR is a full snapshot of the exported surface.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Thanks for opening your first pull request in the Codna CLI! Please make sure the checks are green and that the change follows CONTRIBUTING.md. A maintainer will review it shortly.

@codna-ai codna-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codna review — 2 finding(s): 2 inline, 0 in summary.

Reply @codna fix on a finding to have Codna open a verified, test-green, risk-gated fix PR.

⏸ Not approved: 2 medium/high finding(s) in this review.

Comment thread tests/test_packaging.py
Comment on lines +725 to +792
stamp = tool.write_sidecar_stamp(binary, version="0.2.107", build_id="704e2538", target="darwin-arm64")
assert stamp == {
"version": "0.2.107",
"build_id": "704e2538",
"target": "darwin-arm64",
"sha256": hashlib.sha256(b"a-compiled-escapement").hexdigest(),
}
# …and it is written BESIDE the binary, at the path the consumers read.
assert tool.sidecar_stamp_path(binary) == tmp_path / "codna-sidecar.build.json"
assert json.loads(tool.sidecar_stamp_path(binary).read_text(encoding="utf-8")) == stamp


def test_assert_sidecar_stamp_accepts_a_matching_stamp(tmp_path: Path):
tool = _load_release_builder()
binary = tmp_path / "codna-sidecar"
binary.write_bytes(b"the real bytes")
tool.write_sidecar_stamp(binary, version="0.2.107", build_id="704e2538", target="darwin-arm64")
assert tool.assert_sidecar_stamp(binary, expected_version="0.2.107")["version"] == "0.2.107"


def test_assert_sidecar_stamp_refuses_a_stale_binary(tmp_path: Path):
"""The exact defect: a NEW binary beside an OLD stamp. The digest is what catches it."""
tool = _load_release_builder()
binary = tmp_path / "codna-sidecar"
binary.write_bytes(b"first build")
tool.write_sidecar_stamp(binary, version="0.2.107", build_id="704e2538", target="darwin-arm64")
binary.write_bytes(b"REBUILT build") # new bytes, old stamp

with pytest.raises(tool.ReleaseDistError) as excinfo:
tool.assert_sidecar_stamp(binary, expected_version="0.2.107")
message = str(excinfo.value)
assert "does not describe" in message
assert "stamp is stale" in message


def test_assert_sidecar_stamp_refuses_a_stale_version(tmp_path: Path):
tool = _load_release_builder()
binary = tmp_path / "codna-sidecar"
binary.write_bytes(b"bytes")
tool.write_sidecar_stamp(binary, version="0.2.96", build_id="00cc69f3", target="darwin-arm64")

with pytest.raises(tool.ReleaseDistError) as excinfo:
tool.assert_sidecar_stamp(binary, expected_version="0.2.107")
message = str(excinfo.value)
assert "version 0.2.96 != expected 0.2.107" in message
assert "stamp is stale" in message


def test_assert_sidecar_stamp_refuses_a_missing_stamp(tmp_path: Path):
"""Absent must never degrade into `unknown` — that is the state the comment says must not happen."""
tool = _load_release_builder()
binary = tmp_path / "codna-sidecar"
binary.write_bytes(b"bytes")
with pytest.raises(tool.ReleaseDistError) as excinfo:
tool.assert_sidecar_stamp(binary, expected_version="0.2.107")
message = str(excinfo.value)
assert "no sidecar build stamp beside" in message
assert "unknown" in message


@pytest.mark.parametrize("payload", ["{ not json", "[]", '{"version": "0.2.107"}'])
def test_assert_sidecar_stamp_refuses_an_unusable_stamp(tmp_path: Path, payload: str):
tool = _load_release_builder()
binary = tmp_path / "codna-sidecar"
binary.write_bytes(b"bytes")
(tmp_path / "codna-sidecar.build.json").write_text(payload, encoding="utf-8")
with pytest.raises(tool.ReleaseDistError):
tool.assert_sidecar_stamp(binary, expected_version="0.2.107")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 HIGH · correctness — New tests call functions absent from the release-builder script

The new tests (test_write_sidecar_stamp_binds_the_digest_of_the_bytes_on_disk, test_assert_sidecar_stamp_accepts_a_matching_stamp, test_assert_sidecar_stamp_refuses_a_stale_binary, test_assert_sidecar_stamp_refuses_a_stale_version, test_assert_sidecar_stamp_refuses_a_missing_stamp, test_assert_sidecar_stamp_refuses_an_unusable_stamp, test_cli_version_is_read_from_the_pyproject_not_guessed, test_cli_version_fails_closed_when_the_pyproject_has_none, test_build_id_falls_back_to_the_commit_and_never_to_a_placeholder, test_packaging_target_maps_every_platform_and_refuses_an_unknown_one) all call functions via _load_release_builder(): write_sidecar_stamp, assert_sidecar_stamp, sidecar_build_id, sidecar_stamp_path, cli_version, packaging_target, and ReleaseDistError. A codebase-wide search confirms none of these identifiers exist anywhere in the repository (including scripts/build_cli_release_dist.py). Every one of these tests will raise AttributeError at runtime, causing the entire new test block to fail immediately in CI. The companion implementation was not included in this PR.

Reply @codna fix and Codna opens a verified, test-green, risk-gated fix PR.

Comment thread tests/test_packaging.py
Comment on lines +811 to +815
compile_section = builder[builder.index("def prepare_agent_core_bundle(") : builder.index("def verify_staged_runtime(")]
assert "write_sidecar_stamp(" in compile_section, "the compile must emit the stamp"
assert "cli_version(cli_source)" in compile_section, "the stamp version must come from cli/pyproject.toml"
assert "sidecar_build_id()" in compile_section
assert compile_section.index("_assert_sidecar_binary_clean(binary)") < compile_section.index("write_sidecar_stamp(")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM · correctness — str.index() slice produces empty string if function order is reversed in script

Line 811 computes compile_section = builder[builder.index('def prepare_agent_core_bundle(') : builder.index('def verify_staged_runtime(')]. If 'def verify_staged_runtime(' appears before 'def prepare_agent_core_bundle(' in the file (e.g., after a refactor), Python slicing with start > end silently returns an empty string. The three in assertions on lines 812-814 then immediately fail (not silently pass), but line 815 raises ValueError because str.index raises when the substring is not found in the empty string. The more critical failure mode is that str.index raises ValueError on line 811 itself if either landmark string is absent from the script, turning a semantic test failure into an opaque exception.

Reply @codna fix and Codna opens a verified, test-green, risk-gated fix PR.

@0xamlab

0xamlab commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #75 (a later thyn-ai/codna commit). Every sync PR is a full snapshot of the exported surface, so this one carries nothing #75 does not. Closing.

@0xamlab 0xamlab closed this Nov 6, 2026
auto-merge was automatically disabled November 6, 2026 21:04

Pull request was closed

@0xamlab
0xamlab deleted the sync/b5154ec100489c998cd04b4ce82585415c5a40c3 branch November 6, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant