Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
b49177e
fix(environment): keep read-only POSTs out of the write list
earakely-scale Oct 22, 2026
d5a1fa9
fix(environment): take an entity an unplanned write made when a read …
earakely-scale Oct 22, 2026
004b064
fix(environment): plan a create into the type its returned id is read…
earakely-scale Oct 22, 2026
d8f9c05
fix(environment): end a type's initial reads at the write its reads d…
earakely-scale Oct 22, 2026
64e472a
fix(environment): replay request lines that show entities in another …
earakely-scale Oct 22, 2026
28c3ae9
docs(environment): specify and record the state-target changes
earakely-scale Oct 22, 2026
48d7fae
fix(environment): keep a read-only POST a write when its evidence is …
earakely-scale Oct 22, 2026
5d48df7
fix(environment): answer a field selection only when the state shows …
earakely-scale Oct 22, 2026
ce2301d
fix(environment): hold adopted entities and linked creates to what th…
earakely-scale Oct 22, 2026
48106e1
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 22, 2026
6656816
docs(environment): record the review fixes' measurements
earakely-scale Oct 22, 2026
22e27b1
fix(environment): release a discarded planning pass before planning a…
earakely-scale Oct 22, 2026
5702983
fix(environment): link no create whose id an earlier read showed, and…
earakely-scale Oct 22, 2026
0cf3b27
fix(environment): let the gate skip exactly the reads serving replays
earakely-scale Oct 22, 2026
096b1ca
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 22, 2026
197b1a3
docs(environment): record the second review round's checks
earakely-scale Oct 22, 2026
5e2e84c
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
0ed9e8c
fix(environment): read writes, links and creation cuts only from evid…
earakely-scale Oct 23, 2026
ed78be2
docs(environment): record the third review round's checks
earakely-scale Oct 23, 2026
c983edf
fix(environment): tie linked creates to their returned ids and order …
earakely-scale Oct 23, 2026
fa9f69c
docs(environment): record the fourth review round's checks
earakely-scale Oct 23, 2026
b8c164e
Merge commit '5d6b8a0ab' into st
earakely-scale Oct 23, 2026
f044816
Merge commit 3c5c887a2 into st
earakely-scale Oct 23, 2026
a6adf12
Merge commit '5f702dd6c^' into st
earakely-scale Oct 23, 2026
92f88a9
Merge commit 5f702dd6c into st
earakely-scale Oct 23, 2026
d04ba9d
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
294fa3c
fix(environment): keep foreign keys, stale reads and double decoding …
earakely-scale Oct 23, 2026
ce9a153
docs(environment): record the fifth review round's checks
earakely-scale Oct 23, 2026
169842b
fix(environment): compare linked sources by position, decode path fie…
earakely-scale Oct 23, 2026
e3c5b23
docs(environment): record the sixth review round's checks
earakely-scale Oct 23, 2026
a3dbf79
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
ca3eead
fix(environment): replay late and variant-only items, fill linked pat…
earakely-scale Oct 23, 2026
eb9344b
docs(environment): record the seventh review round's checks
earakely-scale Oct 23, 2026
94b8c55
fix(environment): blame a failed read on the writes whose fields it d…
earakely-scale Oct 23, 2026
fcf8d1a
fix(environment): explain unsent update changes and nested clocks by …
earakely-scale Oct 23, 2026
b1ca254
fix(environment): order collections by whole lines and sort only arra…
earakely-scale Oct 23, 2026
59439f5
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
189152d
feat(environment): serve bulk writes at a collection and target item …
earakely-scale Oct 23, 2026
147ff45
fix(environment): decide late item lines against the lines left, char…
earakely-scale Oct 23, 2026
8876143
docs(environment): record the eighth review round's checks
earakely-scale Oct 23, 2026
6037875
fix(environment): set aside response members a path mints anew on eve…
earakely-scale Oct 23, 2026
342933e
fix(environment): count only reads finished before a linked create be…
earakely-scale Oct 23, 2026
0caf400
Merge #6385 head 342933ea into feat/environment-write-rules
earakely-scale Oct 23, 2026
cfa8310
fix(environment): count a list total nested in a paging object
earakely-scale Oct 23, 2026
65ba035
fix(environment): take a created entity's nested clocks from its read…
earakely-scale Oct 23, 2026
9d0dc27
fix(environment): import the compare tool definition as a type
earakely-scale Oct 23, 2026
c567281
docs(environment): describe the new write rules and trim repeated par…
earakely-scale Oct 23, 2026
7ef08a3
fix(environment): confirm no update whose clocks or fields the eviden…
earakely-scale Oct 23, 2026
434db04
fix(environment): show pinned query and body values in the served cat…
earakely-scale Oct 23, 2026
08c2532
docs(environment): specify and record the write-rule changes
earakely-scale Oct 23, 2026
456cfdf
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
e08f003
fix(environment): keep served creates' items missing, check same-type…
earakely-scale Oct 23, 2026
e4c4940
docs(environment): record the ninth review round's checks
earakely-scale Oct 23, 2026
fd67f4f
Merge commit '0bbd635ab^' into wr2
earakely-scale Oct 23, 2026
d447349
Merge commit 0bbd635ab into wr2
earakely-scale Oct 23, 2026
391fe2c
Merge commit 'e4c494087' into wr2
earakely-scale Oct 23, 2026
1c8588a
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
6ee9703
fix(environment): link creates past empty item reads, sweep repeated …
earakely-scale Oct 23, 2026
88ee22e
docs(environment): record the tenth review round's checks
earakely-scale Oct 23, 2026
72f0442
Merge commit '88ee22e2d' into wr2
earakely-scale Oct 23, 2026
d3828d5
fix(environment): take bulk ids literally, check each recorded call's…
earakely-scale Oct 23, 2026
364891b
docs(environment): record the review fixes' checks
earakely-scale Oct 23, 2026
2c0e7bd
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
12e4df7
Merge remote-tracking branch 'origin/main' into wr2
earakely-scale Oct 24, 2026
5d612dc
Merge commit '2c0e7bdde' into wr2
earakely-scale Oct 24, 2026
c166a69
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 24, 2026
4e622bb
Merge commit 'c166a694e6abd7e9c3c16ae4f938d0ef9f0d8fb6' into wr2
earakely-scale Oct 24, 2026
9614465
perf(environment): compare variant lines through shared entities and …
earakely-scale Oct 24, 2026
53b2966
docs(environment): record the eleventh review round's checks
earakely-scale Oct 24, 2026
715c578
Merge commit '53b2966c5' into wr2
earakely-scale Oct 24, 2026
f151988
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
kaoru0822-kitauji Oct 24, 2026
b82e276
Merge remote-tracking branch 'origin/main' into feat/environment-writ…
kaoru0822-kitauji Oct 24, 2026
3dd85f2
perf(environment): list a type's collections only when the path's own…
earakely-scale Oct 24, 2026
f55c731
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 24, 2026
6273d9b
Merge commit 'f55c73151' into wr2
earakely-scale Oct 24, 2026
dee4dd7
docs(environment): record the twelfth review round's checks and the s…
earakely-scale Oct 24, 2026
751af03
Merge commit 'dee4dd757a5a55f920f32c956f951ab4509c07f0' into wr2
earakely-scale Oct 24, 2026
f01215d
docs(environment): record the 50-capture sweep's wall, CPU and peak m…
earakely-scale Oct 24, 2026
3608c5a
Merge remote-tracking branch 'fork/feat/environment-state-targets' in…
earakely-scale Oct 24, 2026
5a6b4f1
Merge commit '3608c5aa2c2bd5aaa4c9786bdb9855996134e11b' into wr2
earakely-scale Oct 24, 2026
7584387
Merge remote-tracking branch 'fork/feat/environment-write-rules' into…
earakely-scale Oct 24, 2026
192db6c
chore: integrate latest main into environment write rules
gensokyo-dev Oct 24, 2026
3b66ee2
fix(environment): remove duplicate schema after main integration
gensokyo-dev Oct 24, 2026
f501e23
fix(environment): honor recorded bulk identity kinds
gensokyo-dev Oct 24, 2026
2c62bb9
fix(environment): retain scoped evidence and honor write defaults
gensokyo-dev Oct 24, 2026
352c027
test(environment): keep SDK regressions independently scoped
gensokyo-dev Oct 24, 2026
de4035a
docs(environment): record scoped write verification and measured costs
gensokyo-dev Oct 24, 2026
9942863
Merge remote-tracking branch 'origin/main' into integrate/6897-write-…
gensokyo-dev Oct 24, 2026
b3d706f
chore: merge main into environment write rules
morluto Oct 24, 2026
41aff3d
fix(environment): serve bulk writes whose response lists each entity …
earakely-scale Oct 24, 2026
a319ba1
docs(environment): measure the 50 captures at the scoped-envelope head
earakely-scale Oct 24, 2026
3fe3b0a
fix(environment): classify bulk responses and release verifier transf…
morluto Oct 24, 2026
f4bc513
fix(environment): classify and verify complete bulk responses
gensokyo-dev Oct 24, 2026
390541e
fix(javascript): retain capture context along covered mutation paths
morluto Oct 24, 2026
72ce7d6
merge: retain author bulk regressions with shared response verification
gensokyo-dev Oct 24, 2026
5ae634f
test(environment): verify bulk responses through the real MCP SDK
gensokyo-dev Oct 24, 2026
585d71c
test(environment): separate bulk response proof regressions
gensokyo-dev Oct 24, 2026
e73355e
chore: retain concurrent bulk response verification
morluto Oct 24, 2026
3e1b023
fix(environment): preserve request absence and generated value relati…
gensokyo-dev Oct 24, 2026
ac5f217
Merge commit 'e73355e1326aeaf4558d5a913596de627ae35bb2' into integrat…
gensokyo-dev Oct 24, 2026
034eed4
merge: sync main and keep its canonical JavaScript mutation analysis
gensokyo-dev Oct 24, 2026
75817ba
fix(environment): verify complete nested clocks on creates
gensokyo-dev Oct 24, 2026
5b91c99
fix(javascript): erase inline type imports before binding values
morluto Oct 24, 2026
ea64ca4
chore: sync main and retain canonical JavaScript binding fixes
morluto Oct 24, 2026
130121f
fix(environment): share complete generated value verification
gensokyo-dev Oct 24, 2026
7f01865
fix(verifiers): load the Windows source graph only when needed
gensokyo-dev Oct 24, 2026
7360127
fix(environment): validate write responses before stored clock restamps
gensokyo-dev Oct 24, 2026
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
12 changes: 8 additions & 4 deletions docs/specs/agent-environments/write-rules/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ relation rows), and six need only a better recording. This change addresses the
Sort and direction parameters share one vocabulary and are never learned as inert. A create placed by disagreeing
sorts or a random id falls back to `last`.
- **Bulk writes.** A write at a type's collection whose body names entities by id, as an id array or objects carrying
the id field, deletes or updates each one, all or none; serving refuses it unless every id is held. Body ids are
taken as written, and a call naming one entity twice is refused. Each entity's generated values come from that
entity, sharing the call's clock and counters. A delete requires the members its exemplar sent besides the ids, with
their recorded values. Comparison translates a bulk body's ids with the mapping of the collection the write targets.
the id field, deletes or updates each one, all or none; serving refuses it unless every id is held. Body ids are taken
as written, and a call naming one entity twice is refused. Each entity's generated values come from that entity,
sharing the call's clock and counters. A delete requires the members its exemplar sent besides the ids, with their
recorded values. A recorded response is served when it names none of the ids and counts nothing, or is an array with
one element per entity the body names, in the body's order, each that entity with the first element's members or its
id spelled as the first spells its own; serving renders each element from the entity the call wrote, and any other
response naming the ids refuses the tool. Comparison translates a bulk body's ids with the mapping of the collection
the write targets.
- **Item actions.** A write to an item path plus a literal segment that names no collection, whose calls answer
nothing or the entity (never a 201, and with every field its item read always shows), updates that entity; a scalar
it changes without sending is set on every call. It is served only once a call found every field it sets already at
Expand Down
30 changes: 30 additions & 0 deletions docs/specs/agent-environments/write-rules/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ serving, reading records with REA's own capture parser, and compares the reads;
| unshown writes refused | 69 | 46 | 1,153 | 2,087 of 2,162 | 2,766 of 3,031 |
| catalog values, atomic bulk | 69 | 46 | 1,153 | 2,087 of 2,162 | 2,766 of 3,031 |
| review fixes | 69 | 46 | 1,153 | 2,087 of 2,162 | 2,766 of 3,031 |
| scoped envelopes, bulk rows | 69 | 48 | 1,151 | 2,085 of 2,155 | 2,763 of 3,022 |

All 187 write tools are counted at every step, and the served smoke applies every served write tool.

- **Scoped envelopes, bulk rows:** a shared envelope masks only members minted on every path, so Vault's identity entity
and group item views, which matched one of four and one of three recorded reads from the state, replay their
recordings, and Vault's entity update and delete lose their state target. Serving bulk responses that list each
written entity changes no capture's verdict.
- **Review fixes:** literal bulk ids, per-entity bulk values, pinned bulk delete members, comparison ids per
collection, echoed creation clocks, required held clocks, nested clocks checked against every call, learned sorts
kept open to contrary reads and limited to the read's own entities, one query check per recorded call, guards
Expand Down Expand Up @@ -137,3 +142,28 @@ and observed no OOM or limit events. Payload-exit counters were verified;
final whole-scope counters were unavailable. Downloads, builds and runtime
identity preparation are excluded from task measurements. The current
four-capture verification does not requalify the earlier 50-capture totals.

### Bulk-response follow-up qualification

The follow-up at `f4bc513dd` classifies every returned bulk element and checks
all recorded calls with the shared serving renderer. Nested parsed-body leases
retain their enclosing scratch charge. Literal JSON IDs never pass through a
synthetic URL. The author's subsequent bulk regressions and measurement note
were retained when integrating `a319ba1af`; their historical census does not
measure this follow-up.

A fresh four-capture producer sweep and real CLI/MCP replay retained every
previously matching read (109/114 initial, 302/358 session). NocoDB, Ghost and
Metabase plans and complete SDK calls equal `9942863b2`. Mailpit's text/plain
`ok` deletion acknowledgement is not parsed by the state JSON owner, so its
contents remain unknown and its write tool is now withheld as `body-unusable`.
The prior session already refused this deletion for a missing target; no
previously applied mutation was lost. Plain-text acknowledgement support remains
unverified rather than treating unknown contents as empty. The three other
captures retain the same eight applied mutations.

This qualification-only sweep took 5.857 s wall / 5.413 s CPU / 329.9 MiB peak;
the complete SDK replay took 23.264 s / 22.298 s / 474.0 MiB. These single
observations are not pooled with the earlier performance cohort. Payload cleanup
and payload-exit resource counters were verified, with no OOM/limit events;
final whole-scope counters and actual model token usage remain unmeasured.
248 changes: 214 additions & 34 deletions src/application/environment/environmentStateBulkAnswer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type { TimedCaptureRow } from "../../../tests/fixtures/analysisView.js";
import {
BOOK_INIT_ROWS,
BOOK_NOT_FOUND,
BOTH_BOOKS_RENAMED_ROWS,
FIRST_BOOK,
SECOND_BOOK,
bothBooksDeleted,
renamedBook,
type Book,
} from "../../../tests/fixtures/environmentStateWrites.js";
Expand All @@ -29,64 +31,185 @@ const BULK_RENAME_ROWS: readonly TimedCaptureRow[] = [
["GET", "/api/books", [RENAMED_AT_3, SECOND_BOOK]],
];

/** A book with an `archived` flag, which an item action sets. */
const shelved = (entity: Book, archived: boolean) => ({ ...entity, archived });
const DELETED_READS: TimedCaptureRow[] = [
["GET", "/api/books/1", BOOK_NOT_FOUND, 404],
["GET", "/api/books/2", BOOK_NOT_FOUND, 404],
["GET", "/api/books", []],
];

describe("served bulk writes", () => {
it("learns a delete whose recording returned multiple entity objects", () => {
describe("bulk response records and rendering", () => {
it.each([1, 2])(
"serves a multi-entity delete recording for %s caller targets",
(count) => {
const books = servedFrom([
...BOOK_INIT_ROWS,
[
"DELETE",
"/api/books",
[{ id: 1 }, { id: 2 }],
200,
[{ id: 1 }, { id: 2 }],
],
...DELETED_READS,
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: true,
response: { shape: "entity", pointer: "/0" },
});
const body = count === 1 ? [{ id: 2 }] : [{ id: 1 }, { id: 2 }];
expect(books.answer("delete_books", { body })).toMatchObject({
body,
state: { view: "delete" },
});
expect(
books.store.ofType("/api/books").map((entity) => entity.id),
).toEqual(count === 1 ? ["1"] : []);
},
);

it("serves multiple returned identities with their recorded scalar kind", () => {
const books = servedFrom([
...BOOK_INIT_ROWS,
["DELETE", "/api/books", [1, 2], 200, { ids: [1, 2] }],
...DELETED_READS,
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: true,
response: { shape: "identity", pointer: "/0" },
});
expect(books.answer("delete_books", { body: { ids: [2] } }).body).toEqual([
2,
]);
});

it("updates each returned entity without copying the first entity's fields to the others", () => {
const renamed = [
renamedBook(FIRST_BOOK, "Recorded", 3),
renamedBook(SECOND_BOOK, "Recorded", 3),
];
const books = servedFrom([
...BOOK_INIT_ROWS,
["PATCH", "/api/books", renamed, 200, { ids: [1, 2], name: "Recorded" }],
["GET", "/api/books/1", renamed[0]!],
["GET", "/api/books/2", renamed[1]!],
["GET", "/api/books", renamed],
]);
expect(books.state.writes.get("patch_books")).toMatchObject({
served: true,
});
expect(
books.answer("patch_books", { body: { ids: [1, 2], name: "Changed" } })
.body,
).toMatchObject([
{ id: 1, name: "Changed", created_at: FIRST_BOOK.created_at },
{ id: 2, name: "Changed", created_at: SECOND_BOOK.created_at },
]);
expect(books.answer("get_books_by_id", { id: "2" }).body).toMatchObject({
id: 2,
name: "Changed",
});
});
});

describe("bulk response proof and refusals", () => {
it("withholds delete responses whose values differ from the held entities", () => {
const held = [FIRST_BOOK, SECOND_BOOK].map((entry) => ({
...entry,
deleted: false,
}));
const books = servedFrom([
["GET", "/api/books", held],
["GET", "/api/books/1", held[0]!],
["GET", "/api/books/2", held[1]!],
[
"DELETE",
"/api/books",
[{ id: 1 }, { id: 2 }],
held.map((entry) => ({ ...entry, deleted: true })),
200,
[{ id: 1 }, { id: 2 }],
{ ids: [1, 2] },
],
["GET", "/api/books/1", BOOK_NOT_FOUND, 404],
["GET", "/api/books/2", BOOK_NOT_FOUND, 404],
["GET", "/api/books", []],
...DELETED_READS,
]);
expect(books.answer("delete_books", { body: [{ id: 2 }] })).toMatchObject({
status: 200,
body: [{ id: 2 }],
expect(books.state.writes.get("delete_books")).toMatchObject({
served: false,
reason: "body-unusable",
});
expect(books.store.ofType("/api/books").map((book) => book.id)).toEqual([
"1",
]);
});

it("learns an update whose recording returned multiple entity objects", () => {
const renamed = [FIRST_BOOK, SECOND_BOOK].map((book) =>
renamedBook(book, "Renamed Book", 3),
);
it("withholds an unparsed acknowledgement instead of treating unknown contents as absent", () => {
const books = servedFrom([
...BOOK_INIT_ROWS,
[
"PATCH",
"DELETE",
"/api/books",
renamed,
"unparsed acknowledgement",
200,
{ ids: [1, 2], name: "Renamed Book" },
{ ids: [1, 2] },
],
["GET", "/api/books/1", renamed[0]!],
["GET", "/api/books/2", renamed[1]!],
["GET", "/api/books", renamed],
...DELETED_READS,
]);
expect(
books.answer("patch_books", { body: { ids: [2], name: "Changed" } }),
).toMatchObject({
status: 200,
body: [{ id: 2, name: "Changed", slug: "changed" }],
expect(books.state.writes.get("delete_books")).toMatchObject({
served: false,
reason: "body-unusable",
});
expect(books.answer("get_books_by_id", { id: "1" }).body).toEqual(
FIRST_BOOK,
});

it("serves a recorded acknowledgement that names and counts no targets", () => {
const books = servedFrom([
...BOOK_INIT_ROWS,
["DELETE", "/api/books", { ok: true }, 200, { ids: [1, 2] }],
...DELETED_READS,
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: true,
});
expect(books.answer("delete_books", { body: { ids: [2] } }).body).toEqual({
ok: true,
});
expect(books.store.ofType("/api/books").map((entity) => entity.id)).toEqual(
["1"],
);
expect(books.answer("get_books_by_id", { id: "2" }).body).toMatchObject({
name: "Changed",
});

it.each([
{ response: [{ id: 2 }, { id: 1 }] },
{ response: [{ id: 1 }, { id: 2, name: "Second" }] },
])(
"withholds a response the shared first-element renderer cannot reproduce: %j",
({ response }) => {
const books = servedFrom([
...BOOK_INIT_ROWS,
["DELETE", "/api/books", response, 200, [{ id: 1 }, { id: 2 }]],
...DELETED_READS,
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: false,
reason: "body-unusable",
});
},
);

it("withholds a tool whose later response changes its modelled shape", () => {
const books = servedFrom([
...BOOK_INIT_ROWS,
["DELETE", "/api/books", [{ id: 2 }], 200, [{ id: 2 }]],
["GET", "/api/books/2", BOOK_NOT_FOUND, 404],
["GET", "/api/books", [FIRST_BOOK]],
["DELETE", "/api/books", { ok: true }, 200, [{ id: 1 }]],
["GET", "/api/books/1", BOOK_NOT_FOUND, 404],
["GET", "/api/books", []],
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: false,
reason: "body-unusable",
});
});
});

/** A book with an `archived` flag, which an item action sets. */
const shelved = (entity: Book, archived: boolean) => ({ ...entity, archived });

describe("served bulk writes", () => {
it("deletes every row a call names, answering one element per row", () => {
const books = servedFrom(BULK_DELETE_ROWS);
expect(
Expand Down Expand Up @@ -165,6 +288,28 @@ describe("served bulk write queries and capacity", () => {
});

describe("served bulk write targets", () => {
it.each(["part/one", "%31", "A\uD800"])(
"resolves a literal JSON body identity without turning it into a URL: %j",
(id) => {
const unusual = { ...SECOND_BOOK, id };
const books = servedFrom([
["GET", "/api/books", [FIRST_BOOK, unusual]],
["GET", "/api/books/1", FIRST_BOOK],
["DELETE", "/api/books", "", 204, { ids: [id] }],
["GET", "/api/books", [FIRST_BOOK]],
]);
expect(books.state.writes.get("delete_books")).toMatchObject({
served: true,
});
expect(
books.answer("delete_books", { body: { ids: [id] } }),
).toMatchObject({ state: { ids: [id] } });
expect(
books.store.ofType("/api/books").map((entity) => entity.id),
).toEqual(["1"]);
},
);

it.each(["number", "string"] as const)(
"refuses ids whose JSON kind differs from the recorded %s array, without changing state",
(kind) => {
Expand Down Expand Up @@ -229,6 +374,41 @@ describe("served bulk write targets", () => {
});
});

describe("served bulk writes whose recordings answered every entity", () => {
it("answers an update with each entity it wrote, in the call's order", () => {
const books = servedFrom(BOTH_BOOKS_RENAMED_ROWS);
const answer = books.answer("patch_books", {
body: { ids: [2, 1], name: "Other Book" },
});
expect(answer).toMatchObject({
body: [
{ id: 2, name: "Other Book", slug: "other-book" },
{ id: 1, name: "Other Book", slug: "other-book" },
],
state: { source: "state", view: "update", ids: ["2", "1"] },
});
expect(answer.body).toEqual(
["2", "1"].map((id) => books.answer("get_books_by_id", { id }).body),
);
});

it("answers a delete with the rows or ids it names, never the recorded ones", () => {
const rows = servedFrom(
bothBooksDeleted([{ id: 1 }, { id: 2 }], [{ id: 1 }, { id: 2 }]),
);
expect(rows.answer("delete_books", { body: [{ id: 2 }] }).body).toEqual([
{ id: 2 },
]);
expect(rows.store.ofType("/api/books").map((entry) => entry.id)).toEqual([
"1",
]);
const ids = servedFrom(bothBooksDeleted([1, 2], { ids: [1, 2] }));
expect(ids.answer("delete_books", { body: { ids: [2] } }).body).toEqual([
2,
]);
});
});

const uuid = (n: number): string =>
`00000000-0000-4000-8000-${String(n).padStart(12, "0")}`;

Expand Down
Loading