Files
dingtalk-workspace-cli/internal/app/tool_caller_adapter_test.go
audanye-sudo 2d143589f8 feat(cli): add deterministic multi-account profile workflows
Accept corpId:userId and friendly organization/account selectors across global --profile, profile switch/use, event child processes, and multi-profile command execution.

List every local account in storage order with live identity-token status, preserve exact current and previous identities, and require explicit selection when an organization has no deterministic current account.

Extend auth logout to remove one exact account, every account in one organization, or all local accounts while revoking each token with its persisted credentials.

Use in-memory login tokens for identity enrichment before persistence, refresh generated Schema artifacts, and cover the complete CLI flow with isolated beta.3 end-to-end tests.
2026-07-17 00:56:57 +08:00

67 lines
2.1 KiB
Go

// Copyright 2026 Alibaba Group
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
"context"
"testing"
authpkg "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/auth"
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/executor"
)
func TestToolCallerTokenOverrideClearsUnpersistedRuntimeProfile(t *testing.T) {
authpkg.SetRuntimeProfile("corp_not_persisted")
t.Cleanup(func() { authpkg.SetRuntimeProfile("") })
flags := &GlobalFlags{}
runner := runtimeProfileCaptureRunner{flags: flags}
caller := &toolCallerAdapter{runner: runner, flags: flags}
result, err := caller.CallToolWithToken(
context.Background(),
"temporary-access-token",
"contact",
"get_current_user_profile",
nil,
)
if err != nil {
t.Fatalf("CallToolWithToken() error = %v", err)
}
if got := result.Content[0].Text; got != `{"profile":"","token":"temporary-access-token"}` {
t.Fatalf("CallToolWithToken() result = %s", got)
}
if authpkg.RuntimeProfile() != "corp_not_persisted" {
t.Fatalf("runtime profile = %q, want restored selector", authpkg.RuntimeProfile())
}
if flags.Token != "" {
t.Fatalf("token override leaked after call: %q", flags.Token)
}
}
type runtimeProfileCaptureRunner struct {
flags *GlobalFlags
}
func (r runtimeProfileCaptureRunner) Run(_ context.Context, invocation executor.Invocation) (executor.Result, error) {
return executor.Result{
Invocation: invocation,
Response: map[string]any{
"content": []any{map[string]any{
"type": "text",
"text": `{"profile":"` + authpkg.RuntimeProfile() + `","token":"` + r.flags.Token + `"}`,
}},
},
}, nil
}