refactor(agentic): validate forge command inputs
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9f1315d1a8
commit
1dd6170dd4
2 changed files with 30 additions and 0 deletions
|
|
@ -87,6 +87,18 @@ func parseForgeArgs(options core.Options) (org, repo string, num int64) {
|
|||
if v := options.String("number"); v != "" {
|
||||
num, _ = strconv.ParseInt(v, 10, 64)
|
||||
}
|
||||
|
||||
if orgResult := core.ValidateName(org); orgResult.OK {
|
||||
org = orgResult.Value.(string)
|
||||
} else {
|
||||
org = ""
|
||||
}
|
||||
|
||||
if repoResult := core.ValidateName(repo); repoResult.OK {
|
||||
repo = repoResult.Value.(string)
|
||||
} else {
|
||||
repo = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -492,6 +504,13 @@ func (s *PrepSubsystem) cmdRepoList(options core.Options) core.Result {
|
|||
if org == "" {
|
||||
org = "core"
|
||||
}
|
||||
orgResult := core.ValidateName(org)
|
||||
if !orgResult.OK {
|
||||
err, _ := orgResult.Value.(error)
|
||||
core.Print(nil, "usage: core-agent repo list [--org=core]")
|
||||
return core.Result{Value: core.E("agentic.cmdRepoList", "invalid org name", err), OK: false}
|
||||
}
|
||||
org = orgResult.Value.(string)
|
||||
repos, err := s.forge.Repos.ListOrgRepos(ctx, org)
|
||||
if err != nil {
|
||||
core.Print(nil, "error: %v", err)
|
||||
|
|
|
|||
|
|
@ -84,6 +84,17 @@ func TestCommandsforge_ParseForgeArgs_Ugly_NegativeNumber(t *testing.T) {
|
|||
assert.Equal(t, int64(-5), num, "negative numbers parse but are semantically invalid")
|
||||
}
|
||||
|
||||
func TestCommandsforge_ParseForgeArgs_Ugly_InvalidNames(t *testing.T) {
|
||||
opts := core.NewOptions(
|
||||
core.Option{Key: "org", Value: "bad/org"},
|
||||
core.Option{Key: "_arg", Value: "repo/with/slashes"},
|
||||
)
|
||||
org, repo, num := parseForgeArgs(opts)
|
||||
assert.Empty(t, org)
|
||||
assert.Empty(t, repo)
|
||||
assert.Equal(t, int64(0), num)
|
||||
}
|
||||
|
||||
// --- formatIndex Bad/Ugly ---
|
||||
|
||||
func TestCommandsforge_FormatIndex_Bad_Negative(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue