All files / shared squad-db-path.ts

92.3% Statements 12/13
50% Branches 2/4
100% Functions 1/1
92.3% Lines 12/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 271x 1x 1x   1x 102x 102x 102x 102x   102x 102x 102x             102x              
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);
    Iif (!fs.existsSync(dirToEnsure)) {
      fs.mkdirSync(dirToEnsure, { recursive: true });
    }
  } catch {
    // Best effort. DB open will fail loudly if path is invalid.
  }
 
  return dbPath;
}