Skip to content

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

Merged
gxmiranda merged 1 commit into
unbound-force:mainfrom
gxmiranda:opsx/agentkit-hasprefix-refactor
Jun 30, 2026
Merged

refactor: use strings.HasPrefix in agentkit test prefix matching#29
gxmiranda merged 1 commit into
unbound-force:mainfrom
gxmiranda:opsx/agentkit-hasprefix-refactor

Conversation

@gxmiranda

Copy link
Copy Markdown
Contributor

Summary

Replace fragile manual len()+slice prefix matching with strings.HasPrefix in TestScaffold_FileCount.

Problem

The test in internal/agentkit/agentkit_test.go uses manual length-check plus raw slice indexing to categorize scaffold results by directory prefix:

case len(r.Path) > 9 && r.Path[:9] == "commands/":

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 in PR #20.

Solution

Use strings.HasPrefix which is immune to length/index mismatches:

case strings.HasPrefix(r.Path, "commands/"):

Changes

  • Replace 3 manual len()+slice prefix checks with strings.HasPrefix
  • Add "strings" import
  • Include OpenSpec change artifacts

Closes #22

- Replace manual len()+slice prefix checks with strings.HasPrefix
- Add "strings" import to agentkit_test.go
- Include OpenSpec change artifacts (proposal, design, specs, tasks)

Closes unbound-force#22

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a well-scoped, low-risk refactor with proper spec artifacts, passing CI, and full alignment with the constitution. The change eliminates a real maintenance hazard (manual index constants) with a proven stdlib alternative.

@gxmiranda gxmiranda merged commit 6ff0c9a into unbound-force:main Jun 30, 2026
1 check passed
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.

refactor: use strings.HasPrefix in agentkit test prefix matching

2 participants