fix: address CodeRabbit review feedback

- runner.go: fail fast when Input is used on non-string flags
- remote_test.go: rename hasEmbeddedData → hasEmbeddedServices
- profile/list.go: add omitempty to optional JSON fields
- service.go: surface context cancellation errors in scope check

Change-Id: I7072d41f8c711b4b37c542e32dfd8150f42b13c0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
梁硕
2026-04-04 23:35:04 +08:00
parent 107b8d1a85
commit 77fa6e65ab
4 changed files with 14 additions and 8 deletions

View File

@@ -20,8 +20,8 @@ type profileListItem struct {
AppID string `json:"appId"`
Brand core.LarkBrand `json:"brand"`
Active bool `json:"active"`
User string `json:"user"`
TokenStatus string `json:"tokenStatus"`
User string `json:"user,omitempty"`
TokenStatus string `json:"tokenStatus,omitempty"`
}
// NewCmdProfileList creates the profile list subcommand.

View File

@@ -256,6 +256,9 @@ func serviceMethodRun(opts *ServiceMethodOptions) error {
// checkServiceScopes pre-checks user scopes before making the API call.
func checkServiceScopes(ctx context.Context, cred *credential.CredentialProvider, identity core.Identity, config *core.CliConfig, method map[string]interface{}, scopes []interface{}) error {
if ctx.Err() != nil {
return ctx.Err()
}
result, err := cred.ResolveToken(ctx, credential.NewTokenSpec(identity, config.AppID))
if err != nil || result == nil || result.Scopes == "" {
return nil //nolint:nilerr // skip scope check when token resolution fails or has no scopes

View File

@@ -29,8 +29,8 @@ func resetInit() {
testMetaURL = ""
}
// hasEmbeddedData returns true if meta_data.json with real services is compiled in.
func hasEmbeddedData() bool {
// hasEmbeddedServices returns true if meta_data.json with real services is compiled in.
func hasEmbeddedServices() bool {
if len(embeddedMetaJSON) == 0 {
return false
}
@@ -83,7 +83,7 @@ func testEnvelopeNotModifiedJSON() []byte {
}
func TestColdStart_UsesEmbedded(t *testing.T) {
if !hasEmbeddedData() {
if !hasEmbeddedServices() {
t.Skip("no embedded from_meta data")
}
resetInit()
@@ -104,7 +104,7 @@ func TestColdStart_UsesEmbedded(t *testing.T) {
}
func TestColdStart_NoEmbedded_SyncFetch(t *testing.T) {
if hasEmbeddedData() {
if hasEmbeddedServices() {
t.Skip("embedded data present, skipping no-embedded test")
}
resetInit()
@@ -175,7 +175,7 @@ func TestCacheHit_WithinTTL(t *testing.T) {
t.Error("expected custom_svc from cache overlay")
}
// Embedded projects should still be present (if compiled in)
if hasEmbeddedData() {
if hasEmbeddedServices() {
if spec := LoadFromMeta("calendar"); spec == nil {
t.Error("expected calendar from embedded data")
}

View File

@@ -526,7 +526,10 @@ func resolveInputFlags(rctx *RuntimeContext, flags []Flag) error {
if len(fl.Input) == 0 {
continue
}
raw, _ := rctx.Cmd.Flags().GetString(fl.Name)
raw, err := rctx.Cmd.Flags().GetString(fl.Name)
if err != nil {
return FlagErrorf("--%s: Input is only supported for string flags", fl.Name)
}
if raw == "" {
continue
}