Problem or motivation
pkg/aibomgen/bomio.WriteOutputFiles generates output filenames by sanitizing the component name (replacing non-alphanumeric characters with underscores) and writing one file per discovered BOM. This function is the final step of both scan and generate commands and is not covered by any test in io_test.go. The sanitization logic (for _, r := range name { ... }) has edge cases: an all-special-character name produces "model" as fallback; a BOM with no metadata component name falls back through three sources. None of these paths are tested.
Proposed solution
Add tests to pkg/aibomgen/bomio/io_test.go covering:
- A single BOM with a normal
org/model name — verify the output filename is org_model_aibom.json
- A BOM with an empty component name — verify fallback to
Discovery.Name, then Discovery.ID, then "model"
- Two BOMs with the same sanitized name — verify both are written (potential collision case)
- A BOM where
WriteBOM would fail (unwritable directory) — verify the error is propagated and written contains only successfully written paths
Alternatives considered
None.
Additional context
Affected function: pkg/aibomgen/bomio/io.go:WriteOutputFiles (line 188).
Problem or motivation
pkg/aibomgen/bomio.WriteOutputFilesgenerates output filenames by sanitizing the component name (replacing non-alphanumeric characters with underscores) and writing one file per discovered BOM. This function is the final step of bothscanandgeneratecommands and is not covered by any test inio_test.go. The sanitization logic (for _, r := range name { ... }) has edge cases: an all-special-character name produces"model"as fallback; a BOM with no metadata component name falls back through three sources. None of these paths are tested.Proposed solution
Add tests to
pkg/aibomgen/bomio/io_test.gocovering:org/modelname — verify the output filename isorg_model_aibom.jsonDiscovery.Name, thenDiscovery.ID, then"model"WriteBOMwould fail (unwritable directory) — verify the error is propagated andwrittencontains only successfully written pathsAlternatives considered
None.
Additional context
Affected function:
pkg/aibomgen/bomio/io.go:WriteOutputFiles(line 188).