-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_server.py
More file actions
190 lines (154 loc) · 5.93 KB
/
test_server.py
File metadata and controls
190 lines (154 loc) · 5.93 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
"""Enhanced test script for Granola MCP Server."""
import asyncio
import json
import tempfile
from pathlib import Path
from granola_mcp_server.server import GranolaMCPServer
async def create_test_cache_with_panels():
"""Create a synthetic cache that exercises panel parsing."""
state = {
"meetingsMetadata": {
"m1": {
"created_at": "2024-01-15T10:00:00",
"title": "Service Review"
},
"m2": {
"created_at": "2024-01-16T11:00:00",
"title": "Retro"
}
},
"documents": {
"m1": {
"title": "Service Review",
"created_at": "2024-01-15T10:05:00",
"notes_plain": "",
"notes_markdown": "",
"notes": {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": []
}
]
}
},
"m2": {
"title": "Retro",
"created_at": "2024-01-16T11:05:00",
"notes_plain": "Direct notes",
"notes_markdown": "",
"notes": {
"type": "doc",
"content": []
}
}
},
"documentPanels": {
"m1": {
"panel-1": {
"content": [
{
"type": "heading",
"content": [
{"type": "text", "text": "Service Review"}
]
},
{
"type": "paragraph",
"content": [
{"type": "text", "text": "Hello Panel"}
]
}
]
}
}
},
"transcripts": {}
}
cache_wrapper = {"cache": json.dumps({"state": state})}
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as handle:
json.dump(cache_wrapper, handle)
return handle.name
async def test_server():
"""Test the server functionality with panel and plain notes."""
print("Creating synthetic test cache...")
cache_path = await create_test_cache_with_panels()
try:
print(f"Initializing server with cache: {cache_path}")
server = GranolaMCPServer(cache_path=cache_path)
print("Loading cache...")
await server._load_cache()
assert server.cache_data, "Cache data should not be empty"
assert "m1" in server.cache_data.documents, "Document m1 should be parsed"
assert "m2" in server.cache_data.documents, "Document m2 should be parsed"
m1_content = server.cache_data.documents["m1"].content
m2_content = server.cache_data.documents["m2"].content
assert "Hello Panel" in m1_content, "Panel text should be extracted for m1"
assert "Direct notes" in m2_content, "notes_plain should take precedence for m2"
print("Synthetic content checks passed.")
# Minimal smoke for existing flows
await server._search_meetings("Service", 5)
await server._get_meeting_documents("m1")
print("\n✅ Panel fallback test passed!")
except Exception as exc:
print(f"❌ Test failed: {exc}")
import traceback
traceback.print_exc()
raise
finally:
Path(cache_path).unlink()
async def test_v4_cache_format():
"""Test that the v4 cache format (dict instead of JSON string) parses correctly."""
print("\nTesting v4 cache format (dict-based)...")
state = {
"documents": {
"m1": {
"title": "V4 Meeting",
"created_at": "2024-02-01T14:00:00",
"notes_plain": "Notes from v4 format",
}
},
"transcripts": {},
}
# v4 format: cache value is a dict, not a JSON string
cache_wrapper = {"cache": {"state": state}}
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as handle:
json.dump(cache_wrapper, handle)
cache_path = handle.name
try:
server = GranolaMCPServer(cache_path=cache_path)
await server._load_cache()
assert server.cache_data, "Cache data should not be empty"
assert "m1" in server.cache_data.documents, "Document m1 should be parsed from v4 format"
assert server.cache_data.documents["m1"].content == "Notes from v4 format"
print("V4 cache format test passed!")
finally:
Path(cache_path).unlink()
def test_version_detection():
"""Test that cache discovery picks the highest version file."""
import glob as glob_mod
import tempfile
import os
with tempfile.TemporaryDirectory() as tmpdir:
# Create fake cache files for v3, v4, v6
for v in [3, 4, 6]:
Path(os.path.join(tmpdir, f"cache-v{v}.json")).write_text("{}")
cache_files = glob_mod.glob(os.path.join(tmpdir, "cache-v*.json"))
def version_key(p):
try:
return int(os.path.basename(p).replace("cache-v", "").replace(".json", ""))
except ValueError:
return 0
best = max(cache_files, key=version_key)
assert best.endswith("cache-v6.json"), f"Expected v6, got {best}"
# Also verify ordering: v6 > v4 > v3
sorted_files = sorted(cache_files, key=version_key, reverse=True)
versions = [version_key(f) for f in sorted_files]
assert versions == [6, 4, 3], f"Expected [6, 4, 3], got {versions}"
print("Version detection test passed!")
if __name__ == "__main__":
asyncio.run(test_server())
asyncio.run(test_v4_cache_format())
test_version_detection()