Repository navigation
Expand file tree
/
Copy pathusageTranscriptReader.test.ts
More file actions
555 lines (511 loc) · 22.1 KB
/
Copy pathusageTranscriptReader.test.ts
File metadata and controls
555 lines (511 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
// @effect-diagnostics nodeBuiltinImport:off - resume coverage writes, appends
// to, and truncates real transcript files byte-exactly, mirroring the reader's
// own deliberate node:fs usage.
import * as NodeFSP from "node:fs/promises";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
import * as NodeZlib from "node:zlib";
import { afterEach, assert, beforeEach, describe, it } from "@effect/vitest";
import { totalTokens, type TranscriptUsageFormat } from "@t3tools/provider-core/server/usage";
import * as Schema from "effect/Schema";
import { TEST_FORMATS } from "./usageTestFormats.ts";
import {
listTranscriptFiles,
readTranscriptRecords,
transcriptLineGate,
} from "./usageTranscriptReader.ts";
let dir: string;
beforeEach(async () => {
dir = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "usage-reader-test-"));
});
afterEach(async () => {
await NodeFSP.rm(dir, { recursive: true, force: true });
});
function claudeLine(id: number, outputTokens: number): string {
return `${JSON.stringify({
type: "assistant",
timestamp: "2026-08-01T10:00:00Z",
requestId: `req_${id}`,
sessionId: "session-1",
message: {
id: `msg_${id}`,
model: "claude-fable-5",
usage: { input_tokens: 10, output_tokens: outputTokens },
},
})}\n`;
}
function codexMetaLine(): string {
return `${JSON.stringify({
type: "session_meta",
timestamp: "2026-08-01T10:00:00Z",
payload: { type: "session_meta", id: "codex-session-1" },
})}\n`;
}
function codexModelLine(model: string): string {
return `${JSON.stringify({
type: "turn_context",
timestamp: "2026-08-01T10:00:01Z",
payload: { type: "turn_context", model },
})}\n`;
}
function codexTierLine(serviceTier: string): string {
return `${JSON.stringify({
type: "event_msg",
timestamp: "2026-08-01T10:00:01Z",
payload: { type: "thread_settings_applied", thread_settings: { service_tier: serviceTier } },
})}\n`;
}
function codexUsageLine(outputTokens: number, secondsOffset: number): string {
return `${JSON.stringify({
type: "event_msg",
timestamp: `2026-08-01T10:00:${String(secondsOffset).padStart(2, "0")}Z`,
payload: {
type: "token_count",
info: { last_token_usage: { input_tokens: 100, output_tokens: outputTokens } },
},
})}\n`;
}
describe("compressed transcripts", () => {
it("discovers nested plain and zstd JSONL files within the requested window", async () => {
const nested = NodePath.join(dir, "nested");
await NodeFSP.mkdir(nested);
const plain = NodePath.join(dir, "active.jsonl");
const compressed = NodePath.join(nested, "archived.jsonl.zst");
const old = NodePath.join(nested, "old.jsonl.zst");
await NodeFSP.writeFile(plain, claudeLine(1, 5));
await NodeFSP.writeFile(compressed, NodeZlib.zstdCompressSync(claudeLine(2, 7)));
await NodeFSP.writeFile(old, NodeZlib.zstdCompressSync(claudeLine(3, 11)));
await NodeFSP.writeFile(NodePath.join(nested, "unrelated.zst"), "ignored");
await NodeFSP.writeFile(NodePath.join(nested, "partial.jsonl.zst.tmp"), "ignored");
await NodeFSP.utimes(old, 1, 1);
const listed = await listTranscriptFiles(dir, Date.parse("2026-01-01T00:00:00Z"));
assert.deepStrictEqual(
listed.files.map((file) => file.path).sort(),
[plain, compressed].sort(),
);
assert.strictEqual(listed.failedPaths, 0);
assert.isAbove(listed.files.find((file) => file.path === compressed)?.size ?? 0, 0);
});
it.each([
{ parser: "native", streamingThresholdBytes: undefined },
{ parser: "projected", streamingThresholdBytes: 1024 },
])(
"matches plain Codex records and unfinished tails through long lines ($parser)",
async ({ streamingThresholdBytes }) => {
const plain = NodePath.join(dir, "rollout.jsonl");
const compressed = plain + ".zst";
const large = codexUsageLine(9, 5).replace(
'"payload":',
'"padding":' + JSON.stringify("日本語 é".repeat(128 * 1024)) + ',"payload":',
);
const content =
codexMetaLine() +
codexModelLine("gpt-6-astra") +
codexTierLine("ultrafast") +
large +
codexUsageLine(13, 6).replace('"output_tokens":13', '"output_tokens":"invalid"') +
codexUsageLine(21, 8).trimEnd();
await NodeFSP.writeFile(plain, content);
await NodeFSP.writeFile(compressed, NodeZlib.zstdCompressSync(content));
const options =
streamingThresholdBytes === undefined ? undefined : { streamingThresholdBytes };
const expected = await readTranscriptRecords(plain, TEST_FORMATS.codex, undefined, options);
const actual = await readTranscriptRecords(
compressed,
TEST_FORMATS.codex,
undefined,
options,
);
assert.isNotNull(expected);
assert.isNotNull(actual);
assert.strictEqual(expected.records.length, 1);
assert.strictEqual(expected.tailRecords.length, 1);
assert.deepStrictEqual(actual.records, expected.records);
assert.deepStrictEqual(actual.tailRecords, expected.tailRecords);
assert.strictEqual(expected.malformedRecords, 1);
assert.strictEqual(actual.malformedRecords, expected.malformedRecords);
assert.strictEqual(actual.records[0]?.speed, "ultrafast");
assert.isFalse(actual.resumed);
assert.strictEqual(actual.position.resumeOffset, 0);
},
);
it("ignores a prior resume position and rereads compressed rollouts from their start", async () => {
const plain = NodePath.join(dir, "rollout.jsonl");
const content = codexMetaLine() + codexModelLine("gpt-6-astra") + codexUsageLine(9, 5);
await NodeFSP.writeFile(plain, content);
const first = await readTranscriptRecords(plain, TEST_FORMATS.codex);
assert.isNotNull(first);
const compressed = plain + ".zst";
await NodeFSP.writeFile(compressed, NodeZlib.zstdCompressSync(content + codexUsageLine(21, 8)));
const actual = await readTranscriptRecords(compressed, TEST_FORMATS.codex, first.position);
assert.isNotNull(actual);
assert.isFalse(actual.resumed);
assert.deepStrictEqual(
actual.records.map((record) => record.totals.outputTokens),
[9, 21],
);
const repeated = await readTranscriptRecords(compressed, TEST_FORMATS.codex, actual.position);
assert.isNotNull(repeated);
assert.isFalse(repeated.resumed);
assert.deepStrictEqual(repeated.records, actual.records);
});
it("returns null for zstd decoder errors rather than caching an empty parse", async () => {
const path = NodePath.join(dir, "corrupt.jsonl.zst");
await NodeFSP.writeFile(path, "not a zstd frame");
assert.isNull(await readTranscriptRecords(path, TEST_FORMATS.claude));
});
});
describe("readTranscriptRecords resume", () => {
it.each([
{ mode: "buffered", streamingThresholdBytes: Infinity },
{ mode: "streaming", streamingThresholdBytes: 0 },
])("counts malformed tails once across $mode reads and resume", async (options) => {
const format: TranscriptUsageFormat<{ errors: number }> = {
...TEST_FORMATS.claude,
selectFields: { ...TEST_FORMATS.claude.selectFields, usage: true },
state: {
initial: () => ({ errors: 0 }),
schema: Schema.Struct({ errors: Schema.Number }),
},
parseLine(line, state) {
return this.parseProjected(JSON.parse(line), state);
},
parseProjected(value, state) {
if (
typeof value === "object" &&
value !== null &&
"usage" in value &&
value.usage === "malformed"
) {
state.errors += 1;
return [];
}
return TEST_FORMATS.claude.parseProjected(value, undefined);
},
readMalformedRecords: (state: { errors: number }) => state.errors,
};
const path = NodePath.join(dir, "diagnostics.jsonl");
const malformed = JSON.stringify({ usage: "malformed" });
// Completed lines enter the projected parser only when they cross a stream chunk.
const committed = `${JSON.stringify({ usage: "malformed", padding: "x".repeat(256 * 1024) })}\n${claudeLine(1, 5)}`;
await NodeFSP.writeFile(path, committed + malformed);
const first = await readTranscriptRecords(path, format, undefined, options);
assert.isNotNull(first);
assert.deepStrictEqual(
first.records.map((record) => record.totals.outputTokens),
[5],
);
assert.deepStrictEqual(first.tailRecords, []);
assert.strictEqual(first.position.resumeOffset, Buffer.byteLength(committed));
assert.deepStrictEqual(first.position.state, { errors: 1 });
assert.strictEqual(first.malformedRecords, 2);
const savedPosition = JSON.parse(JSON.stringify(first.position));
await NodeFSP.appendFile(path, `\n${claudeLine(2, 7)}${malformed}\n`);
const resumed = await readTranscriptRecords(path, format, savedPosition, options);
assert.isNotNull(resumed);
assert.isTrue(resumed.resumed);
assert.deepStrictEqual(
resumed.records.map((record) => record.totals.outputTokens),
[7],
);
assert.deepStrictEqual(resumed.position.state, { errors: 3 });
assert.strictEqual(resumed.malformedRecords, 3);
const full = await readTranscriptRecords(path, format, undefined, options);
assert.isNotNull(full);
assert.deepStrictEqual([...first.records, ...resumed.records], full.records);
assert.deepStrictEqual(resumed.tailRecords, full.tailRecords);
assert.deepStrictEqual(resumed.position, full.position);
assert.strictEqual(resumed.malformedRecords, full.malformedRecords);
});
it("parses only appended lines when resuming a grown file", async () => {
const path = NodePath.join(dir, "claude.jsonl");
await NodeFSP.writeFile(path, claudeLine(1, 5) + claudeLine(2, 7));
const first = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(first);
assert.strictEqual(first.records.length, 2);
assert.isFalse(first.resumed);
assert.strictEqual(first.malformedRecords, 0);
await NodeFSP.appendFile(path, claudeLine(3, 11));
const second = await readTranscriptRecords(path, TEST_FORMATS.claude, first.position);
assert.isNotNull(second);
assert.isTrue(second.resumed);
assert.strictEqual(second.records.length, 1);
assert.strictEqual(second.records[0]?.totals.outputTokens, 11);
const full = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(full);
assert.deepStrictEqual([...first.records, ...second.records], [...full.records]);
});
it("carries the Codex reducer state across the resume boundary", async () => {
const path = NodePath.join(dir, "rollout.jsonl");
await NodeFSP.writeFile(
path,
codexMetaLine() + codexModelLine("gpt-5.2-codex") + codexTierLine("ultrafast"),
);
const first = await readTranscriptRecords(path, TEST_FORMATS.codex);
assert.isNotNull(first);
assert.strictEqual(first.records.length, 0);
await NodeFSP.appendFile(path, codexUsageLine(9, 5));
const second = await readTranscriptRecords(path, TEST_FORMATS.codex, first.position);
assert.isNotNull(second);
assert.isTrue(second.resumed);
assert.strictEqual(second.records.length, 1);
assert.strictEqual(second.records[0]?.model, "gpt-5.2-codex");
assert.strictEqual(second.records[0]?.speed, "ultrafast");
assert.strictEqual(second.records[0]?.sessionId, "codex-session-1");
});
it("suppresses a Codex duplicate usage event that straddles the boundary", async () => {
const path = NodePath.join(dir, "rollout.jsonl");
await NodeFSP.writeFile(
path,
codexMetaLine() + codexModelLine("gpt-5.2-codex") + codexUsageLine(9, 5),
);
const first = await readTranscriptRecords(path, TEST_FORMATS.codex);
assert.isNotNull(first);
assert.strictEqual(first.records.length, 1);
// Codex duplicates token_count at stream boundaries, including after resume points.
await NodeFSP.appendFile(path, codexUsageLine(9, 5) + codexUsageLine(21, 8));
const second = await readTranscriptRecords(path, TEST_FORMATS.codex, first.position);
assert.isNotNull(second);
assert.isTrue(second.resumed);
assert.deepStrictEqual(
second.records.map((record) => record.totals.outputTokens),
[21],
);
});
it("defers an unterminated trailing line to tailRecords, then consumes it once terminated", async () => {
const path = NodePath.join(dir, "claude.jsonl");
const unterminated = claudeLine(2, 7).trimEnd();
await NodeFSP.writeFile(path, claudeLine(1, 5) + unterminated);
const first = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(first);
assert.strictEqual(first.records.length, 1);
assert.strictEqual(first.tailRecords.length, 1);
assert.strictEqual(first.tailRecords[0]?.totals.outputTokens, 7);
await NodeFSP.appendFile(path, `\n${claudeLine(3, 11)}`);
const second = await readTranscriptRecords(path, TEST_FORMATS.claude, first.position);
assert.isNotNull(second);
assert.isTrue(second.resumed);
assert.deepStrictEqual(
second.records.map((record) => record.totals.outputTokens),
[7, 11],
);
assert.strictEqual(second.tailRecords.length, 0);
});
it.each([
{ mode: "buffered", streamingThresholdBytes: Infinity },
{ mode: "streaming", streamingThresholdBytes: 0 },
])(
"resumes an initial Codex carried-total tail without rebilling it ($mode)",
async (options) => {
const path = NodePath.join(dir, "continuation.jsonl");
const usage = (input: number, output: number) => ({
input_tokens: input,
output_tokens: output,
});
const event = (last: unknown, cumulative: unknown) =>
JSON.stringify({
type: "event_msg",
timestamp: "2026-08-01T10:00:05Z",
payload: {
type: "token_count",
info: { last_token_usage: last, total_token_usage: cumulative },
},
});
const firstLine = event(usage(100, 20), usage(500, 60));
await NodeFSP.writeFile(
path,
codexMetaLine() + codexModelLine("gpt-6-astra") + codexTierLine("ultrafast") + firstLine,
);
const first = await readTranscriptRecords(path, TEST_FORMATS.codex, undefined, options);
assert.isNotNull(first);
assert.strictEqual(first.records.length, 0);
assert.deepStrictEqual(
first.tailRecords.map((r) => [r.totals.outputTokens, r.speed]),
[[20, "ultrafast"]],
);
assert.strictEqual(first.malformedRecords, 0);
await NodeFSP.appendFile(path, `\n${firstLine}\n${event(usage(10, 2), usage(510, 62))}\n`);
const resumed = await readTranscriptRecords(
path,
TEST_FORMATS.codex,
JSON.parse(JSON.stringify(first.position)),
options,
);
const full = await readTranscriptRecords(path, TEST_FORMATS.codex, undefined, options);
assert.isNotNull(resumed);
assert.isNotNull(full);
assert.isTrue(resumed.resumed);
assert.deepStrictEqual(resumed.records, full.records);
assert.deepStrictEqual(
resumed.records.map((r) => [r.totals.outputTokens, r.speed]),
[
[20, "ultrafast"],
[2, "ultrafast"],
],
);
assert.deepStrictEqual(resumed.tailRecords, []);
assert.strictEqual(resumed.malformedRecords, 0);
assert.deepStrictEqual(resumed.position, full.position);
},
);
it.each([
{ mode: "buffered", streamingThresholdBytes: Infinity },
{ mode: "streaming", streamingThresholdBytes: 0 },
])(
"bills a Codex request whose turn was interrupted before its token_count ($mode)",
async (options) => {
const path = NodePath.join(dir, "rollout.jsonl");
const usage = (input: number, output: number) => ({
input_tokens: input,
cached_input_tokens: 0,
cache_write_input_tokens: 0,
output_tokens: output,
reasoning_output_tokens: 0,
total_tokens: input + output,
});
const context = (turn: number) => ({
type: "turn_context",
timestamp: `2026-11-02T10:00:0${turn * 4 - 4}.000Z`,
payload: { turn_id: `turn-${turn}`, model: "gpt-6-sol" },
});
const request = (turn: number, id: number, timestamp: string, last: unknown) => ({
type: "token_usage_record",
timestamp,
payload: { turn_id: `turn-${turn}`, response_id: `resp_${id}`, usage: last },
});
const tokenCount = (timestamp: string, last: unknown, total: unknown) => ({
type: "event_msg",
timestamp,
payload: {
type: "token_count",
info: { last_token_usage: last, total_token_usage: total },
},
});
const lines = [
{
type: "session_meta",
timestamp: "2026-11-02T10:00:00.000Z",
payload: { id: "aborted-turn-repro", model_provider: "openai" },
},
context(1),
request(1, 1, "2026-11-02T10:00:01.000Z", usage(100, 20)),
tokenCount("2026-11-02T10:00:01.001Z", usage(100, 20), usage(100, 20)),
// Interrupted after this request finished: no token_count reports it.
request(1, 2, "2026-11-02T10:00:02.000Z", usage(150, 10)),
{
type: "event_msg",
timestamp: "2026-11-02T10:00:03.000Z",
payload: { type: "turn_aborted", turn_id: "turn-1", reason: "interrupted" },
},
context(2),
request(2, 3, "2026-11-02T10:00:05.000Z", usage(200, 30)),
tokenCount("2026-11-02T10:00:05.001Z", usage(200, 30), usage(450, 60)),
];
// Lines longer than a read chunk take the projected path when streaming.
const padding = "x".repeat(256 * 1024);
await NodeFSP.writeFile(
path,
lines.map((line) => `${JSON.stringify({ padding, ...line })}\n`).join(""),
);
const result = await readTranscriptRecords(path, TEST_FORMATS.codex, undefined, options);
assert.isNotNull(result);
const requests = [...result.records, ...result.tailRecords]
.map((record) => totalTokens(record.totals))
.toSorted((a, b) => a - b);
assert.deepStrictEqual(
{
billedTokens: requests.reduce((sum, tokens) => sum + tokens, 0),
requests,
malformedRecords: result.malformedRecords,
},
{ billedTokens: 510, requests: [120, 160, 230], malformedRecords: 0 },
);
},
);
it("re-parses from the start when the guard bytes no longer match", async () => {
const path = NodePath.join(dir, "claude.jsonl");
await NodeFSP.writeFile(path, claudeLine(1, 5));
const first = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(first);
await NodeFSP.writeFile(path, claudeLine(4, 13) + claudeLine(5, 17));
const second = await readTranscriptRecords(path, TEST_FORMATS.claude, first.position);
assert.isNotNull(second);
assert.isFalse(second.resumed);
assert.deepStrictEqual(
second.records.map((record) => record.totals.outputTokens),
[13, 17],
);
});
it("re-parses from the start when the file shrank below the resume point", async () => {
const path = NodePath.join(dir, "claude.jsonl");
await NodeFSP.writeFile(path, claudeLine(1, 5) + claudeLine(2, 7));
const first = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(first);
await NodeFSP.writeFile(path, claudeLine(3, 11));
const second = await readTranscriptRecords(path, TEST_FORMATS.claude, first.position);
assert.isNotNull(second);
assert.isFalse(second.resumed);
assert.deepStrictEqual(
second.records.map((record) => record.totals.outputTokens),
[11],
);
});
it("parses a line larger than one stream chunk", async () => {
const path = NodePath.join(dir, "claude.jsonl");
const bigLine = `${JSON.stringify({
type: "assistant",
timestamp: "2026-08-01T10:00:00Z",
requestId: "req_big",
sessionId: "session-1",
padding: "x".repeat(512 * 1024),
message: {
id: "msg_big",
model: "claude-fable-5",
usage: { input_tokens: 10, output_tokens: 42 },
},
})}\n`;
await NodeFSP.writeFile(path, bigLine + claudeLine(2, 7));
const parsed = await readTranscriptRecords(path, TEST_FORMATS.claude);
assert.isNotNull(parsed);
assert.deepStrictEqual(
parsed.records.map((record) => record.totals.outputTokens),
[42, 7],
);
});
it("keeps a CRLF Codex reducer line whose marker straddles a stream chunk", async () => {
const path = NodePath.join(dir, "rollout.jsonl");
const crlf = (line: string) => line.replace("\n", "\r\n");
const modelLine = crlf(codexModelLine("gpt-5.2-codex"));
const head = crlf(codexMetaLine());
const fillerBytes =
256 * 1024 - Buffer.byteLength(head) - modelLine.indexOf("turn_context") - 4;
const fillerEnvelope = crlf(`${JSON.stringify({ type: "response_item", output: "" })}\n`);
const padding = "é".repeat((fillerBytes - Buffer.byteLength(fillerEnvelope)) / 2);
const filler = crlf(`${JSON.stringify({ type: "response_item", output: padding })}\n`);
const content = head + filler + modelLine + crlf(codexUsageLine(40, 2));
await NodeFSP.writeFile(path, content);
const result = await readTranscriptRecords(path, TEST_FORMATS.codex);
assert.isNotNull(result);
assert.strictEqual(result.records.length, 1);
assert.strictEqual(result.records[0]?.model, "gpt-5.2-codex");
assert.strictEqual(result.records[0]?.sessionId, "codex-session-1");
assert.strictEqual(result.position.resumeOffset, Buffer.byteLength(content));
});
});
describe("transcriptLineGate", () => {
const gates = {
one: transcriptLineGate(['"usage"']),
several: transcriptLineGate(['"token_count"', '"session_meta"', '"a.b(c)"']),
};
const markers = { one: ['"usage"'], several: ['"token_count"', '"session_meta"', '"a.b(c)"'] };
it("matches markers beside multi-byte and malformed UTF-8", () => {
const invalid = Buffer.from([0xff, 0xc3]);
for (const kind of ["one", "several"] as const) {
for (const marker of markers[kind]) {
assert.isTrue(gates[kind](Buffer.from(`{"text":"日本語 é",${marker}:1}`)));
assert.isTrue(gates[kind](Buffer.concat([invalid, Buffer.from(marker), invalid])));
assert.isFalse(gates[kind](Buffer.from(`{"text":"日本語 é ${marker.slice(1, -1)}"}`)));
}
}
});
});