File size: 24,646 Bytes
f778c12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | import fs from "node:fs";
import path from "node:path";
import { setImmediate as nextEventLoopTurn } from "node:timers/promises";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createDeferred } from "../../../test/helpers/promise.js";
import { createTempDirTracker } from "../../../test/helpers/temp-dir.js";
import {
clearRuntimeAuthProfileStoreSnapshots,
ensureAuthProfileStoreWithoutExternalProfiles,
resolveApiKeyForProfile,
replaceRuntimeAuthProfileStoreSnapshots,
setAuthProfileOrder,
} from "../../agents/auth-profiles.js";
import { loadPersistedAuthProfileStore } from "../../agents/auth-profiles/persisted.js";
import { upsertAuthProfileWithLockOrThrow } from "../../agents/auth-profiles/profiles.js";
import type { AuthProfileCredential } from "../../agents/auth-profiles/types.js";
import { registerRuntimeConfigWriteListener } from "../../config/runtime-snapshot.js";
import {
getRuntimeConfigWriteApplication,
type RuntimeConfigWriteApplicationClaim,
} from "../../config/runtime-write-application.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { redactSensitiveText } from "../../logging/redact.js";
import {
closeOpenClawAgentDatabasesAsync,
closeOpenClawAgentDatabasesForTest,
} from "../../state/openclaw-agent-db.js";
import {
closeOpenClawStateDatabaseAsync,
closeOpenClawStateDatabaseForTest,
} from "../../state/openclaw-state-db.js";
import { saveModelProviderApiKey } from "./auth-api-key.js";
import { removeModelAuthCredentials } from "./auth-logout.js";
import * as configWriter from "./shared.js";
const tempDirs = createTempDirTracker();
const connection = { baseUrl: "http://127.0.0.1:9/v1", models: [] };
let stateDir: string;
const agentDir = (id: string) => path.join(stateDir, "agents", id, "agent");
const configPath = () => path.join(stateDir, "openclaw.json");
const writeConfig = (config: OpenClawConfig) =>
fs.writeFileSync(configPath(), JSON.stringify(config));
const save = (apiKey = "synthetic-new-key", profileId?: string) =>
saveModelProviderApiKey({ provider: "sample", apiKey, profileId, agentDir: agentDir("writer") });
async function readConfig() {
return (await configWriter.loadValidConfigSnapshotOrThrow()).runtimeConfig;
}
beforeEach(() => {
stateDir = tempDirs.make("openclaw-shared-api-key-");
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath());
vi.stubEnv("OPENCLAW_AGENT_DIR", undefined);
vi.stubEnv("OPENCLAW_OAUTH_DIR", undefined);
writeConfig({ plugins: { allow: [] } });
});
afterEach(async () => {
try {
clearRuntimeAuthProfileStoreSnapshots();
await closeOpenClawAgentDatabasesAsync();
closeOpenClawAgentDatabasesForTest();
await closeOpenClawStateDatabaseAsync();
closeOpenClawStateDatabaseForTest();
tempDirs.cleanup();
} finally {
vi.restoreAllMocks();
vi.unstubAllEnvs();
}
});
describe("shared API-key editing and removal", () => {
it("waits for the saved binding to reach the Gateway before allowing immediate removal", async () => {
writeConfig({ models: { providers: { sample: { ...connection, apiKey: "old-inline" } } } });
let claim: RuntimeConfigWriteApplicationClaim | undefined;
const written = createDeferred();
const updateConfig = configWriter.updateConfig;
vi.spyOn(configWriter, "updateConfig").mockImplementationOnce(async (...args) => {
const config = await updateConfig(...args);
written.resolve();
return config;
});
const stop = registerRuntimeConfigWriteListener((event) => {
claim = getRuntimeConfigWriteApplication(event)?.claim() ?? undefined;
});
const response = save();
try {
await written.promise;
expect(
await Promise.race([response.then(() => "completed"), nextEventLoopTurn("pending")]),
).toBe("pending");
const runtimeConfig = await readConfig();
claim?.settle("applied");
expect(await response).toEqual({ profileId: "sample:manual" });
stop();
await removeModelAuthCredentials({
cfg: runtimeConfig,
agentDir: agentDir("writer"),
profileIds: ["sample:manual"],
apiKeyProvider: "sample",
});
expect((await readConfig()).models?.providers?.sample?.apiKey).toBeUndefined();
expect(loadPersistedAuthProfileStore()?.profiles["sample:manual"]).toBeUndefined();
} finally {
claim?.settle("failed");
stop();
await response;
}
});
it.each(["failed", "restart-pending", "unclaimed"] as const)(
"reports a saved key with a warning when config application is %s",
async (status) => {
const stop = registerRuntimeConfigWriteListener((event) => {
if (status !== "unclaimed") {
getRuntimeConfigWriteApplication(event)?.claim()?.settle(status);
}
});
try {
expect(await save()).toEqual({
profileId: "sample:manual",
warning: expect.stringContaining("Gateway has not confirmed applying"),
});
expect((await readConfig()).auth?.profiles?.["sample:manual"]).toEqual({
provider: "sample",
mode: "api_key",
});
expect(
loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:manual"],
).toMatchObject({
key: "synthetic-new-key",
});
} finally {
stop();
}
},
);
it("replaces a configured shared key, preserving metadata, defaults and cross-agent resolution", async () => {
const profileId = "sample:work";
await upsertAuthProfileWithLockOrThrow({
profileId,
credential: {
type: "api_key",
provider: "sample",
key: "old-key",
copyToAgents: false,
displayName: "Stored account",
email: "stored@example.test",
},
});
const configuredProfile = {
provider: "sample",
mode: "api_key" as const,
displayName: "Work",
email: "work@example.test",
};
writeConfig({
plugins: { allow: [] },
agents: { defaults: { model: "kept/model" } },
auth: { profiles: { [profileId]: configuredProfile } },
models: { providers: { sample: { ...connection, apiKey: profileId } } },
});
expect(await save()).toEqual({ profileId });
const config = await readConfig();
expect(config.agents?.defaults?.model).toBe("kept/model");
expect(config.models?.providers?.sample).toEqual({ ...connection, apiKey: profileId });
expect(config.auth?.profiles?.[profileId]).toEqual(configuredProfile);
expect(loadPersistedAuthProfileStore()?.profiles[profileId]).toMatchObject({
key: "synthetic-new-key",
copyToAgents: false,
email: "stored@example.test",
displayName: "Stored account",
});
const reader = agentDir("reader");
await expect(
resolveApiKeyForProfile({
cfg: config,
store: ensureAuthProfileStoreWithoutExternalProfiles(reader),
profileId,
agentDir: reader,
}),
).resolves.toMatchObject({ apiKey: "synthetic-new-key" });
});
it("uses stored key order and preserves the unselected sibling", async () => {
for (const [profileId, key] of [
["sample:work", "old-work"],
["sample:backup", "kept-backup"],
] as const) {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: { type: "api_key", provider: "sample", key },
});
}
await setAuthProfileOrder({
agentDir: agentDir("writer"),
provider: "sample",
order: ["sample:work", "sample:backup"],
});
expect(await save()).toMatchObject({ profileId: "sample:work" });
const store = ensureAuthProfileStoreWithoutExternalProfiles(agentDir("writer"));
expect(store.profiles["sample:work"]).toMatchObject({ key: "synthetic-new-key" });
expect(store.profiles["sample:backup"]).toMatchObject({ key: "kept-backup" });
expect(store.order?.sample).toEqual(["sample:work", "sample:backup"]);
expect((await readConfig()).models).toBeUndefined();
});
it.each(["main", "reader"])(
"removes a shared bound key through %s and retains its sibling and model settings",
async (caller) => {
await upsertAuthProfileWithLockOrThrow({
profileId: "sample:bound",
credential: { type: "api_key", provider: "sample", key: "removed" },
});
await upsertAuthProfileWithLockOrThrow({
profileId: "sample:backup",
credential: { type: "api_key", provider: "sample", key: "kept" },
});
writeConfig({
plugins: { allow: [] },
agents: { defaults: { model: "sample/model" } },
auth: {
profiles: { "sample:bound": { provider: "sample", mode: "api_key" } },
order: { sample: ["sample:bound"], other: [] },
},
models: { providers: { sample: { ...connection, apiKey: "sample:bound" } } },
});
await removeModelAuthCredentials({
cfg: await readConfig(),
agentDir: agentDir(caller),
profileIds: ["sample:bound"],
});
const config = await readConfig();
expect(config.auth).toEqual({ profiles: {}, order: { other: [] } });
expect(config.models?.providers?.sample).toEqual(connection);
expect(config.agents?.defaults?.model).toBe("sample/model");
const store = ensureAuthProfileStoreWithoutExternalProfiles(agentDir(caller));
expect(store.profiles["sample:bound"]).toBeUndefined();
expect(store.profiles["sample:backup"]).toMatchObject({ key: "kept" });
},
);
it("preserves an externally managed key and its binding when removing inline keys", async () => {
const external = {
type: "api_key" as const,
provider: "sample",
keyRef: { source: "env" as const, provider: "default", id: "AUTH_B_EXTERNAL" },
};
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId: "sample:external",
credential: external,
});
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId: "sample:inline",
credential: { type: "api_key", provider: "sample", key: "removed" },
});
writeConfig({
models: { providers: { sample: { ...connection, apiKey: "sample:external" } } },
});
await removeModelAuthCredentials({
cfg: await readConfig(),
agentDir: agentDir("writer"),
profileIds: ["sample:inline"],
apiKeyProvider: "sample",
});
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles).toEqual({
"sample:external": external,
});
expect((await readConfig()).models?.providers?.sample?.apiKey).toBe("sample:external");
});
it("preserves agent overrides when a global key would shadow them", async () => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("reader"),
profileId: "sample:manual",
credential: { type: "api_key", provider: "sample", key: "kept-local" },
});
writeConfig({ models: { providers: { sample: { ...connection, apiKey: "old-inline" } } } });
const before = fs.readFileSync(configPath(), "utf8");
await expect(save()).rejects.toThrow("An agent already overrides this shared key");
expect(fs.readFileSync(configPath(), "utf8")).toBe(before);
expect(
loadPersistedAuthProfileStore(agentDir("reader"))?.profiles["sample:manual"],
).toMatchObject({ key: "kept-local" });
});
it.each([
{ type: "api_key", provider: "other", key: "kept" },
{ type: "token", provider: "sample", token: "kept" },
] satisfies AuthProfileCredential[])(
"does not replace an incompatible $type credential",
async (credential) => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId: "sample:manual",
credential,
});
await expect(save()).rejects.toThrow("belongs to another sign-in");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:manual"]).toEqual(
credential,
);
},
);
it.each([
{
profileId: "sample:external",
config: {
models: {
providers: { sample: { ...connection, apiKey: "sample:external" } },
},
},
},
{
profileId: "sample:manual",
config: {
models: {
providers: { sample: connection },
},
},
},
])("preserves reference-backed profile $profileId during replacement", async (fixture) => {
const credential: AuthProfileCredential = {
type: "api_key",
provider: "sample",
keyRef: { source: "env", provider: "default", id: "SAMPLE_API_KEY" },
copyToAgents: false,
};
await upsertAuthProfileWithLockOrThrow({
profileId: fixture.profileId,
credential,
});
writeConfig(fixture.config);
await expect(save()).rejects.toThrow("uses an external secret reference");
expect(loadPersistedAuthProfileStore()?.profiles[fixture.profileId]).toEqual(credential);
expect((await readConfig()).models).toEqual(fixture.config.models);
});
it("reports saved key material separately from failed config application and redacts it", async () => {
vi.spyOn(configWriter, "updateConfig").mockRejectedValueOnce(new Error("config write failed"));
await expect(save("ordinary-fixture\r\n-key-8304")).rejects.toThrow(
"API key saved, but provider settings could not be applied",
);
expect(
loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:manual"],
).toMatchObject({ key: "ordinary-fixture-key-8304" });
expect(redactSensitiveText("error: ordinary-fixture-key-8304")).not.toContain(
"ordinary-fixture-key-8304",
);
});
it.each([
{ type: "token", provider: "sample", token: "kept-replacement" },
{
type: "api_key",
provider: "sample",
keyRef: { source: "env", provider: "default", id: "AUTH_B_REPLACEMENT" },
},
] satisfies AuthProfileCredential[])(
"preserves a concurrent $type replacement during API-key removal",
async (replacement) => {
const profileId = "sample:race";
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: { type: "api_key", provider: "sample", key: "old-key" },
});
writeConfig({ models: { providers: { sample: { ...connection, apiKey: profileId } } } });
const config = await readConfig();
const updateConfig = configWriter.updateConfig;
vi.spyOn(configWriter, "updateConfig").mockImplementationOnce(async (mutator) => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: replacement,
});
replaceRuntimeAuthProfileStoreSnapshots([
{
agentDir: agentDir("writer"),
store: {
version: 1,
profiles: { [profileId]: { type: "api_key", provider: "sample", key: "stale-key" } },
},
},
]);
return updateConfig(mutator);
});
await expect(
removeModelAuthCredentials({
cfg: config,
agentDir: agentDir("writer"),
profileIds: [profileId],
apiKeyProvider: "sample",
}),
).rejects.toThrow("changed");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles[profileId]).toEqual(
replacement,
);
expect((await readConfig()).models?.providers?.sample?.apiKey).toBe(profileId);
},
);
it("preserves a configured agent-local key instead of rebinding it to a new shared key", async () => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId: "sample:local",
credential: { type: "api_key", provider: "sample", key: "kept-local", copyToAgents: false },
});
writeConfig({ models: { providers: { sample: { ...connection, apiKey: "sample:local" } } } });
await expect(save()).rejects.toThrow("An agent already overrides this shared key");
expect(
loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:local"],
).toMatchObject({ key: "kept-local", copyToAgents: false });
expect((await readConfig()).models?.providers?.sample?.apiKey).toBe("sample:local");
});
it("retains the credential when config reference cleanup fails", async () => {
const { profileId } = await save();
vi.spyOn(configWriter, "updateConfig").mockRejectedValueOnce(new Error("config write failed"));
await expect(
removeModelAuthCredentials({
cfg: await readConfig(),
agentDir: agentDir("writer"),
profileIds: [profileId],
}),
).rejects.toThrow("config write failed");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles[profileId]).toMatchObject({
key: "synthetic-new-key",
});
});
it("cleans references for every profile in the owner's full-provider removal plan", async () => {
for (const profileId of ["sample:old", "sample:new"]) {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: { type: "api_key", provider: "sample", key: "removed-key" },
});
}
writeConfig({ models: { providers: { sample: { ...connection, apiKey: "sample:new" } } } });
await removeModelAuthCredentials({
cfg: await readConfig(),
agentDir: agentDir("writer"),
profileIds: ["sample:old"],
provider: "sample",
});
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles).toEqual({});
expect((await readConfig()).models?.providers?.sample?.apiKey).toBeUndefined();
});
it("preserves a new profile and binding added after full-provider removal was planned", async () => {
await save("old-key", "sample:old");
const config = await readConfig();
const updateConfig = configWriter.updateConfig;
vi.spyOn(configWriter, "updateConfig").mockImplementationOnce(async (mutator) => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId: "sample:new",
credential: { type: "token", provider: "sample", token: "kept-new-token" },
});
writeConfig({ models: { providers: { sample: { ...connection, apiKey: "sample:new" } } } });
return updateConfig(mutator);
});
await expect(
removeModelAuthCredentials({
cfg: config,
agentDir: agentDir("writer"),
profileIds: ["sample:old"],
provider: "sample",
}),
).rejects.toThrow("could not be removed");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:new"]).toMatchObject(
{ token: "kept-new-token" },
);
expect((await readConfig()).models?.providers?.sample?.apiKey).toBe("sample:new");
});
it.each([
{ name: "API-key-only", selection: { apiKeyProvider: "sample" } },
{ name: "full-provider", selection: { provider: "sample" } },
])(
"restores config after a concurrent same-profile replacement rejects $name removal",
async ({ selection }) => {
const profileId = "sample:race";
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: { type: "api_key", provider: "sample", key: "old-key" },
});
writeConfig({
auth: {
profiles: { [profileId]: { provider: "sample", mode: "api_key" } },
order: { sample: [profileId] },
},
models: { providers: { sample: { ...connection, apiKey: profileId } } },
});
const config = await readConfig();
const updateConfig = configWriter.updateConfig;
vi.spyOn(configWriter, "updateConfig").mockImplementationOnce(async (mutator) => {
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: { type: "api_key", provider: "sample", key: "replacement-key" },
});
return updateConfig(mutator);
});
await expect(
removeModelAuthCredentials({
cfg: config,
agentDir: agentDir("writer"),
profileIds: [profileId],
...selection,
}),
).rejects.toThrow("could not be removed");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles[profileId]).toMatchObject({
key: "replacement-key",
});
const restored = await readConfig();
expect(restored.auth?.profiles?.[profileId]).toEqual({
provider: "sample",
mode: "api_key",
});
expect(restored.auth?.order?.sample).toEqual([profileId]);
expect(restored.models?.providers?.sample?.apiKey).toBe(profileId);
},
);
it("does not use a stale runtime key snapshot to authorize removal of a durable token", async () => {
const profileId = "sample:stale";
const replacement: AuthProfileCredential = {
type: "token",
provider: "sample",
token: "kept-durable-token",
};
await upsertAuthProfileWithLockOrThrow({
agentDir: agentDir("writer"),
profileId,
credential: replacement,
});
writeConfig({ models: { providers: { sample: { ...connection, apiKey: profileId } } } });
replaceRuntimeAuthProfileStoreSnapshots([
{
agentDir: agentDir("writer"),
store: {
version: 1,
profiles: {
[profileId]: { type: "api_key", provider: "sample", key: "stale-runtime-key" },
},
},
},
]);
await expect(
removeModelAuthCredentials({
cfg: await readConfig(),
agentDir: agentDir("writer"),
profileIds: [profileId],
apiKeyProvider: "sample",
}),
).rejects.toThrow("changed");
expect(loadPersistedAuthProfileStore(agentDir("writer"))?.profiles[profileId]).toEqual(
replacement,
);
expect((await readConfig()).models?.providers?.sample?.apiKey).toBe(profileId);
});
it.each(["sample:backup", undefined])(
"preserves a newer provider binding of %s after key entry",
async (apiKey) => {
for (const profileId of ["sample:original", "sample:backup"]) {
await upsertAuthProfileWithLockOrThrow({
profileId,
credential: { type: "api_key", provider: "sample", key: profileId },
});
}
writeConfig({
models: { providers: { sample: { ...connection, apiKey: "sample:original" } } },
});
const config = await readConfig();
const updated = { ...connection, apiKey };
writeConfig({ models: { providers: { sample: updated } } });
await expect(
saveModelProviderApiKey({
config,
provider: "sample",
apiKey: "replacement-key",
agentDir: agentDir("writer"),
}),
).rejects.toThrow("API key saved, but provider settings could not be applied");
expect((await readConfig()).models?.providers?.sample).toEqual(updated);
expect(loadPersistedAuthProfileStore()?.profiles["sample:original"]).toMatchObject({
key: "replacement-key",
});
expect(loadPersistedAuthProfileStore()?.profiles["sample:backup"]).toMatchObject({
key: "sample:backup",
});
},
);
it.each(["oauth", "token", "api-key"] as const)(
"keeps the active %s connection when saving an explicit backup profile",
async (auth) => {
const provider = { ...connection, auth, apiKey: "existing-connection-key" };
writeConfig({ models: { providers: { sample: provider } } });
expect(await save("backup-key", "sample:backup")).toMatchObject({
profileId: "sample:backup",
});
expect((await readConfig()).models?.providers?.sample).toEqual(provider);
expect(
loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:backup"],
).toMatchObject({ key: "backup-key" });
},
);
it("updates an explicitly selected shared profile at its existing owner", async () => {
await upsertAuthProfileWithLockOrThrow({
profileId: "sample:shared",
credential: { type: "api_key", provider: "sample", key: "old-shared", copyToAgents: false },
});
await save("replacement-shared", "sample:shared");
expect(loadPersistedAuthProfileStore()?.profiles["sample:shared"]).toMatchObject({
key: "replacement-shared",
copyToAgents: false,
});
expect(
loadPersistedAuthProfileStore(agentDir("writer"))?.profiles["sample:shared"],
).toBeUndefined();
});
});
|