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
4 changes: 3 additions & 1 deletion apps/memos-local-plugin/bridge.cts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const path = require("node:path") as typeof import("node:path");
// eslint-disable-next-line @typescript-eslint/no-require-imports
const fs = require("node:fs") as typeof import("node:fs");
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { homedir } = require("node:os") as typeof import("node:os");
// eslint-disable-next-line @typescript-eslint/no-require-imports
const childProcess = require("node:child_process") as typeof import("node:child_process");
// eslint-disable-next-line @typescript-eslint/no-require-imports
const url = require("node:url") as typeof import("node:url");
Expand Down Expand Up @@ -95,7 +97,7 @@ const STDIO_PID_FILENAME = "bridge-stdio.pid";
function pidFilePath(agent: string, filename: string = PID_FILENAME): string {
const agentHome = agent === "hermes" ? ".hermes" : ".openclaw";
return path.join(
process.env.HOME ?? "/tmp",
homedir(),
agentHome,
"memos-plugin",
"daemon",
Expand Down
3 changes: 2 additions & 1 deletion apps/memos-local-plugin/bridge.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
import * as childProcess from "node:child_process";
import * as fs from "node:fs";
import { homedir } from "node:os";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

Expand Down Expand Up @@ -81,7 +82,7 @@ const PID_FILENAME = "bridge.pid";
function pidFilePath(agent: string): string {
const agentHome = agent === "hermes" ? ".hermes" : ".openclaw";
return path.join(
process.env.HOME ?? "/tmp",
homedir(),
agentHome,
"memos-plugin",
"daemon",
Expand Down
21 changes: 21 additions & 0 deletions apps/memos-local-plugin/tests/unit/bridge/pid-file-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";

import { describe, expect, it } from "vitest";

describe("bridge PID file path", () => {
for (const entry of ["bridge.cts", "bridge.mts"]) {
it(`${entry} resolves the PID directory from the OS home`, () => {
const source = readFileSync(resolve(entry), "utf8");
const start = source.indexOf("function pidFilePath");
const end = source.indexOf("function readPidFile", start);

expect(start, `${entry}: pidFilePath() not found`).toBeGreaterThanOrEqual(0);
expect(end, `${entry}: readPidFile() not found`).toBeGreaterThan(start);

const pidFilePathSource = source.slice(start, end);
expect(pidFilePathSource).toMatch(/\bhomedir\(\)/);
expect(pidFilePathSource).not.toMatch(/process\.env\.HOME|["']\/tmp["']/);
});
}
});