Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/discord-bot/src/features/Alerts.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// @effect-diagnostics nodeBuiltinImport:off
import * as NodeChildProcess from "node:child_process";
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";

import * as Cause from "effect/Cause";
import { describe, expect, it, vi } from "vite-plus/test";

Expand All @@ -12,6 +18,7 @@ import {
fatalAlertDelivery,
formatAlertCause,
isExpectedSessionLastError,
listSessionErrors,
selectSessionErrorsForAlert,
sessionErrorAlertDelivery,
sessionErrorAlertKey,
Expand Down Expand Up @@ -82,6 +89,38 @@ describe("formatAlertCause", () => {
});

describe("Discord alert content", () => {
it("reads the complete persisted session error before attaching it", () => {
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-alert-trace-"));
const dbPath = NodePath.join(tempDir, "state.sqlite");
const trace = `Error: Invalid params\n${" at decodeFrame (file:///long/path.js:1:1)\n".repeat(80)}`;

try {
NodeChildProcess.execFileSync(
"python3",
[
"-c",
[
"import sqlite3, sys",
"db = sqlite3.connect(sys.argv[1])",
"db.execute('CREATE TABLE projection_thread_sessions (thread_id TEXT, last_error TEXT, status TEXT, updated_at TEXT)')",
"db.execute('INSERT INTO projection_thread_sessions VALUES (?, ?, ?, ?)', ('thread-1', sys.argv[2], 'error', '2026-07-28T00:00:00Z'))",
"db.commit()",
].join("\n"),
dbPath,
trace,
],
{ encoding: "utf8" },
);

expect(trace.length).toBeGreaterThan(300);
expect(listSessionErrors(dbPath)).toEqual([
{ threadId: "thread-1", lastError: trace, status: "error" },
]);
} finally {
NodeFS.rmSync(tempDir, { recursive: true, force: true });
}
});

it("attaches the complete T3 session stack as one text file", () => {
const trace = [
"Error: Invalid params",
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/features/Alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ print(json.dumps(out))
return (parsed as Array<{ threadId: string; turnId: string; ageMin: number }>) ?? [];
}

function listSessionErrors(dbPath: string): ReadonlyArray<{
export function listSessionErrors(dbPath: string): ReadonlyArray<{
threadId: string;
lastError: string;
status: string | null;
Expand All @@ -569,7 +569,7 @@ cur = db.execute(
"ORDER BY updated_at DESC LIMIT 40"
)
print(json.dumps([
{"threadId": r[0], "lastError": (r[1] or "")[:300], "status": r[2]}
{"threadId": r[0], "lastError": r[1] or "", "status": r[2]}
for r in cur
]))
`,
Expand Down