From 98518091ae9c5be540127ec20a07934527f8f2de Mon Sep 17 00:00:00 2001 From: tegwick Date: Sat, 22 Aug 2026 19:08:10 +0200 Subject: [PATCH] fix: preserve legacy SBOM source values Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a028f0-a42f-7582-89a8-ebaad7343834 --- api/routers/sbom.py | 10 +++++++++- tests/test_sbom_nexus_compat.py | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/routers/sbom.py b/api/routers/sbom.py index dc7c3d3..5f348a1 100644 --- a/api/routers/sbom.py +++ b/api/routers/sbom.py @@ -343,7 +343,15 @@ async def _translate_snapshots( def _translate_snapshot(item: dict, repo_id: uuid.UUID) -> dict: - return {**item, "repo_id": repo_id} + translated = {**item, "repo_id": repo_id} + source = translated.get("source") + if ( + translated.get("legacy_id") + and isinstance(source, str) + and source.startswith("state-hub:") + ): + translated["source"] = source.removeprefix("state-hub:") + return translated def _translate_entry(item: dict, repo_id: uuid.UUID) -> dict: diff --git a/tests/test_sbom_nexus_compat.py b/tests/test_sbom_nexus_compat.py index a78493f..5580f76 100644 --- a/tests/test_sbom_nexus_compat.py +++ b/tests/test_sbom_nexus_compat.py @@ -53,7 +53,8 @@ async def test_nexus_read_mode_preserves_state_hub_response_contract(client, mon "repo_id": nexus_repo_id, "repo_slug": "testrepo", "snapshot_at": "2026-08-22T12:00:00+00:00", - "source": "state-hub-import", + "source": "state-hub:manual", + "legacy_id": snapshot_id, "entry_count": 1, "created_at": "2026-08-22T12:00:01+00:00", "status": "imported", @@ -113,6 +114,8 @@ async def test_nexus_read_mode_preserves_state_hub_response_contract(client, mon assert repo_view.status_code == 200 assert snapshots.json()[0]["id"] == snapshot_id assert snapshots.json()[0]["repo_id"] == repo["id"] + assert snapshots.json()[0]["source"] == "manual" + assert detail.json()["source"] == "manual" assert detail.json()["entries"][0]["repo_id"] == repo["id"] assert entries.json()[0]["repo_id"] == repo["id"] assert "source_path" not in entries.json()[0]