Skip to content

Sync Extension: v2.4.0 #359

Sync Extension: v2.4.0

Sync Extension: v2.4.0 #359

Workflow file for this run

name: Test
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.11']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Playwright browsers
run: |
python -m pip install --upgrade pip
pip install playwright
playwright install chromium
- name: Install dependencies
shell: bash
run: |
pip cache purge || true
pip uninstall -y sentienceapi || true
# Aggressively clean any bytecode cache (cross-platform Python approach)
python -c "import pathlib; [p.unlink() for p in pathlib.Path('.').rglob('*.pyc')]" || true
python -c "import pathlib, shutil; [shutil.rmtree(p) for p in pathlib.Path('.').rglob('__pycache__') if p.is_dir()]" || true
# Also clean .pyc files in sentience package specifically
find sentience -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || python -c "import pathlib, shutil; [shutil.rmtree(p) for p in pathlib.Path('sentience').rglob('__pycache__') if p.is_dir()]" || true
find sentience -name "*.pyc" -delete 2>/dev/null || python -c "import pathlib; [p.unlink() for p in pathlib.Path('sentience').rglob('*.pyc')]" || true
# Force reinstall to ensure latest code
pip install --no-cache-dir --force-reinstall -e ".[dev]"
pip install pre-commit mypy types-requests
- name: Verify installed package
shell: bash
run: |
echo "=== Git info ==="
git log --oneline -1
git branch --show-current || echo "Detached HEAD"
echo ""
echo "=== Source file line 345 ==="
sed -n '345p' sentience/agent_runtime.py || python -c "with open('sentience/agent_runtime.py', 'r') as f: lines = f.readlines(); print(lines[344] if len(lines) > 344 else 'NOT FOUND')"
echo ""
echo "=== Installed sentience location ==="
python -c "import sentience; print(sentience.__file__)"
echo ""
echo "=== Check assert_done in installed package ==="
python << 'PYEOF'
import inspect
from sentience.agent_runtime import AgentRuntime
source = inspect.getsource(AgentRuntime.assert_done)
print('assert_done method:')
print(source)
print('\n=== Analysis ===')
if 'self.assertTrue(' in source:
print('✗ ERROR: Found self.assertTrue( in installed package!')
print('This means the source code on this branch still has the bug.')
for i, line in enumerate(source.split('\n'), 1):
if 'self.assertTrue(' in line:
print(f' Line {i}: {line.strip()}')
exit(1)
elif 'self.assert_(' in source:
print('✓ OK: assert_done uses self.assert_( correctly')
else:
print('? WARNING: Could not find assert_ method call')
PYEOF
- name: Verify source code
shell: bash
run: |
python << 'EOF'
# Check agent_runtime.py line 345
print("=== Checking agent_runtime.py line 345 ===")
with open('sentience/agent_runtime.py', 'r', encoding='utf-8') as f:
lines = f.readlines()
print(''.join(lines[339:350]))
# Verify assert_ method exists
print("\n=== Verifying assert_ method exists ===")
with open('sentience/agent_runtime.py', 'r', encoding='utf-8') as f:
lines = f.readlines()
for i, line in enumerate(lines, 1):
if 'def assert_' in line:
print(f'{i}:{line}', end='')
# Check for problematic assertTrue patterns (should NOT exist)
print("\n=== Checking for assertTrue patterns (should NOT exist) ===")
import re
with open('sentience/agent_runtime.py', 'r', encoding='utf-8') as f:
content = f.read()
# Check for self.assertTrue( - this is the bug
if re.search(r'self\.assertTrue\s*\(', content):
print('ERROR: Found self.assertTrue( - should be self.assert_( instead!')
exit(1)
# Check for assertTrue( without self. - unittest style (also wrong)
if re.search(r'(?<!self\.)assertTrue\s*\(', content):
print('ERROR: Found assertTrue( without self. - should use self.assert_( instead!')
exit(1)
print('Good: no problematic assertTrue patterns found')
EOF
- name: Lint with pre-commit
continue-on-error: true
run: |
pre-commit run --all-files
- name: Type check with mypy
continue-on-error: true
run: |
mypy sentience --ignore-missing-imports --no-strict-optional
- name: Check code style
continue-on-error: true
run: |
black --check sentience tests --line-length=100
isort --check-only --profile black sentience tests
flake8 sentience tests --max-line-length=100 --extend-ignore=E203,W503,E501 --max-complexity=15
- name: Build extension (if needed)
if: runner.os != 'Windows'
shell: bash
run: |
if [ -d "../sentience-chrome" ]; then
cd ../sentience-chrome && ./build.sh || echo "Extension build skipped (may not be available in CI)"
else
echo "Extension directory not found, skipping build"
fi
- name: Pre-test verification
shell: bash
continue-on-error: true
run: |
echo "=== Final check before tests ==="
python << 'EOF'
import re
import os
# Check the source file directly (not the installed package)
file_path = 'sentience/agent_runtime.py'
if not os.path.exists(file_path):
print(f'WARNING: {file_path} not found!')
exit(0) # Don't fail if file doesn't exist
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
lines = content.split('\n')
# Check for the problematic pattern: self.assertTrue(
# This is the bug we're checking for - it should be self.assert_( instead
problematic_lines = []
for i, line in enumerate(lines, 1):
if re.search(r'self\.assertTrue\s*\(', line):
problematic_lines.append((i, line.strip()))
if problematic_lines:
print('WARNING: Found self.assertTrue( in agent_runtime.py')
print('This should be self.assert_( instead!')
print(f'\nFound {len(problematic_lines)} problematic line(s):')
for line_num, line_content in problematic_lines:
print(f'Line {line_num}: {line_content}')
print('\nTo fix:')
print('1. Replace self.assertTrue( with self.assert_( in the code above')
print('2. If this is a PR, merge or rebase with the latest main branch')
print(' (main branch already has this fix in commit c7a43a9)')
print('\nNOTE: This check is set to continue-on-error for now.')
print('Please fix the code and remove continue-on-error once fixed.')
exit(1) # Still exit with error, but workflow continues due to continue-on-error
else:
# Verify that self.assert_( is used (positive check)
if 'self.assert_(' in content:
print('OK: self.assert_ is used correctly (no self.assertTrue found)')
else:
print('WARNING: self.assert_( not found in agent_runtime.py')
print('This might indicate the code needs to be updated')
EOF
- name: Run tests
shell: bash
run: |
# Final verification before tests - ensure we're using the right code
python -c "import sentience.agent_runtime; import inspect; src = inspect.getsource(sentience.agent_runtime.AgentRuntime.assert_done); assert 'self.assert_(' in src, 'assert_done must use self.assert_(), not self.assertTrue()'; print('✓ Verified: assert_done uses self.assert_()')"
pytest tests/ -v
env:
CI: true