From 34ca2ddc42557a3e144f651a5ae9533a65f59b21 Mon Sep 17 00:00:00 2001 From: zengchuang Date: Mon, 23 Nov 2026 14:36:59 +0800 Subject: [PATCH 1/2] fix(apps): create WorkSwarm cache parents through long paths Convert the cache base before parent creation while retaining unresolved owned children for link rejection. Cover long roots, warm reuse, corruption rejection and both linked cache parents. Agent-assisted-by: Codex (author/integrator) Signed-off-by: zengchuang --- .../skills/inferrsi/scripts/inferrsi.py | 5 ++-- tests/test_workswarm_runtime.py | 23 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/plugins/workswarm/inferrsi/skills/inferrsi/scripts/inferrsi.py b/plugins/workswarm/inferrsi/skills/inferrsi/scripts/inferrsi.py index 95775914b..aa17796ec 100644 --- a/plugins/workswarm/inferrsi/skills/inferrsi/scripts/inferrsi.py +++ b/plugins/workswarm/inferrsi/skills/inferrsi/scripts/inferrsi.py @@ -73,7 +73,9 @@ def cache_runtime(manifest_bytes: bytes, launcher: bytes, content: dict[str, byt base = Path(os.environ.get("LOCALAPPDATA") or Path.home() / ".cache") if not base.is_absolute(): raise ValueError("Runtime cache base must be absolute, outside the target repository") - cache_parent = base / "InferRSI" / "workswarm-runtime" + # Extend the base before parent I/O, keeping owned children unresolved so + # _plain still rejects a linked InferRSI or workswarm-runtime directory. + cache_parent = _io_path(base) / "InferRSI" / "workswarm-runtime" for directory in (cache_parent.parent, cache_parent): directory.mkdir(mode=0o700, parents=True, exist_ok=True) _plain(directory) @@ -81,7 +83,6 @@ def cache_runtime(manifest_bytes: bytes, launcher: bytes, content: dict[str, byt attributes = directory.stat() if attributes.st_uid != os.getuid() or attributes.st_mode & 0o022: raise ValueError("Runtime cache must be owned by this user and not shared writable") - cache_parent = _io_path(cache_parent) identity = hashlib.sha256(manifest_bytes + launcher).hexdigest() root = cache_parent / identity expected = {"runtime/" + name: data for name, data in content.items()} diff --git a/tests/test_workswarm_runtime.py b/tests/test_workswarm_runtime.py index f826c4a9e..30c4f9ed8 100644 --- a/tests/test_workswarm_runtime.py +++ b/tests/test_workswarm_runtime.py @@ -82,6 +82,22 @@ def test_cache_is_persistent_and_concurrent_first_use_is_atomic(cached_runtime): assert not list(root.parent.glob(".staging-*")) +def test_cache_supports_long_absolute_base(cached_runtime, tmp_path, monkeypatch): + base = tmp_path / "cache with spaces" / "\u4e2d\u6587" + while len(str(base)) < 310: + base /= "controlled-profile-segment" + monkeypatch.setenv("LOCALAPPDATA", str(base)) + + first = cached_runtime() + assert first == cached_runtime() + root = first.parents[3] + assert (root / "runtime/inferrsi/data/reference.md").read_bytes() == b"persistent resource" + assert not list(root.parent.glob(".staging-*")) + (root / "runtime/inferrsi/__init__.py").write_bytes(b"must not execute") + with pytest.raises(ValueError, match="cache verification failed"): + cached_runtime() + + @pytest.mark.parametrize("tamper", ["changed", "missing", "extra"]) def test_cache_rejects_modified_missing_or_extra_files(cached_runtime, tamper): root = cached_runtime().parents[3] @@ -96,11 +112,14 @@ def test_cache_rejects_modified_missing_or_extra_files(cached_runtime, tamper): cached_runtime() -def test_cache_rejects_linked_parent_before_writing(cached_runtime, tmp_path): +@pytest.mark.parametrize("linked", ["InferRSI", "InferRSI/workswarm-runtime"]) +def test_cache_rejects_linked_parent_before_writing(cached_runtime, tmp_path, linked): outside = tmp_path / "outside" outside.mkdir() + link = tmp_path / linked + link.parent.mkdir(parents=True, exist_ok=True) try: - (tmp_path / "InferRSI").symlink_to(outside, target_is_directory=True) + link.symlink_to(outside, target_is_directory=True) except OSError: pytest.skip("Creating directory symlinks is unavailable") with pytest.raises(ValueError, match="links or reparse points"): From e54909fd8ae30741ee3708833c551bf6ea792dc0 Mon Sep 17 00:00:00 2001 From: zengchuang Date: Mon, 23 Nov 2026 14:44:26 +0800 Subject: [PATCH 2/2] test(apps): set private cache-parent preconditions Give the owned parent explicit private permissions so linked-child rejection does not depend on a restrictive process umask. Agent-assisted-by: Codex (author/integrator) Signed-off-by: zengchuang --- tests/test_workswarm_runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_workswarm_runtime.py b/tests/test_workswarm_runtime.py index 30c4f9ed8..908b92957 100644 --- a/tests/test_workswarm_runtime.py +++ b/tests/test_workswarm_runtime.py @@ -117,7 +117,7 @@ def test_cache_rejects_linked_parent_before_writing(cached_runtime, tmp_path, li outside = tmp_path / "outside" outside.mkdir() link = tmp_path / linked - link.parent.mkdir(parents=True, exist_ok=True) + link.parent.mkdir(mode=0o700, parents=True, exist_ok=True) try: link.symlink_to(outside, target_is_directory=True) except OSError: