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
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:
@@ -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. =========
|
||||
@@ -0,0 +1,61 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.errors import enoent, enotdir, format_fs_error, fs_strerror
|
||||
|
||||
|
||||
def test_fs_strerror_known_types():
|
||||
assert fs_strerror(FileNotFoundError()) == "No such file or directory"
|
||||
assert fs_strerror(NotADirectoryError()) == "Not a directory"
|
||||
assert fs_strerror(IsADirectoryError()) == "Is a directory"
|
||||
assert fs_strerror(FileExistsError()) == "File exists"
|
||||
assert fs_strerror(PermissionError()) == "Permission denied"
|
||||
|
||||
|
||||
def test_fs_strerror_unknown_returns_none():
|
||||
assert fs_strerror(ValueError("nope")) is None
|
||||
|
||||
|
||||
def test_enoent_uses_virtual_path():
|
||||
spec = PathSpec.from_str_path("/a/missing.txt")
|
||||
exc = enoent(spec)
|
||||
assert isinstance(exc, FileNotFoundError)
|
||||
assert str(exc) == "/a/missing.txt"
|
||||
|
||||
|
||||
def test_enotdir_accepts_plain_string():
|
||||
exc = enotdir("/a/file.txt/x")
|
||||
assert isinstance(exc, NotADirectoryError)
|
||||
assert str(exc) == "/a/file.txt/x"
|
||||
|
||||
|
||||
def test_format_fs_error_appends_strerror():
|
||||
err = format_fs_error("cat", enoent("/b/missing.txt"))
|
||||
assert err == b"cat: /b/missing.txt: No such file or directory\n"
|
||||
|
||||
|
||||
def test_format_fs_error_rewrites_to_raw_path():
|
||||
spec = PathSpec(virtual="/a/missing.txt",
|
||||
directory="/a/",
|
||||
resource_path="missing.txt",
|
||||
raw_path="missing.txt")
|
||||
err = format_fs_error("diff", enoent("/a/missing.txt"), [spec])
|
||||
assert err == b"diff: missing.txt: No such file or directory\n"
|
||||
|
||||
|
||||
def test_format_fs_error_prefers_exc_filename():
|
||||
exc = FileNotFoundError(2, "No such file or directory", "/a/gone.txt")
|
||||
err = format_fs_error("head", exc)
|
||||
assert err == b"head: /a/gone.txt: No such file or directory\n"
|
||||
@@ -0,0 +1,55 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.types import FileType
|
||||
from mirage.utils.filetype import filetype_from_mimetype, guess_type
|
||||
|
||||
|
||||
def test_jpg_extension_maps_to_jpeg():
|
||||
assert guess_type("photo.jpg") == FileType.IMAGE_JPEG
|
||||
|
||||
|
||||
def test_jpeg_extension_maps_to_jpeg():
|
||||
assert guess_type("photo.jpeg") == FileType.IMAGE_JPEG
|
||||
|
||||
|
||||
def test_png_extension():
|
||||
assert guess_type("logo.png") == FileType.IMAGE_PNG
|
||||
|
||||
|
||||
def test_pdf_extension():
|
||||
assert guess_type("doc.pdf") == FileType.PDF
|
||||
|
||||
|
||||
def test_filetype_from_mimetype_image():
|
||||
assert filetype_from_mimetype("image/png") == FileType.IMAGE_PNG
|
||||
assert filetype_from_mimetype("image/jpeg") == FileType.IMAGE_JPEG
|
||||
assert filetype_from_mimetype("image/gif") == FileType.IMAGE_GIF
|
||||
|
||||
|
||||
def test_filetype_from_mimetype_pdf():
|
||||
assert filetype_from_mimetype("application/pdf") == FileType.PDF
|
||||
|
||||
|
||||
def test_filetype_from_mimetype_text_fallback():
|
||||
assert filetype_from_mimetype("text/markdown") == FileType.TEXT
|
||||
|
||||
|
||||
def test_filetype_from_mimetype_empty():
|
||||
assert filetype_from_mimetype("") == FileType.BINARY
|
||||
|
||||
|
||||
def test_filetype_from_mimetype_unknown():
|
||||
assert filetype_from_mimetype(
|
||||
"application/octet-stream") == FileType.BINARY
|
||||
@@ -0,0 +1,253 @@
|
||||
# ========= 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 dataclasses
|
||||
|
||||
import pytest
|
||||
|
||||
from mirage.accessor.base import NOOPAccessor
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.glob_walk import (expand_pattern, has_glob, is_word_shaped,
|
||||
resolve_glob_with, spell_match)
|
||||
|
||||
TREE = {
|
||||
"/notion": ["/notion/pages", "/notion/databases"],
|
||||
"/notion/pages": [
|
||||
"/notion/pages/Demo_page__uuid1",
|
||||
"/notion/pages/Roadmap__uuid2",
|
||||
],
|
||||
"/notion/pages/Demo_page__uuid1": [
|
||||
"/notion/pages/Demo_page__uuid1/page.md",
|
||||
"/notion/pages/Demo_page__uuid1/page.json",
|
||||
],
|
||||
"/notion/pages/Roadmap__uuid2": [
|
||||
"/notion/pages/Roadmap__uuid2/page.json",
|
||||
],
|
||||
"/": ["/alpha", "/beta.txt"],
|
||||
"/alpha": ["/alpha/b.txt"],
|
||||
}
|
||||
|
||||
CALLS: list[str] = []
|
||||
|
||||
|
||||
async def fake_readdir(accessor, path, index=None):
|
||||
CALLS.append(path.virtual)
|
||||
key = path.virtual.rstrip("/") or "/"
|
||||
if key not in TREE:
|
||||
raise FileNotFoundError(key)
|
||||
return TREE[key]
|
||||
|
||||
|
||||
def glob_spec(virtual: str, prefix: str) -> PathSpec:
|
||||
last_slash = virtual.rfind("/")
|
||||
return PathSpec(
|
||||
virtual=virtual,
|
||||
directory=virtual[:last_slash + 1],
|
||||
resource_path=virtual[len(prefix):].strip("/"),
|
||||
pattern=virtual[last_slash + 1:],
|
||||
resolved=False,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_calls():
|
||||
CALLS.clear()
|
||||
|
||||
|
||||
def test_has_glob():
|
||||
assert has_glob("Demo_*")
|
||||
assert has_glob("x?")
|
||||
assert has_glob("[ab]")
|
||||
assert not has_glob("page.md")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mid_path_glob_never_lists_pattern_dir():
|
||||
spec = glob_spec("/notion/pages/Demo_page__*/page.md", "/notion")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual
|
||||
for m in matched] == ["/notion/pages/Demo_page__uuid1/page.md"]
|
||||
assert matched[0].resource_path == "pages/Demo_page__uuid1/page.md"
|
||||
assert all("*" not in c for c in CALLS)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_last_component_glob():
|
||||
spec = glob_spec("/notion/pages/Demo*", "/notion")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual for m in matched] == ["/notion/pages/Demo_page__uuid1"]
|
||||
assert matched[0].resolved
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multiple_glob_segments():
|
||||
spec = glob_spec("/notion/pages/*__uuid*/page.json", "/notion")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual for m in matched] == [
|
||||
"/notion/pages/Demo_page__uuid1/page.json",
|
||||
"/notion/pages/Roadmap__uuid2/page.json",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_zero_match_returns_empty():
|
||||
spec = glob_spec("/notion/pages/Missing__*/page.md", "/notion")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert matched == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_non_directory_intermediate_skipped():
|
||||
spec = glob_spec("/*/b.txt", "")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual for m in matched] == ["/alpha/b.txt"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_directory_shaped_spec():
|
||||
spec = PathSpec(
|
||||
virtual="/notion/pages/",
|
||||
directory="/notion/pages/",
|
||||
resource_path="pages",
|
||||
pattern="Demo*",
|
||||
resolved=False,
|
||||
)
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual for m in matched] == ["/notion/pages/Demo_page__uuid1"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_root_mount_glob():
|
||||
spec = glob_spec("/a*", "")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.virtual for m in matched] == ["/alpha"]
|
||||
assert matched[0].resource_path == "alpha"
|
||||
|
||||
|
||||
def test_spell_match_relative_midpath():
|
||||
assert spell_match("s*/x.txt", "/data/sub/x.txt", 2) == "sub/x.txt"
|
||||
|
||||
|
||||
def test_spell_match_keeps_typed_head():
|
||||
assert spell_match("./sub/*.txt", "/data/sub/a.txt", 1) == "./sub/a.txt"
|
||||
assert spell_match("../s*/x.txt", "/data/sub/x.txt", 2) == "../sub/x.txt"
|
||||
|
||||
|
||||
def test_spell_match_bare_and_absolute():
|
||||
assert spell_match("*.txt", "/data/a.txt", 1) == "a.txt"
|
||||
assert spell_match("/data/s*/x.txt", "/data/sub/x.txt",
|
||||
2) == "/data/sub/x.txt"
|
||||
|
||||
|
||||
def test_is_word_shaped():
|
||||
word = glob_spec("/data/s*/x.txt", "")
|
||||
assert is_word_shaped(word)
|
||||
assert not is_word_shaped(word.dir)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matches_spelled_from_typed_word():
|
||||
spec = glob_spec("/alpha/*.txt", "")
|
||||
typed = dataclasses.replace(spec, raw_path="alpha/*.txt")
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), typed, None)
|
||||
assert [m.raw_path for m in matched] == ["alpha/b.txt"]
|
||||
assert [m.virtual for m in matched] == ["/alpha/b.txt"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dir_shaped_matches_keep_virtual():
|
||||
spec = glob_spec("/alpha/*.txt", "").dir
|
||||
matched = await expand_pattern(fake_readdir, NOOPAccessor(), spec, None)
|
||||
assert [m.raw_path for m in matched] == ["/alpha/b.txt"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_passes_resolved_through():
|
||||
spec = PathSpec.from_str_path("/alpha/b.txt", "alpha/b.txt")
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert result == [spec]
|
||||
assert CALLS == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_expands_pattern():
|
||||
spec = glob_spec("/alpha/*.txt", "")
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert [p.virtual for p in result] == ["/alpha/b.txt"]
|
||||
assert result[0].resolved
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_expands_mid_path_pattern():
|
||||
spec = glob_spec("/notion/pages/Demo_page__*/page.md", "/notion")
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert [p.virtual
|
||||
for p in result] == ["/notion/pages/Demo_page__uuid1/page.md"]
|
||||
assert all("*" not in c for c in CALLS)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_unmatched_word_stays_literal():
|
||||
spec = glob_spec("/notion/pages/Missing__*/page.md", "/notion")
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert len(result) == 1
|
||||
assert result[0].virtual == "/notion/pages/Missing__*/page.md"
|
||||
assert result[0].resolved
|
||||
assert result[0].pattern is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_unmatched_dir_shaped_dropped():
|
||||
spec = PathSpec(
|
||||
virtual="/notion/pages/",
|
||||
directory="/notion/pages/",
|
||||
resource_path="pages",
|
||||
pattern="Missing*",
|
||||
resolved=False,
|
||||
)
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert result == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_cap_truncates_and_warns(caplog):
|
||||
spec = glob_spec("/notion/pages/*", "/notion")
|
||||
with caplog.at_level("WARNING"):
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None, 1)
|
||||
assert [p.virtual for p in result] == ["/notion/pages/Demo_page__uuid1"]
|
||||
assert "exceeds limit" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_no_cap_keeps_all_matches():
|
||||
spec = glob_spec("/notion/pages/*", "/notion")
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(), [spec],
|
||||
None)
|
||||
assert len(result) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_glob_with_coerces_str_path():
|
||||
result = await resolve_glob_with(fake_readdir, NOOPAccessor(),
|
||||
["/alpha/b.txt"], None)
|
||||
assert len(result) == 1
|
||||
assert result[0].virtual == "/alpha/b.txt"
|
||||
assert result[0].resource_path == "alpha/b.txt"
|
||||
assert result[0].directory == "/alpha"
|
||||
@@ -0,0 +1,64 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.utils.key_prefix import mount_key, rekey, strip_mount
|
||||
|
||||
|
||||
def test_strip_mount_removes_prefix_at_boundary():
|
||||
assert strip_mount("/data/sub/x.txt", "/data") == "/sub/x.txt"
|
||||
|
||||
|
||||
def test_strip_mount_respects_path_boundary():
|
||||
assert strip_mount("/database/x.txt", "/data") == "/database/x.txt"
|
||||
|
||||
|
||||
def test_strip_mount_at_mount_root():
|
||||
assert strip_mount("/data", "/data") == "/"
|
||||
|
||||
|
||||
def test_strip_mount_without_prefix():
|
||||
assert strip_mount("/x.txt", "") == "/x.txt"
|
||||
|
||||
|
||||
def test_mount_key_strips_surrounding_slashes():
|
||||
assert mount_key("/data/sub/x.txt", "/data") == "sub/x.txt"
|
||||
|
||||
|
||||
def test_mount_key_at_mount_root_is_empty():
|
||||
assert mount_key("/data", "/data") == ""
|
||||
|
||||
|
||||
def test_mount_key_without_prefix():
|
||||
assert mount_key("/x.txt", "") == "x.txt"
|
||||
|
||||
|
||||
def test_rekey_child_under_named_mount():
|
||||
assert rekey("/data/sub", "sub", "/data/sub/x.txt") == "sub/x.txt"
|
||||
|
||||
|
||||
def test_rekey_child_at_mount_root():
|
||||
assert rekey("/data", "", "/data/x.txt") == "x.txt"
|
||||
|
||||
|
||||
def test_rekey_deep_child():
|
||||
assert rekey("/mnt/s3", "", "/mnt/s3/a/b/c.txt") == "a/b/c.txt"
|
||||
|
||||
|
||||
def test_rekey_matches_mount_key():
|
||||
parent_original = "/data/sub"
|
||||
prefix = "/data"
|
||||
parent_key = mount_key(parent_original, prefix)
|
||||
child = "/data/sub/deep/y.txt"
|
||||
assert rekey(parent_original, parent_key,
|
||||
child) == mount_key(child, prefix)
|
||||
@@ -0,0 +1,168 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.utils.path import (expand_tilde, gnu_basename, gnu_dirname, norm,
|
||||
parent, resolve_path)
|
||||
|
||||
|
||||
def test_norm_strips_and_adds_leading_slash():
|
||||
assert norm("a/b") == "/a/b"
|
||||
assert norm("/a/b/") == "/a/b"
|
||||
assert norm("///a///") == "/a"
|
||||
assert norm("") == "/"
|
||||
assert norm("/") == "/"
|
||||
|
||||
|
||||
def test_parent_of_normalized_key():
|
||||
assert parent("/a/b") == "/a"
|
||||
assert parent("/a") == "/"
|
||||
assert parent("/") == "/"
|
||||
assert parent("/a/b/c") == "/a/b"
|
||||
|
||||
|
||||
def test_basename_simple():
|
||||
assert gnu_basename("/a/b/c.txt") == "c.txt"
|
||||
|
||||
|
||||
def test_basename_no_slash():
|
||||
assert gnu_basename("c.txt") == "c.txt"
|
||||
|
||||
|
||||
def test_basename_trailing_slash():
|
||||
assert gnu_basename("/a/b/") == "b"
|
||||
|
||||
|
||||
def test_basename_multiple_trailing_slashes():
|
||||
assert gnu_basename("/a/b///") == "b"
|
||||
|
||||
|
||||
def test_basename_root():
|
||||
assert gnu_basename("/") == "/"
|
||||
|
||||
|
||||
def test_basename_empty():
|
||||
assert gnu_basename("") == ""
|
||||
|
||||
|
||||
def test_basename_strip_suffix():
|
||||
assert gnu_basename("/a/b/c.txt", ".txt") == "c"
|
||||
|
||||
|
||||
def test_basename_suffix_equal_to_base_not_stripped():
|
||||
assert gnu_basename("/a/.txt", ".txt") == ".txt"
|
||||
|
||||
|
||||
def test_basename_suffix_not_matching():
|
||||
assert gnu_basename("/a/c.txt", ".md") == "c.txt"
|
||||
|
||||
|
||||
def test_dirname_simple():
|
||||
assert gnu_dirname("/a/b/c.txt") == "/a/b"
|
||||
|
||||
|
||||
def test_dirname_relative_nested():
|
||||
assert gnu_dirname("a/b") == "a"
|
||||
|
||||
|
||||
def test_dirname_trailing_slash():
|
||||
assert gnu_dirname("/a/b/") == "/a"
|
||||
|
||||
|
||||
def test_dirname_single_absolute():
|
||||
assert gnu_dirname("/a") == "/"
|
||||
|
||||
|
||||
def test_dirname_single_relative():
|
||||
assert gnu_dirname("a") == "."
|
||||
|
||||
|
||||
def test_dirname_root():
|
||||
assert gnu_dirname("/") == "/"
|
||||
|
||||
|
||||
def test_dirname_empty():
|
||||
assert gnu_dirname("") == "."
|
||||
|
||||
|
||||
def test_resolve_relative_against_cwd():
|
||||
assert resolve_path("file.txt", "/data/") == "/data/file.txt"
|
||||
|
||||
|
||||
def test_resolve_parent_traversal():
|
||||
assert resolve_path("../file.txt", "/data/sub/") == "/data/file.txt"
|
||||
|
||||
|
||||
def test_resolve_absolute_ignores_cwd():
|
||||
assert resolve_path("/abs/path", "/ignored") == "/abs/path"
|
||||
|
||||
|
||||
def test_resolve_current_dir_segment():
|
||||
assert resolve_path("./x", "/a/b") == "/a/b/x"
|
||||
|
||||
|
||||
def test_expand_tilde_alone():
|
||||
assert expand_tilde("~", "/home/u") == "/home/u"
|
||||
|
||||
|
||||
def test_expand_tilde_with_subpath():
|
||||
assert expand_tilde("~/file.txt", "/home/u") == "/home/u/file.txt"
|
||||
|
||||
|
||||
def test_expand_tilde_root_home():
|
||||
assert expand_tilde("~/file.txt", "/") == "/file.txt"
|
||||
|
||||
|
||||
def test_expand_tilde_user_unchanged():
|
||||
assert expand_tilde("~other/x", "/home/u") == "~other/x"
|
||||
|
||||
|
||||
def test_expand_tilde_non_leading_unchanged():
|
||||
assert expand_tilde("a~b", "/home/u") == "a~b"
|
||||
|
||||
|
||||
def test_expand_tilde_plain_word_unchanged():
|
||||
assert expand_tilde("file.txt", "/home/u") == "file.txt"
|
||||
|
||||
|
||||
def test_resolve_symlinks_prefix_substitution():
|
||||
from mirage.utils.path import resolve_symlinks
|
||||
links = {"/a/link": "/a/real"}
|
||||
assert resolve_symlinks("/a/link/f.txt", links) == "/a/real/f.txt"
|
||||
assert resolve_symlinks("/a/link", links) == "/a/real"
|
||||
|
||||
|
||||
def test_resolve_symlinks_relative_target_resolved_against_link_dir():
|
||||
from mirage.utils.path import resolve_symlinks
|
||||
links = {"/a/link": "real"}
|
||||
assert resolve_symlinks("/a/link", links) == "/a/real"
|
||||
|
||||
|
||||
def test_resolve_symlinks_respects_path_boundary():
|
||||
from mirage.utils.path import resolve_symlinks
|
||||
links = {"/a/b": "/x"}
|
||||
assert resolve_symlinks("/a/bc", links) == "/a/bc"
|
||||
|
||||
|
||||
def test_resolve_symlinks_no_links_is_identity():
|
||||
from mirage.utils.path import resolve_symlinks
|
||||
assert resolve_symlinks("/a/b", {}) == "/a/b"
|
||||
|
||||
|
||||
def test_resolve_symlinks_cycle_raises():
|
||||
import pytest
|
||||
|
||||
from mirage.utils.path import CycleError, resolve_symlinks
|
||||
links = {"/a": "/b", "/b": "/a"}
|
||||
with pytest.raises(CycleError):
|
||||
resolve_symlinks("/a", links)
|
||||
@@ -0,0 +1,44 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.utils.score import format_score, score_from_distance
|
||||
|
||||
|
||||
def test_score_from_distance_zero_is_full_similarity():
|
||||
assert score_from_distance(0.0) == "1.00"
|
||||
|
||||
|
||||
def test_score_from_distance_clamps_negative_similarity():
|
||||
assert score_from_distance(2.5) == "0.00"
|
||||
|
||||
|
||||
def test_score_from_distance_fraction():
|
||||
assert score_from_distance(0.25) == "0.75"
|
||||
|
||||
|
||||
def test_score_from_distance_non_numeric():
|
||||
assert score_from_distance(None) == "0.00"
|
||||
assert score_from_distance("0.1") == "0.00"
|
||||
assert score_from_distance(True) == "0.00"
|
||||
|
||||
|
||||
def test_format_score_numeric():
|
||||
assert format_score(0.913) == "0.91"
|
||||
assert format_score(1) == "1.00"
|
||||
|
||||
|
||||
def test_format_score_non_numeric():
|
||||
assert format_score(None) is None
|
||||
assert format_score("0.5") is None
|
||||
assert format_score(False) is None
|
||||
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
|
||||
from mirage.utils.stream import collect_bytes, ensure_stream
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ensure_stream_from_bytes():
|
||||
chunks = [c async for c in ensure_stream(b"hello")]
|
||||
assert chunks == [b"hello"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ensure_stream_from_iterator():
|
||||
|
||||
async def src():
|
||||
yield b"foo"
|
||||
yield b"bar"
|
||||
|
||||
chunks = [c async for c in ensure_stream(src())]
|
||||
assert chunks == [b"foo", b"bar"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_collect_bytes_from_bytes():
|
||||
assert await collect_bytes(b"hello") == b"hello"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_collect_bytes_from_iterator():
|
||||
|
||||
async def src():
|
||||
yield b"foo"
|
||||
yield b"bar"
|
||||
|
||||
assert await collect_bytes(src()) == b"foobar"
|
||||
Reference in New Issue
Block a user