6f8b825f5f
The `weknora` command-line client for the WeKnora RAG server. Full command surface: kb / doc / chunk / session / message / agent / model / search / chat / auth / profile / link / api / mcp / skills / config / doctor / schema / exit-codes. Agent-first wire contract: JSON envelope by default, typed error codes mapped to stable exit codes, error.retry_argv / retryable / partial-failure status, global --dry-run preview, the exit-10 confirmation protocol for writes, and control/ANSI/Bidi input hygiene. Stateless env-credential auth (WEKNORA_API_KEY / WEKNORA_TOKEN + WEKNORA_HOST) for headless/CI/agent use. A curated read-only MCP tool surface (`mcp serve`) and embedded Agent Skills (`skills install`). Extensive unit + contract-golden tests and CI.
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package skillscmd
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
skillsfs "github.com/Tencent/WeKnora/cli/skills"
|
|
)
|
|
|
|
// TestEmbeddedSkillsPresent: the binary embeds the bundled skills with their
|
|
// SKILL.md (the parity tests guard the command vocabulary; this guards the
|
|
// embed itself stays wired).
|
|
func TestEmbeddedSkillsPresent(t *testing.T) {
|
|
skills, err := skillsfs.List()
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, skills, "at least one skill must be embedded")
|
|
for _, s := range skills {
|
|
assert.NotEmpty(t, s.Files, "%s must embed files", s.Name)
|
|
var hasMD bool
|
|
for _, f := range s.Files {
|
|
if filepath.Base(f) == "SKILL.md" {
|
|
hasMD = true
|
|
}
|
|
}
|
|
assert.True(t, hasMD, "%s must embed a SKILL.md", s.Name)
|
|
}
|
|
}
|
|
|
|
// TestWriteSkills_WritesAndIsIdempotent: install writes every embedded file
|
|
// preserving the dir structure; a second run without --force overwrites
|
|
// nothing (returns no newly-written paths); --force rewrites them.
|
|
func TestWriteSkills_WritesAndIsIdempotent(t *testing.T) {
|
|
dir := t.TempDir()
|
|
skills, err := skillsfs.List()
|
|
require.NoError(t, err)
|
|
|
|
// First install: every file written.
|
|
written, err := writeSkills(skills, dir, false)
|
|
require.NoError(t, err)
|
|
var total int
|
|
for _, s := range skills {
|
|
total += len(s.Files)
|
|
}
|
|
assert.Len(t, written, total, "first install writes every embedded file")
|
|
for _, p := range written {
|
|
_, statErr := os.Stat(p)
|
|
assert.NoError(t, statErr, "written file must exist: %s", p)
|
|
}
|
|
|
|
// Second install without --force: nothing overwritten.
|
|
again, err := writeSkills(skills, dir, false)
|
|
require.NoError(t, err)
|
|
assert.Empty(t, again, "without --force, existing files are left untouched")
|
|
|
|
// With --force: all rewritten.
|
|
forced, err := writeSkills(skills, dir, true)
|
|
require.NoError(t, err)
|
|
assert.Len(t, forced, total, "--force rewrites every file")
|
|
}
|
|
|
|
// TestResolveDir: explicit --dir wins; empty falls back to ~/.claude/skills.
|
|
func TestResolveDir(t *testing.T) {
|
|
got, err := resolveDir("/custom/path")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "/custom/path", got)
|
|
|
|
def, err := resolveDir("")
|
|
require.NoError(t, err)
|
|
assert.True(t, filepath.IsAbs(def), "default dir must be absolute")
|
|
assert.Contains(t, def, filepath.Join(".claude", "skills"))
|
|
}
|