ReMe/tests/unit/test_config_parser.py
jinliyl ffb4d08c4f
Some checks are pending
Pre-commit / run (ubuntu-latest) (push) Waiting to run
Tests ReMe / Unit Tests - py3.11 (push) Waiting to run
Tests ReMe / Unit Tests - py3.12 (push) Waiting to run
Tests ReMe / Unit Tests - py3.13 (push) Waiting to run
feat(mem): Enhance daily note system with metadata handling and write functionality (#295)
* feat(file_io): add daily_write step for creating daily notes with conversation metadata

- Add DailyWriteStep class that delegates to write job for creating daily notes
- Register daily_write job in default configuration with proper parameters
- Include validation for name and session_id path components
- Add test coverage for daily_write functionality including metadata handling
- Preserve existing job execution method in application.py after repositioning
- Update base_step.py to use positional-only parameter syntax for job methods
- Import and expose DailyWriteStep in file_io module initialization
- Override reserved metadata keys (name, description, session_id, source_conversation) with fixed values
- Refresh daily index after successful write operation
- Generate proper source conversation links in markdown format

* feat(daily): refactor daily note system with enhanced metadata handling

- Introduce validate_filename_component function and export it
- Add _INDEX_HIDDEN_METADATA_KEYS to hide conversation metadata from index
- Update scan_notes to exclude hidden metadata keys from index rendering
- Modify auto_memory to use daily_write tool and manage session frontmatter
- Implement session note lookup and renaming based on frontmatter name
- Update daily_list to return flattened note metadata including session info
- Change daily_write to dispatch write step instead of running job
- Add test cases for updated daily note functionality and metadata handling
- Update version from 0.4.0.2 to 0.4.0.3

* fix(evolve): correct metadata update in auto memory response

- Fixed trailing comma issue in metadata dictionary update
- Ensured proper formatting of response metadata structure
- Maintained existing functionality while fixing syntax error

* refactor(auto_resource): replace daily_create with dynamic note management

- Remove DailyCreateStep and related exports from file_io module
- Replace static daily note creation with dynamic resource-linked card system
- Implement LLM-suggested naming with frontmatter-driven file management
- Add source_resource linking for tracking original files
- Introduce collision handling with hash-based suffixes
- Update documentation to reflect new resource card workflow
- Modify auto_resource prompts to use write/edit tools instead of daily_create
- Adjust test fixture comments to match new agent behavior
- Update framework diagrams and quick start examples accordingly

* feat(app): add version info to app initialization and update auto-memory logic

- Include version number in application startup logging
- Remove tool result truncation logic from auto-memory step
- Update auto-memory to exclude tool_result blocks from saved history
- Add test case to verify tool results are filtered out from message saving
- Update YAML prompts to clarify filename naming rules without dates
- Modify configuration to support new dispatch steps format with persistence control

* feat(auto_memory): add note modification tracking and optimize frontmatter updates

- Add _note_bytes and _note_modified methods to track actual file changes
- Optimize frontmatter updates by checking existing metadata before update
- Add modified flag to response metadata indicating actual note changes
- Update logging to include modified status in various operations
- Add comprehensive tests for modified/unmodified detection scenarios
- Enhance result hook logic to skip when no actual changes occur
- Refactor metadata handling to properly track creation vs modification status
2026-06-25 21:54:56 +08:00

76 lines
2.3 KiB
Python

"""Tests for configuration parsing helpers."""
from pathlib import Path
import pytest
from reme.config.config_parser import (
_expand_env_vars,
_load_config,
_read_config_file,
parse_args,
parse_dot_notation,
)
def test_load_builtin_config_by_filename_with_suffix():
"""Built-in config names may include the YAML suffix."""
cfg = _load_config("default.yaml")
assert cfg["service"]["backend"] == "http"
def test_default_config_registers_daily_write_job():
"""``daily_write`` is exposed as a base job backed by ``daily_write_step``."""
cfg = _load_config("default.yaml")
job = cfg["jobs"]["daily_write"]
assert job["backend"] == "base"
assert job["steps"] == [{"backend": "daily_write_step"}]
assert job["parameters"]["required"] == ["name", "description", "session_id", "content"]
def test_parse_args_rejects_non_key_value_extra_argument():
"""Extra CLI arguments must use key=value syntax."""
with pytest.raises(ValueError, match="expected key=value"):
parse_args("search", "hello")
@pytest.mark.parametrize("item", ["=1", ".a=1", "a.=1", "a..b=1"])
def test_parse_dot_notation_rejects_empty_key_segments(item):
"""Dot notation keys cannot contain empty path segments."""
with pytest.raises(ValueError, match="Invalid dot notation key"):
parse_dot_notation([item])
def test_read_config_file_rejects_non_mapping_root(tmp_path: Path):
"""Config files must contain a mapping at the root."""
config_path = tmp_path / "bad.yaml"
config_path.write_text("- item\n", encoding="utf-8")
with pytest.raises(ValueError, match="Config root must be a mapping"):
_read_config_file(config_path)
def test_expand_env_vars_converts_expanded_scalar_types(monkeypatch):
"""Expanded environment values keep YAML scalar typing."""
monkeypatch.setenv("PORT", "18080")
monkeypatch.setenv("ENABLED", "false")
expanded = _expand_env_vars(
{
"port": "${PORT}",
"enabled": "${ENABLED}",
"zip": "${ZIP:-007}",
"url": "http://${HOST:-localhost}:${PORT}",
"string_bool": '${STRING_BOOL:-"false"}',
},
)
assert expanded == {
"port": 18080,
"enabled": False,
"zip": "007",
"url": "http://localhost:18080",
"string_bool": "false",
}