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): link no create whose id an earlier read showed, and…
… read only whole batches

A linked create is rejected when an earlier list of its type or read of its collection
showed the returned id. Body ids are walked without spreading children into an argument
list. An RPC call reads only when every operations entry names an operation of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 22, 2026
commit 57029831168d4a27f9c5e2c6cad12e57382bb5f5
6 changes: 3 additions & 3 deletions docs/specs/agent-environments/state-targets/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ its cause in the recordings and the code. The five largest shared causes:
models, puts the entity into the copy within the view's budget; an entity a modelled write touched is never taken
back.
- **Linked creates.** A POST whose path names no state type becomes a create into the type whose item read first names
an id its response returned, when the id is new; serving creates in that read's collection, for the exemplar's path
arguments only. A successful POST that returned an id a type's reads only show after it ends that type's initial
window.
an id its response returned, when the id is new: no earlier read of the id, its type's lists or that collection showed
it. Serving creates in that read's collection, for the exemplar's path arguments only. A successful POST that returned
an id a type's reads only show after it ends that type's initial window.
- **Rewrite cuts.** When a type's reads disagree across a write under another root, the type's initial window ends at
the earliest write within the change and the state is extracted again. The earlier of this and the creation cut wins.
- **Variant lines.** A read line that shows the same entities in another form is a variant: it leaves the view's
Expand Down
18 changes: 11 additions & 7 deletions docs/specs/agent-environments/state-writes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ search. The capture shows it by the first of these that applies:
2. every call names read operations only, in its body's `operation` or
`operations[].operation`, else its query's `operation`, `op` or `action`
(`batch` and similar only wrap them, in either place, so a call needs at
least one other); an operation reads when its words name one of `list`,
least one other, and every `operations` entry must name one of its own, so
an entry with no string operation or another container keeps the call a
write); an operation reads when its words name one of `list`,
`get`, `count`, `aggregate`, `info`, `search`, `find`, `read`, `query`,
`schema`, `describe`, `fetch` or `lookup`, and none of `create`, `insert`,
`update`, `delete`, `remove`, `upsert`, `add`, `set`, `save` and similar;
Expand Down Expand Up @@ -82,12 +84,14 @@ id is read under: its exemplar's response names an id (an identity member of the
body or of an object member, or a scalar body or sole member of four characters
or more), and the first later successful item read naming that id belongs to a
state type. The entity must be new: neither the initial state nor any earlier
read holds that id. An id shorter than four characters may be any type's, so it
links only to a type a successful read showed before the call. The plan records
that read's collection, and serving creates there, since the call's own path
names no collection of the type. That collection holds only for the exemplar's
path arguments: serving refuses a call with others, and the gate counts such a
recorded call as a write no built plan models.
read holds that id, whether an item read of it, a list read of its type, or any
read of the item read's collection, with or without a query, whose body shows it
under an identity member. An id shorter than four characters may be any type's,
so it links only to a type a successful read showed before the call. The plan
records that read's collection, and serving creates there, since the call's own
path names no collection of the type. That collection holds only for the
exemplar's path arguments: serving refuses a call with others, and the gate
counts such a recorded call as a write no built plan models.

**Exemplar.** A plan is built from its first successful (2xx) recorded call,
the exemplar.
Expand Down
19 changes: 19 additions & 0 deletions src/domain/analysisView/environmentStateQueryCalls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,23 @@ describe("POSTs that read state but stay writes", () => {
// A refused call changed nothing, so it does not hold the tool.
expect(readOnlyOf([post(200), post(400)])).toEqual(["post_ids"]);
});

it("keeps a batch a write when one of its entries names no read operation of its own", () => {
const rpc = (operations: JsonValue): Call => ({
method: "POST",
path: "/rpc",
tool: "post_rpc",
request: { operation: "batch", operations },
response: {},
});
const read = { operation: "getUser" };
expect(readOnlyOf([rpc([read, read])])).toEqual(["post_rpc"]);
expect(readOnlyOf([rpc([read, { method: "deleteUser" }])])).toEqual([]);
expect(readOnlyOf([rpc([read, "deleteUser"])])).toEqual([]);
expect(readOnlyOf([rpc([read, { operation: 7 }])])).toEqual([]);
expect(
readOnlyOf([rpc([read, { operation: "batch", operations: [] }])]),
).toEqual([]);
expect(readOnlyOf([rpc({ first: read })])).toEqual([]);
});
});
41 changes: 26 additions & 15 deletions src/domain/analysisView/environmentStateQueryCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,34 @@ const succeeded = (record: StateRecordFacts): boolean =>
const unresolved = (record: StateRecordFacts): boolean =>
isStateWrite(record) && !succeeded(record);

/** Whether a name is an operation's: a string that is no container wrapping others. */
const isOperation = (name: JsonValue | undefined): name is string =>
typeof name === "string" && !OPERATION_CONTAINERS.has(name.toLowerCase());

/** The names among these that are operations rather than containers wrapping them. */
const realOperations = (names: readonly (JsonValue | undefined)[]): string[] =>
names.filter(
(name): name is string =>
typeof name === "string" && !OPERATION_CONTAINERS.has(name.toLowerCase()),
);
names.filter(isOperation);

/** The operations an RPC call names: its body's `operation` or `operations[].operation`, else its query's, containers aside. */
/**
* The operations an RPC call names: its body's `operation` or `operations[].operation`, else its
* query's, containers aside. Undefined when `operations` is no list or one of its entries names no
* operation of its own: no string, or another container.
*/
const operationsOf = (
record: StateRecordFacts,
body: JsonValue | undefined,
): string[] => {
): string[] | undefined => {
const listed = isObject(body) ? body.operations : undefined;
const entries = Array.isArray(listed)
? listed.map((entry) => (isObject(entry) ? entry.operation : undefined))
: [];
if (
(listed !== undefined && !Array.isArray(listed)) ||
!entries.every(isOperation)
)
return undefined;
const named = isObject(body)
? realOperations([
body.operation,
...(Array.isArray(body.operations)
? body.operations.map((entry) =>
isObject(entry) ? entry.operation : undefined,
)
: []),
])
? realOperations([body.operation, ...entries])
: [];
if (named.length > 0) return named;
const query = new URLSearchParams(record.query ?? "");
Expand Down Expand Up @@ -225,7 +232,11 @@ const namesReadOperations = (
): boolean =>
calls.every((call) => {
const operations = operationsOf(call, io.request(call.ordinal));
return operations.length > 0 && operations.every(readsOnly);
return (
operations !== undefined &&
operations.length > 0 &&
operations.every(readsOnly)
);
});

/** The path's last literal segment is a session segment, or names a lookup by its last meaningful word and no write word. */
Expand Down
53 changes: 53 additions & 0 deletions src/domain/analysisView/environmentStateWriteLinks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";

import type { JsonValue } from "../jsonValue.js";
import type { StateRecordFacts } from "./environmentStateRules.js";
import { creationLimit } from "./environmentStateWriteLinks.js";

const record = (
ordinal: number,
method: string,
path: string,
): StateRecordFacts => ({
ordinal,
method,
path,
query: undefined,
status: 200,
start: ordinal,
end: ordinal,
});

describe("creation limits", () => {
it("reads the ids of a list body longer than a call's arguments can spread", () => {
// A million elements overflow the argument limit of a spread, here and in the test workers' larger stack.
const [list, post, later] = [
record(0, "GET", "/api/metrics"),
record(1, "POST", "/api/imports"),
record(2, "GET", "/api/metrics"),
];
const bodies = new Map<number, JsonValue>([
[0, Array.from({ length: 1_000_000 }, () => 0)],
[2, [{ id: "1003" }]],
]);
const limit = creationLimit(
[{ record: post, ids: ["1003"] }],
{
type: "/api/metrics",
tools: [
{
name: "get_metrics",
method: "GET",
path_template: "/api/metrics",
record_ordinals: [0, 2],
},
],
records: new Map([list, post, later].map((at) => [at.ordinal, at])),
position: (at) => at.ordinal,
body: (ordinal) => bodies.get(ordinal),
},
undefined,
);
expect(limit).toBe(post);
});
});
54 changes: 34 additions & 20 deletions src/domain/analysisView/environmentStateWriteLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,29 @@ export const respondedIds = (body: JsonValue | undefined): string[] => {
];
};

/** The identity-named scalar values a read's body shows at any depth, or its path's id for an item read. */
const shownIds = (
record: StateRecordFacts,
item: boolean,
body: () => JsonValue | undefined,
): Set<string> => {
if (item) return new Set([lastSegmentValue(record.path)]);
/** The identity-named scalar values a body shows at any depth. */
const identitiesIn = (root: JsonValue | undefined): Set<string> => {
const shown = new Set<string>();
const pending: JsonValue[] = [];
const root = body();
if (root !== undefined) pending.push(root);
const pending: JsonValue[] = root === undefined ? [] : [root];
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
if (Array.isArray(next)) pending.push(...next);
// One push per child: spreading a large array would exceed the engine's argument limit.
if (Array.isArray(next)) for (const child of next) pending.push(child);
else if (isObject(next)) {
for (const id of identityValues(next)) shown.add(id);
pending.push(...Object.values(next));
for (const child of Object.values(next)) pending.push(child);
}
}
return shown;
};

/** The identity-named scalar values a read's body shows at any depth, or its path's id for an item read. */
const shownIds = (
record: StateRecordFacts,
item: boolean,
body: () => JsonValue | undefined,
): Set<string> =>
item ? new Set([lastSegmentValue(record.path)]) : identitiesIn(body());

/** One read of a type: where it ran, whether it reads one item, and the ids it shows. */
interface ShownRead {
readonly at: number;
Expand Down Expand Up @@ -191,15 +193,16 @@ export const creationLimit = (
/**
* The state type and collection a POST whose path names none creates into: that of the first later
* successful item read naming an id its first successful call returned, when neither the initial
* state nor any earlier read held that id. A short id may be any type's, so it links only to a type
* read before the call.
* state nor any earlier read of that id, its type's lists or its collection showed that id. A short
* id may be any type's, so it links only to a type read before the call.
*/
export const linkedCreate = (input: {
readonly tool: StateToolFacts;
readonly records: readonly StateRecordFacts[];
readonly viewOf: (ordinal: number) => StateView | undefined;
readonly entities: readonly StateEntity[];
readonly respondedIds: (ordinal: number) => readonly string[];
readonly shownIds: (ordinal: number) => ReadonlySet<string>;
}): { readonly type: string; readonly collection: string } | undefined => {
const { tool, records } = input;
const own = new Set(tool.record_ordinals);
Expand All @@ -226,9 +229,21 @@ export const linkedCreate = (input: {
)
continue;
const id = lastSegmentValue(record.path);
const held = input.entities.some(
(entity) => entity.type === view.type && entity.id === id,
);
const collection = collectionPathOf(record, true);
const held =
input.entities.some(
(entity) => entity.type === view.type && entity.id === id,
) ||
records.slice(0, first).some((earlier) => {
const read = input.viewOf(earlier.ordinal);
return (
earlier.method === "GET" &&
succeeded(earlier) &&
((read?.shape === "list" && read.type === view.type) ||
normalizedPath(earlier.path) === normalizedPath(collection)) &&
input.shownIds(earlier.ordinal).has(id)
);
});
const unseen =
id.length < MIN_ID_LENGTH &&
!records.slice(0, first).some((earlier) => {
Expand All @@ -240,9 +255,7 @@ export const linkedCreate = (input: {
read.type === view.type
);
});
return held || unseen
? undefined
: { type: view.type, collection: collectionPathOf(record, true) };
return held || unseen ? undefined : { type: view.type, collection };
}
return undefined;
};
Expand Down Expand Up @@ -307,6 +320,7 @@ export const linkedTarget = (
viewOf: input.viewOf,
entities: input.entities,
respondedIds: (ordinal) => input.io.withBody(ordinal, respondedIds),
shownIds: (ordinal) => input.io.withBody(ordinal, identitiesIn),
})
: undefined;
return link === undefined
Expand Down
60 changes: 42 additions & 18 deletions src/domain/analysisView/environmentStateWrites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,25 +1427,26 @@ describe("types whose reads disagree across a write", () => {
});
});

describe("creates read under another path", () => {
const note = (id: number, title: string) => ({ id, title });
const A = note(1001, "Alpha");
const B = note(1002, "Beta");
const C = note(1003, "Gamma");
const notesOf = (state: StateView) =>
state.entities
.filter((entity) => entity.type === "/api/notes")
.map((entity) => entity.id);
const published = (before: readonly TimedCaptureRow[]): TimedCaptureRow[] => [
["GET", "/api/notes", [A, B]],
["GET", "/api/notes/1001", A],
["GET", "/api/notes/1002", B],
...before,
["POST", "/api/drafts/publish", { id: 1003 }, 201, { title: "Gamma" }],
["GET", "/api/notes/1003", C],
["GET", "/api/notes", [A, B, C]],
];
const note = (id: number, title: string) => ({ id, title });
const A = note(1001, "Alpha");
const B = note(1002, "Beta");
const C = note(1003, "Gamma");
const notesOf = (state: StateView) =>
state.entities
.filter((entity) => entity.type === "/api/notes")
.map((entity) => entity.id);
/** Two notes read, the given exchanges, then a POST elsewhere whose returned id the notes are read under. */
const published = (before: readonly TimedCaptureRow[]): TimedCaptureRow[] => [
["GET", "/api/notes", [A, B]],
["GET", "/api/notes/1001", A],
["GET", "/api/notes/1002", B],
...before,
["POST", "/api/drafts/publish", { id: 1003 }, 201, { title: "Gamma" }],
["GET", "/api/notes/1003", C],
["GET", "/api/notes", [A, B, C]],
];

describe("creates read under another path", () => {
it("plans a POST to another path as a create into the type its returned id is first read under", () => {
const state = stateOf(published([]));
expect(planOf(state, "post_drafts_publish")).toMatchObject({
Expand Down Expand Up @@ -1587,6 +1588,29 @@ describe("creates read under another path", () => {
});
});

describe("creates whose returned id an earlier read showed", () => {
it("links no create whose returned id a list of its collection showed before it", () => {
const listed = (shown: JsonValue[]): TimedCaptureRow[] =>
published([
[
"PATCH",
"/api/notes/1001",
note(1001, "Alpha 2"),
200,
{ title: "Alpha 2" },
],
["GET", "/api/notes?include=archived", shown],
]);
const alpha = note(1001, "Alpha 2");
expect(
planOf(stateOf(listed([alpha, B, C])), "post_drafts_publish"),
).toMatchObject({ effect: "none", reason: "no-state-target" });
expect(
planOf(stateOf(listed([alpha, B])), "post_drafts_publish"),
).toMatchObject({ effect: "create", target: "/api/notes" });
});
});

describe("lines left to replay", () => {
it("plans a list past a line that asks for some fields only and leaves the proved id out", () => {
const created = book(3, "Third Book", bookClock(4));
Expand Down