Skip to content

Commit 6919920

Browse files
committed
fix tests
1 parent ec1e107 commit 6919920

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

apps/sim/executor/execution/snapshot-serializer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ function getBoundedJsonByteLength(
115115
if (hasEntries) bytes += JSON_SYNTAX_BYTES.COMMA
116116
bytes += getEscapedJsonStringByteLength(key) + JSON_SYNTAX_BYTES.COLON
117117
const entrySize = getBoundedJsonByteLength(entryValue, maxBytes - bytes, seen)
118-
if (entrySize === undefined) {
119-
continue
120-
}
121-
bytes += entrySize
118+
bytes += entrySize ?? JSON_SYNTAX_BYTES.NULL
122119
hasEntries = true
123120
if (bytes > maxBytes) return bytes
124121
}

apps/sim/lib/execution/payloads/inline-materialization.server.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@ interface InlineMaterializationOptions {
2020

2121
type InlineMaterializationMemo = WeakMap<object, Promise<unknown>>
2222

23+
interface MaterializedInlineValue {
24+
value: unknown
25+
byteLength: number | undefined
26+
}
27+
2328
export function getInlineJsonByteLength(value: unknown): number | undefined {
2429
const json = JSON.stringify(value)
2530
return json === undefined ? undefined : Buffer.byteLength(json, 'utf8')
2631
}
2732

28-
function getArrayItemByteLength(value: unknown): number {
29-
return getInlineJsonByteLength(value) ?? Buffer.byteLength('null', 'utf8')
33+
function getArrayItemByteLength(value: MaterializedInlineValue): number {
34+
return value.byteLength ?? Buffer.byteLength('null', 'utf8')
3035
}
3136

32-
function getObjectEntryByteLength(key: string, value: unknown): number | undefined {
33-
const valueBytes = getInlineJsonByteLength(value)
34-
if (valueBytes === undefined) {
37+
function getObjectEntryByteLength(key: string, value: MaterializedInlineValue): number | undefined {
38+
if (value.byteLength === undefined) {
3539
return undefined
3640
}
37-
return Buffer.byteLength(JSON.stringify(key), 'utf8') + 1 + valueBytes
41+
return Buffer.byteLength(JSON.stringify(key), 'utf8') + 1 + value.byteLength
3842
}
3943

40-
function withLocalLargeValueExecutionIds(
44+
function withMaterializedAccessKeys(
4145
context: ExecutionMaterializationContext | undefined,
4246
materializedValue: unknown
4347
): ExecutionMaterializationContext | undefined {
@@ -57,20 +61,21 @@ export async function materializeInlineExecutionValue(
5761
context: ExecutionMaterializationContext | undefined,
5862
options: InlineMaterializationOptions = {}
5963
): Promise<unknown> {
60-
return materializeInlineExecutionValueWithinBudget(
64+
const materialized = await materializeInlineExecutionValueWithinBudget(
6165
value,
6266
context,
6367
options.maxBytes ?? MAX_INLINE_MATERIALIZATION_BYTES,
6468
new WeakMap<object, Promise<unknown>>()
6569
)
70+
return materialized.value
6671
}
6772

6873
async function materializeInlineExecutionValueWithinBudget(
6974
value: unknown,
7075
context: ExecutionMaterializationContext | undefined,
7176
maxBytes: number,
7277
memo: InlineMaterializationMemo
73-
): Promise<unknown> {
78+
): Promise<MaterializedInlineValue> {
7479
if (isLargeArrayManifest(value)) {
7580
assertInlineMaterializationSize(value.byteSize, maxBytes)
7681
const materialized = await materializeLargeArrayManifest(value, {
@@ -79,7 +84,7 @@ async function materializeInlineExecutionValueWithinBudget(
7984
})
8085
return materializeInlineExecutionValueWithinBudget(
8186
materialized,
82-
withLocalLargeValueExecutionIds(context, materialized),
87+
withMaterializedAccessKeys(context, materialized),
8388
maxBytes,
8489
memo
8590
)
@@ -96,7 +101,7 @@ async function materializeInlineExecutionValueWithinBudget(
96101
}
97102
return materializeInlineExecutionValueWithinBudget(
98103
materialized,
99-
withLocalLargeValueExecutionIds(context, materialized),
104+
withMaterializedAccessKeys(context, materialized),
100105
maxBytes,
101106
memo
102107
)
@@ -107,12 +112,12 @@ async function materializeInlineExecutionValueWithinBudget(
107112
if (valueBytes !== undefined) {
108113
assertInlineMaterializationSize(valueBytes, maxBytes)
109114
}
110-
return value
115+
return { value, byteLength: valueBytes }
111116
}
112117

113118
const cached = memo.get(value)
114119
if (cached) {
115-
return cached
120+
return { value: await cached, byteLength: 0 }
116121
}
117122

118123
if (Array.isArray(value)) {
@@ -132,9 +137,9 @@ async function materializeInlineExecutionValueWithinBudget(
132137
const itemBytes = getArrayItemByteLength(materializedItem)
133138
usedBytes += commaBytes + itemBytes
134139
assertInlineMaterializationSize(usedBytes, maxBytes)
135-
result.push(materializedItem)
140+
result.push(materializedItem.value)
136141
}
137-
return result
142+
return { value: result, byteLength: usedBytes }
138143
}
139144

140145
const result: Record<string, unknown> = {}
@@ -156,7 +161,7 @@ async function materializeInlineExecutionValueWithinBudget(
156161
usedBytes += commaBytes + entryBytes
157162
assertInlineMaterializationSize(usedBytes, maxBytes)
158163
}
159-
result[key] = materializedEntryValue
164+
result[key] = materializedEntryValue.value
160165
}
161-
return result
166+
return { value: result, byteLength: usedBytes }
162167
}

0 commit comments

Comments
 (0)