Skip to content

Commit 2d5f84b

Browse files
committed
fix: emit fossa project.id as <locator>\$<revision>
Real FOSSA artifacts use \$ as the revision separator in project.id, not \-. Update _build_project_metadata and add two tests that pin the correct separator and fallback behaviour.
1 parent fb58cd8 commit 2d5f84b

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

socketsecurity/fossa_compat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ def _build_project_metadata(diff_report: Diff, config: CliConfig) -> dict[str, A
4545
branch = getattr(config, "branch", None) or "socket-default-branch"
4646
revision = getattr(diff_report, "id", None) or getattr(diff_report, "new_scan_id", None) or "unknown-revision"
4747
report_url = getattr(diff_report, "report_url", None) or getattr(diff_report, "diff_url", None)
48-
project_id = repo
4948
return {
5049
"branch": branch,
51-
"id": f"{project_id}-{revision}",
50+
"id": f"{repo}${revision}",
5251
"project": repo,
53-
"projectId": project_id,
52+
"projectId": repo,
5453
"revision": revision,
5554
"url": report_url,
5655
}

tests/unit/test_fossa_compat.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ def test_fossa_report_payload_vulnerability_shape_is_stable():
144144
assert generated_vulnerability["cve"] == "CVE-2024-47081"
145145

146146

147+
def test_project_metadata_uses_dollar_revision_separator():
148+
"""The composed FOSSA `project.id` is `<projectLocator>$<revision>`."""
149+
from socketsecurity.fossa_compat import _build_project_metadata
150+
config = CliConfig.from_args(["--api-token", "test", "--legal-format", "fossa", "--repo", "acme/widgets", "--branch", "refs/heads/main"])
151+
diff = Diff(id="scan-abc123", report_url="https://socket.dev/x")
152+
project = _build_project_metadata(diff, config)
153+
assert project == {
154+
"branch": "refs/heads/main",
155+
"id": "acme/widgets$scan-abc123",
156+
"project": "acme/widgets",
157+
"projectId": "acme/widgets",
158+
"revision": "scan-abc123",
159+
"url": "https://socket.dev/x",
160+
}
161+
162+
163+
def test_project_metadata_fallbacks_when_missing_fields():
164+
"""Falls back to literal placeholders when config/diff are sparse."""
165+
from socketsecurity.fossa_compat import _build_project_metadata
166+
config = CliConfig.from_args(["--api-token", "test", "--legal-format", "fossa"])
167+
# Force absent repo/branch:
168+
config.repo = None
169+
config.branch = None
170+
diff = Diff()
171+
project = _build_project_metadata(diff, config)
172+
assert project["branch"] == "socket-default-branch"
173+
assert project["project"] == "socket-default-repo"
174+
assert project["revision"] == "unknown-revision"
175+
assert project["id"] == "socket-default-repo$unknown-revision"
176+
assert project["url"] is None
177+
178+
147179
def test_fossa_attribution_payload_shape_is_stable():
148180
config = CliConfig.from_args([
149181
"--api-token", "test",

0 commit comments

Comments
 (0)