Skip to content

Commit 474d6e5

Browse files
committed
docs: document auth health helpers
1 parent 2cba10a commit 474d6e5

10 files changed

Lines changed: 58 additions & 0 deletions

‎src/agents/auth-health.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Tests auth health rollups.
3+
* Covers OAuth/API-key status classification, external CLI bootstrap, provider
4+
* auth ordering, and prompt-free credential checks.
5+
*/
16
import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion";
27
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
38
import type { OAuthCredential } from "./auth-profiles/types.js";

‎src/agents/auth-health.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Auth profile health summarization.
3+
* Classifies stored and runtime credentials into profile/provider rollups for
4+
* status commands and doctor output without prompting keychain access.
5+
*/
16
import {
27
findNormalizedProviderValue,
38
normalizeProviderId,
@@ -61,6 +66,7 @@ function resolveAuthProfileSource(_profileId: string): AuthProfileSource {
6166
return "store";
6267
}
6368

69+
/** Format a remaining-duration value for compact auth status displays. */
6470
export function formatRemainingShort(
6571
remainingMs?: number,
6672
opts?: {
@@ -253,6 +259,7 @@ function buildProfileHealth(params: {
253259
};
254260
}
255261

262+
/** Build profile and provider auth health rollups from an auth profile store. */
256263
export function buildAuthHealthSummary(params: {
257264
store: AuthProfileStore;
258265
cfg?: OpenClawConfig;

‎src/agents/auth-profile-runtime-contract.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Runtime contract tests for auth profile forwarding.
3+
* Ensures CLI and embedded agent runtimes receive the selected auth profile
4+
* across provider aliases and plugin runtime manifests.
5+
*/
16
import fs from "node:fs/promises";
27
import os from "node:os";
38
import path from "node:path";

‎src/agents/auth-profiles/clone.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Auth profile store cloning helpers.
3+
* Keeps store snapshots JSON-serializable before callers mutate or persist
4+
* profile state.
5+
*/
16
import type { AuthProfileStore } from "./types.js";
27

38
/** Deep-clones an auth profile store and rejects non-JSON values. */

‎src/agents/auth-profiles/constants.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
/**
2+
* Shared auth-profile constants.
3+
* Defines store versions, built-in CLI profile ids, lock budgets, refresh
4+
* timing, and logging used by auth profile runtime modules.
5+
*/
16
import { createSubsystemLogger } from "../../logging/subsystem.js";
27
export {
38
AUTH_PROFILE_FILENAME,
49
AUTH_STATE_FILENAME,
510
LEGACY_AUTH_FILENAME,
611
} from "./path-constants.js";
712

13+
/** Current persisted auth profile store schema version. */
814
export const AUTH_STORE_VERSION = 1;
915

1016
/** @deprecated Anthropic provider-owned CLI profile id; do not use from third-party plugins. */
1117
export const CLAUDE_CLI_PROFILE_ID = "anthropic:claude-cli";
1218
/** @deprecated OpenAI provider-owned CLI profile id; do not use from third-party plugins. */
1319
export const CODEX_CLI_PROFILE_ID = "openai:codex-cli";
20+
/** Default OpenAI/Codex OAuth profile id used for migrated stores. */
1421
export const OPENAI_CODEX_DEFAULT_PROFILE_ID = "openai:default";
1522
/** @deprecated MiniMax provider-owned CLI profile id; do not use from third-party plugins. */
1623
export const MINIMAX_CLI_PROFILE_ID = "minimax-portal:minimax-cli";
1724

25+
/** File-lock policy for auth profile store reads/writes. */
1826
export const AUTH_STORE_LOCK_OPTIONS = {
1927
retries: {
2028
retries: 10,
@@ -40,6 +48,7 @@ export const AUTH_STORE_LOCK_OPTIONS = {
4048
// Retry budget note: keep the MINIMUM cumulative retry window comfortably
4149
// above OAUTH_REFRESH_CALL_TIMEOUT_MS so waiters do not give up while a
4250
// legitimate slow refresh is still within its allowed runtime budget.
51+
/** Cross-agent lock policy for shared OAuth refresh operations. */
4352
export const OAUTH_REFRESH_LOCK_OPTIONS = {
4453
retries: {
4554
retries: 20,
@@ -56,9 +65,13 @@ export const OAUTH_REFRESH_LOCK_OPTIONS = {
5665
// surfaced as a refresh failure. Keep strictly below
5766
// OAUTH_REFRESH_LOCK_OPTIONS.stale so the lock is never treated as stale
5867
// by a waiter while the owner is still doing legitimate work.
68+
/** Maximum duration for one OAuth refresh call inside the refresh lock. */
5969
export const OAUTH_REFRESH_CALL_TIMEOUT_MS = 120_000;
6070

71+
/** Freshness window for syncing external CLI auth into auth profiles. */
6172
export const EXTERNAL_CLI_SYNC_TTL_MS = 15 * 60 * 1000;
73+
/** Near-expiry threshold that triggers external CLI credential resync. */
6274
export const EXTERNAL_CLI_NEAR_EXPIRY_MS = 10 * 60 * 1000;
6375

76+
/** Auth profile subsystem logger. */
6477
export const log = createSubsystemLogger("agents/auth-profiles");

‎src/agents/auth-profiles/credential-state.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Tests credential eligibility and expiry classification.
3+
* Protects missing, expired, near-expiry, and SecretRef credential handling for
4+
* auth profile selection.
5+
*/
16
import { describe, expect, it } from "vitest";
27
import {
38
DEFAULT_OAUTH_REFRESH_MARGIN_MS,

‎src/agents/auth-profiles/credential-state.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Credential state classification for auth profiles.
3+
* Centralizes expiry, missing-secret, and unresolved-reference checks used by
4+
* auth selection, refresh, health, and doctor flows.
5+
*/
16
import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion";
27
import { coerceSecretRef, normalizeSecretInputString } from "../../config/types.secrets.js";
38
import type { AuthProfileCredential, OAuthCredential } from "./types.js";

‎src/agents/auth-profiles/display.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Tests auth profile display labels.
3+
* Verifies configured display names/emails are used without fabricating labels.
4+
*/
15
import { describe, expect, it } from "vitest";
26
import { resolveAuthProfileDisplayLabel } from "./display.js";
37

‎src/agents/auth-profiles/display.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Auth profile display labels.
3+
* Combines profile ids with configured human metadata for CLI/status output.
4+
*/
15
import type { OpenClawConfig } from "../../config/types.openclaw.js";
26
import { resolveAuthProfileMetadata } from "./identity.js";
37
import type { AuthProfileStore } from "./types.js";

‎src/agents/auth-profiles/doctor.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provider-specific auth doctor hints.
3+
* Adds local migration guidance for known legacy profiles before falling back
4+
* to provider plugin doctor copy.
5+
*/
16
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
27
import type { OpenClawConfig } from "../../config/types.openclaw.js";
38
import { buildProviderAuthDoctorHintWithPlugin } from "../../plugins/provider-runtime.runtime.js";

0 commit comments

Comments
 (0)