()
| 163 | const deadline = Date.now() + 15_000; |
| 164 | |
| 165 | async function scan(): Promise<{sessionId: string} | null> { |
| 166 | const db = tryOpenDb(); |
| 167 | if (!db) return null; |
| 168 | try { |
| 169 | const rows = db |
| 170 | .prepare( |
| 171 | `SELECT id FROM session |
| 172 | WHERE directory = ? AND time_created >= ? |
| 173 | ORDER BY time_created DESC |
| 174 | LIMIT 5`, |
| 175 | ) |
| 176 | .all(dir, cutoff) as SessionRow[]; |
| 177 | if (rows.length > 0) return {sessionId: rows[0]!.id}; |
| 178 | } catch { |
| 179 | /* ignore */ |
| 180 | } finally { |
| 181 | try { |
| 182 | db.close(); |
| 183 | } catch { |
| 184 | /* ignore */ |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return null; |
| 189 | } |
| 190 | |
| 191 | while (Date.now() < deadline) { |
| 192 | const result = await scan(); |
no test coverage detected