
















@@ -61,14 +61,21 @@ function isPathInsideOrEqual(parentDir: string, candidatePath: string): boolean
6161);
6262}
636364+function expectOAuthProfileRefId(value: unknown): asserts value is string {
65+expect(typeof value).toBe("string");
66+if (typeof value !== "string") {
67+throw new Error("Expected OAuth profile ref id");
68+}
69+expect(value).toMatch(/^[a-f0-9]{32}$/);
70+}
71+6472function readPersistedOAuthRefId(agentDir: string, profileId: string): string {
6573const persisted = JSON.parse(fs.readFileSync(resolveAuthStorePath(agentDir), "utf8")) as {
6674profiles: Record<string, { oauthRef?: { id?: string } }>;
6775};
6876const refId = persisted.profiles[profileId]?.oauthRef?.id;
69-expect(typeof refId).toBe("string");
70-expect(refId?.length).toBeGreaterThan(0);
71-return String(refId);
77+expectOAuthProfileRefId(refId);
78+return refId;
7279}
73807481function resolvePersistedOAuthSecretPath(refId: string): string {
@@ -127,8 +134,7 @@ function expectOpenClawCredentialsOAuthRef(
127134const ref = oauthRef as Record<string, unknown>;
128135expect(ref.source).toBe("openclaw-credentials");
129136expect(ref.provider).toBe(provider);
130-expect(typeof ref.id).toBe("string");
131-expect(String(ref.id).length).toBeGreaterThan(0);
137+expectOAuthProfileRefId(ref.id);
132138}
133139134140describe("promoteAuthProfileInOrder", () => {
@@ -858,9 +864,8 @@ describe("promoteAuthProfileInOrder", () => {
858864profiles: Record<string, { oauthRef?: { id?: string } }>;
859865};
860866const refId = persisted.profiles[profileId]?.oauthRef?.id;
861-expect(typeof refId).toBe("string");
862-expect(refId?.length).toBeGreaterThan(0);
863-const secretPath = resolvePersistedOAuthSecretPath(String(refId));
867+expectOAuthProfileRefId(refId);
868+const secretPath = resolvePersistedOAuthSecretPath(refId);
864869const secretFile = fs.readFileSync(secretPath, "utf8");
865870expect(secretFile).not.toContain("delete-access-token");
866871expect(secretFile).not.toContain("delete-refresh-token");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。