perf(http,auth): persist EASO, Unity, and Piper tokens across CLI invocations via token-store
This commit is contained in:
1 parent
76f7832522
commit
2d744d283b
5 files changed
+248
-32
No files matched your search
@@ -13,8 +13,12 @@ import {
|
||||
createOpenApiClient,
|
||||
getOpenApiHeaders,
|
||||
} from "./openapi-client.js";
|
||||
import { resolveCorpCluster } from "./unity-client.js";
|
||||
import { resolveCorpCluster, getEasoClient, getUnityClient, clearUnityClientCache } from "./unity-client.js";
|
||||
import { getScriptEngineClient } from "./script-engine-client.js";
|
||||
import { setCorpTokens, resetTokenStoreMemory } from "../auth/token-store.js";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { CorpConfig } from "../config/types.js";
|
||||
|
||||
function mockCorp(overrides: Partial<CorpConfig> = {}): CorpConfig {
|
||||
@@ -109,4 +113,41 @@ describe("core/http/unity-client & script-engine-client", () => {
|
||||
it("getScriptEngineClient is defined and callable", () => {
|
||||
expect(getScriptEngineClient).toBeDefined();
|
||||
});
|
||||
|
||||
it("reuses persisted EASO and Unity tokens from token-store across CLI runs without network calls", async () => {
|
||||
const tempDir = mkdtempSync(join(tmpdir(), "hose-tokens-test-"));
|
||||
const prevTokensFile = process.env.HOSE_TOKENS_FILE;
|
||||
process.env.HOSE_TOKENS_FILE = join(tempDir, "tokens.json");
|
||||
|
||||
try {
|
||||
clearUnityClientCache();
|
||||
resetTokenStoreMemory();
|
||||
|
||||
const corp = mockCorp({ id: "corp-persisted" });
|
||||
setCorpTokens("corp-persisted", {
|
||||
eas: {
|
||||
hoseToken: "persisted-hose-token",
|
||||
unityJwt: "persisted-unity-jwt",
|
||||
easToken: "persisted-easo-token",
|
||||
expiresAt: Date.now() + 3600 * 1000,
|
||||
sourceAccessToken: "mock-access-token",
|
||||
},
|
||||
});
|
||||
|
||||
// Simulate fresh process memory
|
||||
resetTokenStoreMemory();
|
||||
|
||||
const easo = await getEasoClient(corp);
|
||||
expect(easo.client).toBeDefined();
|
||||
|
||||
const unity = await getUnityClient(corp);
|
||||
expect(unity.unityJwt).toBe("persisted-unity-jwt");
|
||||
} finally {
|
||||
if (prevTokensFile === undefined) delete process.env.HOSE_TOKENS_FILE;
|
||||
else process.env.HOSE_TOKENS_FILE = prevTokensFile;
|
||||
resetTokenStoreMemory();
|
||||
clearUnityClientCache();
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user