authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-03 18:20:17-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-03 18:22:29-08:00
log0c5be023e4b07c891d117937e966823ce3b109d2
tree697026f42ca69f4c4961ccf7c535433251e89f8c
parent86e87a8789196663e5e919466676566dadb32f20

fix test


1 files changed, 45 insertions(+), 37 deletions(-)

apps/server/src/provider/Layers/EventNdjsonLogger.test.ts+45-37
......@@ -59,11 +59,11 @@ describe("EventNdjsonLogger", () => {
5959 const second = parseLogLine(fs.readFileSync(threadTwoPath, "utf8").trim());
6060
6161 assert.equal(Number.isNaN(Date.parse(first.observedAt)), false);
62 assert.equal(first.stream, "NATIVE");
62 assert.equal(first.stream, "NTIVE");
6363 assert.equal(first.payload, '{"threadId":"provider-thread-1","id":"evt-1"}');
6464
6565 assert.equal(Number.isNaN(Date.parse(second.observedAt)), false);
66 assert.equal(second.stream, "NATIVE");
66 assert.equal(second.stream, "NTIVE");
6767 assert.equal(
6868 second.payload,
6969 '{"type":"turn.completed","threadId":"provider-thread-2","id":"evt-2"}',
......@@ -74,40 +74,42 @@ describe("EventNdjsonLogger", () => {
7474 }),
7575 );
7676
77 it.effect("falls back to a global segment when orchestration thread id is missing or invalid", () =>
78 Effect.gen(function* () {
79 const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-provider-log-"));
80 const basePath = path.join(tempDir, "provider-canonical.ndjson");
81
82 try {
83 const logger = yield* makeEventNdjsonLogger(basePath, { stream: "orchestration" });
84 assert.notEqual(logger, undefined);
85 if (!logger) {
86 return;
77 it.effect(
78 "falls back to a global segment when orchestration thread id is missing or invalid",
79 () =>
80 Effect.gen(function* () {
81 const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-provider-log-"));
82 const basePath = path.join(tempDir, "provider-canonical.ndjson");
83
84 try {
85 const logger = yield* makeEventNdjsonLogger(basePath, { stream: "orchestration" });
86 assert.notEqual(logger, undefined);
87 if (!logger) {
88 return;
89 }
90
91 yield* logger.write({ id: "evt-no-thread" }, null);
92 yield* logger.write({ id: "evt-invalid-thread" }, "!!!" as unknown as ThreadId);
93 yield* logger.close();
94
95 const globalPath = path.join(tempDir, "_global.log");
96 assert.equal(fs.existsSync(globalPath), true);
97 const lines = fs
98 .readFileSync(globalPath, "utf8")
99 .trim()
100 .split("\n")
101 .map((line) => parseLogLine(line));
102 assert.equal(lines.length, 2);
103 assert.equal(Number.isNaN(Date.parse(lines[0]?.observedAt ?? "")), false);
104 assert.equal(Number.isNaN(Date.parse(lines[1]?.observedAt ?? "")), false);
105 assert.equal(lines[0]?.stream, "CANON");
106 assert.equal(lines[0]?.payload, '{"id":"evt-no-thread"}');
107 assert.equal(lines[1]?.stream, "CANON");
108 assert.equal(lines[1]?.payload, '{"id":"evt-invalid-thread"}');
109 } finally {
110 fs.rmSync(tempDir, { recursive: true, force: true });
87111 }
88
89 yield* logger.write({ id: "evt-no-thread" }, null);
90 yield* logger.write({ id: "evt-invalid-thread" }, "!!!" as unknown as ThreadId);
91 yield* logger.close();
92
93 const globalPath = path.join(tempDir, "_global.log");
94 assert.equal(fs.existsSync(globalPath), true);
95 const lines = fs
96 .readFileSync(globalPath, "utf8")
97 .trim()
98 .split("\n")
99 .map((line) => parseLogLine(line));
100 assert.equal(lines.length, 2);
101 assert.equal(Number.isNaN(Date.parse(lines[0]?.observedAt ?? "")), false);
102 assert.equal(Number.isNaN(Date.parse(lines[1]?.observedAt ?? "")), false);
103 assert.equal(lines[0]?.stream, "ORCHESTRATION");
104 assert.equal(lines[0]?.payload, '{"id":"evt-no-thread"}');
105 assert.equal(lines[1]?.stream, "ORCHESTRATION");
106 assert.equal(lines[1]?.payload, '{"id":"evt-invalid-thread"}');
107 } finally {
108 fs.rmSync(tempDir, { recursive: true, force: true });
109 }
110 }),
112 }),
111113 );
112114
113115 it.effect("rotates per-thread files when max size is exceeded", () =>
......@@ -144,12 +146,18 @@ describe("EventNdjsonLogger", () => {
144146 .filter((entry) => entry === fileStem || entry.startsWith(`${fileStem}.`))
145147 .toSorted();
146148
147 assert.equal(matchingFiles.some((entry) => entry === `${fileStem}.1`), true);
149 assert.equal(
150 matchingFiles.some((entry) => entry === `${fileStem}.1`),
151 true,
152 );
148153 assert.equal(
149154 matchingFiles.some((entry) => entry === fileStem || entry === `${fileStem}.2`),
150155 true,
151156 );
152 assert.equal(matchingFiles.some((entry) => entry === `${fileStem}.3`), false);
157 assert.equal(
158 matchingFiles.some((entry) => entry === `${fileStem}.3`),
159 false,
160 );
153161 } finally {
154162 fs.rmSync(tempDir, { recursive: true, force: true });
155163 }