WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s

This commit is contained in:
yawan
2026-09-22 16:19:06 +08:00
commit f7fc992f57
3929 changed files with 1006607 additions and 0 deletions
+119
View File
@@ -0,0 +1,119 @@
package cmd
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
)
// TestSchema_Index: `weknora schema` lists every leaf command with its purpose.
func TestSchema_Index(t *testing.T) {
out, _ := iostreams.SetForTest(t)
root := NewRootCmd(cmdutil.New())
root.SetArgs([]string{"schema", "--format", "json"})
require.NoError(t, root.Execute())
var env struct {
OK bool `json:"ok"`
Data []schemaIndexEntry `json:"data"`
Meta struct {
Count int `json:"count"`
} `json:"meta"`
}
require.NoError(t, json.Unmarshal(out.Bytes(), &env), "got %q", out.String())
assert.True(t, env.OK)
assert.Greater(t, env.Meta.Count, 30, "index should enumerate the whole leaf surface")
byCmd := map[string]string{}
for _, e := range env.Data {
byCmd[e.Command] = e.UsedFor
}
// schema lists itself and other leaves, each with a used_for.
assert.Contains(t, byCmd, "kb create")
assert.Contains(t, byCmd, "schema")
assert.NotEmpty(t, byCmd["kb create"])
// group commands (kb, doc) are not leaves and must not appear.
assert.NotContains(t, byCmd, "kb")
}
// TestSchema_SingleCommand: a command path emits its full contract incl. flags.
func TestSchema_SingleCommand(t *testing.T) {
out, _ := iostreams.SetForTest(t)
root := NewRootCmd(cmdutil.New())
root.SetArgs([]string{"schema", "kb", "create", "--format", "json"})
require.NoError(t, root.Execute())
var env struct {
OK bool `json:"ok"`
Data commandSchema `json:"data"`
}
require.NoError(t, json.Unmarshal(out.Bytes(), &env), "got %q", out.String())
assert.True(t, env.OK)
assert.Equal(t, "kb create", env.Data.Command)
assert.NotEmpty(t, env.Data.UsedFor)
assert.NotEmpty(t, env.Data.Examples)
flagNames := map[string]bool{}
for _, f := range env.Data.Flags {
flagNames[f.Name] = true
}
assert.True(t, flagNames["description"], "kb create local flags should include --description; got %v", flagNames)
// global persistent flags (--format, --profile) are inherited, not local —
// schema lists only command-specific flags.
assert.False(t, flagNames["profile"], "inherited global flags must be excluded")
}
// TestSchema_QuotedMultiWordArg: the no-arg `schema` index prints command
// labels like "agent create"; an agent that pastes that label back as a single
// quoted arg (`schema "agent create"`) must resolve the same as two tokens,
// not fail with unknown_subcommand.
func TestSchema_QuotedMultiWordArg(t *testing.T) {
out, _ := iostreams.SetForTest(t)
root := NewRootCmd(cmdutil.New())
root.SetArgs([]string{"schema", "agent create", "--format", "json"})
require.NoError(t, root.Execute(), "got %q", out.String())
var env struct {
OK bool `json:"ok"`
Data commandSchema `json:"data"`
}
require.NoError(t, json.Unmarshal(out.Bytes(), &env), "got %q", out.String())
assert.True(t, env.OK)
assert.Equal(t, "agent create", env.Data.Command)
}
// TestSchema_SurfacesRisk: a destructive command exposes its risk annotation,
// so an agent can discover confirmation-gating without running the command.
func TestSchema_SurfacesRisk(t *testing.T) {
out, _ := iostreams.SetForTest(t)
root := NewRootCmd(cmdutil.New())
root.SetArgs([]string{"schema", "doc", "update", "--format", "json"})
require.NoError(t, root.Execute())
var env struct {
Data commandSchema `json:"data"`
}
require.NoError(t, json.Unmarshal(out.Bytes(), &env), "got %q", out.String())
require.NotNil(t, env.Data.Risk)
assert.Equal(t, "doc.update", env.Data.Risk.Action)
assert.Equal(t, "write", env.Data.Risk.Level)
}
// TestSchema_UnknownCommand: a bad path returns a typed unknown_subcommand
// error (exit 5) with a did-you-mean hint — never a silent empty result.
func TestSchema_UnknownCommand(t *testing.T) {
iostreams.SetForTest(t)
root := NewRootCmd(cmdutil.New())
root.SetArgs([]string{"schema", "kbb", "--format", "json"})
err := root.Execute()
require.Error(t, err)
var ce *cmdutil.Error
require.ErrorAs(t, err, &ce)
assert.Equal(t, cmdutil.CodeInputUnknownSubcommand, ce.Code)
assert.Contains(t, ce.Hint, "did you mean")
}