Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/github_repo_auditor/portfolio_truth_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,9 @@ def _publish_portfolio_truth_locked(
allow_empty_notion=allow_empty_notion,
)
latest_name = latest_path.name
snapshot_json = json.dumps(build_result.snapshot.to_dict(), indent=2) + "\n"
snapshot_json = (
json.dumps(build_result.snapshot.to_dict(), indent=2, sort_keys=True) + "\n"
)
project_registry_json = _build_project_registry_json(
build_result.snapshot, include_notion=include_notion
)
Expand Down
44 changes: 44 additions & 0 deletions tests/test_snapshot_json_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json
import subprocess
from datetime import datetime, timezone

from github_repo_auditor.portfolio_truth_publish import publish_portfolio_truth


def test_snapshot_bytes_ignore_security_metadata_key_order(tmp_path, monkeypatch):
monkeypatch.setattr(
"github_repo_auditor.portfolio_truth_publish.load_source_paths",
lambda _: dict(bridge_db=None, notion_snapshot=None, memory_dir=None),
)
workspace = tmp_path / "workspace"
repo = workspace / "sample"
repo.mkdir(parents=True)
subprocess.run(["git", "init", "-q", str(repo)], check=True)
(repo / "README.md").write_text("Sample")
clock = datetime(2025, 1, 3, tzinfo=timezone.utc)
metadata = {
"source_id": "github-security-coverage-receipt",
"schema_version": "GitHubSecurityCoverageReceiptV1",
"produced_at": clock.isoformat(),
"state": "fresh",
"age_hours": 0.0,
"producer_commit": "a" * 40,
"cohort_policy": "portfolio-default-attention-v1",
"cohort_repository_count": 0,
"path": "fixture-receipt.json",
}
publications = []
for index, evidence in enumerate((metadata, dict(reversed(metadata.items())))):
generation = publish_portfolio_truth(
workspace_root=workspace,
output_dir=tmp_path / f"generation-{index}",
registry_output=workspace / "registry.md",
portfolio_report_output=workspace / "report.md",
catalog_path=tmp_path / "missing.yaml",
include_notion=False,
now=clock,
security_coverage_metadata=evidence,
)
publications.append(generation.latest_path.read_bytes())
assert json.loads(publications[0]) == json.loads(publications[1])
assert publications[0] == publications[1]
Loading