Skip to content

fix: correct sbom-create-commands []interface{} fallback and test compilation - #1245

Merged
kbarnold merged 2 commits into
masterfrom
fix/sbom-commands-interface-fallback
Jul 22, 2026
Merged

fix: correct sbom-create-commands []interface{} fallback and test compilation#1245
kbarnold merged 2 commits into
masterfrom
fix/sbom-commands-interface-fallback

Conversation

@kbarnold

@kbarnold kbarnold commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a logic bug in GetModuleSBomGenCommands introduced by Fix sbom-create-commands type assertion to handle []interface{} #1212: the ok variable from the []string type assertion was never updated after the []interface{} conversion loop, so custom SBOM commands provided as []interface{} (the normal YAML unmarshal result) always fell back to default generation instead of using the provided commands
  • Fixes the compile error on master (undefined: getTestPath in internal/commands/commands_test.go) also introduced by Fix sbom-create-commands type assertion to handle []interface{} #1212
  • Corrects test assertions to match CmdConverter's actual output structure (working directory prepended as commands[0][0])

Root cause

// ok is false here ([]string cast failed)
customSbomGenCmds, ok := module.BuildParams["sbom-create-commands"].([]string)
if !ok {
    // fills customSbomGenCmds from []interface{}...
}
// ok is STILL false — so this condition is always true, always falling back to default
if !ok || (ok && len(customSbomGenCmds) == 0) {

Fixed by using len(customSbomGenCmds) == 0 which correctly handles all cases.

Test plan

  • go build ./internal/commands/... compiles without errors
  • go test ./internal/commands/... — all 36 tests pass
  • CI on master should go green

kbarnold added 2 commits July 22, 2026 11:19
The ok variable from the []string type assertion was never updated after
the []interface{} conversion, causing custom commands provided as
[]interface{} to always fall back to default SBOM generation. Fix by
checking len(customSbomGenCmds) == 0 instead.

Also fix the GetModuleSBomGenCommands tests from PR #1212: replace
undefined getTestPath calls with dir.Loc{} zero values, and correct
assertions to match CmdConverter's actual output structure (path
prepended as commands[0][0]).
@kbarnold
kbarnold merged commit d36ec2e into master Jul 22, 2026
7 checks passed
@kbarnold
kbarnold deleted the fix/sbom-commands-interface-fallback branch July 22, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant