Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions templates/content/actions/_database-source-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
builderAuthoritativeRawBodyHash,
bulkChunkSizeForColumnCount,
builderCmsEntryAlreadyRepresented,
builderCmsSourceContinuationIsCurrent,
builderExecutionIsProvablyLocallyBlockedUnsent,
canRefreshLocallyBlockedBuilderReview,
buildMockBodyChange,
Expand Down Expand Up @@ -100,6 +101,41 @@ function item(id: string, title: string): ContentDatabaseItem {
}

describe("database source helpers", () => {
it("accepts only the persisted Builder continuation offset", () => {
const metadataJson = JSON.stringify({
sourceFetchState: "fetching",
lastReadHasMore: true,
lastReadNextOffset: 400,
activeReadSourceRowIds: ["entry-1"],
});

expect(builderCmsSourceContinuationIsCurrent(metadataJson, 400)).toBe(true);
expect(builderCmsSourceContinuationIsCurrent(metadataJson, 100)).toBe(
false,
);
expect(builderCmsSourceContinuationIsCurrent(metadataJson, 0)).toBe(false);
expect(
builderCmsSourceContinuationIsCurrent(
JSON.stringify({
sourceFetchState: "fetching",
lastReadHasMore: true,
lastReadNextOffset: 400,
}),
400,
),
).toBe(false);
expect(
builderCmsSourceContinuationIsCurrent(
JSON.stringify({
sourceFetchState: "idle",
lastReadHasMore: false,
lastReadNextOffset: 580,
}),
400,
),
).toBe(false);
});

it("selects document bodies only for explicitly heavy Builder snapshots", () => {
expect(sourceSnapshotDocumentSelection(false)).not.toHaveProperty(
"content",
Expand Down Expand Up @@ -291,6 +327,44 @@ describe("database source helpers", () => {
});
});

it("clears the Builder refresh claim when read metadata is finalized", () => {
const metadata = JSON.parse(
serializeBuilderCmsSourceReadMetadataRecord({
sourceTable: "agent-native-blog-article-test",
readState: "live",
entryCount: 580,
matchedRowCount: 580,
existingMetadataJson: JSON.stringify({
builderContinuationClaimId: "claim-1",
builderContinuationClaimOffset: 400,
}),
completedBuilderContinuationClaimId: "claim-1",
}),
);

expect(metadata).not.toHaveProperty("builderContinuationClaimId");
expect(metadata).not.toHaveProperty("builderContinuationClaimOffset");
});

it("preserves a Builder refresh claim for unrelated metadata writers", () => {
const metadata = JSON.parse(
serializeBuilderCmsSourceReadMetadataRecord({
sourceTable: "agent-native-blog-article-test",
readState: "live",
entryCount: 400,
matchedRowCount: 400,
existingMetadataJson: JSON.stringify({
builderContinuationClaimId: "claim-1",
builderContinuationClaimOffset: 400,
builderContinuationClaimedAt: "2026-01-01T00:00:00.000Z",
}),
}),
);

expect(metadata.builderContinuationClaimId).toBe("claim-1");
expect(metadata.builderContinuationClaimOffset).toBe(400);
});

it("preserves existing Builder model fields during metadata rewrites", () => {
const existingMetadataJson = JSON.stringify({
builderModelFields: [
Expand Down
Loading
Loading