mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-05 16:04:43 +00:00
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:
co-authored by
Ivan Pantic
parent
0ac8175015
commit
02168446fb
@@ -28,7 +28,7 @@ const keySchema = z.object({ type: z.literal("key"), key: z.string().min(1) });
|
||||
export function defaultStorePaths(env: NodeJS.ProcessEnv = process.env): StorePaths {
|
||||
const dataHome = env.XDG_DATA_HOME || join(env.HOME || homedir(), ".local", "share");
|
||||
const directory = join(dataHome, "opencode");
|
||||
const database = env.OPENCODE_DB ? resolve(env.OPENCODE_DB) : join(directory, "opencode.db");
|
||||
const database = resolve(directory, env.OPENCODE_DB || "opencode.db");
|
||||
return { file: join(directory, "auth.json"), database };
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user