From e8592fc930c08ea26b00e9d1c370159dcbf22c6d Mon Sep 17 00:00:00 2001 From: imrewce Date: Wed, 20 May 2026 09:58:15 +0800 Subject: [PATCH] fix: recent unittest inconsistency (#248) * feat: implementation of the read step for reme (markdown) * fix(step): markdown read step fixing pr comments * fix(step): more fixes for pr comments * further fix for better review adaptation * accept absolute path * fixing base job exception * fix: fix test inconsistency --- reme4/steps/crud/_file_io.py | 10 ++++++---- tests4/unittest/test_crud_md_steps.py | 19 ++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/reme4/steps/crud/_file_io.py b/reme4/steps/crud/_file_io.py index 4beaa35d..ce5ec7ca 100644 --- a/reme4/steps/crud/_file_io.py +++ b/reme4/steps/crud/_file_io.py @@ -12,12 +12,14 @@ logger = get_logger() def resolve_path(working_path: Path, raw: str) -> tuple[Path | None, str | None]: - """Resolve a relative `path=` argument under self.working_path. + """Resolve a `path=` argument against ``working_path``. Rules: - - the caller supplies the full relative path under ``self.working_path``; - absolute paths are rejected. - Returns ``(abs_path, None)`` on success, or ``(None, error_message)`` on failure. + - Relative paths are joined under ``working_path``. + - Absolute paths are accepted and returned as-is; a warning is logged + recommending relative paths, but the read still proceeds. + Returns ``(abs_path, None)`` on success, or ``(None, error_message)`` on failure + (currently only when ``raw`` is empty/blank). Filetype-specific gating (e.g. markdown-only / suffix auto-append) is layered on top by callers — see ``reme4/steps/crud/_file_io.py::gate_md``. """ diff --git a/tests4/unittest/test_crud_md_steps.py b/tests4/unittest/test_crud_md_steps.py index d60c72f9..f42074e3 100644 --- a/tests4/unittest/test_crud_md_steps.py +++ b/tests4/unittest/test_crud_md_steps.py @@ -133,8 +133,8 @@ def test_read_line_range(): _run(run()) -def test_read_absolute_path_rejected(): - """Absolute paths are rejected (relative-only after refactor).""" +def test_read_absolute_path_accepted(): + """Absolute paths are accepted (a log warning is emitted but the read proceeds).""" async def run(): with tempfile.TemporaryDirectory() as tmp, _temp_chdir(tmp): @@ -149,12 +149,10 @@ def test_read_absolute_path_rejected(): path=str(target.resolve()), ) if not ( - isinstance(result, dict) - and result.get("success") is False - and "absolute" in str(result.get("answer", "")).lower() + isinstance(result, dict) and result.get("success") is True and "x" in str(result.get("answer", "")) ): - raise AssertionError(f"expected absolute-path rejection, got {result!r}") - print("✓ test_read_absolute_path_rejected passed") + raise AssertionError(f"expected absolute-path read to succeed, got {result!r}") + print("✓ test_read_absolute_path_accepted passed") _run(run()) @@ -265,13 +263,14 @@ def test_read_start_line_exceeds_total(): def test_read_truncation(): - """A small max_bytes triggers truncation with a continuation notice.""" + """A file larger than DEFAULT_MAX_BYTES triggers truncation with a continuation notice.""" async def run(): with tempfile.TemporaryDirectory() as tmp, _temp_chdir(tmp): working = Path(tmp) / ".reme" working.mkdir(parents=True, exist_ok=True) - body = "\n".join(f"line {i}" for i in range(200)) + "\n" + # Seed > DEFAULT_MAX_BYTES (50 KiB) so the default truncation kicks in. + body = "\n".join(f"line {i}" for i in range(8000)) + "\n" _seed_md(working, "Big.md", body) async with mock_reme_server() as (host, port): await call_and_check( @@ -279,7 +278,6 @@ def test_read_truncation(): host=host, port=port, path="Big.md", - max_bytes=64, validator=lambda r: ( isinstance(r, dict) and r.get("success") is True @@ -360,7 +358,6 @@ if __name__ == "__main__": test_read_relative_path() test_read_no_suffix_autoappends_md() test_read_line_range() - test_read_absolute_path_rejected() test_read_non_md_rejected() test_read_missing_file() test_read_start_after_end()