fix(signal): map stderr INFO to log
This commit is contained in:
23
src/signal/daemon.test.ts
Normal file
23
src/signal/daemon.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { classifySignalCliLogLine } from "./daemon.js";
|
||||
|
||||
describe("classifySignalCliLogLine", () => {
|
||||
it("treats INFO/DEBUG as log (even if emitted on stderr)", () => {
|
||||
expect(classifySignalCliLogLine("INFO DaemonCommand - Started")).toBe(
|
||||
"log",
|
||||
);
|
||||
expect(classifySignalCliLogLine("DEBUG Something")).toBe("log");
|
||||
});
|
||||
|
||||
it("treats WARN/ERROR as error", () => {
|
||||
expect(classifySignalCliLogLine("WARN Something")).toBe("error");
|
||||
expect(classifySignalCliLogLine("WARNING Something")).toBe("error");
|
||||
expect(classifySignalCliLogLine("ERROR Something")).toBe("error");
|
||||
});
|
||||
|
||||
it("returns null for empty lines", () => {
|
||||
expect(classifySignalCliLogLine("")).toBe(null);
|
||||
expect(classifySignalCliLogLine(" ")).toBe(null);
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,14 @@ export type SignalDaemonHandle = {
|
||||
stop: () => void;
|
||||
};
|
||||
|
||||
export function classifySignalCliLogLine(line: string): "log" | "error" | null {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) return null;
|
||||
// signal-cli commonly writes all logs to stderr; treat severity explicitly.
|
||||
if (/\b(ERROR|WARN|WARNING)\b/.test(trimmed)) return "error";
|
||||
return "log";
|
||||
}
|
||||
|
||||
function buildDaemonArgs(opts: SignalDaemonOpts): string[] {
|
||||
const args: string[] = [];
|
||||
if (opts.account) {
|
||||
@@ -46,12 +54,18 @@ export function spawnSignalDaemon(opts: SignalDaemonOpts): SignalDaemonHandle {
|
||||
const error = opts.runtime?.error ?? (() => {});
|
||||
|
||||
child.stdout?.on("data", (data) => {
|
||||
const text = data.toString().trim();
|
||||
if (text) log(`signal-cli: ${text}`);
|
||||
for (const line of data.toString().split(/\r?\n/)) {
|
||||
const kind = classifySignalCliLogLine(line);
|
||||
if (kind === "log") log(`signal-cli: ${line.trim()}`);
|
||||
else if (kind === "error") error(`signal-cli: ${line.trim()}`);
|
||||
}
|
||||
});
|
||||
child.stderr?.on("data", (data) => {
|
||||
const text = data.toString().trim();
|
||||
if (text) error(`signal-cli: ${text}`);
|
||||
for (const line of data.toString().split(/\r?\n/)) {
|
||||
const kind = classifySignalCliLogLine(line);
|
||||
if (kind === "log") log(`signal-cli: ${line.trim()}`);
|
||||
else if (kind === "error") error(`signal-cli: ${line.trim()}`);
|
||||
}
|
||||
});
|
||||
child.on("error", (err) => {
|
||||
error(`signal-cli spawn error: ${String(err)}`);
|
||||
|
||||
Reference in New Issue
Block a user