Skip to content

Commit e146a97

Browse files
only21milclaude
andcommitted
test(server): assert which Antigravity tables are paged
The INTEGER PRIMARY KEY case now checks that both tables are read in rowid pages, and the WITHOUT ROWID case that each keeps main's single query. The large-rowid fixture starts at 2^53 + 2, so the first page's cursor is a rowid that a Number would round. The reader comment notes that the equal-key sort order is observed, not documented by SQLite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8d2d9a9 commit e146a97

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎apps/server/src/provider/Drivers/antigravityUsageReader.test.ts‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ describe("readAntigravityUsage", () => {
488488
[{ sql: mainQueries[table], blobRows }],
489489
);
490490

491+
/** Asserts that `table` was read only with the reader's rowid-paged query. */
492+
const assertPagedRead = (
493+
reads: ReadonlyArray<{ sql: string; blobRows: number }>,
494+
table: keyof typeof mainQueries,
495+
) => {
496+
const queries = reads
497+
.filter((read) => read.sql.includes(`FROM ${table}`))
498+
.map((read) => read.sql);
499+
assert.isTrue(
500+
queries.length > 0 && queries.every((sql) => sql.includes("rowid > ?")),
501+
`expected ${table} to be read in rowid pages, got: ${queries.join(" | ")}`,
502+
);
503+
};
504+
491505
it.effect("reads large Antigravity databases a bounded page of blobs at a time", () =>
492506
Effect.gen(function* () {
493507
const path = yield* Path.Path;
@@ -529,12 +543,13 @@ describe("readAntigravityUsage", () => {
529543
const path = yield* Path.Path;
530544
const dir = yield* tempDir;
531545
const rows = 300;
532-
// The smallest rowid and 0 come first, then rowids above 2^53 count up
533-
// while idx counts down; only the last trajectory row has a timestamp.
546+
// The smallest rowid and 0 come first, then rowids from 2^53 + 2 count up
547+
// while idx counts down, so the first page ends on 2^53 + 255, which a
548+
// Number would round; only the last trajectory row has a timestamp.
534549
const rowids = [
535550
-(2n ** 63n),
536551
0n,
537-
...Array.from({ length: rows - 2 }, (_, index) => 2n ** 53n + 1n + BigInt(index)),
552+
...Array.from({ length: rows - 2 }, (_, index) => 2n ** 53n + 2n + BigInt(index)),
538553
];
539554
yield* seedDatabase(path.join(dir, "large-rowid.db"), (db) =>
540555
Effect.gen(function* () {
@@ -748,9 +763,9 @@ describe("readAntigravityUsage", () => {
748763
];
749764

750765
it.effect.each([
751-
{ name: "whose idx is an INTEGER PRIMARY KEY", suffix: "" },
752-
{ name: "declared WITHOUT ROWID", suffix: " WITHOUT ROWID" },
753-
])("reads Antigravity tables $name", ({ suffix }) =>
766+
{ name: "whose idx is an INTEGER PRIMARY KEY", suffix: "", paged: true },
767+
{ name: "declared WITHOUT ROWID", suffix: " WITHOUT ROWID", paged: false },
768+
])("reads Antigravity tables $name", ({ suffix, paged }) =>
754769
Effect.gen(function* () {
755770
const path = yield* Path.Path;
756771
const dir = yield* tempDir;
@@ -762,9 +777,17 @@ describe("readAntigravityUsage", () => {
762777
yield* positionalUsage(db, shuffledGenerations.slice(0, 3));
763778
}),
764779
);
780+
const reads = yield* recordReads;
765781
const result = yield* readAntigravityUsage(dir, 0);
766782
assert.deepStrictEqual(result.errors, []);
767783
assert.deepStrictEqual(summary(result), keyedSummary("keyed"));
784+
if (paged) {
785+
assertPagedRead(reads, "gen_metadata");
786+
assertPagedRead(reads, "steps");
787+
} else {
788+
assertMainRead(reads, "gen_metadata", 3);
789+
assertMainRead(reads, "steps", 2);
790+
}
768791
}).pipe(Effect.provide(NodeServices.layer)),
769792
);
770793

‎apps/server/src/provider/Drivers/antigravityUsageReader.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ const readDatabase = Effect.fn("readDatabase")(function* (
200200
// in an ordinary rowid table with no index and no column named rowid, ORDER BY
201201
// idx sorts a rowid-order scan, which paging plus a stable sort by idx
202202
// reproduces. Equal idx rows keep rowid order because SQLite's default
203-
// single-threaded sorter keeps scan order for equal keys; this client never
204-
// enables sorter threads. Any other table is read with its single query.
203+
// single-threaded sorter keeps scan order for equal keys, an observed behaviour
204+
// SQLite does not document; this client never enables sorter threads. Any
205+
// other table is read with its single query.
205206
const readRows = Effect.fnUntraced(function* (
206207
table: string,
207208
query: string,

0 commit comments

Comments
 (0)