Files
oh-my-pi-telegram/tests/paths.test.ts
evandrodevbr 2aefc7ef5a
Validate / validate (push) Successful in 9m53s
fix: adapt the bridge to omp 18.4.8 host differences
- resolve the agent dir through the host getAgentDir() (registered by the composition root) instead of sniffing execPath/argv
- synthesize agent_settled from the first terminal agent_end on omp
- read the live model through ctx.models.current() and prefer it over the stored model on omp
- adapt omp Settings (reloadFromDisk, global enabledModels) at the SDK boundary and drop scoped-model persistence on omp
2026-10-01 10:07:47 -03:00

88 lines
2.5 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,
setHostAgentDirResolver,
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) => {
t.afterEach(() => setHostAgentDirResolver(undefined));
await t.test("PI_CODING_AGENT_DIR wins over the host directory", () => {
setHostAgentDirResolver(() => {
throw new Error("host directory must not be consulted");
});
assert.equal(
resolveAgentDir({ env: { PI_CODING_AGENT_DIR: "/custom/agent/dir" } }),
resolve("/custom/agent/dir"),
);
});
await t.test(
"uses the registered host runtime directory when env is unset",
() => {
setHostAgentDirResolver(() => "/home/user/.omp/agent");
assert.equal(resolveAgentDir({ env: {} }), "/home/user/.omp/agent");
},
);
await t.test("falls back to ~/.pi/agent when no host is registered", () => {
assert.equal(
resolveAgentDir({ env: {} }),
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",
);
});