fix: stabilize auth identity, record operations, and workflow diagnostics

This commit is contained in:
gitea committed 2026-10-15 14:54:10 +08:00
1 parent c74fdda7da
commit 7ec369f77e
36 files changed
+1021 -337

No files matched your search

+16 -7
View File
@@ -346,11 +346,18 @@ describe("cli/commands/corps > handleCorpsCommand search & aliases", () => {
it("supports dynamic staff switching via corps link [corp] --staff=<id>", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = (async () =>
new Response(JSON.stringify({ items: [] }), {
status: 200,
headers: { "content-type": "application/json" },
})) as unknown as typeof fetch;
const corp = structuredClone(mockCorps[0]);
Object.assign(corp.credentials, { appKey: "staff-switch-key", appSecurity: "staff-switch-security" });
const dynamicRuntime = { ...searchRuntime, selectedCorp: corp, corpContext: { ...searchRuntime.corpContext, resolve: () => corp } } as CliRuntime;
globalThis.fetch = (async (input: string | URL | Request) => {
const url = input instanceof Request ? input.url : String(input);
const body = url.includes("getAccessToken")
? { value: { accessToken: "openapi-staff-switch", corporationId: "alphaPhysicalId", expireTime: Date.now() + 7200000 } }
: url.includes("getProvisionalAuth")
? { value: { message: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=token-new-staff&ekbCorpId=alphaPhysicalId" } }
: { items: [] };
return new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } });
}) as typeof fetch;
try {
const res = await handleCorpsCommand(
@@ -361,7 +368,7 @@ describe("cli/commands/corps > handleCorpsCommand search & aliases", () => {
options: { staff: "alphaPhysicalId:NEW_ADMIN_STAFF" },
raw: ["corps", "link", "corpAlpha", "--staff=alphaPhysicalId:NEW_ADMIN_STAFF"],
},
searchRuntime
dynamicRuntime
);
expect(res.exitCode).toBe(0);
@@ -370,7 +377,7 @@ describe("cli/commands/corps > handleCorpsCommand search & aliases", () => {
expect(res.stdout).toContain("动态换签");
// --json 模式验证
const jsonRuntime = { ...searchRuntime, jsonMode: true };
const jsonRuntime = { ...dynamicRuntime, jsonMode: true };
const jsonRes = await handleCorpsCommand(
{
area: "corps",
@@ -385,6 +392,8 @@ describe("cli/commands/corps > handleCorpsCommand search & aliases", () => {
const parsed = JSON.parse(jsonRes.stdout);
expect(parsed.dynamicStaff).toBe(true);
expect(parsed.staffId).toBe("alphaPhysicalId:NEW_ADMIN_STAFF");
expect(corp.credentials.accessToken).toBe("token-alpha");
expect(corp.credentials.staffId).toBe("STAFF_001");
} finally {
globalThis.fetch = originalFetch;
}