Implement the following plan: Enhance SanitizeName to Handle All Non-Alphanumeric…
- User
Implement the following plan:
Enhance
SanitizeNameto Handle All Non-Alphanumeric CharactersContext
SanitizeNameinpkg/gsync/openvox.goconverts Git ref names into Puppet environment directory names. Puppet environments only allow[a-zA-Z0-9_]. Currently the function only replaces-and.with_, but Git branch names can contain/(e.g.,feature/login),@,~,^,+, spaces, and other characters. A branch likefeature/my-branchwould currently create a nested subdirectory instead of a flat sanitized name.Changes
1. Rewrite
SanitizeName(pkg/gsync/openvox.go:26-30)Replace
strings.NewReplacerwithstrings.Mapusing an allowlist approach — any character not in[a-zA-Z0-9_]becomes_:go// SanitizeName converts a Git ref name into a valid Puppet environment name. // Puppet environments only allow [a-zA-Z0-9_]. Any character outside this set // is replaced with an underscore. func SanitizeName(name string) string { return strings.Map(func(r rune) rune { if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' { return r } return '_' }, name) }This is a superset of current behavior — all existing replacements still hold, plus
/,@, and everything else is now handled. No import changes needed.2. Add test cases (
pkg/gsync/openvox_test.go)Add to
TestSanitizeNametable (lines 12-22):"feature/my-branch"→"feature_my_branch"(forward slash)"bugfix/auth/login"→"bugfix_auth_login"(nested slashes)"user@domain"→"user_domain"(at sign)"release/v1.0.0-rc1"→"release_v1_0_0_rc1"(mixed)- → (tilde)
Assistant
Let me read the current files to implement the changes.
Assistant
Now I'll apply both changes.
Assistant
Now let me run the tests.
Assistant
All tests pass. Let me also run the full test suite to make sure nothing else broke.
Assistant
All tests pass. Here's a summary of the changes:
pkg/gsync/openvox.go— Replacedstrings.NewReplacer(only handling-and.) withstrings.Mapusing an allowlist: any character not in[a-zA-Z0-9_]becomes_. This handles/,@,~,^, spaces, and all other non-alphanumeric characters.pkg/gsync/openvox_test.go— Added 8 newTestSanitizeNamecases (slashes, nested slashes,@, mixed, tilde, caret, space, consecutive slashes) and 1 newTestDetectCollisionssubtest for slash-vs-hyphen collision.- User
commit this and its already in staged
Assistant
Committed as
af44a78.- User
Assistant
Let me read the key files to understand the exact code paths.
Assistant
Let me check how the resolver repo and remote refs work to understand how to detect the default branch.
Assistant
Now let me check how
resolveBranchesworks and how to detect the remote's default branch (HEAD).Assistant
Now let me also check the
SyncOptionsand config structs for relevant fields.Assistant
Now let me read the full
syncRepoOpenVoxflow to understand howSyncOptionsis used and how to add stale pruning.Assistant
Now I have a complete understanding. Let me write the plan.
Assistant
Let me find the backward compatibility code for
sshknownhosts.Assistant
Good, removing the entire backward compat block. Let me also check what tests reference this functionality.
Assistant
Now let me also check the
config.example.yamlto see if top-level fields are documented there.Assistant
Good. Now I have everything I need. Let me update the plan to include both changes.
- User
[Request interrupted by user for tool use]