test: implement testing infrastructure and initial unit tests - #2
test: implement testing infrastructure and initial unit tests#2Axel-DaMage wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a pytest-based testing setup for core FreeClaw modules (agent + tool layer), along with initial unit tests and a baseline .gitignore, aiming to prevent regressions in key behaviors like filesystem boundaries, memory persistence, task scheduling parsing, and web SSRF protections.
Changes:
- Added a new
tests/suite with fixtures and unit tests for agent + tools (fs, memory, task scheduler, web) and config precedence. - Added
testoptional dependencies (pytest,pytest-asyncio,pytest-mock) topyproject.toml. - Added a repository
.gitignorefor common Python/test/runtime artifacts.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/conftest.py | Adds shared ToolContext fixture for tool tests |
| tests/test_agent.py | Adds agent loop + tool-call handling tests |
| tests/test_config.py | Adds config default + env override tests |
| tests/test_tools_fs.py | Adds filesystem CRUD/security boundary tests |
| tests/test_tools_memory.py | Adds SQLite memory CRUD/search/TTL tests |
| tests/test_tools_task_scheduler.py | Adds task parsing/CRUD/disable-enable tests |
| tests/test_tools_web.py | Adds HTML parsing, SSRF validation, and mocked fetch/search tests |
| pyproject.toml | Adds test extra dependencies for pytest tooling |
| .gitignore | Adds ignores for caches, venvs, build artifacts, logs, and runtime dirs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,172 @@ | |||
| import pytest | |||
| import json | |||
| from freeclaw.freeclaw.agent import run_agent, AgentResult | |||
| from freeclaw.freeclaw.config import ( | ||
| load_config, | ||
| write_default_config, | ||
| ClawConfig | ||
| ) |
| @@ -0,0 +1,28 @@ | |||
| import pytest | |||
| from pathlib import Path | |||
| from freeclaw.freeclaw.tools.fs import ToolContext | |||
| # Valid urls | ||
| assert _validate_url("https://google.com") == "https://google.com" |
| import pytest | ||
| from freeclaw.freeclaw.tools.task_scheduler import ( | ||
| task_add, | ||
| task_list, | ||
| task_disable, | ||
| task_enable, | ||
| task_update, | ||
| task_run_now | ||
| ) |
| import pytest | ||
| from freeclaw.freeclaw.tools.memory import ( | ||
| memory_add, | ||
| memory_get, | ||
| memory_list, | ||
| memory_search, | ||
| memory_delete | ||
| ) |
| import pytest | ||
| from pathlib import Path | ||
| from freeclaw.freeclaw.tools.fs import ( | ||
| fs_read, | ||
| fs_write, | ||
| fs_list, | ||
| fs_mkdir, | ||
| fs_rm, | ||
| fs_stat, | ||
| fs_glob, | ||
| fs_diff, | ||
| fs_mv, | ||
| fs_cp | ||
| ) |
| from freeclaw.freeclaw.tools.web import ( | ||
| web_fetch, | ||
| web_search, | ||
| _validate_url, | ||
| _HTMLToText | ||
| ) |
| # Mock python's urllib | ||
| mocker.patch("urllib.request.OpenerDirector.open", return_value=MockResponse(mock_html)) | ||
|
|
||
| # Run fetch | ||
| res = web_fetch(ctx=tool_ctx, url="https://mocked.com") | ||
|
|
…NS hermetic tests
|
I've pushed a new commit (
All 28 tests are running successfully and the regressions mentioned by Copilot have been neutralized. |
|
Closing as stale — testing infrastructure is already implemented on main (675 API + 1219 frontend tests, all green). This branch from April would require major rework to bring up to date. Superseded by current main. |
Implement testing infrastructure and initial unit tests (#1)
This PR introduces a comprehensive testing suite for the FreeClaw core, ensuring reliability for critical modules such as Filesystem, Memory, Agent, and Task Scheduler.
Primary Changes
1. Core Test Suite (29 Tests)
A testing architecture based on pytest has been implemented covering:
2. Security and Robustness
3. Maintenance
How to run tests
Install development dependencies:
pip install -e ".[test]"
Run the full suite:
PYTHONPATH=. pytest -v
Suite Results