Skip to content

Commit 58d3edd

Browse files
committed
tests: Write unit tests for FileSyncer; fix total page calculation bug
1 parent ec0aa37 commit 58d3edd

3 files changed

Lines changed: 392 additions & 7 deletions

File tree

src/sync/FileSyncer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { FileType } from "api";
22
import fs from "fs";
33
import path from "path";
44

5+
import * as pathUtils from "../pathUtils";
56
import LRUCache from "../cache/LRUCache";
67
import { HumanloopRuntimeError } from "../error";
78
import { HumanloopClient } from "../humanloop.client";
8-
import * as pathUtils from "../pathUtils";
99

1010
// Default cache size for file content caching
1111
const DEFAULT_CACHE_SIZE = 100;
@@ -257,8 +257,8 @@ export default class FileSyncer {
257257
let page = 1;
258258
let totalPages = 0;
259259

260-
log(
261-
`Fetching files from ${dirPath || "root"} (environment: ${environment || "default"})`,
260+
log(
261+
`Fetching files from ${dirPath || "root"} (environment: ${environment || "default"})`,
262262
"INFO",
263263
this.verbose,
264264
);
@@ -276,7 +276,8 @@ export default class FileSyncer {
276276

277277
// Calculate total pages on first response
278278
if (page === 1) {
279-
totalPages = Math.ceil(response.total / FileSyncer.PAGE_SIZE);
279+
const actualPageSize = response.size || FileSyncer.PAGE_SIZE;
280+
totalPages = Math.ceil(response.total / actualPageSize);
280281
}
281282

282283
if (response.records.length === 0) {
@@ -315,9 +316,8 @@ export default class FileSyncer {
315316
}
316317
}
317318

318-
// Update pagination based on items received
319-
if (response.records.length < FileSyncer.PAGE_SIZE) {
320-
// Last page (either partial or empty)
319+
// Check if we've reached the last page
320+
if (page >= totalPages) {
321321
break;
322322
}
323323
page += 1;

0 commit comments

Comments
 (0)