fix(approval): treat zero expiry consistently across session handles
This commit is contained in:
1 parent
b69b78fc30
commit
85384bc136
3 files changed
+10
-4
No files matched your search
@@ -366,7 +366,7 @@ export class ApprovalRepository {
|
||||
const trimmed = handle.trim();
|
||||
const now = Date.now();
|
||||
const requireActive = (run: ApprovalRunRecord | null) => {
|
||||
if (run?.expiresAt && run.expiresAt <= now && !options.allowExpired) {
|
||||
if (run && run.expiresAt != null && run.expiresAt <= now && !options.allowExpired) {
|
||||
throw new BusinessError(`审批会话 [${trimmed}] 已过期(有效时长 6 小时),请运行 hose-aipro init 重新发起审批会话`);
|
||||
}
|
||||
return run;
|
||||
@@ -597,7 +597,7 @@ export class ApprovalRepository {
|
||||
return {
|
||||
id: row.id,
|
||||
shortId: row.short_id ?? null,
|
||||
expiresAt: row.expires_at ? Number(row.expires_at) : null,
|
||||
expiresAt: row.expires_at != null ? Number(row.expires_at) : null,
|
||||
flowId: row.flow_id,
|
||||
documentSn: row.document_sn,
|
||||
corpId: row.corp_id,
|
||||
|
||||
@@ -16,3 +16,9 @@ test("all operation handles reject expired sessions while history remains readab
|
||||
expect(reset.expiresAt!).toBeGreaterThan(Date.now());
|
||||
expect(repo.getRunByHandle(run.shortId!)?.id).toBe(run.id);
|
||||
});
|
||||
|
||||
test("epoch-zero expiry is expired rather than an unlimited session", () => {
|
||||
const repo = new ApprovalRepository(getDatabase(":memory:"));
|
||||
const run = repo.createApprovalRun({ documentSn: "ZERO-SN", expiresAt: 0 });
|
||||
for (const handle of [run.shortId!, run.id, run.documentSn]) expect(() => repo.getRunByHandle(handle)).toThrow("已过期");
|
||||
});
|
||||
Reference in new issue
Block a user