Merge pull request #1357 from jbrahy/fix/inspect-open-existing-db
fix: open existing GSD database on /gsd inspect
This commit is contained in:
commit
0028ceef26
2 changed files with 56 additions and 3 deletions
|
|
@ -5,6 +5,9 @@
|
|||
*/
|
||||
|
||||
import type { ExtensionCommandContext } from "@gsd/pi-coding-agent";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { gsdRoot } from "./paths.js";
|
||||
import { getErrorMessage } from "./error-utils.js";
|
||||
|
||||
export interface InspectData {
|
||||
|
|
@ -44,11 +47,15 @@ export function formatInspectOutput(data: InspectData): string {
|
|||
|
||||
export async function handleInspect(ctx: ExtensionCommandContext): Promise<void> {
|
||||
try {
|
||||
const { isDbAvailable, _getAdapter } = await import("./gsd-db.js");
|
||||
const { isDbAvailable, _getAdapter, openDatabase } = await import("./gsd-db.js");
|
||||
|
||||
if (!isDbAvailable()) {
|
||||
ctx.ui.notify("No GSD database available. Run /gsd auto to create one.", "info");
|
||||
return;
|
||||
const gsdDir = gsdRoot(process.cwd());
|
||||
const dbPath = join(gsdDir, "gsd.db");
|
||||
if (!existsSync(gsdDir) || !existsSync(dbPath) || !openDatabase(dbPath)) {
|
||||
ctx.ui.notify("No GSD database available. Run /gsd auto to create one.", "info");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const adapter = _getAdapter();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
import { handleInspect } from "../commands-inspect.ts";
|
||||
import { closeDatabase, openDatabase } from "../gsd-db.ts";
|
||||
|
||||
test("/gsd inspect opens existing database when it was not yet opened in session", async () => {
|
||||
closeDatabase();
|
||||
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "gsd-inspect-db-"));
|
||||
const prevCwd = process.cwd();
|
||||
|
||||
try {
|
||||
const gsdDir = path.join(tmp, ".gsd");
|
||||
fs.mkdirSync(gsdDir, { recursive: true });
|
||||
const dbPath = path.join(gsdDir, "gsd.db");
|
||||
|
||||
assert.equal(openDatabase(dbPath), true);
|
||||
closeDatabase();
|
||||
|
||||
process.chdir(tmp);
|
||||
|
||||
const notifications: Array<{ message: string; level: string }> = [];
|
||||
const ctx = {
|
||||
ui: {
|
||||
notify(message: string, level: string) {
|
||||
notifications.push({ message, level });
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
|
||||
await handleInspect(ctx);
|
||||
|
||||
assert.equal(notifications.length, 1);
|
||||
assert.equal(notifications[0].level, "info");
|
||||
assert.match(notifications[0].message, /=== GSD Database Inspect ===/);
|
||||
assert.doesNotMatch(notifications[0].message, /No GSD database available/);
|
||||
} finally {
|
||||
process.chdir(prevCwd);
|
||||
closeDatabase();
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue