Files
xinmi/internal/agent/tools/skill_execute_test.go
yawan f7fc992f57
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
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

89 lines
3.2 KiB
Go

package tools
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSkillScriptCommandDoesNotJoinWorkspacePaths(t *testing.T) {
got := skillScriptCommand(ExecuteSkillScriptInput{
SkillName: "ppt-generator",
ScriptPath: "/workspace/output/generate_rencui_ppt.py",
Args: []string{"--flag"},
})
require.Equal(t, "/workspace/output/generate_rencui_ppt.py --flag", got)
assert.NotContains(t, got, "ppt-generator/")
}
func TestSkillScriptCommandKeepsRelativeSkillPaths(t *testing.T) {
got := skillScriptCommand(ExecuteSkillScriptInput{
SkillName: "pdf",
ScriptPath: "scripts/extract.py",
})
require.Equal(t, "pdf/scripts/extract.py", got)
}
func TestExecuteSkillScriptDescriptionAcceptsWorkspacePaths(t *testing.T) {
assert.Contains(t, executeSkillScriptTool.Description(), "write_sandbox_file")
assert.Contains(t, executeSkillScriptTool.Description(), "edit_sandbox_file")
assert.Contains(t, executeSkillScriptTool.Description(), "/workspace/output")
assert.Contains(t, executeSkillScriptTool.Description(), "/workspace/input")
assert.Contains(t, executeSkillScriptTool.Description(), "install_deps.py")
assert.Contains(t, executeSkillScriptTool.Description(), ".skill-packages")
}
// TestExecuteSkillScriptInputUnmarshalJSON covers the model-emitted shapes the
// UnmarshalJSON fallback must tolerate. The provider does not always honor the
// []string schema: it sometimes emits a stringified JSON array or a single
// command-line string. Each must round-trip to the intended argv.
func TestExecuteSkillScriptInputUnmarshalJSON(t *testing.T) {
t.Run("real array", func(t *testing.T) {
var in ExecuteSkillScriptInput
require.NoError(t, json.Unmarshal([]byte(`{
"skill_name": "s", "script_path": "p",
"args": ["--project-name", "X", "--creator", "admin"]
}`), &in))
require.Equal(t, []string{"--project-name", "X", "--creator", "admin"}, in.Args)
})
t.Run("stringified json array", func(t *testing.T) {
// Some providers emit args as a JSON string whose content is itself a
// JSON array. strings.Fields would mangle the brackets/quotes into
// one garbage token; the array must be recovered instead.
var in ExecuteSkillScriptInput
require.NoError(t, json.Unmarshal([]byte(`{
"skill_name": "s", "script_path": "p",
"args": "[\"--project-name\", \"X\", \"--creator\", \"admin\"]"
}`), &in))
require.Equal(t, []string{"--project-name", "X", "--creator", "admin"}, in.Args)
})
t.Run("single command line string", func(t *testing.T) {
var in ExecuteSkillScriptInput
require.NoError(t, json.Unmarshal([]byte(`{
"skill_name": "s", "script_path": "p",
"args": "ls --workspace /workspace/output"
}`), &in))
require.Equal(t, []string{"ls", "--workspace", "/workspace/output"}, in.Args)
})
t.Run("absent args", func(t *testing.T) {
var in ExecuteSkillScriptInput
require.NoError(t, json.Unmarshal([]byte(`{
"skill_name": "s", "script_path": "p"
}`), &in))
require.Empty(t, in.Args)
})
t.Run("null args", func(t *testing.T) {
var in ExecuteSkillScriptInput
require.NoError(t, json.Unmarshal([]byte(`{
"skill_name": "s", "script_path": "p", "args": null
}`), &in))
require.Empty(t, in.Args)
})
}