Skip to content

Commit d6f188c

Browse files
Lagojaclaude
andcommitted
Use normalized TTL in cache keys and skip tests when git is missing
Use ttl.String() instead of raw env var in cache keys to avoid path-separator injection and trailing slashes. Add t.Skip guard in setupLocalGitRepo for CI environments without git. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 95059ba commit d6f188c

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

internal/plugin/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (p *gitPlugin) FileContent(subpath string) ([]byte, error) {
199199
return nil, fmt.Errorf("invalid DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL=%q: %w", ttlStr, err)
200200
}
201201
}
202-
cacheKey := p.LockfileKey() + "/" + subpath + "/" + ttlStr
202+
cacheKey := p.LockfileKey() + "/" + subpath + "/" + ttl.String()
203203
return gitCache.GetOrSet(cacheKey, func() ([]byte, time.Duration, error) {
204204
content, err := p.cloneAndRead(subpath)
205205
if err != nil {

internal/plugin/git_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ func TestIsSSHURL(t *testing.T) {
408408
func setupLocalGitRepo(t *testing.T, content string) string {
409409
t.Helper()
410410

411+
if _, err := exec.LookPath("git"); err != nil {
412+
t.Skip("skipping: git not found in PATH")
413+
}
414+
411415
// Create a working repo, commit a file, then clone it as bare.
412416
workDir := t.TempDir()
413417
runGit := func(args ...string) {

internal/plugin/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
9191
}
9292

9393
return githubCache.GetOrSet(
94-
contentURL+ttlStr,
94+
contentURL+ttl.String(),
9595
func() ([]byte, time.Duration, error) {
9696
req, err := p.request(contentURL)
9797
if err != nil {

0 commit comments

Comments
 (0)