Merge remote-tracking branch 'origin/main' into xuanwo/add-node-version-parity

# Conflicts:
#	nodejs/src/table.rs
This commit is contained in:
Xuanwo
2026-11-20 22:40:02 +00:00
51 changed files with 4218 additions and 173 deletions
+83
View File
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import {
type CleanupOptions,
decodeCleanupPlan,
decodeCleanupResult,
validateCleanupOptions,
} from "../lancedb/cleanup";
test.each([null, [], 1, true, "options"])(
"cleanup rejects malformed options instead of inheriting retention (%p)",
(options) => {
expect(() =>
validateCleanupOptions(options as unknown as CleanupOptions),
).toThrow("cleanup options must be an object");
},
);
test("cleanup never silently discards an unknown option", () => {
expect(() =>
validateCleanupOptions({ force: true } as unknown as CleanupOptions),
).toThrow("Unknown cleanup option");
});
test.each([undefined, 0, 604800])(
"cleanup retention accepts omission and explicit zero (%s)",
(age) => {
expect(() => validateCleanupOptions({ minAgeSeconds: age })).not.toThrow();
},
);
test.each([
-1,
1.5,
Number.NaN,
Number.POSITIVE_INFINITY,
Number.MAX_SAFE_INTEGER + 1,
])("cleanup retention rejects invalid values (%s)", (age) => {
expect(() => validateCleanupOptions({ minAgeSeconds: age })).toThrow();
});
test.each([0, 2, null])(
"cleanup results distinguish known zero and unknown (%s)",
(count) => {
const result = decodeCleanupResult(
JSON.parse(
JSON.stringify({
["format_version"]: 1,
["min_age_seconds"]: 0,
["statistics_complete"]: count !== null,
["old_versions"]: count,
["bytes_removed"]: count,
future: "ignored",
}),
),
);
expect(result.oldVersions).toBe(count);
},
);
test.each([
null,
{},
{ ["format_version"]: 2 },
{
["format_version"]: 1,
["min_age_seconds"]: 0,
["statistics_complete"]: false,
["old_versions"]: 1,
},
])("cleanup rejects incompatible results (%p)", (value) => {
expect(() => decodeCleanupResult(value)).toThrow();
});
test("cleanup preview validates its versioned contract", () => {
const value = JSON.parse(
'{"format_version":1,"source_version":42,"min_age_seconds":0,"cutoff_millis":-1,"versions_to_remove":2,"bytes_to_remove":100}',
);
expect(decodeCleanupPlan(value).versionsToRemove).toBe(2);
value.format_version = 2;
expect(() => decodeCleanupPlan(value)).toThrow();
});
+56
View File
@@ -3328,3 +3328,59 @@ describe("table overrides", () => {
expect(requests).toEqual([]);
});
});
describe("cleanup typed results", () => {
test.each(["counts", "no_op", "unknown", "missing", "FAILED", "CANCELLED"])(
"reopens and waits for cleanup (%s)",
async (outcome) => {
const known = outcome !== "unknown";
await withMockDatabase(
(request, response) => {
expect(request.url).toBe("/v1/jobs/describe");
response.writeHead(200, { "Content-Type": "application/json" });
response.end(
JSON.stringify({
["job_id"]: "cleanup-job",
["job_type"]: "cleanup",
["job_state"]: ["FAILED", "CANCELLED"].includes(outcome)
? outcome
: "DONE",
result:
outcome === "missing"
? null
: {
["format_version"]: 1,
["min_age_seconds"]: 0,
["statistics_complete"]: known,
["old_versions"]: known
? outcome === "no_op"
? 0
: 2
: null,
["bytes_removed"]: known
? outcome === "no_op"
? 0
: 123
: null,
},
}),
);
},
async (db) => {
const job =
await db.openJob<import("../lancedb").CleanupResult>("cleanup-job");
if (["missing", "FAILED", "CANCELLED"].includes(outcome)) {
await expect(job.wait()).rejects.toThrow();
} else {
const result = await job.wait();
expect(result.statisticsComplete).toBe(known);
expect(result.oldVersions).toBe(
known ? (outcome === "no_op" ? 0 : 2) : null,
);
expect(result.minAgeSeconds).toBe(0);
}
},
);
},
);
});