mirror of
https://github.com/larksuite/cli.git
synced 2026-07-10 11:04:26 +08:00
Add 8 new shortcut commands under `lark-cli apps`: Plugin package management (aligned with fullstack-cli): - +plugin-install: download tgz, extract to node_modules, update package.json - +plugin-uninstall: remove from node_modules and package.json actionPlugins - +plugin-list: list declared plugins with installation status Plugin instance CRUD (aligned with feida-ai): - +plugin-instance-create: validate + write capability JSON with formValue validation - +plugin-instance-update: merge mutable fields, re-validate formValue - +plugin-instance-delete: idempotent file removal - +plugin-instance-get: read capability JSON - +plugin-instance-list: scan capabilities directory Shared infrastructure (plugin_common.go): - 4-level capabilities dir resolution (flag → env → .env.local MIAODA_APP_TYPE → detection) - formValue validation ported from feida-ai (5 rules: forbidden Handlebars, paramsSchema type constraints, input ref existence, unconsumed params, array double-wrap auto-fix) - tgz extraction with path traversal protection - package.json actionPlugins management - Install version check with mismatch warnings
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package apps
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/errs"
|
|
)
|
|
|
|
func TestPluginInstanceGet_Basic(t *testing.T) {
|
|
dir := setupPluginTestProject(t, "server")
|
|
capDir := filepath.Join(dir, "server", "capabilities")
|
|
writeTestCapJSON(t, capDir, "my-inst.json", map[string]interface{}{
|
|
"id": "my-inst", "pluginKey": "@test/plugin", "pluginVersion": "1.0.0",
|
|
"name": "My Instance", "createdAt": 1718500000000,
|
|
})
|
|
|
|
factory, stdout, _ := newAppsExecuteFactory(t)
|
|
err := runAppsShortcut(t, AppsPluginInstanceGet,
|
|
[]string{"+plugin-instance-get", "--id", "my-inst", "--project-path", dir, "--as", "user"},
|
|
factory, stdout)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
got := stdout.String()
|
|
if !strings.Contains(got, "my-inst") {
|
|
t.Errorf("output missing instance id: %s", got)
|
|
}
|
|
if !strings.Contains(got, "@test/plugin") {
|
|
t.Errorf("output missing pluginKey: %s", got)
|
|
}
|
|
}
|
|
|
|
func TestPluginInstanceGet_JSON(t *testing.T) {
|
|
dir := setupPluginTestProject(t, "server")
|
|
capDir := filepath.Join(dir, "server", "capabilities")
|
|
writeTestCapJSON(t, capDir, "my-inst.json", map[string]interface{}{
|
|
"id": "my-inst", "pluginKey": "@test/plugin", "pluginVersion": "1.0.0", "name": "Test",
|
|
})
|
|
|
|
factory, stdout, _ := newAppsExecuteFactory(t)
|
|
err := runAppsShortcut(t, AppsPluginInstanceGet,
|
|
[]string{"+plugin-instance-get", "--id", "my-inst", "--project-path", dir, "--format", "json", "--as", "user"},
|
|
factory, stdout)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
var env map[string]interface{}
|
|
if err := json.Unmarshal(stdout.Bytes(), &env); err != nil {
|
|
t.Fatalf("invalid JSON: %v\nraw: %s", err, stdout.String())
|
|
}
|
|
data, _ := env["data"].(map[string]interface{})
|
|
if data["id"] != "my-inst" {
|
|
t.Errorf("id = %v, want my-inst", data["id"])
|
|
}
|
|
}
|
|
|
|
func TestPluginInstanceGet_NotFound(t *testing.T) {
|
|
dir := setupPluginTestProject(t, "server")
|
|
factory, stdout, _ := newAppsExecuteFactory(t)
|
|
|
|
err := runAppsShortcut(t, AppsPluginInstanceGet,
|
|
[]string{"+plugin-instance-get", "--id", "nonexistent", "--project-path", dir, "--as", "user"},
|
|
factory, stdout)
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
p, ok := errs.ProblemOf(err)
|
|
if !ok {
|
|
t.Fatalf("expected typed error, got %T: %v", err, err)
|
|
}
|
|
if p.Subtype != errs.SubtypeInvalidArgument {
|
|
t.Errorf("subtype = %q, want invalid_argument", p.Subtype)
|
|
}
|
|
}
|
|
|
|
func TestPluginInstanceGet_MissingID(t *testing.T) {
|
|
dir := setupPluginTestProject(t, "server")
|
|
factory, stdout, _ := newAppsExecuteFactory(t)
|
|
|
|
err := runAppsShortcut(t, AppsPluginInstanceGet,
|
|
[]string{"+plugin-instance-get", "--project-path", dir, "--as", "user"},
|
|
factory, stdout)
|
|
if err == nil {
|
|
t.Fatal("expected error when --id is missing")
|
|
}
|
|
}
|