You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: wrap all production sqlite3.connect() in context managers (closes#17) (#23)
* fix: wrap all production sqlite3.connect() in context managers (closes#17)
19 production sqlite3.connect() call sites used a bare local variable
with no `with` block, no try/finally, and no guaranteed .close() on
exception. On a long-lived Flask process, leaks accumulate before the
user notices.
Two patterns applied:
`with closing(sqlite3.connect(...)) as conn:` — used at 15 short-scope
sites (composers ×3, cli_chat_reader ×2, cursor_md_exporter ×1,
workspaces ×2 small helpers, logs ×2, search ×2, export_api ×1).
sqlite3.Connection's own context manager only commits/rolls back, not
closes. closing() is what guarantees .close().
`try / except / finally: if conn is not None: conn.close()` — used at
4 long-scope sites (workspaces.get_workspace_tabs ~400 lines,
search.search ×2 deep blocks, export_api.export_chats ~340 lines,
scripts/export.py). Same cleanup guarantee, no 100-300-line indent
shift. Equivalent semantics to a body-wide `with closing(...)` block.
Plus utils/workspaces._open_global_db converted to @contextmanager so
its two callers write `with _open_global_db(...) as (conn, _):` and
the connection is released automatically.
Test-side sqlite3.connect calls are out of scope (per-test fixtures,
short-lived).
Verification:
- All 19 production sites classified and confirmed protected (no bare
`sqlite3.connect()` outside a closing()/finally guard).
- pytest tests/ → 137 / 137 OK.
- AST clean on all 8 modified files; contextlib imports correctly
added wherever used.
- Live HTTP smoke against the running app: home, /api/workspaces,
/api/logs, /api/composers, /api/search all return 200 with no
Python tracebacks in the log (exercises every wrapping pattern).
* refactor: reuse _open_global_db in get_workspace_tabs; document unittest in README
- Route GET /api/workspaces/<id>/tabs through the existing _open_global_db
context manager instead of a duplicate sqlite3.connect + outer finally,
matching list_workspaces and closing issue #17 review follow-ups.
- README: add Tests section with python -m unittest discover tests -v.
- test_exclusion_rules: docstring prefers unittest over pytest.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: f"file:{local_db_path}?mode=ro" builds an invalid SQLite URI when local_db_path contains characters that must be escaped in URIs
---------
Co-authored-by: Monkey Dev <headit74@hotmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: README.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,20 @@ python app.py
69
69
70
70
Open <http://localhost:3000> in your browser.
71
71
72
+
## Tests
73
+
74
+
Run the full suite from the repository root (install `requirements.txt` first):
75
+
76
+
```bash
77
+
python -m unittest discover tests -v
78
+
```
79
+
80
+
Run a single module, for example:
81
+
82
+
```bash
83
+
python -m unittest tests.test_cli_args -v
84
+
```
85
+
72
86
## CLI Export
73
87
74
88
Export chat history to Markdown without starting the web server. Running with no arguments exports **everything** (all chats + composer logs) as a zip archive into the current directory.
0 commit comments