Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFS from "node:fs";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5
6import { ThreadId } from "@t3tools/contracts";
7import { assert, describe, it } from "@effect/vitest";
8import * as Clock from "effect/Clock";
9import * as Effect from "effect/Effect";
10import * as Fiber from "effect/Fiber";
11import * as Logger from "effect/Logger";
12import * as Schema from "effect/Schema";
13import * as TestClock from "effect/testing/TestClock";
14
15import * as ResourceAttribution from "../../resourceTelemetry/ResourceAttribution.ts";
16import {
17 makeEventNdjsonLogger,
18 makeEventNdjsonLogStore,
19 type PendingRecord,
20 writeBatchedMessages,
21} from "./EventNdjsonLogger.ts";
22
23const encodeUnknownJson = Schema.encodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
24
25function ownedLogPath(basePath: string, segment: string): string {
26 const basename = NodePath.basename(basePath);
27 const extension = NodePath.extname(basename);
28 const stem = extension.length > 0 ? basename.slice(0, -extension.length) : basename;
29 return NodePath.join(NodePath.dirname(basePath), `${stem}.${segment}.log`);
30}
31
32function parseLogLine(line: string) {
33 const match = /^\[([^\]]+)\] ([A-Z]+): (.+)$/.exec(line);
34 assert.notEqual(match, null);
35 if (!match) {
36 throw new Error(`invalid log line: ${line}`);
37 }
38 const observedAt = match[1];
39 const stream = match[2];
40 const payload = match[3];
41 if (!observedAt || !stream || payload === undefined) {
42 throw new Error(`invalid log line: ${line}`);
43 }
44 return {
45 observedAt,
46 stream,
47 payload,
48 };
49}
50
51describe("EventNdjsonLogger", () => {
52 it.effect("logs bounded diagnostics when an event cannot be serialized", () => {
53 const messages: Array<unknown> = [];
54 const logCapture = Logger.make<unknown, void>(({ message }) => {
55 if (Array.isArray(message)) {
56 messages.push(...message);
57 } else {
58 messages.push(message);
59 }
60 });
61 const secret = "secret-circular-event-value";
62
63 return Effect.gen(function* () {
64 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
65 const basePath = NodePath.join(tempDir, "provider-native.ndjson");
66 const circular: Record<string, unknown> = { secret };
67 circular.self = circular;
68
69 try {
70 const logger = yield* makeEventNdjsonLogger(basePath, { stream: "native" });
71 assert.exists(logger);
72 if (!logger) return;
73 yield* logger.write(circular, ThreadId.make("thread-1"));
74
75 const serialized = encodeUnknownJson(messages);
76 assert.notInclude(serialized, secret);
77 assert.include(serialized, '"errorTag":"SchemaError"');
78 } finally {
79 NodeFS.rmSync(tempDir, { recursive: true, force: true });
80 }
81 }).pipe(Effect.provide(Logger.layer([logCapture], { mergeWithExisting: false })));
82 });
83
84 it.effect("writes effect-style lines to thread-scoped files", () =>
85 Effect.gen(function* () {
86 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
87 const basePath = NodePath.join(tempDir, "provider-native.ndjson");
88
89 try {
90 const logger = yield* makeEventNdjsonLogger(basePath, { stream: "native" });
91 assert.notEqual(logger, undefined);
92 if (!logger) {
93 return;
94 }
95
96 yield* logger.write(
97 { threadId: "provider-thread-1", id: "evt-1" },
98 ThreadId.make("thread-1"),
99 );
100 yield* logger.write(
101 { type: "turn.completed", threadId: "provider-thread-2", id: "evt-2" },
102 ThreadId.make("thread-2"),
103 );
104 yield* logger.close();
105
106 const threadOnePath = ownedLogPath(basePath, "thread-1");
107 const threadTwoPath = ownedLogPath(basePath, "thread-2");
108 assert.equal(NodeFS.existsSync(threadOnePath), true);
109 assert.equal(NodeFS.existsSync(threadTwoPath), true);
110
111 const first = parseLogLine(NodeFS.readFileSync(threadOnePath, "utf8").trim());
112 const second = parseLogLine(NodeFS.readFileSync(threadTwoPath, "utf8").trim());
113
114 assert.equal(Number.isNaN(Date.parse(first.observedAt)), false);
115 assert.equal(first.stream, "NTIVE");
116 assert.equal(first.payload, '{"threadId":"provider-thread-1","id":"evt-1"}');
117
118 assert.equal(Number.isNaN(Date.parse(second.observedAt)), false);
119 assert.equal(second.stream, "NTIVE");
120 assert.equal(
121 second.payload,
122 '{"type":"turn.completed","threadId":"provider-thread-2","id":"evt-2"}',
123 );
124 } finally {
125 NodeFS.rmSync(tempDir, { recursive: true, force: true });
126 }
127 }),
128 );
129
130 it.effect(
131 "falls back to a global segment when orchestration thread id is missing or invalid",
132 () =>
133 Effect.gen(function* () {
134 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
135 const basePath = NodePath.join(tempDir, "provider-canonical.ndjson");
136
137 try {
138 const logger = yield* makeEventNdjsonLogger(basePath, { stream: "orchestration" });
139 assert.notEqual(logger, undefined);
140 if (!logger) {
141 return;
142 }
143
144 yield* logger.write({ id: "evt-no-thread" }, null);
145 yield* logger.write({ id: "evt-invalid-thread" }, "!!!" as unknown as ThreadId);
146 yield* logger.close();
147
148 const globalPath = ownedLogPath(basePath, "_global");
149 assert.equal(NodeFS.existsSync(globalPath), true);
150 const lines = NodeFS.readFileSync(globalPath, "utf8")
151 .trim()
152 .split("\n")
153 .map((line) => parseLogLine(line));
154 assert.equal(lines.length, 2);
155 assert.equal(Number.isNaN(Date.parse(lines[0]?.observedAt ?? "")), false);
156 assert.equal(Number.isNaN(Date.parse(lines[1]?.observedAt ?? "")), false);
157 assert.equal(lines[0]?.stream, "ORCH");
158 assert.equal(lines[0]?.payload, '{"id":"evt-no-thread"}');
159 assert.equal(lines[1]?.stream, "ORCH");
160 assert.equal(lines[1]?.payload, '{"id":"evt-invalid-thread"}');
161 } finally {
162 NodeFS.rmSync(tempDir, { recursive: true, force: true });
163 }
164 }),
165 );
166
167 it.effect("shares one thread writer across native and canonical streams", () =>
168 Effect.gen(function* () {
169 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
170 const basePath = NodePath.join(tempDir, "events.log");
171
172 try {
173 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
174 const native = store.logger("native");
175 const canonical = store.logger("canonical");
176 const threadId = ThreadId.make("thread-shared");
177
178 yield* native.write({ id: "native-event" }, threadId);
179 yield* canonical.write({ type: "item.completed", id: "canonical-event" }, threadId);
180 yield* store.close();
181
182 const lines = NodeFS.readFileSync(ownedLogPath(basePath, "thread-shared"), "utf8")
183 .trim()
184 .split("\n")
185 .map(parseLogLine);
186
187 assert.deepEqual(
188 lines.map(({ stream, payload }) => ({ stream, payload })),
189 [
190 { stream: "NTIVE", payload: '{"id":"native-event"}' },
191 {
192 stream: "CANON",
193 payload: '{"type":"item.completed","id":"canonical-event"}',
194 },
195 ],
196 );
197 } finally {
198 NodeFS.rmSync(tempDir, { recursive: true, force: true });
199 }
200 }),
201 );
202
203 it.effect("keeps shared store views non-owning when one adapter closes", () =>
204 Effect.gen(function* () {
205 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
206 const basePath = NodePath.join(tempDir, "events.log");
207
208 try {
209 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
210 const native = store.logger("native");
211 const canonical = store.logger("canonical");
212 const threadId = ThreadId.make("thread-shared-close");
213
214 yield* native.write({ id: "before-close" }, threadId);
215 yield* native.close();
216 yield* canonical.write({ type: "item.completed", id: "after-close" }, threadId);
217 yield* store.close();
218
219 const lines = NodeFS.readFileSync(ownedLogPath(basePath, "thread-shared-close"), "utf8")
220 .trim()
221 .split("\n")
222 .map(parseLogLine);
223
224 assert.deepEqual(
225 lines.map(({ stream, payload }) => ({ stream, payload })),
226 [
227 { stream: "NTIVE", payload: '{"id":"before-close"}' },
228 {
229 stream: "CANON",
230 payload: '{"type":"item.completed","id":"after-close"}',
231 },
232 ],
233 );
234 } finally {
235 NodeFS.rmSync(tempDir, { recursive: true, force: true });
236 }
237 }),
238 );
239
240 it.effect("flushes an active batch without a permanent polling loop", () =>
241 Effect.gen(function* () {
242 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
243 const basePath = NodePath.join(tempDir, "events.log");
244 const threadPath = ownedLogPath(basePath, "thread-batched");
245
246 try {
247 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 1_000 });
248 yield* store
249 .logger("native")
250 .write({ id: "batched-event" }, ThreadId.make("thread-batched"));
251
252 assert.equal(NodeFS.existsSync(threadPath), false);
253 yield* TestClock.adjust(1_000);
254 assert.equal(NodeFS.existsSync(threadPath), true);
255 yield* store.close();
256 } finally {
257 NodeFS.rmSync(tempDir, { recursive: true, force: true });
258 }
259 }),
260 );
261
262 it.effect("does not strand a later batch after an interrupted write", () =>
263 Effect.gen(function* () {
264 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
265 const basePath = NodePath.join(tempDir, "events.log");
266 const threadPath = ownedLogPath(basePath, "thread-interrupted");
267
268 try {
269 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 1_000 });
270 const logger = store.logger("native");
271 const interruptedWrite = yield* logger
272 .write({ id: "possibly-interrupted" }, ThreadId.make("thread-interrupted"))
273 .pipe(Effect.forkChild);
274 yield* Effect.yieldNow;
275 yield* Fiber.interrupt(interruptedWrite);
276 yield* logger.write({ id: "accepted" }, ThreadId.make("thread-interrupted"));
277
278 yield* TestClock.adjust(1_000);
279
280 assert.equal(NodeFS.existsSync(threadPath), true);
281 assert.include(NodeFS.readFileSync(threadPath, "utf8"), '{"id":"accepted"}');
282 yield* store.close();
283 } finally {
284 NodeFS.rmSync(tempDir, { recursive: true, force: true });
285 }
286 }),
287 );
288
289 it.effect("drops transient provider events before serialization", () =>
290 Effect.gen(function* () {
291 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
292 const basePath = NodePath.join(tempDir, "events.log");
293
294 try {
295 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
296 const canonical = store.logger("canonical");
297 const native = store.logger("native");
298 const threadId = ThreadId.make("thread-filtered");
299 const circularDelta: Record<string, unknown> = { type: "content.delta" };
300 circularDelta["self"] = circularDelta;
301
302 yield* canonical.write(circularDelta, threadId);
303 yield* canonical.write({ type: "item.completed", id: "final" }, threadId);
304 yield* native.write({ type: "content.delta", id: "native-delta" }, threadId);
305 yield* native.write(
306 { method: "item/agentMessage/delta", payload: circularDelta },
307 threadId,
308 );
309 yield* native.write(
310 { method: "thread/realtime/outputAudio/delta", payload: circularDelta },
311 threadId,
312 );
313 yield* native.write(
314 { method: "thread/realtime/transcript/delta", payload: circularDelta },
315 threadId,
316 );
317 yield* native.write(
318 {
319 event: {
320 method: "claude/stream_event/content_block_delta/text_delta",
321 payload: circularDelta,
322 },
323 },
324 threadId,
325 );
326 yield* native.write(
327 {
328 event: {
329 method: "session/update",
330 payload: { update: { sessionUpdate: "agent_message_chunk" } },
331 },
332 },
333 threadId,
334 );
335 yield* native.write(
336 {
337 event: {
338 type: "message.part.updated",
339 payload: { properties: { part: { type: "text" } } },
340 },
341 },
342 threadId,
343 );
344 yield* native.write(
345 {
346 event: {
347 type: "message.part.updated",
348 payload: {
349 properties: {
350 part: { type: "tool", state: { status: "running", output: "progress" } },
351 },
352 },
353 },
354 },
355 threadId,
356 );
357 yield* native.write({ type: "turn.completed", id: "native-final" }, threadId);
358 yield* store.close();
359
360 const lines = NodeFS.readFileSync(ownedLogPath(basePath, "thread-filtered"), "utf8")
361 .trim()
362 .split("\n")
363 .map(parseLogLine);
364
365 assert.deepEqual(
366 lines.map(({ stream, payload }) => ({ stream, payload })),
367 [
368 { stream: "CANON", payload: '{"type":"item.completed","id":"final"}' },
369 { stream: "NTIVE", payload: '{"type":"turn.completed","id":"native-final"}' },
370 ],
371 );
372 } finally {
373 NodeFS.rmSync(tempDir, { recursive: true, force: true });
374 }
375 }),
376 );
377
378 it.effect("keeps OpenCode tool input, final output, and errors in native logs", () =>
379 Effect.gen(function* () {
380 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
381 const basePath = NodePath.join(tempDir, "events.log");
382 const threadId = ThreadId.make("thread-tool-lifecycle");
383
384 try {
385 const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
386 const native = store.logger("native");
387 const input = { command: "run-build" };
388 const states = [
389 { status: "pending", input },
390 { status: "completed", input, output: "Build complete", time: { start: 1, end: 2 } },
391 { status: "error", input, error: "Build failed", time: { start: 3, end: 4 } },
392 { status: "unknown", input },
393 null,
394 ];
395 const events = states.map((state) => ({
396 event: {
397 type: "message.part.updated",
398 payload: { properties: { part: { type: "tool", state } } },
399 },
400 }));
401 for (const event of events) {
402 yield* native.write(event, threadId);
403 }
404 yield* store.close();
405
406 const payloads = NodeFS.readFileSync(
407 ownedLogPath(basePath, "thread-tool-lifecycle"),
408 "utf8",
409 )
410 .trim()
411 .split("\n")
412 .map((line) => parseLogLine(line).payload);
413 assert.deepEqual(
414 payloads,
415 events.map((event) => encodeUnknownJson(event)),
416 );
417 } finally {
418 NodeFS.rmSync(tempDir, { recursive: true, force: true });
419 }
420 }),
421 );
422
423 it.effect("contains hostile event accessors inside guarded serialization", () =>
424 Effect.gen(function* () {
425 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
426 const basePath = NodePath.join(tempDir, "events.log");
427
428 try {
429 const logger = yield* makeEventNdjsonLogger(basePath, {
430 stream: "canonical",
431 batchWindowMs: 0,
432 });
433 assert.exists(logger);
434 if (!logger) return;
435 const hostile = new Proxy(
436 { id: "hostile" },
437 {
438 get(_target, property) {
439 if (property === "type") throw new Error("blocked");
440 return undefined;
441 },
442 },
443 );
444
445 yield* logger.write(hostile, ThreadId.make("thread-hostile"));
446 yield* logger.close();
447
448 const contents = NodeFS.readFileSync(ownedLogPath(basePath, "thread-hostile"), "utf8");
449 assert.notInclude(contents, "blocked");
450 } finally {
451 NodeFS.rmSync(tempDir, { recursive: true, force: true });
452 }
453 }),
454 );
455
456 it.effect("serializes concurrent first writes for the same segment", () =>
457 Effect.gen(function* () {
458 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
459 const basePath = NodePath.join(tempDir, "provider-canonical.ndjson");
460
461 try {
462 const logger = yield* makeEventNdjsonLogger(basePath, {
463 stream: "canonical",
464 batchWindowMs: 0,
465 });
466 assert.notEqual(logger, undefined);
467 if (!logger) {
468 return;
469 }
470
471 yield* Effect.all(
472 [
473 logger.write({ id: "evt-concurrent-1" }, null),
474 logger.write({ id: "evt-concurrent-2" }, null),
475 ],
476 { concurrency: "unbounded" },
477 );
478 yield* logger.close();
479
480 const globalPath = ownedLogPath(basePath, "_global");
481 assert.equal(NodeFS.existsSync(globalPath), true);
482 const lines = NodeFS.readFileSync(globalPath, "utf8")
483 .trim()
484 .split("\n")
485 .map((line) => parseLogLine(line));
486
487 assert.equal(lines.length, 2);
488 assert.deepEqual(lines.map((line) => line.payload).toSorted(), [
489 '{"id":"evt-concurrent-1"}',
490 '{"id":"evt-concurrent-2"}',
491 ]);
492 } finally {
493 NodeFS.rmSync(tempDir, { recursive: true, force: true });
494 }
495 }),
496 );
497
498 it.effect("rotates per-thread files when max size is exceeded", () =>
499 Effect.gen(function* () {
500 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
501 const basePath = NodePath.join(tempDir, "provider-native.ndjson");
502
503 try {
504 const store = yield* makeEventNdjsonLogStore(basePath, {
505 maxBytes: 120,
506 maxFiles: 2,
507 batchWindowMs: 0,
508 });
509 const native = store.logger("native");
510 const canonical = store.logger("canonical");
511
512 for (let index = 0; index < 10; index += 1) {
513 const logger = index % 2 === 0 ? native : canonical;
514 yield* logger.write(
515 {
516 type: "session.started",
517 threadId: "provider-thread-rotate",
518 id: `evt-${index}`,
519 payload: "x".repeat(40),
520 },
521 ThreadId.make("thread-rotate"),
522 );
523 }
524 yield* store.close();
525
526 const fileStem = NodePath.basename(ownedLogPath(basePath, "thread-rotate"));
527 const matchingFiles = NodeFS.readdirSync(tempDir)
528 .filter((entry) => entry === fileStem || entry.startsWith(`${fileStem}.`))
529 .toSorted();
530
531 assert.equal(
532 matchingFiles.some((entry) => entry === `${fileStem}.1`),
533 true,
534 );
535 assert.equal(
536 matchingFiles.some((entry) => entry === fileStem || entry === `${fileStem}.2`),
537 true,
538 );
539 assert.equal(
540 matchingFiles.some((entry) => entry === `${fileStem}.3`),
541 false,
542 );
543 } finally {
544 NodeFS.rmSync(tempDir, { recursive: true, force: true });
545 }
546 }),
547 );
548
549 it.effect("enforces aggregate age and byte retention on startup", () =>
550 Effect.gen(function* () {
551 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
552 const basePath = NodePath.join(tempDir, "events.log");
553 const expiredPath = ownedLogPath(basePath, "expired");
554 const oldPath = ownedLogPath(basePath, "old");
555 const newPath = ownedLogPath(basePath, "new");
556 const unrelatedLogPath = NodePath.join(tempDir, "unrelated.log");
557 const legacyLogPath = NodePath.join(tempDir, "legacy-thread.log");
558 const ignoredPath = NodePath.join(tempDir, "ignored.txt");
559
560 try {
561 yield* TestClock.setTime(1_800_000_000_000);
562 const now = yield* Clock.currentTimeMillis;
563 for (const filePath of [expiredPath, oldPath, newPath, unrelatedLogPath, ignoredPath]) {
564 NodeFS.writeFileSync(filePath, "x".repeat(40));
565 }
566 NodeFS.writeFileSync(
567 legacyLogPath,
568 "[2026-01-01T00:00:00.000Z] CANON: legacy provider event\n",
569 );
570 NodeFS.utimesSync(expiredPath, (now - 20_000) / 1_000, (now - 20_000) / 1_000);
571 NodeFS.utimesSync(legacyLogPath, (now - 20_000) / 1_000, (now - 20_000) / 1_000);
572 NodeFS.utimesSync(oldPath, (now - 5_000) / 1_000, (now - 5_000) / 1_000);
573 NodeFS.utimesSync(newPath, now / 1_000, now / 1_000);
574
575 const store = yield* makeEventNdjsonLogStore(basePath, {
576 maxAgeMs: 10_000,
577 maxTotalBytes: 60,
578 });
579 yield* store.close();
580
581 assert.equal(NodeFS.existsSync(expiredPath), false);
582 assert.equal(NodeFS.existsSync(legacyLogPath), false);
583 assert.equal(NodeFS.existsSync(oldPath), false);
584 assert.equal(NodeFS.existsSync(newPath), true);
585 assert.equal(NodeFS.existsSync(unrelatedLogPath), true);
586 assert.equal(NodeFS.existsSync(ignoredPath), true);
587 } finally {
588 NodeFS.rmSync(tempDir, { recursive: true, force: true });
589 }
590 }),
591 );
592
593 it.effect("does not prune an active thread sink during an unrelated flush", () =>
594 Effect.gen(function* () {
595 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
596 const basePath = NodePath.join(tempDir, "events.log");
597 const activePath = ownedLogPath(basePath, "active");
598
599 try {
600 yield* TestClock.setTime(1_800_000_000_000);
601 const store = yield* makeEventNdjsonLogStore(basePath, {
602 batchWindowMs: 0,
603 maxAgeMs: 1,
604 retentionCheckIntervalMs: 1,
605 });
606 const logger = store.logger("native");
607
608 yield* logger.write({ id: "active-before-retention" }, ThreadId.make("active"));
609 assert.equal(NodeFS.existsSync(activePath), true);
610
611 yield* TestClock.adjust("2 millis");
612 yield* logger.write({ id: "retention-trigger" }, ThreadId.make("other"));
613
614 assert.equal(NodeFS.existsSync(activePath), true);
615 yield* store.close();
616 } finally {
617 NodeFS.rmSync(tempDir, { recursive: true, force: true });
618 }
619 }),
620 );
621
622 it("attributes batches that were written before a later chunk fails", () => {
623 const records: ReadonlyArray<PendingRecord> = [
624 {
625 stream: "native",
626 threadSegment: "thread",
627 line: "first",
628 bytes: 5,
629 },
630 {
631 stream: "canonical",
632 threadSegment: "thread",
633 line: "second",
634 bytes: 6,
635 },
636 ];
637 const attributed: Array<PendingRecord> = [];
638 let writes = 0;
639
640 assert.throws(() =>
641 writeBatchedMessages(
642 {
643 write: () => {
644 writes += 1;
645 if (writes === 2) throw new Error("simulated disk exhaustion");
646 },
647 },
648 records,
649 5,
650 (written) => attributed.push(...written),
651 ),
652 );
653 assert.deepEqual(attributed, [records[0]]);
654 });
655
656 it.effect("reports logical provider log writes to resource attribution", () =>
657 Effect.gen(function* () {
658 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
659 const basePath = NodePath.join(tempDir, "provider-native.ndjson");
660
661 try {
662 const attribution = yield* ResourceAttribution.make();
663 const logger = yield* makeEventNdjsonLogger(basePath, {
664 stream: "native",
665 batchWindowMs: 0,
666 attribution,
667 });
668 assert.notEqual(logger, undefined);
669 if (!logger) {
670 return;
671 }
672
673 yield* logger.write({ id: "attributed-event" }, ThreadId.make("thread-attribution"));
674 yield* logger.close();
675
676 const snapshot = yield* attribution.snapshot;
677 assert.equal(snapshot.entries.length, 1);
678 assert.equal(snapshot.entries[0]?.component, "provider-event-log");
679 assert.equal(snapshot.entries[0]?.operation, "native.append");
680 assert.equal(snapshot.entries[0]?.count, 1);
681 assert.isAbove(snapshot.entries[0]?.logicalWriteBytes ?? 0, 0);
682 } finally {
683 NodeFS.rmSync(tempDir, { recursive: true, force: true });
684 }
685 }),
686 );
687});