chore: import upstream snapshot with attribution
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 12:30:44 +08:00
commit bcbd1bdb22
5748 changed files with 562488 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
+53
View File
@@ -0,0 +1,53 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.core.disk.du import du, du_all
from mirage.types import PathSpec
@pytest.mark.asyncio
async def test_du_single_file(tmp_path):
(tmp_path / "a.txt").write_bytes(b"hello")
accessor = DiskAccessor(tmp_path)
result = await du(
accessor,
PathSpec(resource_path="a.txt", virtual="/a.txt", directory="/a.txt"))
assert result == 5
@pytest.mark.asyncio
async def test_du_directory(tmp_path):
(tmp_path / "a.txt").write_bytes(b"aaa")
(tmp_path / "b.txt").write_bytes(b"bb")
accessor = DiskAccessor(tmp_path)
result = await du(accessor,
PathSpec(resource_path="", virtual="/", directory="/"))
assert result == 5
@pytest.mark.asyncio
async def test_du_all_returns_pairs(tmp_path):
(tmp_path / "a.txt").write_bytes(b"aaa")
(tmp_path / "sub").mkdir()
(tmp_path / "sub" / "b.txt").write_bytes(b"bb")
accessor = DiskAccessor(tmp_path)
entries, total = await du_all(
accessor, PathSpec(resource_path="", virtual="/", directory="/"))
paths = [p for p, _ in entries]
assert "/a.txt" in paths
assert "/sub/b.txt" in paths
assert total == 5
+84
View File
@@ -0,0 +1,84 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.core.disk.find import find
from mirage.types import PathSpec
@pytest.mark.asyncio
async def test_find_all_files(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "sub").mkdir()
(tmp_path / "sub" / "b.txt").write_text("b")
accessor = DiskAccessor(tmp_path)
result = await find(accessor,
PathSpec(resource_path="", virtual="/", directory="/"))
assert "/a.txt" in result
assert "/sub/b.txt" in result
assert "/sub" in result
@pytest.mark.asyncio
async def test_find_with_name_pattern(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "b.py").write_text("b")
accessor = DiskAccessor(tmp_path)
result = await find(accessor,
PathSpec(resource_path="", virtual="/", directory="/"),
name="*.txt")
assert result == ["/a.txt"]
@pytest.mark.asyncio
async def test_find_with_type_filter_file(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "sub").mkdir()
accessor = DiskAccessor(tmp_path)
result = await find(accessor,
PathSpec(resource_path="", virtual="/", directory="/"),
type="f")
assert "/a.txt" in result
assert "/sub" not in result
@pytest.mark.asyncio
async def test_find_with_type_filter_directory(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "sub").mkdir()
accessor = DiskAccessor(tmp_path)
result = await find(accessor,
PathSpec(resource_path="", virtual="/", directory="/"),
type="d")
assert "/sub" in result
assert "/a.txt" not in result
@pytest.mark.asyncio
async def test_find_with_maxdepth(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "sub").mkdir()
(tmp_path / "sub" / "b.txt").write_text("b")
(tmp_path / "sub" / "deep").mkdir()
(tmp_path / "sub" / "deep" / "c.txt").write_text("c")
accessor = DiskAccessor(tmp_path)
result = await find(accessor,
PathSpec(resource_path="", virtual="/", directory="/"),
maxdepth=1)
assert "/a.txt" in result
assert "/sub" in result
assert "/sub/b.txt" not in result
assert "/sub/deep/c.txt" not in result
+65
View File
@@ -0,0 +1,65 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.cache.index import RAMIndexCacheStore
from mirage.core.disk.glob import resolve_glob
from mirage.types import PathSpec
@pytest.mark.asyncio
async def test_resolve_file_path(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path="a.txt",
virtual="/a.txt",
directory="/",
resolved=True)
result = await resolve_glob(accessor, [scope], index)
assert len(result) == 1
assert result[0].virtual == "/a.txt"
assert result[0].resolved is True
@pytest.mark.asyncio
async def test_resolve_glob_pattern(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "b.txt").write_text("b")
(tmp_path / "c.py").write_text("c")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path="*.txt",
virtual="/*.txt",
directory="/",
pattern="*.txt",
resolved=False)
result = await resolve_glob(accessor, [scope], index)
originals = sorted(r.virtual for r in result)
assert originals == ["/a.txt", "/b.txt"]
@pytest.mark.asyncio
async def test_resolve_directory_path(tmp_path):
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path="",
virtual="/",
directory="/",
resolved=False)
result = await resolve_glob(accessor, [scope], index)
assert len(result) == 1
assert result[0].virtual == "/"
+58
View File
@@ -0,0 +1,58 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.cache.index import RAMIndexCacheStore
from mirage.core.disk.read import read_bytes
from mirage.types import PathSpec
from mirage.utils.key_prefix import mount_key
@pytest.mark.asyncio
async def test_read_file(tmp_path):
(tmp_path / "hello.txt").write_bytes(b"hello world")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await read_bytes(
accessor,
PathSpec(resource_path=mount_key("/hello.txt", "/disk"),
virtual="/hello.txt",
directory="/hello.txt"), index)
assert result == b"hello world"
@pytest.mark.asyncio
async def test_read_file_not_found(tmp_path):
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
with pytest.raises(FileNotFoundError):
await read_bytes(
accessor,
PathSpec(resource_path="missing.txt",
virtual="/missing.txt",
directory="/missing.txt"), index)
@pytest.mark.asyncio
async def test_read_with_glob_scope_and_prefix(tmp_path):
(tmp_path / "data.bin").write_bytes(b"\x00\x01\x02")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path=mount_key("/disk/data.bin", "/disk"),
virtual="/disk/data.bin",
directory="/disk/")
result = await read_bytes(accessor, scope, index)
assert result == b"\x00\x01\x02"
+140
View File
@@ -0,0 +1,140 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.cache.index import RAMIndexCacheStore
from mirage.core.disk.readdir import readdir
from mirage.types import PathSpec
from mirage.utils.key_prefix import mount_key
@pytest.mark.asyncio
async def test_empty_directory(tmp_path):
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await readdir(
accessor,
PathSpec(resource_path=mount_key("/", "/disk"),
virtual="/",
directory="/"), index)
assert result == []
@pytest.mark.asyncio
async def test_directory_with_files(tmp_path):
(tmp_path / "a.txt").write_text("a")
(tmp_path / "b.txt").write_text("b")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await readdir(
accessor, PathSpec(resource_path="", virtual="/", directory="/"),
index)
assert result == ["/a.txt", "/b.txt"]
@pytest.mark.asyncio
async def test_directory_with_subdirectories(tmp_path):
(tmp_path / "sub").mkdir()
(tmp_path / "file.txt").write_text("x")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await readdir(
accessor, PathSpec(resource_path="", virtual="/", directory="/"),
index)
assert result == ["/file.txt", "/sub"]
@pytest.mark.asyncio
async def test_cache_hit(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=600)
first = await readdir(
accessor, PathSpec(resource_path="", virtual="/", directory="/"),
index)
(tmp_path / "b.txt").write_text("b")
second = await readdir(
accessor, PathSpec(resource_path="", virtual="/", directory="/"),
index)
assert first == second
@pytest.mark.asyncio
async def test_with_prefix(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await readdir(
accessor,
PathSpec(resource_path=mount_key("/disk/", "/disk"),
virtual="/disk/",
directory="/disk/"), index)
assert result == ["/disk/a.txt"]
@pytest.mark.asyncio
async def test_with_glob_scope(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path=mount_key("/disk/", "/disk"),
virtual="/disk/",
directory="/disk/")
result = await readdir(accessor, scope, index)
assert result == ["/disk/a.txt"]
@pytest.mark.asyncio
async def test_not_a_directory(tmp_path):
(tmp_path / "file.txt").write_text("x")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
with pytest.raises(NotADirectoryError):
await readdir(
accessor,
PathSpec(resource_path="file.txt",
virtual="/file.txt",
directory="/file.txt"), index)
@pytest.mark.asyncio
async def test_cache_hit_entries_stay_clean(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=600)
spec = PathSpec(resource_path=mount_key("/data/", "/data"),
virtual="/data/",
directory="/data/")
cold = await readdir(accessor, spec, index)
warm = await readdir(accessor, spec, index)
assert cold == ["/data/a.txt"]
assert warm == cold
@pytest.mark.asyncio
async def test_cache_key_ignores_trailing_slash(tmp_path):
(tmp_path / "a.txt").write_text("a")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=600)
slashed = PathSpec(resource_path=mount_key("/data/", "/data"),
virtual="/data/",
directory="/data/")
bare = PathSpec(resource_path=mount_key("/data", "/data"),
virtual="/data",
directory="/data")
first = await readdir(accessor, slashed, index)
second = await readdir(accessor, bare, index)
assert first == second == ["/data/a.txt"]
+90
View File
@@ -0,0 +1,90 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.cache.index import RAMIndexCacheStore
from mirage.core.disk.stat import stat
from mirage.types import FileType, PathSpec
from mirage.utils.key_prefix import mount_key
@pytest.mark.asyncio
async def test_stat_file(tmp_path):
(tmp_path / "hello.txt").write_text("hello")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await stat(
accessor,
PathSpec(resource_path=mount_key("/hello.txt", "/disk"),
virtual="/hello.txt",
directory="/hello.txt"), index)
assert result.name == "hello.txt"
assert result.size == 5
assert result.modified is not None
assert result.modified.endswith("Z")
assert "+00:00" not in result.modified
assert result.type != FileType.DIRECTORY
@pytest.mark.asyncio
async def test_stat_directory(tmp_path):
(tmp_path / "sub").mkdir()
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await stat(
accessor,
PathSpec(resource_path="sub", virtual="/sub", directory="/sub"), index)
assert result.type == FileType.DIRECTORY
assert result.size is None
@pytest.mark.asyncio
async def test_stat_file_not_found(tmp_path):
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
with pytest.raises(FileNotFoundError):
await stat(
accessor,
PathSpec(resource_path="missing.txt",
virtual="/missing.txt",
directory="/missing.txt"), index)
@pytest.mark.asyncio
async def test_stat_with_glob_scope(tmp_path):
(tmp_path / "a.txt").write_text("data")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path=mount_key("/disk/a.txt", "/disk"),
virtual="/disk/a.txt",
directory="/disk/")
result = await stat(accessor, scope, index)
assert result.name == "a.txt"
assert result.size == 4
@pytest.mark.asyncio
async def test_stat_with_prefix(tmp_path):
(tmp_path / "a.txt").write_text("data")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
result = await stat(
accessor,
PathSpec(resource_path=mount_key("/disk/a.txt", "/disk"),
virtual="/disk/a.txt",
directory="/disk/a.txt"), index)
assert result.name == "a.txt"
assert result.size == 4
@@ -0,0 +1,29 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import asyncio
from mirage.accessor.disk import DiskAccessor
from mirage.core.disk.stat import stat
from mirage.types import PathSpec
def test_disk_stat_returns_fingerprint_from_mtime(tmp_path):
p = tmp_path / "f.txt"
p.write_bytes(b"hi")
accessor = DiskAccessor(root=tmp_path)
scope = PathSpec(resource_path="f.txt", virtual="/f.txt", directory="/")
result = asyncio.run(stat(accessor, scope))
assert result.fingerprint is not None
assert result.fingerprint == result.modified
+50
View File
@@ -0,0 +1,50 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.cache.index import RAMIndexCacheStore
from mirage.core.disk.stream import read_stream
from mirage.types import PathSpec
from mirage.utils.key_prefix import mount_key
@pytest.mark.asyncio
async def test_stream_file(tmp_path):
(tmp_path / "data.txt").write_bytes(b"stream content")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
chunks = []
async for chunk in read_stream(
accessor,
PathSpec(resource_path="data.txt",
virtual="/data.txt",
directory="/data.txt"), index):
chunks.append(chunk)
assert b"".join(chunks) == b"stream content"
@pytest.mark.asyncio
async def test_stream_with_glob_scope(tmp_path):
(tmp_path / "data.txt").write_bytes(b"abc")
accessor = DiskAccessor(tmp_path)
index = RAMIndexCacheStore(ttl=0)
scope = PathSpec(resource_path=mount_key("/disk/data.txt", "/disk"),
virtual="/disk/data.txt",
directory="/disk/")
chunks = []
async for chunk in read_stream(accessor, scope, index):
chunks.append(chunk)
assert b"".join(chunks) == b"abc"
+53
View File
@@ -0,0 +1,53 @@
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import pytest
from mirage.accessor.disk import DiskAccessor
from mirage.core.disk.write import write_bytes
from mirage.types import PathSpec
@pytest.mark.asyncio
async def test_write_new_file(tmp_path):
accessor = DiskAccessor(tmp_path)
await write_bytes(
accessor,
PathSpec(resource_path="new.txt",
virtual="/new.txt",
directory="/new.txt"), b"content")
assert (tmp_path / "new.txt").read_bytes() == b"content"
@pytest.mark.asyncio
async def test_overwrite_existing_file(tmp_path):
(tmp_path / "exist.txt").write_bytes(b"old")
accessor = DiskAccessor(tmp_path)
await write_bytes(
accessor,
PathSpec(resource_path="exist.txt",
virtual="/exist.txt",
directory="/exist.txt"), b"new")
assert (tmp_path / "exist.txt").read_bytes() == b"new"
@pytest.mark.asyncio
async def test_parent_directory_auto_creation(tmp_path):
accessor = DiskAccessor(tmp_path)
await write_bytes(
accessor,
PathSpec(resource_path="a/b/c/file.txt",
virtual="/a/b/c/file.txt",
directory="/a/b/c/file.txt"), b"deep")
assert (tmp_path / "a" / "b" / "c" / "file.txt").read_bytes() == b"deep"