Skip to content

refactor: use strings.HasPrefix in agentkit test prefix matching #22

Description

@yvonnedevlinrh

Summary

TestScaffold_FileCount in internal/agentkit/agentkit_test.go uses manual length-check + raw slice indexing to categorize scaffold results by directory prefix:
case len(r.Path) > 9 && r.Path[:9] == "commands/":
commands++
case len(r.Path) > 7 && r.Path[:7] == "skills/":
skills++
case len(r.Path) > 7 && r.Path[:7] == "agents/":
agents++
This pattern is fragile - the integer constants (9, 7, 7) must be manually kept in sync with the prefix string lengths. An off-by-one error is easy to introduce (as happened during the command/ - commands/ rename, where the constant changed from 8 to 9).

Expected behavior

Use strings.HasPrefix which is immune to length/index mismatches:
case strings.HasPrefix(r.Path, "commands/"):
commands++
case strings.HasPrefix(r.Path, "skills/"):
skills++
case strings.HasPrefix(r.Path, "agents/"):
agents++

Location

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
In Review 👀

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions