惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
小众软件
小众软件
F
Fortinet All Blogs
博客园 - 叶小钗
博客园_首页
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
U
Unit 42
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
IT之家
IT之家
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(auth): migrate flat auth profiles in doctor · opencla...
steipete · 2026-04-28 · via Recent Commits to openclaw:main

@@ -0,0 +1,128 @@

1+

import fs from "node:fs";

2+

import os from "node:os";

3+

import path from "node:path";

4+

import { afterEach, describe, expect, it, vi } from "vitest";

5+

import { clearRuntimeAuthProfileStoreSnapshots } from "../agents/auth-profiles/store.js";

6+

import { maybeRepairLegacyFlatAuthProfileStores } from "./doctor-auth-flat-profiles.js";

7+

import type { DoctorPrompter } from "./doctor-prompter.js";

8+9+

const roots: string[] = [];

10+11+

function makeTempRoot(): string {

12+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-doctor-flat-auth-"));

13+

roots.push(root);

14+

return root;

15+

}

16+17+

function makePrompter(shouldRepair: boolean): DoctorPrompter {

18+

return {

19+

confirm: vi.fn(async () => shouldRepair),

20+

confirmAutoFix: vi.fn(async () => shouldRepair),

21+

confirmAggressiveAutoFix: vi.fn(async () => shouldRepair),

22+

confirmRuntimeRepair: vi.fn(async () => shouldRepair),

23+

select: vi.fn(async (_params, fallback) => fallback),

24+

shouldRepair,

25+

shouldForce: false,

26+

repairMode: {

27+

shouldRepair,

28+

shouldForce: false,

29+

nonInteractive: false,

30+

canPrompt: true,

31+

updateInProgress: false,

32+

},

33+

};

34+

}

35+36+

function withStateDir<T>(root: string, run: () => T): T {

37+

const previousStateDir = process.env.OPENCLAW_STATE_DIR;

38+

const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;

39+

process.env.OPENCLAW_STATE_DIR = root;

40+

delete process.env.OPENCLAW_AGENT_DIR;

41+

try {

42+

return run();

43+

} finally {

44+

if (previousStateDir === undefined) {

45+

delete process.env.OPENCLAW_STATE_DIR;

46+

} else {

47+

process.env.OPENCLAW_STATE_DIR = previousStateDir;

48+

}

49+

if (previousAgentDir === undefined) {

50+

delete process.env.OPENCLAW_AGENT_DIR;

51+

} else {

52+

process.env.OPENCLAW_AGENT_DIR = previousAgentDir;

53+

}

54+

}

55+

}

56+57+

afterEach(() => {

58+

clearRuntimeAuthProfileStoreSnapshots();

59+

for (const root of roots.splice(0)) {

60+

fs.rmSync(root, { recursive: true, force: true });

61+

}

62+

});

63+64+

describe("maybeRepairLegacyFlatAuthProfileStores", () => {

65+

it("rewrites legacy flat auth-profiles.json stores with a backup", async () => {

66+

const root = makeTempRoot();

67+

await withStateDir(root, async () => {

68+

const agentDir = path.join(root, "agents", "main", "agent");

69+

fs.mkdirSync(agentDir, { recursive: true });

70+

const authPath = path.join(agentDir, "auth-profiles.json");

71+

const legacy = {

72+

"ollama-windows": {

73+

apiKey: "ollama-local",

74+

baseUrl: "http://10.0.2.2:11434/v1",

75+

},

76+

};

77+

fs.writeFileSync(authPath, `${JSON.stringify(legacy)}\n`, "utf8");

78+79+

const result = await maybeRepairLegacyFlatAuthProfileStores({

80+

cfg: {},

81+

prompter: makePrompter(true),

82+

now: () => 123,

83+

});

84+85+

expect(result.detected).toEqual([authPath]);

86+

expect(result.changes).toHaveLength(1);

87+

expect(result.warnings).toEqual([]);

88+

expect(JSON.parse(fs.readFileSync(authPath, "utf8"))).toEqual({

89+

version: 1,

90+

profiles: {

91+

"ollama-windows:default": {

92+

type: "api_key",

93+

provider: "ollama-windows",

94+

key: "ollama-local",

95+

},

96+

},

97+

});

98+

expect(JSON.parse(fs.readFileSync(`${authPath}.legacy-flat.123.bak`, "utf8"))).toEqual(

99+

legacy,

100+

);

101+

});

102+

});

103+104+

it("reports legacy flat stores without rewriting when repair is declined", async () => {

105+

const root = makeTempRoot();

106+

await withStateDir(root, async () => {

107+

const agentDir = path.join(root, "agents", "main", "agent");

108+

fs.mkdirSync(agentDir, { recursive: true });

109+

const authPath = path.join(agentDir, "auth-profiles.json");

110+

const legacy = {

111+

openai: {

112+

apiKey: "sk-openai",

113+

},

114+

};

115+

fs.writeFileSync(authPath, `${JSON.stringify(legacy)}\n`, "utf8");

116+117+

const result = await maybeRepairLegacyFlatAuthProfileStores({

118+

cfg: {},

119+

prompter: makePrompter(false),

120+

});

121+122+

expect(result.detected).toEqual([authPath]);

123+

expect(result.changes).toEqual([]);

124+

expect(result.warnings).toEqual([]);

125+

expect(JSON.parse(fs.readFileSync(authPath, "utf8"))).toEqual(legacy);

126+

});

127+

});

128+

});