mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
1ab853023a
* feat(apps): read LARKSUITE_CLI_AGENT env var and pass app_source in +create
* feat(apps): add queryAppMeta shared function for app_type/arch_type lookup
* feat(apps): skip scaffold for legacy html apps, pass app_type/arch_type for arch_type=4 html in +init
* feat(apps): add zip packaging for arch_type=4 html publish path
* feat(apps): add TOS upload path for arch_type=4 html in +html-publish with arch_type-based routing
* refactor(apps): replace appMeta struct with queryAppType string for simpler routing
* refactor(apps): simplify to source_agent in +create, unified scaffold in +init, revert html-publish changes
* feat(apps): add --source-path flag to +init for existing source file incorporation
* fix(apps): align queryAppType with actual API path and response structure
* refactor(apps): use appInfo struct to parse GET /apps/{id} response
* test(apps): add full_stack scaffold test case
* feat(apps): surface sync field in +release-create response
* refactor(apps): remove --template flag from +init, derive template from queryAppType with full_stack fallback
* style(apps): fix gofmt formatting in apps_init.go
* test(apps): improve coverage for sync field, queryAppType, and scaffoldInitArgs
* chore(apps): pin miaoda-cli to alpha version 0.1.20-alpha.dd573f8
* feat(apps): add modern_html enum and pass --app-type instead of --template to miaoda-cli
* chore: add global PPE headers for testing (x-use-ppe, x-tt-env)
* feat(apps): add TOS upload path in +html-publish for modern_html, add --tos-path to +release-create
* feat(apps): unify html-publish output structure with app_id for both html and modern_html
* fix(apps): use newFileTransferClient for TOS presigned upload to satisfy forbidigo lint
* test(apps): add coverage for runHTMLPublishTOS success, errors, and upload failures
* fix(apps): change pre_release API method from POST to GET
* fix(apps): adapt pre_release response from map to list<KV> format
* fix(apps): use PUT method and Content-Length for TOS presigned upload
* fix(apps): use tos_path instead of tosPath in release-create request body
* chore(apps): add npmmirror registry for npx miaoda-cli, fix TOS upload test to expect PUT
* refactor(apps): use envvars.AgentName() for source_agent in +create
* feat(apps): integrate release-create into html-publish for modern_html, auto-detect modern_html from doubao agent env
* refactor(apps): remove --tos-path flag from +release-create (now internal to html-publish)
* refactor(apps): remove app_id from html-publish output, update skill doc
* docs(apps): update html-publish description to reflect dual return values
* refactor(apps): remove doubao app_type conversion in +create, let server decide via source_agent
* feat(apps): skip env-pull for modern_html apps in +init
* test(apps): add tests for modern_html env-pull skip in +init
* refactor(apps): introduce appTypePolicy for init control points (skipInstall, skipEnvPull, skipSkillsSync)
* feat(apps): add init step timing and default git config for +init
* feat(apps): add +get shortcut to fetch single app detail by app_id
* chore(apps): remove init step timing (not ready for production)
* test(apps): add coverage for +get shortcut
* chore: remove PPE headers and revert miaoda-cli to @latest for production
* refactor(apps): extract shared prepareHTMLPublishTarball, fix stale comments, simplify queryAppType
* fix(apps): update html-publish dry-run desc, remove hardcoded API path
* fix(apps): use rctx.IO().ErrOut instead of os.Stderr, remove unused appInfo struct
* fix(apps): restore dry-run API path output for E2E compatibility
* refactor(apps): move --source-path control char validation to Validate for dry-run coverage
* fix(apps): update stale --template comments to --app-type in init tests
* test(apps): explicitly unset agent env var for test isolation
150 lines
4.3 KiB
Go
150 lines
4.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package apps
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
"github.com/larksuite/cli/internal/httpmock"
|
|
"github.com/larksuite/cli/shortcuts/common"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func TestBuildPublishBody(t *testing.T) {
|
|
// branch included when non-empty; app_id is NOT in body (it's in the path)
|
|
b := buildPublishBody("feat/devops")
|
|
if b["branch"] != "feat/devops" {
|
|
t.Errorf("body = %v", b)
|
|
}
|
|
if _, ok := b["app_id"]; ok {
|
|
t.Errorf("app_id must not be in body, got %v", b)
|
|
}
|
|
// branch omitted when empty
|
|
b2 := buildPublishBody("")
|
|
if _, ok := b2["branch"]; ok {
|
|
t.Errorf("branch should be omitted when empty, got %v", b2)
|
|
}
|
|
}
|
|
|
|
func TestAppsReleaseCreateMeta(t *testing.T) {
|
|
if AppsReleaseCreate.Command != "+release-create" || AppsReleaseCreate.Risk != "write" {
|
|
t.Errorf("meta mismatch: %+v", AppsReleaseCreate)
|
|
}
|
|
if len(AppsReleaseCreate.Scopes) != 1 || AppsReleaseCreate.Scopes[0] != "spark:app:write" {
|
|
t.Errorf("scopes = %v", AppsReleaseCreate.Scopes)
|
|
}
|
|
}
|
|
|
|
// newReleaseCreateRuntimeContext builds a RuntimeContext whose cobra.Command has the
|
|
// flags that AppsReleaseCreate.Execute reads (app-id, branch). Flag values are set
|
|
// via the returned setter helper.
|
|
func newReleaseCreateRuntimeContext(t *testing.T, appID, branch string) (*common.RuntimeContext, *bytes.Buffer, *httpmock.Registry) {
|
|
t.Helper()
|
|
cfg := &core.CliConfig{
|
|
AppID: "test-app-" + strings.ToLower(t.Name()),
|
|
AppSecret: "test-secret",
|
|
Brand: core.BrandFeishu,
|
|
UserOpenId: "ou_test",
|
|
}
|
|
factory, stdoutBuf, _, reg := cmdutil.TestFactory(t, cfg)
|
|
|
|
cmd := &cobra.Command{Use: "test-release-create"}
|
|
cmd.SetContext(context.Background())
|
|
cmd.Flags().String("app-id", "", "")
|
|
cmd.Flags().String("branch", "", "")
|
|
_ = cmd.Flags().Set("app-id", appID)
|
|
if branch != "" {
|
|
_ = cmd.Flags().Set("branch", branch)
|
|
}
|
|
|
|
rctx := common.TestNewRuntimeContextForAPI(context.Background(), cmd, cfg, factory, core.AsUser)
|
|
return rctx, stdoutBuf, reg
|
|
}
|
|
|
|
func TestAppsReleaseCreateExecute_Success(t *testing.T) {
|
|
rctx, stdoutBuf, reg := newReleaseCreateRuntimeContext(t, "app_x", "main")
|
|
reg.Register(&httpmock.Stub{
|
|
Method: "POST",
|
|
URL: "/open-apis/spark/v1/apps/app_x/releases",
|
|
Body: map[string]interface{}{
|
|
"code": 0,
|
|
"msg": "",
|
|
"data": map[string]interface{}{
|
|
"release_id": "123",
|
|
"status": "publishing",
|
|
},
|
|
},
|
|
})
|
|
|
|
err := AppsReleaseCreate.Execute(context.Background(), rctx)
|
|
if err != nil {
|
|
t.Fatalf("Execute() = %v", err)
|
|
}
|
|
|
|
var env struct {
|
|
OK bool `json:"ok"`
|
|
Data map[string]interface{} `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(stdoutBuf.Bytes(), &env); err != nil {
|
|
t.Fatalf("unmarshal output: %v\nraw: %s", err, stdoutBuf.String())
|
|
}
|
|
if !env.OK {
|
|
t.Fatalf("expected ok=true, got: %s", stdoutBuf.String())
|
|
}
|
|
if env.Data["release_id"] != "123" {
|
|
t.Errorf("release_id = %v, want 123", env.Data["release_id"])
|
|
}
|
|
if env.Data["status"] != "publishing" {
|
|
t.Errorf("status = %v, want publishing", env.Data["status"])
|
|
}
|
|
}
|
|
|
|
func TestAppsReleaseCreate_SyncField(t *testing.T) {
|
|
rctx, stdoutBuf, reg := newReleaseCreateRuntimeContext(t, "app_sync", "main")
|
|
reg.Register(&httpmock.Stub{
|
|
Method: "POST",
|
|
URL: "/open-apis/spark/v1/apps/app_sync/releases",
|
|
Body: map[string]interface{}{
|
|
"code": 0,
|
|
"msg": "",
|
|
"data": map[string]interface{}{
|
|
"release_id": "456",
|
|
"status": "publishing",
|
|
"sync": true,
|
|
},
|
|
},
|
|
})
|
|
|
|
err := AppsReleaseCreate.Execute(context.Background(), rctx)
|
|
if err != nil {
|
|
t.Fatalf("Execute() = %v", err)
|
|
}
|
|
|
|
var env struct {
|
|
OK bool `json:"ok"`
|
|
Data map[string]interface{} `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(stdoutBuf.Bytes(), &env); err != nil {
|
|
t.Fatalf("unmarshal output: %v\nraw: %s", err, stdoutBuf.String())
|
|
}
|
|
if !env.OK {
|
|
t.Fatalf("expected ok=true, got: %s", stdoutBuf.String())
|
|
}
|
|
if env.Data["release_id"] != "456" {
|
|
t.Errorf("release_id = %v, want 456", env.Data["release_id"])
|
|
}
|
|
if env.Data["status"] != "publishing" {
|
|
t.Errorf("status = %v, want publishing", env.Data["status"])
|
|
}
|
|
if env.Data["sync"] != true {
|
|
t.Errorf("sync = %v, want true", env.Data["sync"])
|
|
}
|
|
}
|