Files
skillshare/tests/integration/theme_test.go
T
Willie 788f9bc6e9 feat(agents): JSON output + audit gate for install/update
Extend install/update with agent-aware --json output and apply the same
audit block-threshold gate skills already use.

Install:
- install --json: imply --force; imply --all only when neither
  --skill nor --agent is set (so explicit selectors still work)
- project-mode install now routes through cmdInstallProjectParsed
  so --json suppresses UI and emits a pure-JSON payload
- agent installs propagate SourceDir so metadata lands in the
  agents root, not the install subdir
- validation error lists --agent / --kind / --branch explicitly

Update agents:
- update agents supports --force, --skip-audit, --audit-threshold
- tracked agent repos + metadata-backed single-file agents now run
  the same audit gate as skills; blocks roll back from a temp stage
- JSON output returns the final per-agent status
  (updated/skipped/failed/up_to_date/...) by merging check results
  with batch update outcomes

Audit:
- auditInstalledAgent shares one helper with auditInstalledSkill
  (scan + cleanup callbacks); single-file agent scans now use
  audit.ScanFile / ScanFileForProject instead of staging the file
  into a temp directory
- UpdateAgentFromDiscovery stages to temp, audits, then renames
  atomically (rename already overwrites on POSIX)

Refactors pulled in while reworking these paths:
- extract jsonUISuppressor helper in json_output.go and use it
  from install/update/update_agents; collapses 4 copies of the
  suppress/restore closure dance and the per-error failJSON block
- drop relPath plumbing from installAgentFromDiscoveryInternal
  now that ScanFile doesn't need a staged relative path
- list.go render functions now use theme.ANSI() so NO_COLOR is
  respected in plain-text output

Tests:
- add TestInstallAgentFromDiscovery_HighFindingBlocked (unit)
- add TestUpdate_Agents_HighFindingBlockedByThreshold (integration)
- add TestInstall_Project_JSON_Agent_PureJSON,
  TestUpdate_Agents_JSON_ReportsFinalStatus
- fix TestList_SKILLSHARE_THEME_Light / TestList_NO_COLOR to
  write a config before invoking list
- fix TestTargetList_NoTUI_FallsBackToPlainText assertion to match
  the new structured Mode: merge output
- fix TestDoctor_AllGood_PassesAll by pinning SKILLSHARE_THEME=dark
  so the no-TTY theme fallback warning doesn't fire
- add list_tui_content_test.go covering light/dark glamour base
- list detail pane now picks LightStyleConfig on light terminals

Docs:
- update install.md, update.md, understand/agents.md for the new
  flags, JSON shapes, and agents update workflow
2026-04-10 23:27:26 +08:00

68 lines
1.8 KiB
Go

//go:build !online
package integration
import (
"strings"
"testing"
"skillshare/internal/testutil"
)
// TestList_SKILLSHARE_THEME_Light verifies that when SKILLSHARE_THEME=light
// is set, the list output uses the light Primary color (232) and does not
// contain pure bright white (15), resolving issue #125.
func TestList_SKILLSHARE_THEME_Light(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("hello-world", map[string]string{
"SKILL.md": "---\nname: hello-world\ndescription: A test skill\n---\n# Hello",
})
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
result := sb.RunCLIEnv(
map[string]string{"SKILLSHARE_THEME": "light"},
"list", "--no-tui",
)
if result.ExitCode != 0 {
t.Fatalf("list exited %d: %s", result.ExitCode, result.Output())
}
// Light Primary is 232 — the rendered 256-color escape is
// ESC[38;5;232m. Plain text from tables etc. may not include this,
// so we only assert that pure white 15 is NOT present.
if strings.Contains(result.Stdout, "\x1b[38;5;15m") {
t.Error("light theme output must not contain pure white (Color 15)")
}
}
// TestList_NO_COLOR verifies that NO_COLOR strips all ANSI escape sequences.
func TestList_NO_COLOR(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("hello", map[string]string{
"SKILL.md": "---\nname: hello\ndescription: A test skill\n---\n# H",
})
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
result := sb.RunCLIEnv(
map[string]string{"NO_COLOR": "1"},
"list", "--no-tui",
)
if result.ExitCode != 0 {
t.Fatalf("list exited %d: %s", result.ExitCode, result.Output())
}
if strings.Contains(result.Stdout, "\x1b[") {
t.Errorf("NO_COLOR must strip all ANSI escapes, got: %q", result.Stdout)
}
}