






















@@ -87,7 +87,7 @@ describe("discord exec approval monitor helpers", () => {
8787const interaction = createInteraction();
8888const button = new ExecApprovalButton({
8989getApprovers: () => ["123"],
90-resolveApproval: async () => true,
90+resolveApproval: async () => ({ ok: true }),
9191});
92929393await button.run(interaction, { id: "", action: "" });
@@ -102,7 +102,7 @@ describe("discord exec approval monitor helpers", () => {
102102const interaction = createInteraction({ userId: "999" });
103103const button = new ExecApprovalButton({
104104getApprovers: () => ["123"],
105-resolveApproval: async () => true,
105+resolveApproval: async () => ({ ok: true }),
106106});
107107108108await button.run(interaction, { id: "abc", action: "allow-once" });
@@ -115,7 +115,7 @@ describe("discord exec approval monitor helpers", () => {
115115116116it("acknowledges and resolves valid approval clicks", async () => {
117117const interaction = createInteraction();
118-const resolveApproval = vi.fn(async () => true);
118+const resolveApproval = vi.fn(async () => ({ ok: true }) as const);
119119const button = new ExecApprovalButton({
120120getApprovers: () => ["123"],
121121 resolveApproval,
@@ -132,7 +132,7 @@ describe("discord exec approval monitor helpers", () => {
132132const interaction = createInteraction();
133133const button = new ExecApprovalButton({
134134getApprovers: () => ["123"],
135-resolveApproval: async () => false,
135+resolveApproval: async () => ({ ok: false, reason: "error" }),
136136});
137137138138await button.run(interaction, { id: "abc", action: "deny" });
@@ -144,6 +144,19 @@ describe("discord exec approval monitor helpers", () => {
144144});
145145});
146146147+it("keeps already-resolved approval clicks quiet", async () => {
148+const interaction = createInteraction();
149+const button = new ExecApprovalButton({
150+getApprovers: () => ["123"],
151+resolveApproval: async () => ({ ok: false, reason: "not-found" }),
152+});
153+154+await button.run(interaction, { id: "abc", action: "allow-once" });
155+156+expect(interaction.acknowledge).toHaveBeenCalled();
157+expect(interaction.followUp).not.toHaveBeenCalled();
158+});
159+147160it("builds button context from config and routes resolution over gateway", async () => {
148161const cfg = buildConfig({ enabled: true, approvers: ["123"] });
149162resolveApprovalOverGatewayMock.mockResolvedValue(undefined);
@@ -155,7 +168,7 @@ describe("discord exec approval monitor helpers", () => {
155168});
156169157170expect(ctx.getApprovers()).toEqual(["123"]);
158-await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toBe(true);
171+await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toEqual({ ok: true });
159172expect(resolveApprovalOverGatewayMock).toHaveBeenCalledWith({
160173 cfg,
161174approvalId: "abc",
@@ -173,6 +186,41 @@ describe("discord exec approval monitor helpers", () => {
173186config: { enabled: true, approvers: ["123"] },
174187});
175188176-await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toBe(false);
189+await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toEqual({
190+ok: false,
191+reason: "error",
192+});
193+});
194+195+it("classifies structured approval-not-found gateway errors as stale clicks", async () => {
196+const err = Object.assign(new Error("unknown or expired approval id"), {
197+gatewayCode: "INVALID_REQUEST",
198+details: { reason: "APPROVAL_NOT_FOUND" },
199+});
200+resolveApprovalOverGatewayMock.mockRejectedValue(err);
201+const ctx = createDiscordExecApprovalButtonContext({
202+cfg: buildConfig({ enabled: true, approvers: ["123"] }),
203+accountId: "default",
204+config: { enabled: true, approvers: ["123"] },
205+});
206+207+await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toEqual({
208+ok: false,
209+reason: "not-found",
210+});
211+});
212+213+it("keeps message-only approval-not-found errors visible", async () => {
214+resolveApprovalOverGatewayMock.mockRejectedValue(new Error("unknown or expired approval id"));
215+const ctx = createDiscordExecApprovalButtonContext({
216+cfg: buildConfig({ enabled: true, approvers: ["123"] }),
217+accountId: "default",
218+config: { enabled: true, approvers: ["123"] },
219+});
220+221+await expect(ctx.resolveApproval("abc", "allow-once")).resolves.toEqual({
222+ok: false,
223+reason: "error",
224+});
177225});
178226});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。