refactor(corps): normalize credential categories and format workflow history logs

This commit is contained in:
gitea committed 2026-10-14 18:19:13 +08:00
1 parent f91a80f9dd
commit 0499ccb2cc
9 files changed
+161 -49

No files matched your search

+58
View File
@@ -7,6 +7,8 @@ import {
protectLargeOutput,
printJson,
redactSensitiveText,
formatSourceLabel,
formatExpiresAt,
} from "./printer.js";
describe("cli/printer - 上下文防爆与敏感脱敏", () => {
@@ -114,4 +116,60 @@ describe("cli/printer - 上下文防爆与敏感脱敏", () => {
expect(savedContent[0].id).toBe("id-0");
});
});
describe("formatSourceLabel 4大凭证类别规范格式化", () => {
test("企业开放接口 (OpenAPI 密钥)", () => {
expect(formatSourceLabel("openapi")).toBe("企业开放接口 (OpenAPI 密钥)");
expect(formatSourceLabel("account", true)).toBe("企业开放接口 (OpenAPI 密钥)");
expect(formatSourceLabel("link", true)).toBe("企业开放接口 (OpenAPI 密钥)");
});
test("个人账号凭证 (手机号)", () => {
expect(formatSourceLabel("account")).toBe("个人账号凭证 (手机号)");
});
test("合思协助平台授权链接 (协助链接)", () => {
expect(formatSourceLabel("link")).toBe("合思协助平台授权链接 (协助链接)");
expect(formatSourceLabel("assist")).toBe("合思协助平台授权链接 (协助链接)");
});
test("网页临时抓包凭证 (Cookie)", () => {
expect(formatSourceLabel("curl")).toBe("网页临时抓包凭证 (Cookie)");
expect(formatSourceLabel("browser")).toBe("网页临时抓包凭证 (Cookie)");
expect(formatSourceLabel("f12")).toBe("网页临时抓包凭证 (Cookie)");
});
test("兜底处理", () => {
expect(formatSourceLabel("manual")).toBe("手动配置");
expect(formatSourceLabel("other")).toBe("其他 (other)");
expect(formatSourceLabel(undefined)).toBe("未知来源");
});
});
describe("formatExpiresAt 过期状态精准描述", () => {
test("长期有效凭据", () => {
expect(formatExpiresAt(undefined, true, "openapi")).toBe("长期有效 (OpenAPI 密钥)");
expect(formatExpiresAt(0, false)).toBe("长期有效 / 服务端未显式限制");
});
test("已过期但具备自动续期能力的凭据", () => {
const pastTime = Date.now() - 3600000;
expect(formatExpiresAt(pastTime, true, "account")).toContain("(🔄 随主账号自动换票)");
expect(formatExpiresAt(pastTime, true, "openapi")).toContain("(🔄 OpenAPI 密钥自动续期)");
expect(formatExpiresAt(pastTime, true)).toContain("(🔄 自动续期)");
});
test("已过期且不可续期的凭据精准告警", () => {
const pastTime = Date.now() - 3600000;
expect(formatExpiresAt(pastTime, false, "link")).toContain("(⚠️ 协助授权已失效)");
expect(formatExpiresAt(pastTime, false, "curl")).toContain("(⚠️ Cookie 已失效)");
expect(formatExpiresAt(pastTime, false, "manual")).toContain("(⚠️ 已过期)");
});
test("未来有效期的剩余提示", () => {
const futureMins = Date.now() + 30 * 60000;
expect(formatExpiresAt(futureMins, true, "account")).toContain("支持主账号自动换票");
expect(formatExpiresAt(futureMins, true, "openapi")).toContain("支持 OpenAPI 密钥自动续期");
});
});
});