fix(usage): find Go logins in the configured data directory

Resolve relative database overrides against the OpenCode data directory so usage discovery follows the same store as the CLI.

Co-authored-by: Ivan Pantic <panta@talentkit.io>
This commit is contained in:
paseo-bot[bot]
2026-11-04 03:27:55 +00:00
co-authored by Ivan Pantic
parent 0ac8175015
commit 02168446fb
2 changed files with 30 additions and 2 deletions
@@ -1,4 +1,4 @@
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { afterEach, beforeEach, expect, test } from "vitest";
@@ -181,6 +181,34 @@ test("resolves default and overridden OpenCode store paths", () => {
});
});
test("discovers a relative OPENCODE_DB under the OpenCode data directory", async () => {
const paths = defaultStorePaths({
XDG_DATA_HOME: fixtureDirectory,
OPENCODE_DB: "go.db",
});
const databasePath = join(fixtureDirectory, "opencode", "go.db");
await mkdir(dirname(databasePath));
const { DatabaseSync } = await import("node:sqlite");
const db = new DatabaseSync(databasePath);
db.exec(
"CREATE TABLE credential (id TEXT PRIMARY KEY, integration_id TEXT, value TEXT, active INTEGER, time_updated INTEGER)",
);
db.prepare("INSERT INTO credential VALUES (?, ?, ?, ?, ?)").run(
"go",
"opencode-go",
JSON.stringify({ type: "key", key: "relative-key" }),
1,
1,
);
db.close();
expect(await discover(paths)).toEqual([
{
key: expect.stringMatching(/^[a-f0-9]{64}$/),
input: { store: "database", path: databasePath },
},
]);
});
test("discovers and fetches the default key from read-only auth.json", async () => {
const directory = await mkdtemp(join(tmpdir(), "paseo-go-usage-"));
const path = join(directory, "auth.json");