Fix #137: decouple hose-link cache and add issue PR rule
- Decouple getHoseProvisionalAuthLink from internal closeapi session cache to prevent silent truncation and cache pollution (#137) - Add --force, --refresh, -f options and positive integer validation to auth hose-link - Clarify distinction between Hose web assistance links and Seal delegation tokens across CLI help, SKILL.md, and docs - Add modular issue resolution and PR workflow rule under .agents/rules/
This commit is contained in:
1 parent
0fad6359b5
commit
1f8bd016aa
12 files changed
+286
-139
No files matched your search
@@ -8,11 +8,14 @@ import {
|
||||
assertHoseAssistTenantMatches,
|
||||
defaultSealUrl,
|
||||
exchangeHoseAssistLink,
|
||||
fetchHoseOpenApiKeysFromLink,
|
||||
fetchHoseStaffDetails,
|
||||
getHoseEnterpriseUrl,
|
||||
getHoseProvisionalAuthLink,
|
||||
normalizeBaseUrl,
|
||||
parseHoseAssistLink
|
||||
} from "./hose.js";
|
||||
import { getHoseAuthCache } from "./token-store.js";
|
||||
|
||||
const ORIGINAL_ENV = process.env.SEAL_HOME_TOKEN_STORE;
|
||||
const ORIGINAL_FETCH = globalThis.fetch;
|
||||
@@ -267,4 +270,98 @@ describe("hose auth helpers", () => {
|
||||
expect(res.keys[0]!.appSecurity).toBe("sec_secret_password_456789");
|
||||
expect(res.keys[0]!.active).toBe(true);
|
||||
});
|
||||
|
||||
test("getHoseProvisionalAuthLink generates independent provisional link and ignores internal cache", async () => {
|
||||
const initialExpiresAt = Date.now() + 7134_000;
|
||||
setupTokenStore({
|
||||
"corp-test": {
|
||||
hose: {
|
||||
openapi: {
|
||||
token: "existing-openapi-token",
|
||||
expiresAt: Date.now() + 3600_000
|
||||
},
|
||||
closeapi: {
|
||||
token: "existing-close-token",
|
||||
url: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=existing-close-token&ekbCorpId=CORP-TEST",
|
||||
expiresAt: initialExpiresAt
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-test",
|
||||
name: "Corp Test",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source: {
|
||||
type: "hose",
|
||||
domain: "https://app.ekuaibao.com",
|
||||
appKey: "key",
|
||||
appSecurity: "sec",
|
||||
staffId: "staff-1",
|
||||
corpId: "CORP-TEST"
|
||||
},
|
||||
auth: { refreshTtl: 300 }
|
||||
};
|
||||
|
||||
let requestedExpireDate: number | undefined;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const urlStr = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
const url = new URL(urlStr);
|
||||
|
||||
if (url.pathname === "/api/openapi/v1.1/provisional/getProvisionalAuth") {
|
||||
let body: Record<string, unknown> = {};
|
||||
if (input instanceof Request) {
|
||||
body = await input.clone().json().catch(() => ({}));
|
||||
} else if (typeof init?.body === "string") {
|
||||
body = JSON.parse(init.body);
|
||||
}
|
||||
requestedExpireDate = typeof body.expireDate === "number" ? body.expireDate : undefined;
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
value: {
|
||||
message: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=fresh-token-86400&ekbCorpId=CORP-TEST&pageType=home"
|
||||
}
|
||||
}),
|
||||
{ status: 200, headers: { "content-type": "application/json" } }
|
||||
);
|
||||
}
|
||||
|
||||
return new Response("not found", { status: 404 });
|
||||
}) as typeof fetch;
|
||||
|
||||
const result = await getHoseProvisionalAuthLink(corp, 86400);
|
||||
|
||||
expect(requestedExpireDate).toBe(86400);
|
||||
expect(result.expiresIn).toBe(86400);
|
||||
expect(result.token).toBe("fresh-token-86400");
|
||||
expect(result.url).toContain("fresh-token-86400");
|
||||
|
||||
// Ensure internal closeapi cache was NOT overwritten
|
||||
const cacheAfter = getHoseAuthCache("corp-test");
|
||||
expect(cacheAfter.closeapi?.token).toBe("existing-close-token");
|
||||
expect(cacheAfter.closeapi?.expiresAt).toBe(initialExpiresAt);
|
||||
});
|
||||
|
||||
test("getHoseProvisionalAuthLink rejects invalid or non-positive expiresIn", async () => {
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-test",
|
||||
name: "Corp Test",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source: {
|
||||
type: "hose",
|
||||
domain: "https://app.ekuaibao.com",
|
||||
appKey: "key",
|
||||
appSecurity: "sec",
|
||||
staffId: "staff-1",
|
||||
corpId: "CORP-TEST"
|
||||
},
|
||||
auth: { refreshTtl: 300 }
|
||||
};
|
||||
|
||||
expect(getHoseProvisionalAuthLink(corp, -100)).rejects.toThrow("Invalid expire seconds");
|
||||
expect(getHoseProvisionalAuthLink(corp, 0)).rejects.toThrow("Invalid expire seconds");
|
||||
});
|
||||
});
|
||||
+4
-11
@@ -403,7 +403,8 @@ export async function getHoseEnterpriseUrl(corp: CorpConfig): Promise<string> {
|
||||
|
||||
export async function getHoseProvisionalAuthLink(
|
||||
corp: CorpConfig,
|
||||
expiresIn = 7200
|
||||
expiresIn = 7200,
|
||||
_options?: { force?: boolean }
|
||||
): Promise<{
|
||||
corpId: string;
|
||||
staffId: string;
|
||||
@@ -415,16 +416,8 @@ export async function getHoseProvisionalAuthLink(
|
||||
throw new Error(`Unsupported Seal source: ${corp.source.type}`);
|
||||
}
|
||||
|
||||
const cache = getHoseAuthCache(corp.id);
|
||||
if (isFresh(cache.closeapi) && cache.closeapi.url && cache.closeapi.token) {
|
||||
const remainingSeconds = Math.max(60, Math.floor((cache.closeapi.expiresAt - Date.now()) / 1000));
|
||||
return {
|
||||
corpId: corp.source.corpId,
|
||||
staffId: corp.source.staffId,
|
||||
url: cache.closeapi.url,
|
||||
token: cache.closeapi.token,
|
||||
expiresIn: Math.min(expiresIn, remainingSeconds)
|
||||
};
|
||||
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
||||
throw new Error(`Invalid expire seconds: ${expiresIn}. Must be a positive integer.`);
|
||||
}
|
||||
|
||||
const openapiToken = await ensureHoseOpenapiToken(corp);
|
||||
|
||||
Reference in new issue
Block a user