96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
/**
|
|
* Regression tests for Telegram bridge path resolution
|
|
* Guards agent-dir detection for Pi-compatible runtimes and path derivation helpers.
|
|
*/
|
|
|
|
import assert from "node:assert/strict";
|
|
import { homedir } from "node:os";
|
|
import { join, resolve } from "node:path";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
resolveAgentDir,
|
|
resolveTelegramConfigPath,
|
|
resolveTelegramLocksPath,
|
|
resolveTelegramTempDir,
|
|
resolveTelegramRuntimeLogPath,
|
|
getTelegramDiagnosticsDisplayPaths,
|
|
resolveTelegramProfileTempFilePath,
|
|
} from "../lib/paths.ts";
|
|
|
|
test("Diagnostics use the resolved agent root and profile suffix", () => {
|
|
const agentDir = resolveAgentDir();
|
|
for (const profile of [undefined, "work"]) {
|
|
assert.deepEqual(getTelegramDiagnosticsDisplayPaths(profile), {
|
|
state: resolveTelegramProfileTempFilePath("state", "json", agentDir, profile),
|
|
logs: resolveTelegramProfileTempFilePath("logs", "jsonl", agentDir, profile),
|
|
});
|
|
}
|
|
});
|
|
|
|
await test("resolveAgentDir", async (t) => {
|
|
await t.test("returns PI_CODING_AGENT_DIR when env is set", () => {
|
|
assert.equal(
|
|
resolveAgentDir({
|
|
env: { PI_CODING_AGENT_DIR: "/custom/agent/dir" },
|
|
execPath: "/usr/bin/omp",
|
|
argv: ["omp"],
|
|
}),
|
|
resolve("/custom/agent/dir"),
|
|
);
|
|
});
|
|
|
|
await t.test("returns ~/.omp/agent for OMP-compatible runtimes", () => {
|
|
assert.equal(
|
|
resolveAgentDir({ env: {}, execPath: "/home/user/.local/bin/omp" }),
|
|
join(homedir(), ".omp", "agent"),
|
|
);
|
|
assert.equal(
|
|
resolveAgentDir({
|
|
env: {},
|
|
execPath: "/usr/bin/node",
|
|
argv: ["node", "omp"],
|
|
}),
|
|
join(homedir(), ".omp", "agent"),
|
|
);
|
|
});
|
|
|
|
await t.test(
|
|
"returns ~/.pi/agent as fallback when no env and no OMP runtime",
|
|
() => {
|
|
assert.equal(
|
|
resolveAgentDir({ env: {}, execPath: "/usr/bin/node", argv: ["node"] }),
|
|
join(homedir(), ".pi", "agent"),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
|
|
await test("resolveTelegramConfigPath", () => {
|
|
assert.ok(
|
|
resolveTelegramConfigPath().endsWith("telegram.json"),
|
|
"config path ends with telegram.json",
|
|
);
|
|
});
|
|
|
|
await test("resolveTelegramLocksPath", () => {
|
|
assert.ok(
|
|
resolveTelegramLocksPath().endsWith("locks.json"),
|
|
"locks path ends with locks.json",
|
|
);
|
|
});
|
|
|
|
await test("resolveTelegramTempDir", () => {
|
|
assert.ok(
|
|
resolveTelegramTempDir().endsWith("/tmp/telegram"),
|
|
"temp dir ends with /tmp/telegram",
|
|
);
|
|
});
|
|
|
|
await test("resolveTelegramRuntimeLogPath", () => {
|
|
assert.ok(
|
|
resolveTelegramRuntimeLogPath().endsWith("/tmp/telegram/logs.jsonl"),
|
|
"runtime log path ends with logs.jsonl",
|
|
);
|
|
});
|