test: implement testing infrastructure and initial unit tests#2
Open
Axel-DaMage wants to merge 2 commits intoopenconstruct:mainfrom
Open
test: implement testing infrastructure and initial unit tests#2Axel-DaMage wants to merge 2 commits intoopenconstruct:mainfrom
Axel-DaMage wants to merge 2 commits intoopenconstruct:mainfrom
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 | |||
Comment on lines
+5
to
+9
| 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 | |||
Comment on lines
+24
to
+25
| # Valid urls | ||
| assert _validate_url("https://google.com") == "https://google.com" |
Comment on lines
+1
to
+9
| import pytest | ||
| from freeclaw.freeclaw.tools.task_scheduler import ( | ||
| task_add, | ||
| task_list, | ||
| task_disable, | ||
| task_enable, | ||
| task_update, | ||
| task_run_now | ||
| ) |
Comment on lines
+1
to
+8
| import pytest | ||
| from freeclaw.freeclaw.tools.memory import ( | ||
| memory_add, | ||
| memory_get, | ||
| memory_list, | ||
| memory_search, | ||
| memory_delete | ||
| ) |
Comment on lines
+1
to
+14
| 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 | ||
| ) |
Comment on lines
+4
to
+9
| from freeclaw.freeclaw.tools.web import ( | ||
| web_fetch, | ||
| web_search, | ||
| _validate_url, | ||
| _HTMLToText | ||
| ) |
Comment on lines
+63
to
+68
| # 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
Author
|
I've pushed a new commit (
All 28 tests are running successfully and the regressions mentioned by Copilot have been neutralized. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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