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,147 @@
|
||||
# ========= 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.cache.context import push_cache_manager
|
||||
from mirage.cache.file.ram import RAMFileCacheStore
|
||||
from mirage.cache.manager import CacheManager
|
||||
from mirage.commands.builtin.generic.grep import grep as generic_grep
|
||||
from mirage.commands.builtin.generic.head import head_multi
|
||||
from mirage.commands.builtin.generic.rg import rg as generic_rg
|
||||
from mirage.commands.builtin.generic.tail import tail_multi
|
||||
from mirage.commands.builtin.generic.wc import format_multi
|
||||
from mirage.io.types import materialize
|
||||
from mirage.types import FileStat, FileType, PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_PAYLOAD = b"alpha\nbeta\n"
|
||||
|
||||
|
||||
class _CountingReader:
|
||||
|
||||
def __init__(self, data: bytes) -> None:
|
||||
self.data = data
|
||||
self.calls = 0
|
||||
|
||||
async def __call__(self, accessor, path, *args, **kwargs) -> bytes:
|
||||
self.calls += 1
|
||||
return self.data
|
||||
|
||||
|
||||
def _spec() -> PathSpec:
|
||||
return PathSpec(resource_path=mount_key("/s3/a.txt", "/s3/"),
|
||||
virtual="/s3/a.txt",
|
||||
directory="/s3/")
|
||||
|
||||
|
||||
async def _warm_manager() -> CacheManager:
|
||||
cache = RAMFileCacheStore()
|
||||
await cache.set("/s3/a.txt", _PAYLOAD)
|
||||
return CacheManager(cache, None, "/s3/", True)
|
||||
|
||||
|
||||
async def _stat(accessor, path, index=None) -> FileStat:
|
||||
return FileStat(name="a.txt", type=FileType.TEXT, size=len(_PAYLOAD))
|
||||
|
||||
|
||||
async def _readdir(accessor, path, index=None) -> list[str]:
|
||||
return ["/s3/a.txt"]
|
||||
|
||||
|
||||
async def _drain(source) -> bytes:
|
||||
return b"".join([c async for c in source])
|
||||
|
||||
|
||||
# Every read-content command funnels its file read through one of these shared
|
||||
# consumers, which wrap the injected reader with cache_aware_* at the choke
|
||||
# point. A backend can therefore pass a RAW reader and warm reads still serve
|
||||
# from cache. These tests pin that guarantee: with a warm manager active, the
|
||||
# consumer must NOT call the backend reader. If a consumer loses its wrap, the
|
||||
# call count goes non-zero and the matching test fails.
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_head_multi_serves_cache_without_backend():
|
||||
# head_multi is built in-scope but drained AFTER the manager scope is
|
||||
# popped (mirroring the mount lifecycle), so this also pins eager capture:
|
||||
# a lazily-captured manager would be gone by drain and the read would miss.
|
||||
reader = _CountingReader(_PAYLOAD)
|
||||
manager = await _warm_manager()
|
||||
prev = push_cache_manager(manager)
|
||||
source = head_multi([_spec()], read=reader, n=1)
|
||||
push_cache_manager(prev)
|
||||
out = await _drain(source)
|
||||
assert out == b"alpha\n"
|
||||
assert reader.calls == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tail_multi_serves_cache_without_backend():
|
||||
reader = _CountingReader(_PAYLOAD)
|
||||
manager = await _warm_manager()
|
||||
prev = push_cache_manager(manager)
|
||||
source = tail_multi([_spec()], read=reader, n=1)
|
||||
push_cache_manager(prev)
|
||||
out = await _drain(source)
|
||||
assert out == b"beta\n"
|
||||
assert reader.calls == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wc_format_multi_serves_cache_without_backend():
|
||||
reader = _CountingReader(_PAYLOAD)
|
||||
manager = await _warm_manager()
|
||||
prev = push_cache_manager(manager)
|
||||
try:
|
||||
out, err = await format_multi([_spec()], read=reader, args_l=True)
|
||||
finally:
|
||||
push_cache_manager(prev)
|
||||
assert b"2" in out
|
||||
assert err == b""
|
||||
assert reader.calls == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generic_grep_serves_cache_without_backend():
|
||||
reader = _CountingReader(_PAYLOAD)
|
||||
manager = await _warm_manager()
|
||||
prev = push_cache_manager(manager)
|
||||
try:
|
||||
out, io = await generic_grep([_spec()], ("alpha", ), {},
|
||||
readdir=_readdir,
|
||||
stat=_stat,
|
||||
read_bytes=reader,
|
||||
read_stream=None)
|
||||
finally:
|
||||
push_cache_manager(prev)
|
||||
assert b"alpha" in await materialize(out)
|
||||
assert reader.calls == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generic_rg_serves_cache_without_backend():
|
||||
reader = _CountingReader(_PAYLOAD)
|
||||
manager = await _warm_manager()
|
||||
prev = push_cache_manager(manager)
|
||||
try:
|
||||
out, io = await generic_rg([_spec()], ("alpha", ), {},
|
||||
readdir=_readdir,
|
||||
stat=_stat,
|
||||
read_bytes=reader,
|
||||
read_stream=None)
|
||||
finally:
|
||||
push_cache_manager(prev)
|
||||
assert b"alpha" in await materialize(out)
|
||||
assert reader.calls == 0
|
||||
Reference in New Issue
Block a user