fix: confine Agent and MCP data access

This commit is contained in:
2026-07-10 16:38:08 +08:00
parent 73fa28a178
commit f4968d6657
25 changed files with 1521 additions and 221 deletions
+20 -1
View File
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from "vite
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { sendFile, withRetry, type FeishuRuntime } from "../../src/feishu/client.js";
import { sendFile, sendFileData, withRetry, type FeishuRuntime } from "../../src/feishu/client.js";
describe("withRetry", () => {
beforeEach(() => {
@@ -127,6 +127,25 @@ describe("sendFile retry", () => {
await rm(dir, { recursive: true, force: true });
}
});
it("sendFileData preserves an exhausted upload failure as its cause", async () => {
vi.useFakeTimers();
const cause = new Error("persistent upload failure");
const fileCreate = vi.fn(async () => { throw cause; });
const rt = mockRuntime({ fileCreate, messageCreate: vi.fn() });
const result = sendFileData(rt, "chat-1", Buffer.from("pdf bytes"), "student.pdf");
const assertion = expect(result).rejects.toMatchObject({
name: "FeishuFileDeliveryError",
cause,
});
await Promise.resolve();
await vi.advanceTimersByTimeAsync(1000);
await vi.advanceTimersByTimeAsync(2000);
await assertion;
expect(fileCreate).toHaveBeenCalledTimes(3);
});
});
async function waitForCalls(mock: Mock, expectedCalls: number): Promise<void> {