Skip to content
Open
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
5 changes: 5 additions & 0 deletions apps/memos-local-plugin/bridge.mts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ async function main(): Promise<void> {
pkgVersion,
hostLlmBridge: args.daemon ? null : lazyHostLlmBridge,
home: resolvedHome,
// Standalone bridge owns its stdio — initialize the logger from
// config.logging (timezone, level, channels, file sinks). Without this the
// logger stays on the bootstrap console default (tz pinned to "UTC"), which
// makes logging.timezone inert in the daemon.
initLogging: true,
});

const telemetry = new Telemetry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ interface SpawnResult {

function spawnBridge(
args: readonly string[],
options: { home: string; timeoutMs: number },
options: {
home: string;
timeoutMs: number;
/** Extra environment overrides (e.g. MEMOS_HOME). */
env?: Record<string, string>;
},
): Promise<SpawnResult> {
return new Promise((resolve, reject) => {
const proc = spawn(process.execPath, [BRIDGE_MJS, ...args], {
env: {
...process.env,
HOME: options.home,
...options.env,
},
stdio: ["pipe", "pipe", "pipe"],
});
Expand Down Expand Up @@ -128,3 +134,49 @@ describe("Issue #1736 — bridge ESM entry boots without CJS 'exports' error", (
}
}, 20_000);
});

describe("Issue #2399 — ESM bridge entry initializes file logging sinks", () => {
it("dist/bridge.mjs startup creates the config.logging file sinks under <home>/logs", async () => {
// The build step is a precondition for this test (same contract as the
// #1736 case above): skip silently when the artifact is missing.
if (!fs.existsSync(BRIDGE_MJS)) {
return;
}

const home = fs.mkdtempSync(path.join(os.tmpdir(), "memos-2399-"));
try {
// Pass the runtime home explicitly and pin it through both channels —
// MEMOS_HOME is what clobbers any developer shell export, and it
// outranks the --home flag in resolveHome's precedence (see
// core/config/paths.ts) — so the assertion target is deterministic:
// resolveHome("hermes", home).root === home, hence
// home.logsDir === <home>/logs.
const result = await spawnBridge(
["--agent=hermes", "--no-viewer", `--home=${home}`],
{ home, timeoutMs: 8_000, env: { MEMOS_HOME: home } },
);

// Environment tolerance, mirroring the #1736 test above: a missing
// better-sqlite3 native binding kills the bridge in a clean sandbox
// and is unrelated to this issue.
const combined = `${result.stdout}\n${result.stderr}`;
if (combined.includes("Could not locate the bindings file")) {
return;
}

// The standalone ESM entry owns its stdio and must therefore bootstrap
// the global logger from config.logging — the legacy CJS entry
// (bridge.cts) already passes `initLogging: true`, but bridge.mts never
// did. Because the transports open their files eagerly during
// initLogger (before any downstream work), the sinks are a
// deterministic post-fix marker: no timing sensitivity.
expect(
fs.existsSync(path.join(home, "logs", "memos.log")),
`expected a file sink at ${path.join(home, "logs", "memos.log")} after startup; stderr:\n${result.stderr}`,
).toBe(true);
expect(fs.existsSync(path.join(home, "logs", "error.log"))).toBe(true);
} finally {
fs.rmSync(home, { recursive: true, force: true });
}
}, 20_000);
});
Loading