refactor(cli,auth): consolidate auth/profile model (BREAKING)

Auth now acts on the active profile instead of per-command --host/--name:
register a target with `profile add <name> --host <url> --use`, then
`auth login`. `auth login --with-token` reads an API key from stdin
(non-interactive, agent default); password login is interactive-only.

`auth token` prints the raw credential by default (clean $(...) capture);
--format json emits the {token,mode,profile} envelope, --jq implies json.
Login mode label corrected (api-key vs bearer). profile use and the auth/
profile read commands gain --dry-run / agent-help where they were missing.
This commit is contained in:
nullkey
2026-05-29 20:06:19 +08:00
committed by lyingbug
parent 6a1d0834c4
commit a68cc59310
17 changed files with 493 additions and 156 deletions
+7 -7
View File
@@ -71,19 +71,19 @@ func TestAuthLogout_DryRun_RejectsNoProfiles(t *testing.T) {
assert.Equal(t, cmdutil.CodeAuthUnauthenticated, typed.Code)
}
// TestAuthLogout_DryRun_RejectsUnknownName: --name on a profile that doesn't
// exist → live path returns local.profile_not_found; --dry-run must do the
// same.
func TestAuthLogout_DryRun_RejectsUnknownName(t *testing.T) {
// TestAuthLogout_DryRun_RejectsMissingActiveProfile: the active profile name
// (e.g. set via the global --profile) has no config entry → live path returns
// local.profile_not_found; --dry-run must do the same.
func TestAuthLogout_DryRun_RejectsMissingActiveProfile(t *testing.T) {
iostreams.SetForTest(t)
cfg := &config.Config{
CurrentProfile: "prod",
CurrentProfile: "ghost", // active profile with no matching entry
Profiles: map[string]config.Profile{"prod": {Host: "https://prod"}},
}
root := withRootHarnessAuth(NewCmdLogout(authDryRunFactory(t, cfg)),
"--name", "ghost", "--dry-run", "--format", "json")
"--dry-run", "--format", "json")
err := root.Execute()
require.Error(t, err, "dry-run must reject unknown --name")
require.Error(t, err, "dry-run must reject a missing active profile")
var typed *cmdutil.Error
require.True(t, errors.As(err, &typed), "expected *cmdutil.Error, got %T %v", err, err)
assert.Equal(t, cmdutil.CodeLocalProfileNotFound, typed.Code)