Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
51 changes: 27 additions & 24 deletions docs/specs/agent-environments/state-targets/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,40 @@ its cause in the recordings and the code. The five largest shared causes:

- **Read-only calls.** A POST is not a state write when its response repeats the read of its path that finished last
before it began, with no write between, it tunnels only read operations, its last literal segment names a lookup and
no write, or it renews a session; it is replayed. It stays a write when one of its calls was redirected or
unanswered, or when a related read line changes across one of its calls, or finds its entity there on one side only,
with no write but other read-only calls between; a read overlapping the call counts on neither side.
no write, or it renews a session; it is replayed. It stays a write when one of its calls was redirected or unanswered,
or when a related read line changes across one of its calls, or finds its entity there on one side only, with no write
but other read-only calls between; a read overlapping the call counts on neither side. Each response body compared is
parsed once and kept only as its canonical digest, charged to the view's budget until the decision ends.
- **Adopted entities.** A successful item read of an entity the gate's copy never held, after a write no built plan
models or one redirected or unanswered, 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, before any other tool's write, when the id is new: no read finished before it began
showed it, whether an item read of the id under that type or collection whose body shows the item, a list of the
type or a read of that collection. Its observation is a read of an id its response returned, in an envelope too.
Serving creates in that read's collection, for the exemplar's path arguments only (segment by segment, in either
spelling), and fills path fields with its exemplar's path values decoded once. A successful POST that returned an id
a type's reads only show once it began ends that type's initial window: a read still running then may show it, and a
list read shows its listed entities' own ids (identity-named, or a suffix-named field such as `projectId` distinct
across two or more when no id-named field identifies them), not those they nest.
showed it, whether an item read of the id under that type or collection whose body shows the item, a list of the type
or a read of that collection. Its observation is a read of an id its response returned, in an envelope too. Serving
creates in that read's collection, for the exemplar's path arguments only (segment by segment, in either spelling),
and fills path fields with its exemplar's path values decoded once. A successful POST that returned an id a type's
reads only show once it began ends that type's initial window: a read still running then may show it, and a list read
shows its listed entities' own ids (identity-named, or a suffix-named field such as `projectId` distinct across two or
more when no id-named field identifies them), not those they nest. A read at or after the write that ends the initial
reads is not parsed for that cut, since it cannot show a new id.
- **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
checks, the entity observations (an entity's first sighting comes from the lines left) and the membership changes
that cut a type's initial window, and the view names it with the query keys that pick it out
(`projected_query_keys`, on item and list views). Beside a line showing whole entities, a list line asking for some
fields only (a projection value other than `*`) is set aside before the identity proof the same way. A call matching
those keys replays its recording, so it does not show served writes; a 400, 404 or 410 on such a line is still
evidence. A call asking for some fields only replays unless every value it gives is `*` or one a checked line gave,
and no replayed read gave it. The write gate skips exactly the successful reads serving replays, by the same
decision. A filter role whose name matches no field needs two agreeing values. A tool whose lines would take more
than 2^24 line pairs and entity lookups to compare pairwise keeps every line checked. An item line first recorded
after the initial window is a variant too, judged against the lines left once variants are dropped: when it names a
new shaping parameter and its object carries or lacks members theirs do not, or selects some fields and leaves out
members they always show, and an item only a replayed line showed, which the state never started with and in whose
type no served create has added an entity since, answers with its own recording.
- **Variant lines.** A read line that shows the same entities in another form is a variant: it leaves the view's checks,
the entity observations (an entity's first sighting comes from the lines left) and the membership changes that cut a
type's initial window, and the view names it with the query keys that pick it out (`projected_query_keys`, on item and
list views). Beside a line showing whole entities, a list line asking for some fields only (a projection value other
than `*`) is set aside before the identity proof the same way. A call matching those keys replays its recording, so it
does not show served writes; a 400, 404 or 410 on such a line is still evidence. A call asking for some fields only
replays unless every value it gives is `*` or one a checked line gave, and no replayed read gave it. The write gate
skips exactly the successful reads serving replays, by the same decision. A filter role whose name matches no field
needs two agreeing values. A tool whose lines would take more than 2^24 line pairs and entity lookups to compare
pairwise keeps every line checked; otherwise lines are compared only with those showing one of the same entities,
through an index charged to the budget while it is held. An item line first recorded after the initial window is a
variant too, judged against the lines left once variants are dropped: when it names a new shaping parameter and its
object carries or lacks members theirs do not, or selects some fields and leaves out members they always show, and an
item only a replayed line showed, which the state never started with and in whose type no served create has added an
entity since, answers with its own recording.

## Acceptance

Expand Down
5 changes: 5 additions & 0 deletions docs/specs/agent-environments/state-targets/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ write tool is lost.
matching).
- **Tenth round** (on main `a2235b09`): no verdict, read view, recorded read or session replay changes on the restored
captures.
- **Eleventh round** (on main `2968d1e9`, performance review): variant lines compare only lines that share an entity,
read-only decisions parse each body once and keep its digest, and the creation cut skips reads that cannot count.
Every census, serving-check and session-replay row equals the previous head's. On a synthetic capture of a list and
1,000 items read plainly and with `?expand=`, the variant pass falls from 401 ms to 2 ms and the state build from 659
ms to 216 ms (Node v22.23.1).

Of the 40 views variant lines make state-backed, 146 of 151 recorded reads before the first write match; the other five
(Sentry projects) are replayed, and replay returns the first of several differing recordings, as before. A paged
Expand Down
9 changes: 7 additions & 2 deletions src/domain/analysisView/EnvironmentStateExtraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ export class EnvironmentStateExtraction {

/** The timeline's state writes, less the calls of tools that only read. */
#findWrites(): void {
// The body digests the decision keeps are dropped with it, so what they were charged is released.
const release = this.#budget.checkpoint();
({ readOnly: this.#readOnly, writes: this.#writes } = stateWritesOf(
this.#tools,
this.#records,
{
response: (ordinal) => this.#withBody(ordinal, (body) => body),
withBody: (ordinal, use) => this.#withBody(ordinal, use),
request: (ordinal) => this.#requestBody(ordinal),
retain: (bytes) => this.#retain(bytes),
},
));
release();
this.#writeWithin = writeSpanCheck(this.#writes);
}

Expand Down Expand Up @@ -236,6 +240,7 @@ export class EnvironmentStateExtraction {
queryOf: (ordinal) => this.#byOrdinal.get(ordinal)?.query,
position: (ordinal) => this.#position.get(ordinal)!,
retain: (bytes) => this.#retain(bytes),
checkpoint: () => this.#budget.checkpoint(),
});
if (split === undefined) continue;
this.#retain(ENTRY_BYTES * (split.dropped.size + 2));
Expand Down Expand Up @@ -341,7 +346,7 @@ export class EnvironmentStateExtraction {
tools: this.#tools,
records: this.#byOrdinal,
position: (record) => this.#position.get(record.ordinal)!,
body: (ordinal) => this.#withBody(ordinal, (body) => body),
withBody: (ordinal, use) => this.#withBody(ordinal, use),
retain: (bytes) => this.#retain(bytes),
},
first,
Expand Down
34 changes: 33 additions & 1 deletion src/domain/analysisView/EnvironmentStateWriteSimulation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OmittedFields } from "./environmentStateWriteOmitted.js";
import { checkedLines, servedLine } from "./environmentStateCheckedLines.js";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

import {
timedCaptureEvidence,
Expand Down Expand Up @@ -2298,6 +2298,38 @@ describe("entities an unmodelled write made", () => {
expect(retained).toBeGreaterThan(20_000);
});

it("finds no read's target among the held entities until an unplanned write came before the read", () => {
const state = new SimulatedState([], []);
const targets = vi.spyOn(state, "ofType");
const unseen = new UnseenEntities([], {
state,
io: { withBody: (_ordinal, use) => use(THIRD_BOOK), retain: () => 0 },
lastCheck: new Map(),
idField: () => "id",
});
const view = { shape: "item", type: "/api/books", pointer: "" };
const read = (index: number) => ({
record: {
ordinal: index,
method: "GET",
path: "/api/books/3",
query: undefined,
status: 200,
start: index,
end: index,
},
index,
});
const adopt = (index: number) =>
unseen.adopt(view as unknown as StateItemView, read(index));
expect(adopt(1)).toBeUndefined();
// A write after the read cannot have made what it shows either.
unseen.unplanned(2);
expect(adopt(1)).toBeUndefined();
expect(targets).not.toHaveBeenCalled();
expect(adopt(3)).toMatchObject({ id: "3" });
});

it("takes back no book a modelled delete removed, so a list showing it again confirms no delete", () => {
expect(
gated(deletedAfterRead([RENAME, IMPORT]), "delete_books_by_id"),
Expand Down
98 changes: 92 additions & 6 deletions src/domain/analysisView/environmentStateQueryCalls.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { describe, expect, it } from "vitest";

import type { JsonValue } from "../jsonValue.js";
import { readOnlyTools } from "./environmentStateQueryCalls.js";
import {
readOnlyTools,
type QueryCallIo,
} from "./environmentStateQueryCalls.js";
import type {
StateRecordFacts,
StateToolFacts,
Expand All @@ -20,8 +23,14 @@ interface Call {
readonly end?: number;
}

/** How the read-only pass parses response bodies and charges what it keeps of them, when a test watches either. */
interface Bodies {
readonly withBody?: QueryCallIo["withBody"];
readonly retain?: (bytes: number) => void;
}

/** The read-only tools of a timeline of calls, ordinals in order; a call spans its index unless it gives its times. */
const readOnlyOf = (calls: readonly Call[]): string[] => {
const readOnlyOf = (calls: readonly Call[], bodies: Bodies = {}): string[] => {
const records: StateRecordFacts[] = calls.map((call, index) => ({
ordinal: index,
method: call.method,
Expand All @@ -41,10 +50,13 @@ const readOnlyOf = (calls: readonly Call[]): string[] => {
record_ordinals: [...(known?.record_ordinals ?? []), index],
});
});
const withBody: QueryCallIo["withBody"] =
bodies.withBody ?? ((ordinal, use) => use(calls[ordinal]?.response));
return [
...readOnlyTools([...tools.values()], records, {
response: (ordinal) => calls[ordinal]?.response,
withBody,
request: (ordinal) => calls[ordinal]?.request,
retain: bodies.retain ?? (() => undefined),
}),
].sort();
};
Expand Down Expand Up @@ -476,8 +488,9 @@ describe("read-only decisions over many calls", () => {
visits = 0;
expect([
...readOnlyTools(tools, records, {
response: () => [],
withBody: (_ordinal, use) => use([]),
request: () => undefined,
retain: () => undefined,
}),
]).toEqual(["post_ids"]);
expect(visits).toBeLessThan(50 * records.length);
Expand Down Expand Up @@ -531,8 +544,9 @@ describe("read-only decisions over a long run of calls", () => {
visits = 0;
expect([
...readOnlyTools(tools, records, {
response: () => JOBS,
withBody: (_ordinal, use) => use(JOBS),
request: () => ({ jobs: ["night-watch"] }),
retain: () => undefined,
}),
]).toEqual(["post_statuses"]);
expect(visits).toBeLessThan(50 * records.length);
Expand Down Expand Up @@ -583,10 +597,82 @@ describe("read-only decisions over many lines", () => {
];
expect([
...readOnlyTools(tools, records, {
response: () => [],
withBody: (_ordinal, use) => use([]),
request: () => undefined,
retain: () => undefined,
}),
]).toEqual(["post_ids"]);
expect(reads).toBeLessThan(20 * records.length);
});
});

describe("the bodies read-only decisions compare", () => {
const read = (members: string[]): Call => ({
method: "GET",
path: "/api/members",
tool: "get_members",
response: members,
});
const lookup: Call = {
method: "POST",
path: "/api/members/ids",
tool: "post_ids",
response: ["a"],
};
const refresh: Call = {
method: "POST",
path: "/api/collections/_superusers/auth-refresh",
tool: "post_auth_refresh",
response: { token: "x" },
};
// The change across the lookup's calls drops it on the first pass, so the refresh is checked again.
const calls = [read(["a"]), lookup, lookup, refresh, read(["a", "b"])];

it("parses each read once across a tool's calls and the passes that drop vetoed tools", () => {
const parses = new Map<number, number>();
expect(
readOnlyOf(calls, {
withBody: (ordinal, use) => {
parses.set(ordinal, (parses.get(ordinal) ?? 0) + 1);
return use(calls[ordinal]?.response);
},
}),
).toEqual(["post_auth_refresh"]);
expect([...parses].filter(([, count]) => count > 1)).toEqual([]);
});

it("compares bodies only while their parse is charged, and charges what it keeps of each", () => {
const [parsed, outside] = [new Set<number>(), new Set<number>()];
let parsing = false;
let retained = 0;
expect(
readOnlyOf(calls, {
withBody: (ordinal, use) => {
parsed.add(ordinal);
const body = calls[ordinal]?.response;
parsing = true;
try {
return use(
typeof body === "object" && body !== null
? new Proxy(body, {
get: (target, key, receiver) => {
if (!parsing) outside.add(ordinal);
return Reflect.get(target, key, receiver) as unknown;
},
})
: body,
);
} finally {
parsing = false;
}
},
retain: (bytes) => {
retained += bytes;
},
}),
).toEqual(["post_auth_refresh"]);
expect([...outside]).toEqual([]);
// Each body is kept as its digest's hex text, charged before it is.
expect(retained).toBeGreaterThanOrEqual(parsed.size * 64);
});
});
Loading
Loading