Skip to content

Commit a38b162

Browse files
Fix PR review: stats exclusion, export_session errors, mypy 2.1, CI cache
1 parent 72f0f96 commit a38b162

6 files changed

Lines changed: 38 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ jobs:
6767
with:
6868
python-version: "3.12"
6969
cache: pip
70-
cache-dependency-path: requirements-dev.txt
70+
cache-dependency-path: |
71+
requirements.txt
72+
requirements-dev.txt
7173
7274
- name: Install dev dependencies
7375
run: pip install -r requirements-dev.txt

api/export_api.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,36 @@ def export_session(project_name: str, session_id: str) -> FlaskReturn:
277277
return json_ok({"error": "Session not found"}), 404
278278

279279
fmt = request.args.get("format", "md")
280-
session = parse_session(filepath)
281-
rules = current_app.config.get("EXCLUSION_RULES") or []
282-
if is_session_excluded(rules, session, project_name):
283-
return json_ok({"error": "Session not found"}), 404
284-
stats = compute_stats(session)
285-
title_slug = slugify(session["title"], default="session")
280+
try:
281+
session = parse_session(filepath)
282+
rules = current_app.config.get("EXCLUSION_RULES") or []
283+
if is_session_excluded(rules, session, project_name):
284+
return json_ok({"error": "Session not found"}), 404
285+
stats = compute_stats(session)
286+
title_slug = slugify(session["title"], default="session")
287+
288+
if fmt == "json":
289+
content = session_to_json(session, stats)
290+
buf = io.BytesIO(content.encode("utf-8"))
291+
buf.seek(0)
292+
return send_file(
293+
buf,
294+
mimetype="application/json",
295+
as_attachment=True,
296+
download_name=f"{title_slug}.json", # type: ignore[call-arg]
297+
)
286298

287-
if fmt == "json":
288-
content = session_to_json(session, stats)
289-
buf = io.BytesIO(content.encode("utf-8"))
299+
md = session_to_markdown(session, stats)
300+
buf = io.BytesIO(md.encode("utf-8"))
290301
buf.seek(0)
291302
return send_file(
292303
buf,
293-
mimetype="application/json",
304+
mimetype="text/markdown",
294305
as_attachment=True,
295-
download_name=f"{title_slug}.json", # type: ignore[call-arg]
306+
download_name=f"{title_slug}.md", # type: ignore[call-arg]
296307
)
297-
298-
md = session_to_markdown(session, stats)
299-
buf = io.BytesIO(md.encode("utf-8"))
300-
buf.seek(0)
301-
return send_file(
302-
buf,
303-
mimetype="text/markdown",
304-
as_attachment=True,
305-
download_name=f"{title_slug}.md", # type: ignore[call-arg]
306-
)
308+
except Exception:
309+
current_app.logger.exception(
310+
"Failed to export session %s/%s", project_name, session_id
311+
)
312+
return json_ok({"error": "Internal server error exporting session"}), 500

api/sessions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def get_session_stats(project_name: str, session_id: str) -> FlaskReturn:
5454

5555
try:
5656
session = parse_session(filepath)
57+
rules = current_app.config.get("EXCLUSION_RULES") or []
58+
if is_session_excluded(rules, session, project_name):
59+
return json_ok({"error": "Session not found"}), 404
5760
stats = compute_stats(session)
5861
return json_ok(stats)
5962
except Exception:

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ python_version = "3.12"
33
strict = true
44
packages = ["api", "utils", "models"]
55
exclude = ["tests/"]
6-
7-
[[tool.mypy.overrides]]
8-
module = "tests.*"
9-
ignore_errors = true

requirements-dev.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
-r requirements.txt
22
pytest==9.0.2
3-
mypy==1.15.0
4-
types-Flask==1.1.6
3+
mypy==2.1.0

utils/session_path.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ def list_projects(base_dir: str | None = None) -> list[ProjectDict]:
5252
latest_mtime, tz=timezone.utc
5353
).isoformat()
5454
# Read cwd from sessions to get the real project path
55-
display_name = None
55+
display_name = name
5656
for jf in jsonl_files:
57-
display_name = _get_display_name(
57+
candidate = _get_display_name(
5858
os.path.join(project_dir, jf), name
5959
)
60-
if display_name:
60+
if candidate:
61+
display_name = candidate
6162
break
62-
if not display_name:
63-
display_name = name
6463
projects.append({
6564
"name": name,
6665
"path": project_dir,

0 commit comments

Comments
 (0)