diff --git a/internal/install/install_apply.go b/internal/install/install_apply.go index cd03fc288..585e0aac6 100644 --- a/internal/install/install_apply.go +++ b/internal/install/install_apply.go @@ -250,24 +250,9 @@ func installFromGitSubdir(source *Source, destPath string, result *InstallResult var resolved string var commitHash string - // Fast path 1: GitHub/GHE Contents API - if isGitHubAPISource(source) { - owner, repo := source.GitHubOwner(), source.GitHubRepo() - resolved = source.Subdir - subdirPath = filepath.Join(tempRepoPath, resolved) - hash, dlErr := downloadGitHubDir(owner, repo, source.Subdir, subdirPath, source, opts.OnProgress) - if dlErr == nil { - commitHash = hash - } else { - result.Warnings = append(result.Warnings, fmt.Sprintf("GitHub API install fallback: %v", dlErr)) - subdirPath = "" - _ = os.RemoveAll(tempRepoPath) - } - } - - // Fast path 2: sparse checkout fallback when API path is unavailable - // or unsupported (works for GitHub and non-GitHub hosts). - if subdirPath == "" && gitSupportsSparseCheckout() { + // Fast path 1: sparse checkout (preferred for speed if git is modern) + // Works for GitHub and non-GitHub hosts. + if gitSupportsSparseCheckout() { resolved = source.Subdir if err := sparseCloneSubdir(source.CloneURL, resolved, tempRepoPath, authEnv(source.CloneURL), opts.OnProgress); err == nil { subdirPath = filepath.Join(tempRepoPath, resolved) @@ -281,6 +266,23 @@ func installFromGitSubdir(source *Source, destPath string, result *InstallResult } else { result.Warnings = append(result.Warnings, fmt.Sprintf("sparse checkout install fallback: %v", err)) _ = os.RemoveAll(tempRepoPath) + subdirPath = "" + } + } + + // Fast path 2: GitHub/GHE Contents API + // Fallback for when sparse checkout is unavailable or fails. + if subdirPath == "" && isGitHubAPISource(source) { + owner, repo := source.GitHubOwner(), source.GitHubRepo() + resolved = source.Subdir + subdirPath = filepath.Join(tempRepoPath, resolved) + hash, dlErr := downloadGitHubDir(owner, repo, source.Subdir, subdirPath, source, opts.OnProgress) + if dlErr == nil { + commitHash = hash + } else { + result.Warnings = append(result.Warnings, fmt.Sprintf("GitHub API install fallback: %v", dlErr)) + subdirPath = "" + _ = os.RemoveAll(tempRepoPath) } } diff --git a/internal/install/install_discovery.go b/internal/install/install_discovery.go index 74a70594d..13d3c5028 100644 --- a/internal/install/install_discovery.go +++ b/internal/install/install_discovery.go @@ -206,27 +206,8 @@ func discoverFromGitSubdirWithProgressImpl(source *Source, onProgress ProgressCa var commitHash string var subdirPath string - // Fast path 1: GitHub/GHE Contents API - if isGitHubAPISource(source) { - owner, repo := source.GitHubOwner(), source.GitHubRepo() - subdirPath = filepath.Join(repoPath, source.Subdir) - hash, dlErr := downloadGitHubDir(owner, repo, source.Subdir, subdirPath, source, onProgress) - if dlErr == nil { - commitHash = hash - skills := discoverSkills(subdirPath, true) - return &DiscoveryResult{ - RepoPath: tempDir, - Skills: skills, - Source: source, - CommitHash: commitHash, - }, nil - } - warnings = append(warnings, fmt.Sprintf("GitHub API discovery fallback: %v", dlErr)) - _ = os.RemoveAll(repoPath) - } - - // Fast path 2: sparse checkout fallback when API path is unavailable - // or unsupported (works for GitHub and non-GitHub hosts). + // Fast path 1: sparse checkout (preferred for speed if git is modern) + // Works for GitHub and non-GitHub hosts. if gitSupportsSparseCheckout() { if err := sparseCloneSubdir(source.CloneURL, source.Subdir, repoPath, authEnv(source.CloneURL), onProgress); err == nil { subdirPath = filepath.Join(repoPath, source.Subdir) @@ -245,12 +226,35 @@ func discoverFromGitSubdirWithProgressImpl(source *Source, onProgress ProgressCa } warnings = append(warnings, "sparse checkout discovery fallback: subdirectory missing after checkout") _ = os.RemoveAll(repoPath) + subdirPath = "" } else { warnings = append(warnings, fmt.Sprintf("sparse checkout discovery fallback: %v", err)) _ = os.RemoveAll(repoPath) + subdirPath = "" } } + // Fast path 2: GitHub/GHE Contents API + // Fallback for when sparse checkout is unavailable or fails. + if subdirPath == "" && isGitHubAPISource(source) { + owner, repo := source.GitHubOwner(), source.GitHubRepo() + subdirPath = filepath.Join(repoPath, source.Subdir) + hash, dlErr := downloadGitHubDir(owner, repo, source.Subdir, subdirPath, source, onProgress) + if dlErr == nil { + commitHash = hash + skills := discoverSkills(subdirPath, true) + return &DiscoveryResult{ + RepoPath: tempDir, + Skills: skills, + Source: source, + CommitHash: commitHash, + }, nil + } + warnings = append(warnings, fmt.Sprintf("GitHub API discovery fallback: %v", dlErr)) + _ = os.RemoveAll(repoPath) + subdirPath = "" + } + // Fallback: full clone + fuzzy subdir resolution _ = os.RemoveAll(repoPath) if onProgress != nil { diff --git a/scripts/red_team/_helpers.sh b/scripts/red_team/_helpers.sh index 55426a57e..b7f5ef932 100644 --- a/scripts/red_team/_helpers.sh +++ b/scripts/red_team/_helpers.sh @@ -49,17 +49,21 @@ $content SKILL_EOF } -# Run skillshare with isolated config +# Run skillshare with isolated config. +# -g is placed after the subcommand to force global mode, +# preventing auto-detection of .skillshare/ in the working directory. ss() { - SKILLSHARE_CONFIG="$CONFIG_PATH" "$BIN" "$@" 2>&1 + local cmd="$1"; shift + SKILLSHARE_CONFIG="$CONFIG_PATH" "$BIN" "$cmd" -g "$@" 2>&1 } # Run skillshare, capture output + exit code # Sets: SS_OUTPUT, SS_EXIT ss_capture() { + local cmd="$1"; shift SS_OUTPUT="" SS_EXIT=0 - SS_OUTPUT="$(SKILLSHARE_CONFIG="$CONFIG_PATH" "$BIN" "$@" 2>&1)" || SS_EXIT=$? + SS_OUTPUT="$(SKILLSHARE_CONFIG="$CONFIG_PATH" "$BIN" "$cmd" -g "$@" 2>&1)" || SS_EXIT=$? } # ── Assertion helpers ────────────────────────────────────────────── diff --git a/tests/integration/update_test.go b/tests/integration/update_test.go index b6408b290..58dfec1ca 100644 --- a/tests/integration/update_test.go +++ b/tests/integration/update_test.go @@ -421,6 +421,10 @@ func TestUpdate_BatchAll_FailsOnMalicious(t *testing.T) { result.AssertFailure(t) // Must exit non-zero even though clean repo succeeded result.AssertAnyOutputContains(t, "blocked by security audit") + // Blocked section shows details (not just a count) + result.AssertAnyOutputContains(t, "Blocked / Rolled Back") + result.AssertAnyOutputContains(t, maliciousName) + // Clean repo should be updated cleanContent := sb.ReadFile(filepath.Join(sb.SourcePath, cleanName, "my-skill", "SKILL.md")) if !contains(cleanContent, "Updated clean") {