Skip to content

Commit f871cbf

Browse files
committed
fix: write fossa-sbom.json with indent=2 for consistency
1 parent b643f53 commit f871cbf

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

socketsecurity/socketcli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def build_license_artifact_payload(
5858
all_packages[package.id] = output
5959
return all_packages
6060

61+
def _write_attribution_file(config, payload: dict) -> None:
62+
Core.save_file(config.license_file_name, json.dumps(payload, indent=2))
63+
64+
6165
def cli():
6266
try:
6367
main_code()
@@ -780,7 +784,7 @@ def _is_unprocessed(c):
780784
legal_format=getattr(config, "legal_format", "socket"),
781785
config=config,
782786
)
783-
core.save_file(config.license_file_name, json.dumps(all_packages))
787+
_write_attribution_file(config, all_packages)
784788

785789
# If we forced API mode due to no supported files, behave as if --disable-blocking was set
786790
if force_api_mode:

tests/unit/test_socketcli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ class Config:
6969
}
7070

7171

72+
def test_fossa_attribution_file_is_written_indented(tmp_path):
73+
"""fossa-sbom.json should be written with indent=2, matching fossa-analyze.json."""
74+
import json
75+
from socketsecurity import socketcli
76+
from types import SimpleNamespace
77+
78+
target = tmp_path / "fossa-sbom.json"
79+
config = SimpleNamespace(license_file_name=str(target))
80+
payload = {
81+
"copyrightsByLicense": {},
82+
"deepDependencies": [],
83+
"directDependencies": [],
84+
"licenses": {},
85+
"project": {"name": "x", "revision": "y"},
86+
}
87+
socketcli._write_attribution_file(config, payload)
88+
content = target.read_text()
89+
assert "\n " in content, f"Expected indented JSON, got: {content!r}"
90+
assert json.loads(content) == payload
91+
92+
7293
def test_build_license_artifact_payload_fossa_format_serializes_dependencies():
7394
class Config:
7495
repo = "owner/repo"

0 commit comments

Comments
 (0)