mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
be2a96f490
Aggregate the sheets work from feat/lark-sheets-develop: - Improve validation errors with schema hints, aggregated issues, enum guidance, and prescriptive flag/style-field messages. - Harden +batch-update input contracts, key normalization, style vocabulary handling, and resource-budget checks. - Add read offload and truncation handling for cells, csv, and table-get, with typed output-path errors and safer jq/output-path semantics. - Correct freeze semantics by emitting full-state freeze/unfreeze operations and adding --rows/--cols for +dim-freeze. - Improve +styles-put and shared --styles parsing for styles, merges, row/column sizing, freeze, and sheet-prefixed range validation. - Fix dim-insert inherit-style mapping, table-get date/time handling, table-put style anchors, and CSV path-shaped input guards. - Update lark-sheets skill docs, scripts, tests, and generated flag data. Tested with: - go test ./shortcuts/common ./shortcuts/sheets/... - go test ./shortcuts/... ./internal/... - python3 -m py_compile skills/lark-sheets/scripts/*.py
67 lines
2.5 KiB
Go
67 lines
2.5 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
)
|
|
|
|
// TestNewRuntimeContext creates a RuntimeContext for testing purposes.
|
|
// Only Cmd and Config are set; other fields (Factory, larkSDK, etc.) are nil.
|
|
func TestNewRuntimeContext(cmd *cobra.Command, cfg *core.CliConfig) *RuntimeContext {
|
|
return &RuntimeContext{Cmd: cmd, Config: cfg}
|
|
}
|
|
|
|
// TestNewRuntimeContextWithCtx creates a RuntimeContext with an explicit context
|
|
// for tests that invoke functions which call Ctx() (e.g. HTTP request helpers).
|
|
func TestNewRuntimeContextWithCtx(ctx context.Context, cmd *cobra.Command, cfg *core.CliConfig) *RuntimeContext {
|
|
return &RuntimeContext{ctx: ctx, Cmd: cmd, Config: cfg}
|
|
}
|
|
|
|
// TestNewRuntimeContextWithIdentity creates a RuntimeContext with a specific identity for testing.
|
|
func TestNewRuntimeContextWithIdentity(cmd *cobra.Command, cfg *core.CliConfig, as core.Identity) *RuntimeContext {
|
|
return &RuntimeContext{Cmd: cmd, Config: cfg, resolvedAs: as}
|
|
}
|
|
|
|
// TestNewRuntimeContextWithBotInfo creates a RuntimeContext with a pre-set BotInfo for testing.
|
|
func TestNewRuntimeContextWithBotInfo(cmd *cobra.Command, cfg *core.CliConfig, info *BotInfo) *RuntimeContext {
|
|
rctx := &RuntimeContext{Cmd: cmd, Config: cfg}
|
|
rctx.botInfoFunc = sync.OnceValues(func() (*BotInfo, error) {
|
|
return info, nil
|
|
})
|
|
return rctx
|
|
}
|
|
|
|
// TestMarkInputResolved marks a flag as resolved from @file / stdin, so
|
|
// domain tests can exercise guards that branch on InputResolvedFromSource
|
|
// without wiring the full resolveInputFlags path.
|
|
func TestMarkInputResolved(rctx *RuntimeContext, name string) {
|
|
rctx.markInputResolved(name)
|
|
}
|
|
|
|
// TestNewRuntimeContextForAPI creates a RuntimeContext ready for HTTP tests:
|
|
// sets Cmd, Config, Factory, context, and the requested identity so callers
|
|
// can invoke DoAPI / CallAPI directly without wiring through a cobra parent
|
|
// command.
|
|
//
|
|
// Pass core.AsBot or core.AsUser explicitly — exposing the identity as a
|
|
// parameter keeps the helper reusable for tests that need to exercise the
|
|
// user-identity code path (token store, auth login, etc.) without forking
|
|
// into a second near-identical helper.
|
|
func TestNewRuntimeContextForAPI(ctx context.Context, cmd *cobra.Command, cfg *core.CliConfig, f *cmdutil.Factory, as core.Identity) *RuntimeContext {
|
|
return &RuntimeContext{
|
|
ctx: ctx,
|
|
Cmd: cmd,
|
|
Config: cfg,
|
|
Factory: f,
|
|
resolvedAs: as,
|
|
}
|
|
}
|