Skip to content

Commit 8513204

Browse files
authored
fix(file-transfer): report fetched file count accurately (#126439)
Count successful directory fetches from the extracted regular-file manifest while retaining the node wire count for compatibility.
1 parent 61416e1 commit 8513204

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

‎extensions/file-transfer/src/tools/dir-fetch-tool.test.ts‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function importTool(tarBuffer: Buffer) {
6161
tarBase64: tarBuffer.toString("base64"),
6262
tarBytes: tarBuffer.byteLength,
6363
sha256: crypto.createHash("sha256").update(tarBuffer).digest("hex"),
64-
fileCount: 1,
64+
fileCount: 3,
6565
},
6666
startedAt: Date.now(),
6767
})),
@@ -84,30 +84,42 @@ async function executeDirFetch(module: typeof import("./dir-fetch-tool.js")) {
8484
describe("dir.fetch archive extraction", () => {
8585
it("extracts a bounded tar and returns the plugin-side manifest", async () => {
8686
const tarBuffer = await createTarBuffer({
87-
entries: ["ok.txt"],
87+
entries: ["ok.txt", "nested"],
8888
setup: async (sourceDir) => {
8989
await fs.writeFile(path.join(sourceDir, "ok.txt"), "ok");
90+
await fs.mkdir(path.join(sourceDir, "nested"));
91+
await fs.writeFile(path.join(sourceDir, "nested", "also-ok.txt"), "also ok");
9092
},
9193
});
9294
const { appendFileTransferAudit, module, saveMediaBuffer } = await importTool(tarBuffer);
9395

9496
const result = await executeDirFetch(module);
9597

9698
expect(result).toMatchObject({
99+
content: [{ type: "text", text: expect.stringContaining("Fetched 2 files") }],
97100
details: {
98101
path: "/tmp/project",
99-
fileCount: 1,
100-
files: [
101-
{
102-
relPath: "ok.txt",
103-
size: 2,
104-
sha256: crypto.createHash("sha256").update("ok").digest("hex"),
105-
},
106-
],
102+
fileCount: 2,
107103
},
108104
});
109-
const localPath = (result.details as { files: Array<{ localPath: string }> }).files[0]
110-
?.localPath;
105+
const files = (result.details as { files: Array<{ relPath: string; localPath: string }> })
106+
.files;
107+
expect(files).toHaveLength(2);
108+
expect(files).toEqual(
109+
expect.arrayContaining([
110+
expect.objectContaining({
111+
relPath: "ok.txt",
112+
size: 2,
113+
sha256: crypto.createHash("sha256").update("ok").digest("hex"),
114+
}),
115+
expect.objectContaining({
116+
relPath: path.join("nested", "also-ok.txt"),
117+
size: 7,
118+
sha256: crypto.createHash("sha256").update("also ok").digest("hex"),
119+
}),
120+
]),
121+
);
122+
const localPath = files.find((file) => file.relPath === "ok.txt")?.localPath;
111123
await expect(fs.readFile(localPath!, "utf8")).resolves.toBe("ok");
112124
expect(saveMediaBuffer).toHaveBeenCalledWith(
113125
tarBuffer,

‎extensions/file-transfer/src/tools/dir-fetch-tool.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export function createDirFetchTool(): AnyAgentTool {
153153
const tarBase64 = typeof payload.tarBase64 === "string" ? payload.tarBase64 : "";
154154
const tarBytes = typeof payload.tarBytes === "number" ? payload.tarBytes : -1;
155155
const sha256 = typeof payload.sha256 === "string" ? payload.sha256 : "";
156-
const fileCount = typeof payload.fileCount === "number" ? payload.fileCount : 0;
157156

158157
if (!canonicalPath || !tarBase64 || tarBytes < 0 || !sha256) {
159158
throw new Error("invalid dir.fetch payload (missing fields)");
@@ -236,6 +235,7 @@ export function createDirFetchTool(): AnyAgentTool {
236235
const fileSha256 = await computeFileSha256(absPath);
237236
files.push({ relPath, size, mimeType, sha256: fileSha256, localPath: absPath });
238237
}
238+
const fileCount = files.length;
239239

240240
const imageFiles = files.filter((f) => IMAGE_MIME_INLINE_SET.has(f.mimeType));
241241
const nonImageFiles = files.filter((f) => !IMAGE_MIME_INLINE_SET.has(f.mimeType));

0 commit comments

Comments
 (0)