Skip to content

Commit aa78b12

Browse files
committed
browser fix tests2
1 parent 66ee090 commit aa78b12

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

sentience/browser.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,23 @@ def start(self) -> None:
104104
for file in files_to_copy:
105105
src = extension_source / file
106106
if src.exists():
107+
# Verify source file is not empty
108+
src_size = src.stat().st_size
109+
if src_size == 0:
110+
raise ValueError(
111+
f"Extension file is empty: {src}\n"
112+
f"Extension source: {extension_source}\n"
113+
f"This suggests the extension files weren't synced correctly."
114+
)
107115
dst = os.path.join(temp_dir, file)
108116
shutil.copy2(src, dst)
117+
# Verify copy succeeded
118+
if not os.path.exists(dst) or os.path.getsize(dst) == 0:
119+
raise RuntimeError(
120+
f"Failed to copy {file} to temp directory\n"
121+
f"Source: {src} (size: {src_size} bytes)\n"
122+
f"Destination: {dst} (exists: {os.path.exists(dst)}, size: {os.path.getsize(dst) if os.path.exists(dst) else 0} bytes)"
123+
)
109124
copied_files.append(file)
110125
else:
111126
raise FileNotFoundError(
@@ -160,17 +175,47 @@ def start(self) -> None:
160175

161176
# Verify manifest.json is valid JSON
162177
manifest_path = os.path.join(temp_dir, "manifest.json")
178+
if not os.path.exists(manifest_path):
179+
raise FileNotFoundError(
180+
f"manifest.json not found at {manifest_path}\n"
181+
f"Temp dir: {temp_dir}\n"
182+
f"Files in temp dir: {os.listdir(temp_dir)}"
183+
)
184+
185+
# Check file size
186+
manifest_size = os.path.getsize(manifest_path)
187+
if manifest_size == 0:
188+
raise ValueError(
189+
f"manifest.json is empty (0 bytes) at {manifest_path}\n"
190+
f"Extension source: {extension_source}\n"
191+
f"Source manifest exists: {(extension_source / 'manifest.json').exists()}\n"
192+
f"Source manifest size: {os.path.getsize(extension_source / 'manifest.json') if (extension_source / 'manifest.json').exists() else 'N/A'}"
193+
)
194+
163195
try:
164196
import json
165-
with open(manifest_path, 'r') as f:
166-
manifest = json.load(f)
197+
with open(manifest_path, 'r', encoding='utf-8') as f:
198+
content = f.read()
199+
if not content.strip():
200+
raise ValueError(f"manifest.json is empty or contains only whitespace")
201+
manifest = json.loads(content)
167202
# Verify required manifest fields
168203
if "manifest_version" not in manifest:
169204
raise ValueError("manifest.json missing 'manifest_version' field")
170205
except json.JSONDecodeError as e:
171-
raise ValueError(f"manifest.json is not valid JSON: {e}")
206+
raise ValueError(
207+
f"manifest.json is not valid JSON: {e}\n"
208+
f"File path: {manifest_path}\n"
209+
f"File size: {manifest_size} bytes\n"
210+
f"First 100 chars: {content[:100] if 'content' in locals() else 'N/A'}"
211+
)
172212
except Exception as e:
173-
raise ValueError(f"Error reading manifest.json: {e}")
213+
raise ValueError(
214+
f"Error reading manifest.json: {e}\n"
215+
f"File path: {manifest_path}\n"
216+
f"File exists: {os.path.exists(manifest_path)}\n"
217+
f"File size: {manifest_size} bytes"
218+
)
174219

175220
# Launch Playwright
176221
self.playwright = sync_playwright().start()

0 commit comments

Comments
 (0)