mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
Enable IDE autocompletion, validation, and hover docs for config.yaml by adding JSON Schema support via yaml-language-server directive. - Add schemas/config.schema.json (global) and project-config.schema.json - Prepend schema comment in Config.Save() and ProjectConfig.Save() - Add unit and integration tests for schema comment roundtrip - Document IDE setup in configuration.md
121 lines
3.5 KiB
Go
121 lines
3.5 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
func TestInitProject_Fresh_CreatesStructure(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := filepath.Join(sb.Root, "project")
|
|
os.MkdirAll(projectRoot, 0755)
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude,cursor")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Initialized successfully")
|
|
|
|
// Verify structure
|
|
if !sb.FileExists(filepath.Join(projectRoot, ".skillshare", "config.yaml")) {
|
|
t.Error(".skillshare/config.yaml should exist")
|
|
}
|
|
if !sb.FileExists(filepath.Join(projectRoot, ".skillshare", "skills")) {
|
|
t.Error(".skillshare/skills/ should exist")
|
|
}
|
|
if !sb.FileExists(filepath.Join(projectRoot, ".skillshare", ".gitignore")) {
|
|
t.Error(".skillshare/.gitignore should exist")
|
|
}
|
|
// Target dirs created
|
|
if !sb.FileExists(filepath.Join(projectRoot, ".claude", "skills")) {
|
|
t.Error(".claude/skills/ should exist")
|
|
}
|
|
if !sb.FileExists(filepath.Join(projectRoot, ".cursor", "skills")) {
|
|
t.Error(".cursor/skills/ should exist")
|
|
}
|
|
}
|
|
|
|
func TestInitProject_AlreadyInitialized_Error(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := sb.SetupProjectDir("claude")
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "already initialized")
|
|
}
|
|
|
|
func TestInitProject_DryRun_NoFiles(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := filepath.Join(sb.Root, "project")
|
|
os.MkdirAll(projectRoot, 0755)
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude", "--dry-run")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Dry run")
|
|
|
|
if sb.FileExists(filepath.Join(projectRoot, ".skillshare", "config.yaml")) {
|
|
t.Error("dry-run should not create config")
|
|
}
|
|
}
|
|
|
|
func TestInitProject_ConfigContainsTargets(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := filepath.Join(sb.Root, "project")
|
|
os.MkdirAll(projectRoot, 0755)
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude,cursor")
|
|
result.AssertSuccess(t)
|
|
|
|
cfg := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", "config.yaml"))
|
|
if !strings.Contains(cfg, "claude") {
|
|
t.Error("config should contain claude target")
|
|
}
|
|
if !strings.Contains(cfg, "cursor") {
|
|
t.Error("config should contain cursor target")
|
|
}
|
|
}
|
|
|
|
func TestInitProject_ConfigHasSchemaComment(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := filepath.Join(sb.Root, "project")
|
|
os.MkdirAll(projectRoot, 0755)
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude")
|
|
result.AssertSuccess(t)
|
|
|
|
cfg := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", "config.yaml"))
|
|
firstLine := strings.SplitN(cfg, "\n", 2)[0]
|
|
if !strings.HasPrefix(firstLine, "# yaml-language-server: $schema=") {
|
|
t.Errorf("project config should start with schema comment, got first line: %q", firstLine)
|
|
}
|
|
}
|
|
|
|
func TestInitProject_GitignoreIncludesLogsDirectory(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectRoot := filepath.Join(sb.Root, "project")
|
|
os.MkdirAll(projectRoot, 0755)
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "init", "-p", "--targets", "claude")
|
|
result.AssertSuccess(t)
|
|
|
|
gitignore := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"))
|
|
if !strings.Contains(gitignore, "logs/") {
|
|
t.Errorf("project .gitignore should include logs/, got:\n%s", gitignore)
|
|
}
|
|
}
|