- 彻底移除旧内部狭隘命名与垫片包袱,一步到位全仓整体重命名: * session-client.ts ➔ hose-web-session-client.ts (合思 Web 主站会话客户端) * script-engine-client.ts ➔ piper-workflow-client.ts (Piper 工作流引擎客户端) * unity-client.ts ➔ unity-easo-client.ts (Unity / EASO 运营中台与动态集群客户端) * sso-client.ts ➔ sso-auth-client.ts (SSO 与扫码鉴权客户端) - 新增 hose-docs-client.ts 纳为第 7 大通信底座客户端,收口 docs.ekuaibao.com 文档站点通信 - 端正 Piper 工作流引擎定位,完整覆盖工作流创建、保存、发布、108 类节点编排与 Job 流转 - 彻底整体替换全仓 import 引用与测试套件,新增 clients-semantics.test.ts 自动化校验 - 全量自动化测试 150 files 1155 tests 全部通过,类型检查零错误
33 lines
2.7 KiB
TypeScript
33 lines
2.7 KiB
TypeScript
import { afterEach, expect, test } from "bun:test";
|
|
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { getEasoClient, getUnityClient, clearUnityClientCache } from "./unity-easo-client.js";
|
|
import { getScriptEngineClient, clearScriptEngineClientCache } from "./piper-workflow-client.js";
|
|
import { resetTokenStoreMemory, setCorpTokens } from "../auth/token-store.js";
|
|
const oldFetch = globalThis.fetch, oldFile = process.env.HOSE_TOKENS_FILE;
|
|
afterEach(() => { clearScriptEngineClientCache(); clearUnityClientCache(); resetTokenStoreMemory(); globalThis.fetch = oldFetch; if (oldFile === undefined) delete process.env.HOSE_TOKENS_FILE; else process.env.HOSE_TOKENS_FILE = oldFile; });
|
|
for (const kind of ["piper", "easo", "unity"] as const) {
|
|
for (const denied of [false, true]) {
|
|
test(`${kind} replaces cached credentials and replays a POST at most once (denied=${denied})`, async () => {
|
|
process.env.HOSE_TOKENS_FILE = join(mkdtempSync(join(tmpdir(), "hose-renew-")), "tokens.json"); resetTokenStoreMemory();
|
|
const corp = { id: `renew-${kind}-${denied}`, source: "manual", credentials: { accessToken: "source", corpId: "corp", staffId: "staff" } } as any;
|
|
const shared = { sourceAccessToken: "source", expiresAt: Date.now() + 3600000 };
|
|
setCorpTokens(corp.id, { piper: { ...shared, easJwt: "stale", hoseToken: "old-hose" }, unity: { ...shared, unityJwt: "stale" }, eas: { ...shared, easToken: "stale", unityJwt: "stale", hoseToken: "old-hose" } });
|
|
const sent: Array<{ auth: string | null; body: string }> = [];
|
|
globalThis.fetch = (async (input: any, init: any) => {
|
|
const req = input instanceof Request ? input : new Request(input, init);
|
|
if (req.url.includes("/grant/")) return Response.json({ data: "new-hose" });
|
|
if (req.url.includes("/actions/jwt")) return Response.json({ id: "fresh" });
|
|
if (req.url.includes("/realms/")) return Response.json({ value: { accessToken: "fresh" } });
|
|
sent.push({ auth: req.headers.get("authorization"), body: await req.text() });
|
|
return denied || req.headers.get("authorization") === "Bearer stale" ? new Response("expired", { status: 401 }) : Response.json({ ok: true });
|
|
}) as any;
|
|
const client = kind === "piper" ? await getScriptEngineClient(corp, "app") : kind === "easo" ? (await getEasoClient(corp)).client : (await getUnityClient(corp)).client;
|
|
const request = client.post("api/review", { json: { amount: 42 } }).json();
|
|
if (denied) await expect(request).rejects.toThrow(); else expect(await request).toEqual({ ok: true });
|
|
expect(sent).toEqual([{ auth: "Bearer stale", body: '{"amount":42}' }, { auth: "Bearer fresh", body: '{"amount":42}' }]);
|
|
});
|
|
}
|
|
}
|