Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(environment): explain unsent update changes and nested clocks by …
…what the recording shows

An update's unsent change can be a modified-by stamp beside a created-by counterpart, a
value derived from the one sent member stored nowhere (accepted only while the target
holds the recorded before-value), or a sent clock the call left in its own second.
Objects whose clocks all moved with the request are nested clocks, opaque tokens of a
type's own length are generated, and an enveloped body is learned as its one object.
A write takes only its recorded query, an echoed reference to a nested object and a
state word paired with other fields stay at their recorded values, and a slug is tried
before a token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 23, 2026
commit fcf8d1a600127f2f9823f15894381660b413815b
2 changes: 1 addition & 1 deletion docs/agent-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ every MCP session and `data/get` then see:
| Effect | Call |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `create` | Adds an entity to the collection the path names, built from the observed entity with each ruled field taken from the call or generated, at the plan's `insert` position. A plan tied to its exemplar's collection writes only there. |
| `update` | Sets the sent members on the entity the path names, constants for members accepted only with their recorded value, and the clock, increment, slug, unique and renewed changes the plan models. |
| `update` | Sets the sent members on the entity the path names, constants for members accepted only with their recorded value, and the clock, nested clock, increment, slug, stamp, derived, unique and renewed changes the plan models. |
| `delete` | Removes the entity the path names. |
| `document` | Merges the body into the plan's document object, or replaces it for `PUT`. |

Expand Down
71 changes: 61 additions & 10 deletions docs/specs/agent-environments/state-writes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ the exemplar.
- **Request body.** The exemplar's request body must be a JSON object that
could enter the state: a JSON-like media type, complete UTF-8 text within
256 KiB, exact numbers, no `__proto__` member. Otherwise the reason is
`body-unusable`. A `DELETE` takes no body.
`body-unusable`. A `DELETE` takes no body. A create's or update's body
whose only member wraps one object in a one-element array (Ghost's
`{"posts":[{...}]}`) is that object, and the plan records the member as
`body.envelope`: serving takes only a body wrapped that way.
- **Query.** Serving takes only the query parameters the exemplar sent, with
its values, since they may change what the body does (Ghost reads `html`
only with `?source=html`); a call with others is refused. The gate treats a
later recorded call sent with another query, or wrapped otherwise, as a
write its plan does not explain: it brings the entity to what the call
recorded, without attribution.
- **The written entity.** The entity is observed in the exemplar's response,
located by its identity value at the root, in one member, or in a
one-element array, as item views locate it. When the response does not carry
Expand Down Expand Up @@ -140,14 +149,25 @@ identity the client sends is an echo:
classes.
6. **Clock.** A timestamp within 10 minutes of the exemplar's start time. The
format is kept: ISO-8601 with its separator, fraction digits and zone, or
epoch seconds or milliseconds.
epoch seconds or milliseconds. An object whose every clock lies between 1
second before the start time (a whole second's truncation) and 2 seconds
after it, in one format, is a nested clock when the type's other entities
hold that field as objects agreeing with it in every other member and
holding other clocks: served, those members take the write's clock and the
others are kept. A reference to another entity, which differs by entity or
was made before the request, is not one.
7. **Sequence.** An integer one greater than the largest value of the field in
the collection, else in the type. The integer may be written as `-`-separated
digit groups of one width of at least two digits (an asset number `000-005`;
not a date, version or address); a served value keeps the recorded value's
groups and zero padding, and digits that outgrow them lead. A later call must
record the value spelled that way.
8. **Unique.** A UUID-shaped string that no other entity of the type shares.
8. **Unique.** A UUID-shaped string that no other entity of the type shares,
or an opaque token (16 to 64 letters, digits, `_` or `-`, with letters and
digits both) that no other field of the entity repeats, where every other
entity of the type holds a token of the same length and none this one.
Serving generates a token of the same length, character classes and
separator positions.
9. **Template.** A string containing a generated value, or else a copied
value, as a delimited token (for example a URL that ends in the new id or in
a slug the call sent under another name). It is rebuilt around the new
Expand Down Expand Up @@ -179,6 +199,14 @@ of (an end date stored as a time in another zone).
name and stored under none of its own, or the identity field's value. A
member copied whole must have the JSON type of the field it is copied into.
Every member the exemplar sent is required.
- **Accepted only as recorded.** An echoed member naming the object the entity
nests under the field it refers to (`collection_id` and a `collection`
object), whose other members serving would keep as recorded; and a state
word other fields go with: a lowercase word several entities share, where
every entity in another state holds a field the new one leaves null, or the
reverse (Ghost's `status: "draft"` beside `published_at: null`), unless the
tool's recorded calls sent other values of it. Updates take a member naming
a nested object only as recorded too.
- **Not accepted.** A member the application stored with a different value
(transformed), or one it did not show. A call that sends such a member is a
tool error naming the accepted members.
Expand All @@ -200,15 +228,38 @@ as sent in another letter case is the sent value, not a fresh one. A member a la
which the plan's observation does not show, keeps the JSON type that call stored
it as (the body's `kinds`), as an exemplar's member keeps the observation's.
`PUT` requires every member the exemplar sent; `PATCH` and `POST` require at
least one. A field the exemplar's update changed without sending it is
explained as one of:
least one. A sent clock the call left as it was, stored in whole seconds and
naming the second the call ran in, is a `held-clock` the application stamps
anew (Ghost's `updated_at`, which a client sends back as it read it), when it is
the only such member the call sent: a call must send it as the entity holds it,
or it is refused, and it is served as the write's clock. A field the exemplar's
update changed without sending it is explained as one of:

- clock;
- a nested clock: an object the entity held whose only changes are clocks
within 10 minutes of the start time, in one format, where the type's other
entities hold that field as objects agreeing in every other member. The gate
stores the object the first later read of the entity shows when it differs
from the write's only in those members, each within 2 seconds, as Metabase
answers an update with one instant and stores another. Serving refuses it on
an entity holding no such object;
- an increment by one;
- a slug of an echoed member;
- `unique`: a UUID in place of another UUID, that no other entity of the type
holds and the call sent nowhere in its body (a version the application assigns
on every update);
- a slug of an echoed member, judged before a token, since a renamed slug is
spelled like one;
- `unique`: a UUID in place of another UUID, or an opaque token in place of
another of the same length, that no other entity of the type holds and the
call sent nowhere in its body (a version the application assigns on every
update);
- `stamp`: the acting user on a field named `modified…by`, `updated…by`,
`edited…by` or `changed…by` (or `last…`), stored on every call, when the
entity already held the value under its `created…by` counterpart
(`modifiedByName` and `createdByName`), and the call sent no member naming
the same thing (`modifiedById`);
- `derived`: when the call sent exactly one member the entity stores nowhere,
a value showing that member's text, markup aside (at least 8 characters): a
field Ghost derives from the `html` it was sent. The member is accepted only
with its recorded value, and a call sending it is served only on an entity
holding the value the recorded call found (`from`), else refused;
- `renewed`: an array or object whose only changes are UUIDs replaced by ones
that neither it nor another entity of the type held, as child rows an update
rewrites are. The rule names the pointers it renewed at (`*` for any array
Expand All @@ -219,7 +270,7 @@ explained as one of:

A field the entity lacked before is a change too when the view that observed
the update had shown the entity, so a field the application fills in on update
follows its rule. Any other change is `unexplained-change`. An increment or a slug applies to
follows its rule. Any other change is `unexplained-change`. An increment, a slug, a stamp or a derived value applies to
every call that could take it, and `unique` and `renewed` to every call, so the
plan is also `unexplained-change` when such a rule would give a call of the
tool another value than the one it recorded, a recorded call kept a `unique` or
Expand Down
15 changes: 10 additions & 5 deletions docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,19 @@ explains it: generated `identity` (a sequence, UUID or token, by the recorded
value's shape), `echo` of a body member, `copy` of a body string of 8 or more
characters, a `path` value, a `slug` of a body member, a `clock` value within 10
minutes of the request in its recorded format, a `sequence` one past the
largest value of its collection or type, a `unique` UUID, or a `template` around
a generated value; other fields keep the observed value. An update's members
largest value of its collection or type, a `unique` UUID or opaque token, a
`nested-clock` object whose clocks the request stamped, or a `template` around
a generated value; other fields keep the observed value. A body that wraps one
object in a one-element array is that object, wrapped so on every call
(`body.envelope`). An update's members
echo when stored as sent; a member stored differently is accepted only with its
recorded value (`body.fixed`) and stores the value the call that showed it
recorded (the `value` of its `constant` rule), and a field it changed without
sending must be a clock, an increment or a slug, or the plan is
`unexplained-change`; an increment or slug must hold for every call of the
tool. Every member the first call sent is required, except by `PATCH` and
sending must be a clock, a nested clock, an increment, a slug, a fresh `unique`
value, a `stamp` of the acting user or a value `derived` from the one member it
stores nowhere, or the plan is `unexplained-change`; an increment, slug, stamp
or derived value must hold for every call of the tool. A write is served only
with the query its first call sent. Every member the first call sent is required, except by `PATCH` and
`POST` updates.

A read on a line `query` answers is checked against the query evaluated over
Expand Down
171 changes: 171 additions & 0 deletions src/application/environment/environmentStateWriteAnswer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,177 @@ describe("path values of creates read under another path", () => {
});
});

/** A card whose token is a NanoID and whose edit info a create stamps, created at exchange 3 and read back. */
const tokenCard = (id: number, token: string, at: string) => ({
id,
name: `Card ${String(id)}`,
token,
edit: { at, by: "rea" },
});
const CARD_ROWS: readonly TimedCaptureRow[] = [
[
"GET",
"/api/cards",
[
tokenCard(1, "chYl65ZvCJ9U6yNk-YyqK", "2026-10-01T09:00:00.000Z"),
tokenCard(2, "Qx81mP0aZkT3vB7n-Lw2e", "2026-10-01T10:00:00.000Z"),
],
],
[
"GET",
"/api/cards/1",
tokenCard(1, "chYl65ZvCJ9U6yNk-YyqK", "2026-10-01T09:00:00.000Z"),
],
[
"GET",
"/api/cards/2",
tokenCard(2, "Qx81mP0aZkT3vB7n-Lw2e", "2026-10-01T10:00:00.000Z"),
],
[
"POST",
"/api/cards",
tokenCard(3, "cdMLcknG-Lcu6oWL-3ZgA", `${bookClock(3).slice(0, -1)}.030Z`),
201,
{ name: "Card 3" },
],
[
"GET",
"/api/cards/3",
tokenCard(3, "cdMLcknG-Lcu6oWL-3ZgA", `${bookClock(3).slice(0, -1)}.030Z`),
],
];

/** Notes whose update sends html the application stores nowhere and derives the excerpt from, and sends back the clock it read. */
const note = (id: number, title: string, excerpt: string) => ({
id,
title,
excerpt,
updated_at: bookClock(3),
});
const EDITED_NOTE = note(1, "First (edited)", "Edited body text.");
const NOTE_ROWS: readonly TimedCaptureRow[] = [
[
"GET",
"/api/notes",
[note(1, "First", "Old body text."), note(2, "Second", "Custom excerpt.")],
],
["GET", "/api/notes/1", note(1, "First", "Old body text.")],
["GET", "/api/notes/2", note(2, "Second", "Custom excerpt.")],
[
"PATCH",
"/api/notes/1?source=html",
EDITED_NOTE,
200,
{
title: "First (edited)",
html: "<p>Edited body text.</p>",
updated_at: bookClock(3),
},
],
["GET", "/api/notes/1", EDITED_NOTE],
];

describe("served values an application stamps", () => {
it("takes an enveloped body as the capture sent it, and refuses one sent bare", () => {
const books = servedFrom([
...BOOK_INIT_ROWS,
[
"PATCH",
"/api/books/1",
{ books: [renamedBook(FIRST_BOOK, "Renamed Book", 3)] },
200,
{ books: [{ name: "Renamed Book" }] },
],
["GET", "/api/books/1", renamedBook(FIRST_BOOK, "Renamed Book", 3)],
]);
const before = books.snapshot();
expect(
books.refusal("patch_books_by_id", {
id: "2",
body: { name: "Second Edition" },
}).message,
).toContain('wrapped as {"books":[{...}]}');
expect(books.snapshot()).toBe(before);
const answered = books.answer("patch_books_by_id", {
id: "2",
body: { books: [{ name: "Second Edition" }] },
});
expect(answered).toMatchObject({
status: 200,
body: {
books: [{ id: 2, name: "Second Edition", slug: "second-edition" }],
},
});
expect(books.answer("get_books_by_id", { id: "2" }).body).toMatchObject({
name: "Second Edition",
});
});

it("generates a token spelled like the type's and stamps the edit info with the served clock", () => {
const cards = servedFrom(CARD_ROWS);
const created = cards.answer("post_cards", { body: { name: "Card 4" } })
.body as { token: string; edit: { at: string; by: string } };
expect(created.token).toMatch(
/^[A-Za-z0-9]{8}-[A-Za-z0-9]{7}-[A-Za-z0-9]{4}$/u,
);
expect([
"chYl65ZvCJ9U6yNk-YyqK",
"Qx81mP0aZkT3vB7n-Lw2e",
"cdMLcknG-Lcu6oWL-3ZgA",
]).not.toContain(created.token);
expect(created.edit.by).toBe("rea");
expect(created.edit.at).not.toBe(`${bookClock(3).slice(0, -1)}.030Z`);
expect(created.edit.at).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,
);
});

it("derives a value only on an entity holding what it was derived from, with the recorded query and the held clock", () => {
const notes = servedFrom(NOTE_ROWS);
const edit = (
id: string,
updated: string,
query: { source?: string } = { source: "html" },
) => ({
id,
...query,
body: {
title: "Renamed",
html: "<p>Edited body text.</p>",
updated_at: updated,
},
});
const before = notes.snapshot();
expect(
notes.refusal("patch_notes_by_id", edit("2", bookClock(3))).message,
).toContain("derives excerpt");
expect(
notes.refusal("patch_notes_by_id", edit("1", bookClock(3), {})).message,
).toContain("takes only the query its recording sent (source=html)");
expect(
notes.refusal("patch_notes_by_id", edit("1", "2026-01-01T00:00:00Z"))
.message,
).toContain("must repeat the value the entity holds");
expect(notes.snapshot()).toBe(before);
const answered = notes.answer("patch_notes_by_id", edit("1", bookClock(3)));
expect(answered).toMatchObject({
status: 200,
body: { id: 1, title: "Renamed", excerpt: "Edited body text." },
});
expect((answered.body as { updated_at: string }).updated_at).not.toBe(
bookClock(3),
);
// Without the member the value derives from, the update keeps the excerpt the note holds.
expect(
notes.answer("patch_notes_by_id", {
id: "2",
source: "html",
body: { title: "Second (renamed)", updated_at: bookClock(3) },
}).body,
).toMatchObject({ title: "Second (renamed)", excerpt: "Custom excerpt." });
});
});

describe("path fields of creates read under another path", () => {
it("fills a linked create's path field from its exemplar decoded once, whichever accepted spelling the call uses", () => {
const note = (id: number, title: string) => ({
Expand Down
Loading