-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Issue #1540: Changes from Claude #1792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
281adcf
09f7f4e
a9777bf
d79481b
41a6878
da26269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,11 @@ | |
| import tempfile | ||
| import threading | ||
| import time | ||
| import builtins | ||
| import importlib | ||
| import pytest | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from unittest.mock import patch | ||
|
|
||
| from praisonaiagents.session.store import ( | ||
| DefaultSessionStore, | ||
|
|
@@ -160,6 +163,26 @@ def worker(worker_id): | |
| if start_idx < other_start < end_idx: | ||
| pytest.fail(f"Lock interleaving detected: {results}") | ||
|
|
||
| def test_import_without_fcntl(self): | ||
| """Test module import succeeds when fcntl is unavailable.""" | ||
| import praisonaiagents.session.store as store_module | ||
| import importlib.util | ||
| original_import = builtins.__import__ | ||
|
|
||
| def import_without_fcntl(name, *args, **kwargs): | ||
| if name == "fcntl": | ||
| raise ImportError("fcntl unavailable") | ||
| return original_import(name, *args, **kwargs) | ||
|
|
||
| try: | ||
| with patch("builtins.__import__", side_effect=import_without_fcntl): | ||
| reloaded_module = importlib.reload(store_module) | ||
| assert reloaded_module._HAS_FCNTL is False | ||
| finally: | ||
| restored_module = importlib.reload(store_module) | ||
|
|
||
| assert restored_module._HAS_FCNTL is (importlib.util.find_spec("fcntl") is not None) | ||
|
Comment on lines
+166
to
+184
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guarantee module restoration with The restoring reload at Line 180 sits outside the 🛡️ Proposed fix to always restore the module def test_import_without_fcntl(self):
"""Test module import succeeds when fcntl is unavailable."""
import praisonaiagents.session.store as store_module
+ import importlib.util
original_import = builtins.__import__
def import_without_fcntl(name, *args, **kwargs):
if name == "fcntl":
raise ImportError("fcntl unavailable")
return original_import(name, *args, **kwargs)
- with patch("builtins.__import__", side_effect=import_without_fcntl):
- reloaded_module = importlib.reload(store_module)
- assert reloaded_module._HAS_FCNTL is False
-
- restored_module = importlib.reload(store_module)
- assert restored_module._HAS_FCNTL is (importlib.util.find_spec("fcntl") is not None)
+ try:
+ with patch("builtins.__import__", side_effect=import_without_fcntl):
+ reloaded_module = importlib.reload(store_module)
+ assert reloaded_module._HAS_FCNTL is False
+ finally:
+ restored_module = importlib.reload(store_module)
+ assert restored_module._HAS_FCNTL is (importlib.util.find_spec("fcntl") is not None)🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm how store.py detects fcntl and sets _HAS_FCNTL
fd -t f 'store.py' -p 'session' --exec rg -n -C3 '_HAS_FCNTL|import fcntl|find_spec' {}Repository: MervinPraison/PraisonAI Length of output: 162 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Locate the test file and print the relevant section around the assertion.
rg -n "importlib(\.util)?\.find_spec|_HAS_FCNTL" src/praisonai-agents/tests/unit/session/test_session_store.py
echo "---- test file context (around assertion) ----"
python3 - <<'PY'
from pathlib import Path
p = Path("src/praisonai-agents/tests/unit/session/test_session_store.py")
lines = p.read_text().splitlines()
# Print around line 181 (1-based). Clamp safely.
start = max(1, 181-15)
end = min(len(lines), 181+5)
for i in range(start, end+1):
print(f"{i:4d}: {lines[i-1]}")
PY
# 2) Find the relevant store.py and inspect how _HAS_FCNTL is set.
echo "---- locating store.py and _HAS_FCNTL ----"
# Find any file that defines _HAS_FCNTL
fd --type f "store.py" src/praisonai-agents -a || true
rg -n "_HAS_FCNTL" src/praisonai-agents -S
# Also try to locate a 'session store' implementation file for context.
rg -n "class .*Session|session.*store|Session.*Store|store.*session" src/praisonai-agents -S --glob='*.py' | head -n 50
# Print the relevant part of the file(s) defining _HAS_FCNTL
python3 - <<'PY'
import subprocess, json, os, re
from pathlib import Path
# Get files containing _HAS_FCNTL
import sys
out = subprocess.check_output(["bash","-lc","rg -l \"_HAS_FCNTL\" src/praisonai-agents -S --glob='*.py'"], text=True).splitlines()
for f in out:
p = Path(f)
txt = p.read_text().splitlines()
print(f"\n---- {f} ----")
for i,line in enumerate(txt, start=1):
if "_HAS_FCNTL" in line:
start=max(1,i-10); end=min(len(txt), i+15)
for j in range(start,end+1):
print(f"{j:4d}: {txt[j-1]}")
break
PYRepository: MervinPraison/PraisonAI Length of output: 12284 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path("src/praisonai-agents/tests/unit/session/test_session_store.py")
for i, line in enumerate(p.read_text().splitlines()[:60], start=1):
print(f"{i:3d}: {line}")
PYRepository: MervinPraison/PraisonAI Length of output: 1992 🏁 Script executed: python3 - <<'PY'
import importlib, sys
print("Python", sys.version)
try:
print("importlib.util exists:", hasattr(importlib, "util"))
print("importlib.util:", importlib.util)
except Exception as e:
print("Error accessing importlib.util:", type(e).__name__, e)
# also try calling find_spec if possible
try:
print("find_spec fcntl:", importlib.util.find_spec("fcntl") is not None)
except Exception as e:
print("Error calling find_spec:", type(e).__name__, e)
PYRepository: MervinPraison/PraisonAI Length of output: 326 🏁 Script executed: #!/bin/bash
python3 - <<'PY'
import importlib, sys
print("Python", sys.version)
try:
print("hasattr(importlib, 'util'):", hasattr(importlib, "util"))
print("importlib.util:", importlib.util)
print("find_spec('fcntl') is not None:", importlib.util.find_spec("fcntl") is not None)
except Exception as e:
print("Error accessing importlib.util:", type(e).__name__, e)
PYRepository: MervinPraison/PraisonAI Length of output: 248 Fix test determinism: explicitly import
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| class TestDefaultSessionStore: | ||
| """Tests for DefaultSessionStore.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.