fix(environment): preserve capture evidence during state inference (#9897)

fix(environment): preserve evidence when inferring and serving state

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morlutoandCursor Agent authored and GitHub committed 2026-11-11 00:14:27 -05:00
1 parent bae4ec0cda
commit 6a2b690440
47 files changed
+1551 -287

No files matched your search

@@ -1418,7 +1418,7 @@ describe("encoded parent spellings", () => {
path: "/api/orgs/uid/acme1/books",
query: undefined,
status: 200,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
};
const lines = checkedLines({
tools: [tool],
@@ -1621,7 +1621,7 @@ describe("resolved encoded item observations", () => {
path: "/api/orgs/acme1/books/%61",
query: undefined,
status: 204,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
};
const target = itemTarget(state, "/api/orgs/{org_id}/books", write);
const itemView = {
@@ -1642,7 +1642,7 @@ describe("resolved encoded item observations", () => {
path: "/api/orgs/acme1/books/%61",
query: undefined,
status: 200,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
},
];
const search: ObservationSearch = {
@@ -2308,23 +2308,53 @@ describe("reads and calls on an entity an unmodelled write left unknown", () =>
{},
];
it("keeps the entity unknown through a failed read that is no absence, for a later read to check", () => {
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [named("A"), other]],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/2", other],
["PATCH", "/api/books/1", named("Z"), 200, { name: "Z" }],
ARCHIVE,
// The application was briefly unavailable, so this answer shows nothing of the book.
["GET", "/api/books/1", { error: "unavailable" }, 503],
["GET", "/api/books/1", named("Z")],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served: true,
checked_record_ordinals: [6],
contradicted_by: null,
});
});
it.each([
{ label: "scalar", read: "unavailable", served: false },
{ label: "array", read: [], served: false },
{ label: "object", read: named("A"), served: true },
])(
"requires a usable item baseline after an unmodelled write ($label)",
({ read, served }) => {
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [named("A"), other]],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/2", other],
ARCHIVE,
["GET", "/api/books/1", read],
["PATCH", "/api/books/1", named("Z"), 200, { name: "Z" }],
["GET", "/api/books/1", named("Z")],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served,
checked_record_ordinals: served ? [6] : [],
});
},
);
it.each([
{ status: 503, body: { error: "unavailable" } },
{ status: 200, body: "unavailable" },
{ status: 200, body: [] },
])(
"keeps pending effects through an unusable item read ($status, $body)",
({ status, body }) => {
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [named("A"), other]],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/2", other],
["PATCH", "/api/books/1", named("Z"), 200, { name: "Z" }],
ARCHIVE,
// Neither failure nor a successful non-object response shows the book.
["GET", "/api/books/1", body, status],
["GET", "/api/books/1", named("Z")],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served: true,
checked_record_ordinals: [6],
contradicted_by: null,
});
},
);
it("confirms no update of a volatile field by a read that shows the entity again, as no other read does", () => {
const seen = (id: number, count: number) => ({
@@ -2468,7 +2498,7 @@ describe("entities an unmodelled write made", () => {
path: "/api/books/3",
query: undefined,
status: 200,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
};
expect(
unseen.adopt(view as unknown as StateItemView, { record, index: 1 }),
@@ -2493,7 +2523,7 @@ describe("entities an unmodelled write made", () => {
path: "/api/books/3",
query: undefined,
status: 200,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
},
index,
});
@@ -3201,7 +3231,7 @@ it("learns omitted fields using the raw ID resolved by the item owner", () => {
path: "/api/books/%63",
query: undefined,
status: 200,
timing: { start: undefined, endMs: undefined },
timing: { start: undefined, end: undefined, endMs: undefined },
};
const target = itemTarget(state, view.type, record);
expect(target.id).toBe("%63");