Skip to content

Commit 13251fa

Browse files
test review edge cases in tab metadata and export
1 parent 5197228 commit 13251fa

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

tests/test_cursor_md_exporter.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
if str(_root) not in sys.path:
1919
sys.path.insert(0, str(_root))
2020

21-
from utils.cursor_md_exporter import cursor_cli_session_to_markdown
21+
from utils.cursor_md_exporter import (
22+
_build_ide_session_summary,
23+
cursor_cli_session_to_markdown,
24+
)
2225

2326

2427
def _make_meta_hex(meta: dict) -> str:
@@ -241,6 +244,43 @@ def test_title_quoting_with_special_chars(self):
241244
# Frontmatter title must have embedded quotes escaped as \"
242245
self.assertIn('title: "He said \\"hello\\""', result)
243246

247+
def test_non_dict_meta_json_falls_back_to_empty_mapping(self):
248+
"""List/scalar meta JSON must not crash; agentId falls back to parent dir name."""
249+
db_path = self._db_path("scalar-meta")
250+
os.makedirs(os.path.dirname(db_path), exist_ok=True)
251+
conn = sqlite3.connect(db_path)
252+
conn.execute("CREATE TABLE meta (key TEXT PRIMARY KEY, value TEXT)")
253+
conn.execute("CREATE TABLE blobs (id TEXT PRIMARY KEY, data BLOB)")
254+
conn.execute(
255+
"INSERT INTO meta VALUES ('0', ?)",
256+
(json.dumps(["not", "a", "dict"]).encode("utf-8").hex(),),
257+
)
258+
conn.commit()
259+
conn.close()
260+
261+
result = cursor_cli_session_to_markdown(db_path)
262+
self.assertIn(f'log_id: "{Path(db_path).parent.name}"', result)
263+
self.assertIn("log_type: cli_agent", result)
264+
265+
def test_web_only_tool_stats_produce_session_summary(self):
266+
"""Search/web-only sessions still get a Tool Results summary block."""
267+
summary = _build_ide_session_summary(
268+
[],
269+
[],
270+
[],
271+
{
272+
"terminal_success": 0,
273+
"terminal_error": 0,
274+
"file_reads": 0,
275+
"file_edits": 0,
276+
"searches": 0,
277+
"web": 2,
278+
},
279+
)
280+
self.assertIn("## Session Summary", summary)
281+
self.assertIn("### Tool Results", summary)
282+
self.assertIn("Web Fetches: 2", summary)
283+
244284

245285
if __name__ == "__main__":
246286
unittest.main()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Regression tests for tab-level metadata aggregation edge cases."""
2+
3+
from __future__ import annotations
4+
5+
import unittest
6+
7+
from models import Composer
8+
from services.workspace_tabs import _aggregate_tab_metadata
9+
10+
11+
class TestAggregateTabMetadata(unittest.TestCase):
12+
def test_context_token_limit_only_produces_tab_metadata(self):
13+
"""A positive contextTokenLimit alone must not be dropped by has_any."""
14+
bubbles = [{
15+
"type": "user",
16+
"text": "hello",
17+
"timestamp": 1,
18+
"metadata": {"contextTokenLimit": 128_000},
19+
}]
20+
composer = Composer(
21+
composer_id="composer-limit-only",
22+
full_conversation_headers_only=[],
23+
created_at=1,
24+
)
25+
26+
tab_meta = _aggregate_tab_metadata(bubbles, composer)
27+
28+
self.assertEqual(tab_meta, {"contextTokenLimit": 128_000})
29+
30+
31+
if __name__ == "__main__":
32+
unittest.main()

0 commit comments

Comments
 (0)