Skip to content

Commit c1f793b

Browse files
Gozalaseefeldb
andauthored
fix: log reads despite errors (#1506)
* fix: log reads despite errors * only look for relevant reads (list now contains many more) * fix traversing over shortened paths to objects * fix test for shim flow --------- Co-authored-by: Bernhard Seefeld <berni@common.tools>
1 parent 8522fff commit c1f793b

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

packages/runner/src/reactive-dependencies.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ export function determineTriggeredActions(
150150
if (i <= beforeLastObject) {
151151
beforeValues[i + 1] = (beforeValues[i] as Keyable)[targetPath[i]!];
152152
if (isRecord(beforeValues[i + 1])) beforeLastObject = i + 1;
153+
else beforeLastObject = i;
153154
}
154155
if (i <= afterLastObject) {
155156
afterValues[i + 1] = (afterValues[i] as Keyable)[targetPath[i]!];
156157
if (isRecord(afterValues[i + 1])) afterLastObject = i + 1;
158+
else afterLastObject = i;
157159
}
158160
}
159161
currentPath = targetPath;

packages/runner/src/storage/transaction/journal.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,19 @@ export const read = (
109109
if (error) {
110110
return { error };
111111
} else {
112+
// Track read activity with metadata
113+
journal.state.activity.push({
114+
read: {
115+
...address,
116+
space,
117+
meta: options?.meta ?? {},
118+
},
119+
});
120+
112121
const result = branch.read(address, options);
113122
if (result.error) {
114123
return { error: result.error.from(space) };
115124
} else {
116-
// Track read activity with metadata
117-
journal.state.activity.push({
118-
read: {
119-
...address,
120-
space,
121-
meta: options?.meta ?? {},
122-
},
123-
});
124125
return result;
125126
}
126127
}

packages/runner/test/schema.test.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,25 @@ describe("Schema Support", () => {
370370
});
371371
const log = txToReactivityLog(tx);
372372
const reads = sortAndCompactPaths(log.reads);
373-
expect(reads.length).toEqual(3);
374-
expect(
375-
reads.map((r: IMemorySpaceAddress) => ({ id: r.id, path: r.path }))
376-
.sort((a, b) => a.id.localeCompare(b.id)),
377-
).toEqual([
378-
{ id: toURI(docCell.entityId!), path: ["current"] },
379-
{ id: toURI(linkEntityId), path: [] },
380-
{ id: toURI(initialEntityId), path: ["foo"] },
381-
].sort((a, b) => a.id.localeCompare(b.id)));
373+
console.log(reads);
374+
expect(reads).toContainEqual({
375+
space,
376+
id: toURI(linkEntityId),
377+
path: [],
378+
type: "application/json",
379+
});
380+
expect(reads).toContainEqual({
381+
space,
382+
id: toURI(docCell.entityId!),
383+
path: ["current"],
384+
type: "application/json",
385+
});
386+
expect(reads).toContainEqual({
387+
space,
388+
id: toURI(initialEntityId),
389+
path: ["foo"],
390+
type: "application/json",
391+
});
382392

383393
// Then update it
384394
initial.withTx(tx).set({ foo: { label: "first - update" } });
@@ -405,7 +415,7 @@ describe("Schema Support", () => {
405415

406416
await runtime.idle();
407417

408-
(expect(rootValues) as any).toEqualIgnoringSymbols([
418+
expect(rootValues).toEqual([
409419
"root",
410420
"cancelled",
411421
"root",
@@ -418,7 +428,7 @@ describe("Schema Support", () => {
418428

419429
await runtime.idle();
420430

421-
(expect(rootValues) as any).toEqualIgnoringSymbols([
431+
expect(rootValues).toEqual([
422432
"root",
423433
"cancelled",
424434
"root",

0 commit comments

Comments
 (0)