All files / shared squad-db-path.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 1/1
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 272x 2x 2x   2x 106x 106x 106x 106x   106x 106x 106x 1x           106x              
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
 
export function resolveSquadDbPath(): string {
  const homeDir = os.homedir();
  const defaultDir = path.join(homeDir, '.gs-squad-mcp');
  const defaultPath = path.join(defaultDir, 'squad.db');
  const dbPath = process.env.SQUAD_DB_PATH ?? defaultPath;
 
  try {
    const dirToEnsure = path.dirname(dbPath);
    if (!fs.existsSync(dirToEnsure)) {
      fs.mkdirSync(dirToEnsure, { recursive: true });
    }
  } catch {
    // Best effort. DB open will fail loudly if path is invalid.
  }
 
  return dbPath;
}