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. =========
+360
View File
@@ -0,0 +1,360 @@
# ========= 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
import os
import subprocess
import uuid
from collections.abc import AsyncIterator
from contextlib import ExitStack
from datetime import datetime, timezone
from unittest.mock import patch
import pytest
from mirage.core.ram.mkdir import mkdir
from mirage.core.ram.write import write_bytes as mem_write
from mirage.io.types import ByteSource
from mirage.resource.disk import DiskResource
from mirage.resource.ram import RAMResource
from mirage.resource.redis import RedisResource
from mirage.resource.s3 import S3Config, S3Resource
from mirage.types import MountMode
from mirage.workspace import Workspace
BUCKET = "test-bucket"
REGION = "us-east-1"
LAST_MODIFIED = datetime(2026, 3, 31, tzinfo=timezone.utc)
_CORE_MODULES = [
"mirage.core.s3.read",
"mirage.core.s3.write",
"mirage.core.s3.stat",
"mirage.core.s3.readdir",
"mirage.core.s3.find",
"mirage.core.s3.du",
"mirage.core.s3.stream",
"mirage.core.s3.copy",
"mirage.core.s3.rename",
"mirage.core.s3.unlink",
"mirage.core.s3.rmdir",
"mirage.core.s3.rm",
"mirage.core.s3.mkdir",
"mirage.core.s3.create",
"mirage.core.s3.truncate",
]
class AsyncMockBody:
def __init__(self, data: bytes) -> None:
self._data = data
async def read(self) -> bytes:
return self._data
async def iter_chunks(self, chunk_size: int = 8192):
for i in range(0, len(self._data), chunk_size):
yield self._data[i:i + chunk_size]
class AsyncMockPaginator:
def __init__(self, objects: dict[str, bytes]) -> None:
self.objects = objects
async def paginate(self,
Bucket: str,
Prefix: str = "",
Delimiter: str | None = None):
del Bucket
if Delimiter == "/":
yield _paginate_directory(self.objects, Prefix)
else:
yield _paginate_flat(self.objects, Prefix)
class AsyncMockS3Client:
def __init__(self, objects: dict[str, bytes]) -> None:
self.objects = objects
async def get_object(self,
Bucket: str,
Key: str,
Range: str | None = None) -> dict:
del Bucket
if Key not in self.objects:
raise _mock_s3_error("NoSuchKey")
data = self.objects[Key]
if Range is not None:
data = _slice_range(data, Range)
return {"Body": AsyncMockBody(data)}
async def head_object(self, Bucket: str, Key: str) -> dict:
del Bucket
if Key not in self.objects:
raise _mock_s3_error("NoSuchKey")
return {
"ContentLength": len(self.objects[Key]),
"LastModified": LAST_MODIFIED,
"ETag": f'"{Key}"',
}
def get_paginator(self, name: str) -> AsyncMockPaginator:
assert name == "list_objects_v2"
return AsyncMockPaginator(self.objects)
async def put_object(self, Bucket: str, Key: str, Body: bytes) -> None:
self.objects[Key] = Body
async def delete_object(self, Bucket: str, Key: str) -> None:
self.objects.pop(Key, None)
async def copy_object(self, Bucket: str, CopySource: dict,
Key: str) -> None:
src_key = CopySource["Key"]
if src_key in self.objects:
self.objects[Key] = self.objects[src_key]
async def delete_objects(self, Bucket: str, Delete: dict) -> None:
for obj in Delete.get("Objects", []):
self.objects.pop(obj["Key"], None)
async def list_objects_v2(self,
Bucket: str,
Prefix: str = "",
Delimiter: str = "",
MaxKeys: int = 1000,
**kwargs) -> dict:
if Delimiter == "/":
return _paginate_directory(self.objects, Prefix)
return _paginate_flat(self.objects, Prefix)
async def __aenter__(self):
return self
async def __aexit__(self, *args):
pass
class MockAsyncSession:
def __init__(self, objects: dict[str, bytes]) -> None:
self._client = AsyncMockS3Client(objects)
def client(self, **kwargs):
return self._client
def _mock_s3_error(code: str) -> Exception:
exc = Exception(code)
exc.response = {"Error": {"Code": code}}
return exc
def _paginate_directory(objects, prefix):
common_prefixes: set[str] = set()
contents: list[dict[str, object]] = []
for key, data in sorted(objects.items()):
if not key.startswith(prefix):
continue
relative = key[len(prefix):]
if not relative:
contents.append({"Key": key, "Size": len(data)})
continue
if "/" in relative:
child = relative.split("/", 1)[0]
common_prefixes.add(prefix + child + "/")
continue
contents.append({"Key": key, "Size": len(data)})
return {
"CommonPrefixes": [{
"Prefix": v
} for v in sorted(common_prefixes)],
"Contents": contents,
}
def _paginate_flat(objects, prefix):
return {
"Contents": [{
"Key": k,
"Size": len(v)
} for k, v in sorted(objects.items()) if k.startswith(prefix)]
}
def _slice_range(data: bytes, range_spec: str) -> bytes:
if not range_spec.startswith("bytes="):
return data
bounds = range_spec.removeprefix("bytes=").split("-", 1)
start = int(bounds[0]) if bounds[0] else 0
end = int(bounds[1]) if bounds[1] else len(data) - 1
return data[start:end + 1]
def _patch_async_session(objects):
mock_session = MockAsyncSession(objects)
stack = ExitStack()
for mod in _CORE_MODULES:
stack.enter_context(
patch(f"{mod}.async_session", return_value=mock_session))
return stack
def _make_s3_env(tmp_path):
objects: dict[str, bytes] = {}
config = S3Config(
bucket=BUCKET,
region=REGION,
aws_access_key_id="testing",
aws_secret_access_key="testing",
)
resource = S3Resource(config)
return NativeTestEnv(tmp_path, resource, "s3", objects=objects)
def _make_memory_env(tmp_path):
resource = RAMResource()
return NativeTestEnv(tmp_path, resource, "ram")
def _make_disk_env(tmp_path):
disk_root = tmp_path / "disk_root"
disk_root.mkdir()
resource = DiskResource(root=str(disk_root))
return NativeTestEnv(tmp_path, resource, "disk", disk_root=disk_root)
def _make_redis_env(tmp_path):
url = os.environ["REDIS_URL"]
prefix = f"mirage:test:{uuid.uuid4().hex[:8]}:"
resource = RedisResource(url=url, key_prefix=prefix)
return NativeTestEnv(tmp_path, resource, "redis")
def _redis_available():
return "REDIS_URL" in os.environ
_PARAMS = ["ram", "s3", "disk"]
if _redis_available():
_PARAMS.append("redis")
@pytest.fixture(params=_PARAMS)
def env(request, tmp_path):
if request.param == "s3":
test_env = _make_s3_env(tmp_path)
with _patch_async_session(test_env.objects):
yield test_env
elif request.param == "disk":
yield _make_disk_env(tmp_path)
elif request.param == "redis":
test_env = _make_redis_env(tmp_path)
yield test_env
asyncio.run(test_env.resource._store.clear())
else:
yield _make_memory_env(tmp_path)
async def _drain(ait: AsyncIterator[bytes]) -> list[bytes]:
return [chunk async for chunk in ait]
def _collect(stdout: ByteSource | None) -> bytes:
if stdout is None:
return b""
if isinstance(stdout, bytes):
return stdout
return b"".join(asyncio.run(_drain(stdout)))
class NativeTestEnv:
def __init__(self,
tmp_path,
resource,
resource_type,
objects=None,
disk_root=None):
self.tmp_path = tmp_path
self.resource = resource
self.resource_type = resource_type
self.objects = objects
self.disk_root = disk_root
self.ws = Workspace(
{"/data": (resource, MountMode.WRITE)},
mode=MountMode.WRITE,
)
def create_file(self, name: str, content: bytes):
local_path = self.tmp_path / name
local_path.parent.mkdir(parents=True, exist_ok=True)
local_path.write_bytes(content)
remote_path = "/" + name
if self.resource_type == "disk":
resource_path = self.disk_root / name
resource_path.parent.mkdir(parents=True, exist_ok=True)
resource_path.write_bytes(content)
elif self.resource_type == "s3":
key = name
self.objects[key] = content
elif self.resource_type == "redis":
self._redis_write(remote_path, content)
else:
self._memory_write(remote_path, content)
def _redis_write(self, path: str, content: bytes):
store = self.resource._store
parts = path.strip("/").split("/")
for i in range(1, len(parts)):
d = "/" + "/".join(parts[:i])
asyncio.run(store.add_dir(d))
asyncio.run(store.set_file(path, content))
def _memory_write(self, path: str, content: bytes):
accessor = self.resource.accessor
parts = path.strip("/").split("/")
for i in range(1, len(parts)):
d = "/" + "/".join(parts[:i])
if d not in accessor.store.dirs:
try:
asyncio.run(mkdir(accessor, d))
except (FileExistsError, ValueError):
pass
asyncio.run(mem_write(accessor, path, content))
def native(self, cmd: str, stdin: bytes | None = None) -> str:
native_cwd = self.disk_root if self.disk_root else self.tmp_path
result = subprocess.run(
["/bin/sh", "-c", cmd],
cwd=str(native_cwd),
capture_output=True,
input=stdin,
)
return result.stdout.decode(errors="replace")
def mirage(self, cmd: str, stdin: bytes | None = None) -> str:
self.ws._cwd = "/data"
io = asyncio.run(self.ws.execute(cmd, stdin=stdin))
if io.exit_code:
import sys
err = _collect(io.stderr).decode(errors="replace")
print(
f"\nMIRAGE-DEBUG exit={io.exit_code} cmd={cmd!r} "
f"stderr={err!r}",
file=sys.stderr)
return _collect(io.stdout).decode(errors="replace")
+47
View File
@@ -0,0 +1,47 @@
# ========= 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. =========
def test_awk_print_field(env):
data = b"alice 30\nbob 25\n"
assert env.mirage("awk '{print $1}'",
stdin=data) == env.native("awk '{print $1}'", stdin=data)
def test_awk_F(env):
data = b"a,b,c\n1,2,3\n"
assert env.mirage("awk -F , '{print $2}'",
stdin=data) == env.native("awk -F , '{print $2}'",
stdin=data)
def test_awk_file(env):
env.create_file("f.txt", b"alice 30\nbob 25\n")
assert env.mirage("awk '{print $2}' /data/f.txt") == env.native(
"awk '{print $2}' f.txt")
def test_awk_f(env):
if env.resource_type == "redis":
return
env.create_file("prog.awk", b"{print $1}")
env.create_file("data.txt", b"hello world\nfoo bar\n")
assert env.mirage("awk -f /data/prog.awk /data/data.txt") == env.native(
"awk -f prog.awk data.txt")
def test_awk_v(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("awk -v x=hello '{print x}' /data/f.txt") == env.native(
"awk -v x=hello '{print x}' f.txt")
@@ -0,0 +1,42 @@
# ========= 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. =========
def test_base64_encode(env):
data = b"hello world\n"
assert env.mirage("base64", stdin=data) == env.native("base64", stdin=data)
def test_base64_decode(env):
data = b"aGVsbG8gd29ybGQK\n"
assert env.mirage("base64 -d", stdin=data) == env.native("base64 -d",
stdin=data)
def test_base64_file(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("base64 /data/f.txt") == env.native("base64 < f.txt")
def test_base64_w(env):
data = b"hello world this is a longer string for wrapping"
result = env.mirage("base64 -w 20", stdin=data)
lines = result.strip().split("\n")
assert all(len(line) <= 20 for line in lines[:-1])
def test_base64_D(env):
data = b"aGVsbG8=\n"
result = env.mirage("base64 -D", stdin=data)
assert result == "hello"
@@ -0,0 +1,18 @@
# ========= 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. =========
def test_basename(env):
assert env.mirage("basename /foo/bar/baz.txt") == env.native(
"basename /foo/bar/baz.txt")
+24
View File
@@ -0,0 +1,24 @@
# ========= 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. =========
def test_bc_q(env):
data = b"2+3\n"
assert env.mirage("bc -q", stdin=data) == env.native("bc -q", stdin=data)
def test_bc_l(env):
data = b"sqrt(2)\n"
result = env.mirage("bc -l", stdin=data)
assert "1.41" in result
+33
View File
@@ -0,0 +1,33 @@
# ========= 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. =========
def test_cat_basic(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("cat /data/f.txt") == env.native("cat f.txt")
def test_cat_n(env):
env.create_file("f.txt", b"hello\nworld\n")
assert env.mirage("cat -n /data/f.txt") == env.native("cat -n f.txt")
def test_cat_stdin(env):
data = b"from stdin\n"
assert env.mirage("cat", stdin=data) == env.native("cat", stdin=data)
def test_cat_multiline(env):
env.create_file("f.txt", b"line1\nline2\nline3\n")
assert env.mirage("cat /data/f.txt") == env.native("cat f.txt")
+66
View File
@@ -0,0 +1,66 @@
# ========= 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. =========
def test_cmp_identical(env):
env.create_file("a.txt", b"same\n")
env.create_file("b.txt", b"same\n")
assert env.mirage("cmp /data/a.txt /data/b.txt") == env.native(
"cmp a.txt b.txt")
def test_cmp_s(env):
env.create_file("a.txt", b"aaa\n")
env.create_file("b.txt", b"bbb\n")
assert env.mirage("cmp -s /data/a.txt /data/b.txt") == ""
assert env.native("cmp -s a.txt b.txt") == ""
def test_cmp_n(env):
env.create_file("a.txt", b"hello world")
env.create_file("b.txt", b"hello earth")
m = env.mirage("cmp -n 5 /data/a.txt /data/b.txt")
n = env.native("cmp -n 5 a.txt b.txt")
assert m == n
def test_cmp_n_differ(env):
env.create_file("a.txt", b"hello world")
env.create_file("b.txt", b"hello earth")
m = env.mirage("cmp -n 10 /data/a.txt /data/b.txt")
n = env.native("cmp -n 10 a.txt b.txt")
assert (len(m) > 0) == (len(n) > 0)
def test_cmp_i(env):
env.create_file("a.txt", b"XXhello")
env.create_file("b.txt", b"YYhello")
m = env.mirage("cmp -i 2 /data/a.txt /data/b.txt")
n = env.native("cmp -i 2 a.txt b.txt")
assert m == n
def test_cmp_l(env):
env.create_file("a.txt", b"abc")
env.create_file("b.txt", b"axc")
result = env.mirage("cmp -l /data/a.txt /data/b.txt")
native = env.native("cmp -l a.txt b.txt")
assert result.split() == native.split()
def test_cmp_b(env):
env.create_file("a.txt", b"abc")
env.create_file("b.txt", b"axc")
result = env.mirage("cmp -b /data/a.txt /data/b.txt")
assert "differ" in result
@@ -0,0 +1,25 @@
# ========= 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. =========
def test_column_o(env):
data = b"a b c\nd e f\n"
result = env.mirage("column -t -o '|'", stdin=data)
assert result == "a|b|c\nd|e|f\n"
def test_column_s(env):
data = b"a:b:c\nd:e:f\n"
result = env.mirage("column -t -s :", stdin=data)
assert "a" in result and "b" in result
+55
View File
@@ -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. =========
def test_comm_default(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
assert env.mirage("comm /data/a.txt /data/b.txt") == env.native(
"comm a.txt b.txt")
def test_comm_1(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
assert env.mirage("comm -1 /data/a.txt /data/b.txt") == env.native(
"comm -1 a.txt b.txt")
def test_comm_23(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
assert env.mirage("comm -23 /data/a.txt /data/b.txt") == env.native(
"comm -23 a.txt b.txt")
def test_comm_nocheck_order(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
assert env.mirage("comm --nocheck-order /data/a.txt /data/b.txt"
) == env.mirage("comm /data/a.txt /data/b.txt")
def test_comm_3(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
assert env.mirage("comm -3 /data/a.txt /data/b.txt") == env.native(
"comm -3 a.txt b.txt")
def test_comm_check_order(env):
env.create_file("a.txt", b"a\nb\nc\n")
env.create_file("b.txt", b"b\nc\nd\n")
result = env.mirage("comm --check-order /data/a.txt /data/b.txt")
assert len(result) > 0
+59
View File
@@ -0,0 +1,59 @@
# ========= 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. =========
def test_cp_basic(env):
env.create_file("src.txt", b"hello")
env.mirage("cp /data/src.txt /data/dst.txt")
assert env.mirage("cat /data/dst.txt") == "hello"
def test_cp_a(env):
env.create_file("src/a.txt", b"aaa")
env.mirage("cp -a /data/src/ /data/dst/")
assert env.mirage("cat /data/dst/a.txt") == "aaa"
def test_cp_n(env):
env.create_file("src.txt", b"new")
env.create_file("dst.txt", b"old")
env.mirage("cp -n /data/src.txt /data/dst.txt")
assert env.mirage("cat /data/dst.txt") == "old"
def test_cp_v(env):
env.create_file("src.txt", b"hello")
result = env.mirage("cp -v /data/src.txt /data/dst.txt")
assert "src.txt" in result and "->" in result and "dst.txt" in result
def test_cp_f(env):
env.create_file("src.txt", b"hello")
env.create_file("dst.txt", b"old")
env.mirage("cp -f /data/src.txt /data/dst.txt")
assert env.mirage("cat /data/dst.txt") == "hello"
def test_cp_r(env):
env.create_file("src/a.txt", b"hello")
env.mirage("cp -r /data/src /data/dst")
result = env.mirage("cat /data/dst/a.txt")
assert "hello" in result
def test_cp_R(env):
env.create_file("src/a.txt", b"hello")
env.mirage("cp -R /data/src /data/dst2")
result = env.mirage("cat /data/dst2/a.txt")
assert "hello" in result
@@ -0,0 +1,259 @@
# ========= 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 contextlib import ExitStack
from unittest.mock import patch
import pytest
from mirage.core.ram.mkdir import mkdir
from mirage.core.ram.write import write_bytes as mem_write
from mirage.provision import Precision
from mirage.resource.disk import DiskResource
from mirage.resource.ram import RAMResource
from mirage.resource.s3 import S3Config, S3Resource
from mirage.types import DEFAULT_SESSION_ID, MountMode
from mirage.workspace import Workspace
from tests.commands.native.conftest import (_CORE_MODULES, BUCKET, REGION,
MockAsyncSession)
def _run(ws, cmd):
async def _inner():
io = await ws.execute(cmd)
return await io.stdout_str()
return asyncio.run(_inner())
def _exit(ws, cmd):
io = asyncio.run(ws.execute(cmd))
return io.exit_code
def _make_s3_resource(shared_objects):
config = S3Config(bucket=BUCKET,
region=REGION,
aws_access_key_id="testing",
aws_secret_access_key="testing")
return S3Resource(config)
def _make_resource(ptype, tmp_path, idx, shared_s3_objects):
if ptype == "ram":
return RAMResource(), None
elif ptype == "disk":
root = tmp_path / f"disk{idx}"
root.mkdir()
return DiskResource(root=str(root)), root
elif ptype == "s3":
return _make_s3_resource(shared_s3_objects), None
raise ValueError(f"Unknown resource type: {ptype}")
def _write_file(ptype,
name,
content,
disk_root=None,
s3_objects=None,
mem_accessor=None):
path = "/" + name
if ptype == "ram":
parts = path.strip("/").split("/")
for i in range(1, len(parts)):
d = "/" + "/".join(parts[:i])
if d not in mem_accessor.store.dirs:
try:
asyncio.run(mkdir(mem_accessor, d))
except (FileExistsError, ValueError):
pass
asyncio.run(mem_write(mem_accessor, path, content))
elif ptype == "disk":
file_path = disk_root / name
file_path.parent.mkdir(parents=True, exist_ok=True)
file_path.write_bytes(content)
elif ptype == "s3":
s3_objects[name] = content
_PAIRS = [
("ram", "ram"),
("ram", "s3"),
("s3", "ram"),
("ram", "disk"),
("disk", "ram"),
]
class CrossMountEnv:
def __init__(self, ws, p1_type, p2_type, p1_root, p2_root,
shared_s3_objects, p1_accessor, p2_accessor):
self.ws = ws
self._types = (p1_type, p2_type)
self._roots = (p1_root, p2_root)
self._s3_objects = shared_s3_objects
self._accessors = (p1_accessor, p2_accessor)
def create_file(self, mount_idx, name, content):
idx = mount_idx - 1
ptype = self._types[idx]
_write_file(ptype,
name,
content,
disk_root=self._roots[idx],
s3_objects=self._s3_objects,
mem_accessor=self._accessors[idx])
def run(self, cmd):
return _run(self.ws, cmd)
def exit(self, cmd):
return _exit(self.ws, cmd)
@pytest.fixture(params=_PAIRS, ids=[f"{a}->{b}" for a, b in _PAIRS])
def cross(request, tmp_path):
p1_type, p2_type = request.param
shared_s3_objects = {}
p1, p1_root = _make_resource(p1_type, tmp_path, 1, shared_s3_objects)
p2, p2_root = _make_resource(p2_type, tmp_path, 2, shared_s3_objects)
ws = Workspace({
"/m1": (p1, MountMode.WRITE),
"/m2": (p2, MountMode.WRITE)
},
mode=MountMode.WRITE)
ws.get_session(DEFAULT_SESSION_ID).cwd = "/m1"
p1_acc = p1.accessor if hasattr(p1, "accessor") else None
p2_acc = p2.accessor if hasattr(p2, "accessor") else None
env = CrossMountEnv(ws, p1_type, p2_type, p1_root, p2_root,
shared_s3_objects, p1_acc, p2_acc)
if p1_type == "s3" or p2_type == "s3":
mock_session = MockAsyncSession(shared_s3_objects)
stack = ExitStack()
for mod in _CORE_MODULES:
stack.enter_context(
patch(f"{mod}.async_session", return_value=mock_session))
with stack:
yield env
else:
yield env
def test_cp_cross(cross):
cross.create_file(1, "f.txt", b"hello\n")
cross.run("cp /m1/f.txt /m2/copy.txt")
assert cross.run("cat /m2/copy.txt") == "hello\n"
def test_mv_cross(cross):
cross.create_file(1, "f.txt", b"hello\n")
cross.run("mv /m1/f.txt /m2/moved.txt")
assert cross.run("cat /m2/moved.txt") == "hello\n"
assert cross.exit("cat /m1/f.txt") != 0
def test_diff_cross(cross):
cross.create_file(1, "a.txt", b"hello\n")
cross.create_file(2, "b.txt", b"world\n")
result = cross.run("diff /m1/a.txt /m2/b.txt")
assert "hello" in result or "world" in result
def test_diff_identical_cross(cross):
cross.create_file(1, "a.txt", b"same\n")
cross.run("cp /m1/a.txt /m2/b.txt")
assert cross.run("diff /m1/a.txt /m2/b.txt") == ""
def test_cat_multi_cross(cross):
cross.create_file(1, "a.txt", b"aaa\n")
cross.create_file(2, "b.txt", b"bbb\n")
assert cross.run("cat /m1/a.txt /m2/b.txt") == "aaa\nbbb\n"
def test_head_cross(cross):
cross.create_file(1, "a.txt", b"aaa\n")
cross.create_file(2, "b.txt", b"bbb\n")
result = cross.run("head -n 1 /m1/a.txt /m2/b.txt")
assert "==> /m1/a.txt <==" in result
assert "==> /m2/b.txt <==" in result
def test_grep_cross(cross):
cross.create_file(1, "a.txt", b"hello world\n")
cross.create_file(2, "b.txt", b"foo bar\n")
result = cross.run("grep hello /m1/a.txt /m2/b.txt")
assert "/m1/a.txt:" in result
def test_wc_cross(cross):
cross.create_file(1, "a.txt", b"one\ntwo\n")
cross.create_file(2, "b.txt", b"three\n")
result = cross.run("wc -l /m1/a.txt /m2/b.txt")
assert "/m1/a.txt" in result
assert "/m2/b.txt" in result
def test_redirect_cross(cross):
cross.create_file(1, "f.txt", b"hello\n")
cross.run("cat /m1/f.txt > /m2/out.txt")
assert cross.run("cat /m2/out.txt") == "hello\n"
def test_pipe_cross(cross):
cross.create_file(1, "f.txt", b"hello\nworld\n")
result = cross.run("cat /m1/f.txt | grep hello")
assert "hello" in result
def test_cross_resource_md5_fans_out(cross):
cross.create_file(1, "a.txt", b"hello\n")
cross.create_file(2, "b.txt", b"world\n")
single = cross.run("md5 /m1/a.txt") + cross.run("md5 /m2/b.txt")
assert cross.run("md5 /m1/a.txt /m2/b.txt") == single
def test_cross_resource_du_fans_out(cross):
cross.create_file(1, "a.txt", b"hello\n")
cross.create_file(2, "b.txt", b"world!!\n")
out = cross.run("du -c /m1/a.txt /m2/b.txt")
assert "6\t/m1/a.txt" in out
assert "8\t/m2/b.txt" in out
assert "14\ttotal" in out
def test_cross_resource_file_fans_out(cross):
cross.create_file(1, "a.txt", b"hello\n")
cross.create_file(2, "b.txt", b"world\n")
out = cross.run("file /m1/a.txt /m2/b.txt")
assert "/m1/a.txt:" in out
assert "/m2/b.txt:" in out
def test_plan_cross_resource_aggregate_sums(cross):
cross.create_file(1, "a.txt", b"hello\n")
cross.create_file(2, "b.txt", b"world\n")
result = asyncio.run(
cross.ws.execute("md5 /m1/a.txt /m2/b.txt", provision=True))
assert result.precision == Precision.EXACT
assert result.network_read == "12"
@@ -0,0 +1,47 @@
# ========= 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. =========
def test_csplit_s(env):
env.create_file("f.txt", b"aaa\n---\nbbb\n")
result = env.mirage("csplit -s /data/f.txt /---/")
assert result.strip() == ""
def test_csplit_b(env):
env.create_file("f.txt", b"aaa\n---\nbbb\n")
result = env.mirage("csplit -b %03d /data/f.txt /---/")
lines = result.strip().splitlines()
assert len(lines) == 2
def test_csplit_k(env):
env.create_file("f.txt", b"aaa\nbbb\nccc\n")
env.mirage("csplit -k /data/f.txt /bbb/")
result = env.mirage("cat /data/xx00")
assert "aaa" in result
def test_csplit_f(env):
env.create_file("f.txt", b"aaa\nbbb\nccc\n")
env.mirage("csplit -f part /data/f.txt /bbb/")
result = env.mirage("cat /data/part00")
assert "aaa" in result
def test_csplit_n(env):
env.create_file("f.txt", b"aaa\nbbb\nccc\n")
env.mirage("csplit -n 3 /data/f.txt /bbb/")
result = env.mirage("ls /data")
assert "xx000" in result
+47
View File
@@ -0,0 +1,47 @@
# ========= 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. =========
def test_cut_f_d(env):
env.create_file("f.txt", b"a:b:c\nd:e:f\n")
assert env.mirage("cut -f 1 -d : /data/f.txt") == env.native(
"cut -f 1 -d : f.txt")
def test_cut_f_tab(env):
env.create_file("f.txt", b"a\tb\tc\n")
assert env.mirage("cut -f 2 /data/f.txt") == env.native("cut -f 2 f.txt")
def test_cut_c(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("cut -c 1-5 /data/f.txt") == env.native(
"cut -c 1-5 f.txt")
def test_cut_stdin(env):
data = b"a,b,c\nd,e,f\n"
assert env.mirage("cut -f 1 -d ,",
stdin=data) == env.native("cut -f 1 -d ,", stdin=data)
def test_cut_complement(env):
data = b"a:b:c:d\n"
assert env.mirage("cut -d: -f2 --complement", stdin=data) == "a:c:d\n"
def test_cut_z(env):
data = b"a:b\x00c:d\x00"
result = env.mirage("cut -d: -f1 -z", stdin=data)
assert result == "a\x00c\x00"
+33
View File
@@ -0,0 +1,33 @@
# ========= 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. =========
def test_date_I(env):
result = env.mirage("date -I")
assert len(result.strip()) == 10
def test_date_R(env):
result = env.mirage("date -R")
assert "," in result
def test_date_u(env):
result = env.mirage("date -u")
assert "UTC" in result or "GMT" in result or len(result.strip()) > 0
def test_date_d(env):
result = env.mirage("date -d '2024-01-15'")
assert "2024" in result or "Jan" in result
+129
View File
@@ -0,0 +1,129 @@
# ========= 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. =========
def test_diff_identical(env):
env.create_file("a.txt", b"same\n")
env.create_file("b.txt", b"same\n")
assert env.mirage("diff /data/a.txt /data/b.txt") == env.native(
"diff a.txt b.txt")
def test_diff_different(env):
if env.resource_type == "redis":
return
env.create_file("a.txt", b"hello\n")
env.create_file("b.txt", b"world\n")
m = env.mirage("diff /data/a.txt /data/b.txt")
n = env.native("diff a.txt b.txt")
assert ("hello" in m) == ("hello" in n)
assert ("world" in m) == ("world" in n)
def test_diff_i(env):
env.create_file("a.txt", b"Hello\n")
env.create_file("b.txt", b"hello\n")
assert env.mirage("diff -i /data/a.txt /data/b.txt") == env.native(
"diff -i a.txt b.txt")
def test_diff_u(env):
env.create_file("a.txt", b"hello\n")
env.create_file("b.txt", b"world\n")
result = env.mirage("diff -u /data/a.txt /data/b.txt")
assert "@@" in result
assert "-hello" in result
assert "+world" in result
def test_diff_q_differ(env):
if env.resource_type == "redis":
return
env.create_file("a.txt", b"hello\n")
env.create_file("b.txt", b"world\n")
result = env.mirage("diff -q /data/a.txt /data/b.txt")
assert "differ" in result
def test_diff_q_same(env):
env.create_file("a.txt", b"hello\n")
env.create_file("b.txt", b"hello\n")
result = env.mirage("diff -q /data/a.txt /data/b.txt")
assert result.strip() == ""
def test_diff_w(env):
env.create_file("a.txt", b"hello world\n")
env.create_file("b.txt", b"helloworld\n")
result = env.mirage("diff -w /data/a.txt /data/b.txt")
assert result.strip() == ""
def test_diff_b(env):
env.create_file("a.txt", b"hello world\n")
env.create_file("b.txt", b"hello world\n")
result = env.mirage("diff -b /data/a.txt /data/b.txt")
assert result.strip() == ""
def test_diff_e(env):
if env.resource_type == "redis":
return
env.create_file("a.txt", b"hello\n")
env.create_file("b.txt", b"world\n")
result = env.mirage("diff -e /data/a.txt /data/b.txt")
assert "c" in result or "d" in result or "a" in result
def test_diff_r(env):
env.create_file("dir1/a.txt", b"hello\n")
env.create_file("dir2/a.txt", b"world\n")
result = env.mirage("diff -r /data/dir1 /data/dir2")
assert "differ" in result or "hello" in result or "world" in result
def test_diff_r_recurses_subdirs(env):
env.create_file("d1/top.txt", b"same\n")
env.create_file("d2/top.txt", b"same\n")
env.create_file("d1/sub/x.txt", b"alpha\n")
env.create_file("d2/sub/x.txt", b"beta\n")
result = env.mirage("diff -r /data/d1 /data/d2")
assert "alpha" in result and "beta" in result
assert "/data/d1/sub/x.txt" in result
def test_diff_r_only_in(env):
env.create_file("o1/shared.txt", b"s\n")
env.create_file("o2/shared.txt", b"s\n")
env.create_file("o1/leftonly.txt", b"l\n")
env.create_file("o2/rightonly.txt", b"r\n")
result = env.mirage("diff -r /data/o1 /data/o2")
assert "Only in /data/o1: leftonly.txt" in result
assert "Only in /data/o2: rightonly.txt" in result
def test_diff_r_on_files(env):
env.create_file("f1.txt", b"hello\n")
env.create_file("f2.txt", b"world\n")
result = env.mirage("diff -r /data/f1.txt /data/f2.txt")
assert "hello" in result and "world" in result
assert "Not a directory" not in result
def test_diff_r_identical_tree(env):
env.create_file("s1/a.txt", b"x\n")
env.create_file("s1/sub/b.txt", b"y\n")
env.create_file("s2/a.txt", b"x\n")
env.create_file("s2/sub/b.txt", b"y\n")
assert env.mirage("diff -r /data/s1 /data/s2") == ""
@@ -0,0 +1,23 @@
# ========= 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. =========
def test_dirname(env):
assert env.mirage("dirname /foo/bar/baz.txt") == env.native(
"dirname /foo/bar/baz.txt")
def test_dirname_root(env):
assert env.mirage("dirname /foo").strip() == env.native(
"dirname /foo").strip()
+55
View File
@@ -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. =========
def test_du_c(env):
env.create_file("a.txt", b"hello")
env.create_file("b.txt", b"world")
result = env.mirage("du -c /data")
lines = result.strip().splitlines()
assert lines[-1].endswith("total") or lines[-1].split()[-1] == "total"
def test_du_max_depth(env):
env.create_file("sub/a.txt", b"hello")
result = env.mirage("du --max-depth 0 /data")
lines = result.strip().splitlines()
assert len(lines) == 1
def test_du_max_depth_1(env):
env.create_file("sub/deep/a.txt", b"hello")
result = env.mirage("du --max-depth 1 /data")
lines = result.strip().splitlines()
assert not any("deep" in ln for ln in lines)
def test_du_h(env):
env.create_file("f.txt", b"x" * 1024)
result = env.mirage("du -h /data/f.txt")
assert "K" in result or "B" in result or len(result.strip()) > 0
def test_du_s(env):
env.create_file("sub/a.txt", b"hello")
result = env.mirage("du -s /data")
lines = result.strip().splitlines()
assert len(lines) == 1
def test_du_a(env):
env.create_file("a.txt", b"hello")
env.create_file("b.txt", b"world")
result = env.mirage("du -a /data")
assert "a.txt" in result and "b.txt" in result
+49
View File
@@ -0,0 +1,49 @@
# ========= 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. =========
def test_echo_basic(env):
assert env.mirage("echo hello world") == env.native("echo hello world")
def test_echo_n(env):
assert env.mirage("echo -n hello") == env.native("/bin/echo -n hello")
def test_echo_e_newline(env):
assert env.mirage(r"echo -e 'hello\nworld'") == env.native(
r"printf '%s\n' 'hello' 'world'")
def test_echo_e_tab(env):
assert env.mirage(r"echo -e 'col1\tcol2'") == env.native(
r"printf 'col1\tcol2\n'")
def test_echo_e_backslash(env):
assert env.mirage(r"echo -e 'a\\b'") == env.native(r"printf 'a\\b\n'")
def test_echo_e_carriage_return(env):
assert env.mirage(r"echo -e 'hello\rbye'") == env.native(
r"printf 'hello\rbye\n'")
def test_echo_e_mixed(env):
assert env.mirage(r"echo -e 'a\tb\nc'") == env.native(
r"printf 'a\tb\nc\n'")
def test_echo_e_no_escape(env):
assert env.mirage("echo -e hello") == env.native("printf 'hello\n'")
@@ -0,0 +1,41 @@
# ========= 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. =========
def test_expand_default(env):
data = b"hello\tworld\n"
assert env.mirage("expand", stdin=data) == env.native("expand", stdin=data)
def test_expand_t(env):
data = b"hello\tworld\n"
assert env.mirage("expand -t 4", stdin=data) == env.native("expand -t 4",
stdin=data)
def test_expand_file(env):
env.create_file("f.txt", b"a\tb\tc\n")
assert env.mirage("expand /data/f.txt") == env.native("expand f.txt")
def test_expand_i(env):
data = b"\thello\tworld\n"
result = env.mirage("expand -i", stdin=data)
assert result == " hello\tworld\n"
def test_expand_i_multiple_leading(env):
data = b"\t\thello\tworld\n"
result = env.mirage("expand -i", stdin=data)
assert result == " hello\tworld\n"
+25
View File
@@ -0,0 +1,25 @@
# ========= 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. =========
def test_file_b(env):
env.create_file("f.txt", b"hello world\n")
result = env.mirage("file -b /data/f.txt")
assert ":" not in result.strip()
def test_file_i(env):
env.create_file("f.txt", b"hello world\n")
result = env.mirage("file -i /data/f.txt")
assert "text/" in result or "application/" in result
+72
View File
@@ -0,0 +1,72 @@
# ========= 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. =========
def test_find_iname(env):
env.create_file("Hello.txt", b"hi")
result = env.mirage("find /data -iname hello.txt")
assert "Hello.txt" in result
def test_find_mindepth(env):
env.create_file("a.txt", b"a")
env.create_file("sub/b.txt", b"b")
result_all = env.mirage("find /data -type f")
result_md1 = env.mirage("find /data -mindepth 1 -type f")
result_md2 = env.mirage("find /data -mindepth 2 -type f")
assert "a.txt" in result_all
assert "a.txt" in result_md1
assert "b.txt" in result_md1
assert "a.txt" not in result_md2
assert "b.txt" in result_md2
def test_find_path(env):
env.create_file("sub/hello.txt", b"hi")
env.create_file("other/hello.txt", b"hi")
result = env.mirage("find /data -path '*/sub/*'")
assert "sub" in result
assert "other" not in result
def test_find_name(env):
env.create_file("hello.txt", b"hi")
env.create_file("world.txt", b"hi")
result = env.mirage("find /data -name hello.txt")
assert "hello.txt" in result
assert "world.txt" not in result
def test_find_maxdepth(env):
env.create_file("a.txt", b"hi")
env.create_file("sub/deep/c.txt", b"hi")
result = env.mirage("find /data -maxdepth 1 -type f")
assert "a.txt" in result
assert "c.txt" not in result
def test_find_size(env):
env.create_file("big.txt", b"x" * 1000)
env.create_file("small.txt", b"x")
result = env.mirage("find /data -size +500c -type f")
assert "big.txt" in result
assert "small.txt" not in result
def test_find_mtime(env):
if env.resource_type == "redis":
return
env.create_file("f.txt", b"hello")
result = env.mirage("find /data -mtime -1 -type f")
assert "f.txt" in result
+35
View File
@@ -0,0 +1,35 @@
# ========= 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 sys
import pytest
skip_linux = pytest.mark.skipif(
sys.platform == "linux",
reason="fmt behavior differs between macOS and Linux",
)
@skip_linux
def test_fmt_w(env):
data = b"this is a long line that should be wrapped\n"
assert env.mirage("fmt -w 20", stdin=data) == env.native("fmt -w 20",
stdin=data)
@skip_linux
def test_fmt_file(env):
env.create_file("f.txt", b"short words in a line\n")
assert env.mirage("fmt -w 15 /data/f.txt") == env.native("fmt -w 15 f.txt")
+31
View File
@@ -0,0 +1,31 @@
# ========= 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. =========
def test_fold_w(env):
data = b"abcdefghijklmnopqrstuvwxyz\n"
assert env.mirage("fold -w 10", stdin=data) == env.native("fold -w 10",
stdin=data)
def test_fold_file(env):
env.create_file("f.txt", b"abcdefghijklmnopqrstuvwxyz\n")
assert env.mirage("fold -w 10 /data/f.txt") == env.native(
"fold -w 10 f.txt")
def test_fold_s(env):
data = b"hello world this is a test\n"
assert env.mirage("fold -w 12 -s",
stdin=data) == env.native("fold -w 12 -s", stdin=data)
+223
View File
@@ -0,0 +1,223 @@
# ========= 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. =========
def test_grep_basic(env):
env.create_file("f.txt", b"hello world\nfoo bar\nhello again\n")
assert env.mirage("grep hello /data/f.txt") == env.native(
"grep hello f.txt")
def test_grep_i(env):
env.create_file("f.txt", b"Hello\nworld\nHELLO\n")
assert env.mirage("grep -i hello /data/f.txt") == env.native(
"grep -i hello f.txt")
def test_grep_v(env):
env.create_file("f.txt", b"hello\nworld\nfoo\n")
assert env.mirage("grep -v hello /data/f.txt") == env.native(
"grep -v hello f.txt")
def test_grep_n(env):
env.create_file("f.txt", b"hello\nworld\nhello\n")
assert env.mirage("grep -n hello /data/f.txt") == env.native(
"grep -n hello f.txt")
def test_grep_c(env):
env.create_file("f.txt", b"hello\nworld\nhello\n")
assert env.mirage("grep -c hello /data/f.txt") == env.native(
"grep -c hello f.txt")
def test_grep_w(env):
env.create_file("f.txt", b"hello\nhelloworld\nhello there\n")
assert env.mirage("grep -w hello /data/f.txt") == env.native(
"grep -w hello f.txt")
def test_grep_F(env):
env.create_file("f.txt", b"a.b\na*b\naXb\n")
assert env.mirage("grep -F 'a.b' /data/f.txt") == env.native(
"grep -F 'a.b' f.txt")
def test_grep_o(env):
env.create_file("f.txt", b"hello world\nfoo hello\n")
assert env.mirage("grep -o hello /data/f.txt") == env.native(
"grep -o hello f.txt")
def test_grep_m(env):
env.create_file("f.txt", b"a\na\na\na\n")
assert env.mirage("grep -m 2 a /data/f.txt") == env.native(
"grep -m 2 a f.txt")
def test_grep_iv(env):
env.create_file("f.txt", b"Hello\nworld\nHELLO\nfoo\n")
assert env.mirage("grep -iv hello /data/f.txt") == env.native(
"grep -iv hello f.txt")
def test_grep_nw(env):
env.create_file("f.txt", b"hello\nhelloworld\nhello there\n")
assert env.mirage("grep -nw hello /data/f.txt") == env.native(
"grep -nw hello f.txt")
def test_grep_Fc(env):
env.create_file("f.txt", b"a.b\na.b\naXb\n")
assert env.mirage("grep -Fc 'a.b' /data/f.txt") == env.native(
"grep -Fc 'a.b' f.txt")
def test_grep_no_match(env):
env.create_file("f.txt", b"hello\nworld\n")
assert env.mirage("grep zzz /data/f.txt") == env.native("grep zzz f.txt")
def test_grep_stdin(env):
data = b"hello world\nfoo bar\nhello again\n"
assert env.mirage("grep hello", stdin=data) == env.native("grep hello",
stdin=data)
def test_grep_stdin_i(env):
data = b"Hello\nworld\nHELLO\n"
assert env.mirage("grep -i hello",
stdin=data) == env.native("grep -i hello", stdin=data)
def test_grep_stdin_c(env):
data = b"a\nb\na\n"
assert env.mirage("grep -c a", stdin=data) == env.native("grep -c a",
stdin=data)
def test_grep_A(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("grep -A 1 c /data/f.txt") == env.native(
"grep -A 1 c f.txt")
def test_grep_B(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("grep -B 1 c /data/f.txt") == env.native(
"grep -B 1 c f.txt")
def test_grep_C(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("grep -C 1 c /data/f.txt") == env.native(
"grep -C 1 c f.txt")
def test_grep_A_multiple_matches(env):
env.create_file("f.txt", b"x\na\nb\nc\na\nd\ne\n")
assert env.mirage("grep -A 1 a /data/f.txt") == env.native(
"grep -A 1 a f.txt")
def test_grep_B_multiple_matches(env):
env.create_file("f.txt", b"x\ny\na\nb\nc\na\n")
assert env.mirage("grep -B 1 a /data/f.txt") == env.native(
"grep -B 1 a f.txt")
def test_grep_C_multiple_matches(env):
env.create_file("f.txt", b"w\nx\na\ny\nz\na\nb\n")
assert env.mirage("grep -C 1 a /data/f.txt") == env.native(
"grep -C 1 a f.txt")
def test_grep_A_overlapping(env):
env.create_file("f.txt", b"a\nb\na\nc\nd\n")
assert env.mirage("grep -A 2 a /data/f.txt") == env.native(
"grep -A 2 a f.txt")
def test_grep_e_stdin(env):
data = b"hello\nworld\nfoo\n"
assert env.mirage("grep -e hello",
stdin=data) == env.native("grep -e hello", stdin=data)
def test_grep_An_combined(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("grep -n -A 1 c /data/f.txt") == env.native(
"grep -n -A 1 c f.txt")
def test_grep_Ci(env):
env.create_file("f.txt", b"aaa\nbbb\nAAA\nccc\n")
assert env.mirage("grep -C 1 -i aaa /data/f.txt") == env.native(
"grep -C 1 -i aaa f.txt")
def test_grep_A_stdin(env):
data = b"a\nb\nc\nd\ne\n"
assert env.mirage("grep -A 1 c", stdin=data) == env.native("grep -A 1 c",
stdin=data)
def test_grep_C_stdin(env):
data = b"a\nb\nc\nd\ne\n"
assert env.mirage("grep -C 1 c", stdin=data) == env.native("grep -C 1 c",
stdin=data)
def test_grep_r(env):
env.create_file("f.txt", b"hello\nworld\n")
result = env.mirage("grep -r -l hello /data")
assert "f.txt" in result
def test_grep_l(env):
env.create_file("a.txt", b"hello\n")
result = env.mirage("grep -r -l hello /data")
assert "a.txt" in result
def test_grep_E(env):
data = b"foo\nbar\nbaz\n"
assert env.mirage("grep -E 'foo|bar'",
stdin=data) == env.native("grep -E 'foo|bar'",
stdin=data)
def test_grep_q(env):
env.create_file("f.txt", b"hello\n")
result = env.mirage("grep -q hello /data/f.txt")
assert result == ""
def test_grep_R(env):
env.create_file("f.txt", b"hello\n")
result = env.mirage("grep -R hello /data")
assert "hello" in result
def test_grep_H(env):
env.create_file("f.txt", b"hello\n")
result = env.mirage("grep -H hello /data/f.txt")
assert "hello" in result
def test_grep_h(env):
env.create_file("f.txt", b"hello\n")
result = env.mirage("grep -r -h hello /data")
assert "hello" in result
@@ -0,0 +1,43 @@
# ========= 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. =========
def test_gunzip_t(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("gunzip -t /data/f.txt.gz")
assert result.strip() == "" or "ok" in result.lower()
def test_gunzip_k(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
env.mirage("gunzip -k /data/f.txt.gz")
result = env.mirage("cat /data/f.txt")
assert "hello" in result
def test_gunzip_c(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("gunzip -c /data/f.txt.gz")
assert "hello" in result
def test_gunzip_f(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
env.mirage("gunzip -f /data/f.txt.gz")
result = env.mirage("cat /data/f.txt")
assert "hello" in result
+48
View File
@@ -0,0 +1,48 @@
# ========= 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. =========
def test_gzip_c(env):
data = b"hello world\n"
result = env.mirage("gzip -c", stdin=data)
assert len(result) > 0
def test_gzip_level(env):
data = b"hello world " * 100
r1 = env.mirage("gzip -1 -c", stdin=data)
r9 = env.mirage("gzip -9 -c", stdin=data)
assert len(r9) <= len(r1)
def test_gzip_d(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
env.mirage("gzip -d /data/f.txt.gz")
result = env.mirage("cat /data/f.txt")
assert "hello" in result
def test_gzip_k(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip -k /data/f.txt")
original = env.mirage("cat /data/f.txt")
assert "hello" in original
def test_gzip_f(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip -f /data/f.txt")
result = env.mirage("gunzip -c /data/f.txt.gz")
assert "hello" in result
+40
View File
@@ -0,0 +1,40 @@
# ========= 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. =========
def test_head_default(env):
lines = "".join(f"line{i}\n" for i in range(1, 20))
env.create_file("f.txt", lines.encode())
assert env.mirage("head /data/f.txt") == env.native("head f.txt")
def test_head_n5(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\nf\n")
assert env.mirage("head -n 5 /data/f.txt") == env.native("head -n 5 f.txt")
def test_head_c5(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("head -c 5 /data/f.txt") == env.native("head -c 5 f.txt")
def test_head_stdin(env):
data = b"a\nb\nc\nd\ne\nf\n"
assert env.mirage("head -n 3", stdin=data) == env.native("head -n 3",
stdin=data)
def test_head_fewer_lines(env):
env.create_file("f.txt", b"a\nb\n")
assert env.mirage("head /data/f.txt") == env.native("head f.txt")
@@ -0,0 +1,26 @@
# ========= 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. =========
def test_iconv_c(env):
data = b"hello \xff world\n"
result = env.mirage("iconv -f utf-8 -t ascii -c", stdin=data)
assert "hello" in result
def test_iconv_o(env):
env.create_file("f.txt", b"hello\n")
env.mirage("iconv -f utf-8 -t ascii -o /data/out.txt /data/f.txt")
result = env.mirage("cat /data/out.txt")
assert "hello" in result
+55
View File
@@ -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. =========
def test_join_a1(env):
env.create_file("a.txt", b"1 a\n2 b\n3 c\n")
env.create_file("b.txt", b"2 x\n3 y\n4 z\n")
assert env.mirage("join -a 1 /data/a.txt /data/b.txt") == env.native(
"join -a 1 a.txt b.txt")
def test_join_v1(env):
env.create_file("a.txt", b"1 a\n2 b\n3 c\n")
env.create_file("b.txt", b"2 x\n3 y\n4 z\n")
assert env.mirage("join -v 1 /data/a.txt /data/b.txt") == env.native(
"join -v 1 a.txt b.txt")
def test_join_e(env):
env.create_file("a.txt", b"1 a\n2 b\n")
env.create_file("b.txt", b"1 x\n3 y\n")
assert env.mirage("join -a 1 -e EMPTY /data/a.txt /data/b.txt"
) == env.native("join -a 1 -e EMPTY a.txt b.txt")
def test_join_t(env):
env.create_file("a.txt", b"1:a\n2:b\n")
env.create_file("b.txt", b"1:x\n2:y\n")
assert env.mirage("join -t : /data/a.txt /data/b.txt") == env.native(
"join -t : a.txt b.txt")
def test_join_o(env):
env.create_file("a.txt", b"1 a c\n2 b d\n")
env.create_file("b.txt", b"1 x z\n2 y w\n")
result = env.mirage("join -o 1.1,2.1 /data/a.txt /data/b.txt")
assert "a" in result and "x" in result
def test_join_12(env):
env.create_file("a.txt", b"a 1\nb 2\n")
env.create_file("b.txt", b"1 x\n2 y\n")
result = env.mirage("join -1 1 -2 1 /data/a.txt /data/b.txt")
assert len(result.strip()) > 0 or result.strip() == ""
+31
View File
@@ -0,0 +1,31 @@
# ========= 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. =========
def test_jq_r(env):
data = b'{"name": "hello"}\n'
assert env.mirage("jq -r .name", stdin=data) == env.native("jq -r .name",
stdin=data)
def test_jq_c(env):
data = b'{"a": 1, "b": 2}\n'
assert env.mirage("jq -c .", stdin=data) == env.native("jq -c .",
stdin=data)
def test_jq_s(env):
data = b'1\n2\n3\n'
assert env.mirage("jq -s .", stdin=data) == env.native("jq -s .",
stdin=data)
+35
View File
@@ -0,0 +1,35 @@
# ========= 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. =========
def test_ln_v(env):
env.create_file("a.txt", b"hello")
result = env.mirage("ln -s -v /data/a.txt /data/link.txt")
assert "->" in result
def test_ln_sf(env):
env.create_file("a.txt", b"hello")
env.create_file("b.txt", b"world")
env.mirage("ln -s /data/a.txt /data/link.txt")
env.mirage("ln -s -f /data/b.txt /data/link.txt")
result = env.mirage("readlink /data/link.txt")
assert "/data/b.txt" in result
def test_ln_n(env):
env.create_file("a.txt", b"hello")
result = env.mirage(
"ln -s -n /data/a.txt /data/link.txt && readlink /data/link.txt")
assert "/data/a.txt" in result
+19
View File
@@ -0,0 +1,19 @@
# ========= 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. =========
def test_look_f(env):
env.create_file("dict.txt", b"Apple\nbanana\nCherry\n")
result = env.mirage("look -f apple /data/dict.txt")
assert "Apple" in result
+117
View File
@@ -0,0 +1,117 @@
# ========= 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
def test_ls_lists_same_files(env):
env.create_file("a.txt", b"aaa")
env.create_file("b.txt", b"bbb")
m_names = set(env.mirage("ls /data/").strip().split("\n"))
n_names = set(env.native("ls").strip().split("\n"))
assert m_names == n_names
def test_ls_a_shows_hidden(env):
env.create_file(".hidden", b"h")
env.create_file("visible.txt", b"v")
m_names = set(env.mirage("ls -a /data/").strip().split("\n"))
assert ".hidden" in m_names
assert "visible.txt" in m_names
def test_ls_r_reverse(env):
env.create_file("a.txt", b"a")
env.create_file("b.txt", b"b")
env.create_file("c.txt", b"c")
m_names = env.mirage("ls -r /data/").strip().split("\n")
n_names = env.native("ls -r").strip().split("\n")
assert m_names == n_names
def test_ls_l(env):
env.create_file("f.txt", b"hello")
result = env.mirage("ls -l /data")
assert "f.txt" in result
def test_ls_a(env):
env.create_file("f.txt", b"hello")
result = env.mirage("ls -a /data")
assert "f.txt" in result
def test_ls_F(env):
if env.resource_type == "s3":
pytest.skip("S3 cannot stat virtual directories")
env.create_file("sub/a.txt", b"hi")
result = env.mirage("ls -F /data")
assert "sub/" in result
def test_ls_A(env):
env.create_file("f.txt", b"hi")
result = env.mirage("ls -A /data")
assert "f.txt" in result
def test_ls_h(env):
env.create_file("f.txt", b"x" * 1024)
result = env.mirage("ls -l -h /data")
assert "K" in result or "f.txt" in result
def test_ls_t(env):
env.create_file("a.txt", b"a")
env.create_file("b.txt", b"b")
result = env.mirage("ls -t /data")
assert "a.txt" in result and "b.txt" in result
def test_ls_S(env):
env.create_file("big.txt", b"x" * 100)
env.create_file("small.txt", b"x")
result = env.mirage("ls -S /data")
lines = result.strip().splitlines()
assert len(lines) >= 2
def test_ls_1(env):
env.create_file("a.txt", b"a")
env.create_file("b.txt", b"b")
result = env.mirage("ls -1 /data")
assert "\n" in result
def test_ls_1_overrides_l(env):
env.create_file("a.txt", b"hello")
env.create_file("b.txt", b"world")
short = env.mirage("ls -1 /data").strip()
one_overrides_long = env.mirage("ls -l -1 /data").strip()
assert one_overrides_long == short
def test_ls_R(env):
if env.resource_type == "s3":
pytest.skip("not supported on S3")
env.create_file("sub/a.txt", b"hi")
result = env.mirage("ls -R /data")
assert "sub" in result and "a.txt" in result
def test_ls_d(env):
if env.resource_type == "s3":
pytest.skip("not supported on S3")
result = env.mirage("ls -d /data")
assert len(result.strip()) > 0
@@ -0,0 +1,28 @@
# ========= 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
def test_mkdir_v(env):
result = env.mirage("mkdir -v /data/newdir")
assert "newdir" in result
def test_mkdir_p(env):
if env.resource_type == "s3":
pytest.skip("S3 virtual directories not listable after mkdir -p")
env.mirage("mkdir -p /data/a/b/c")
result = env.mirage("ls /data/a/b")
assert "c" in result
@@ -0,0 +1,32 @@
# ========= 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
def test_mktemp_t(env):
result = env.mirage("mktemp -t foo.XXXXXX")
assert "/tmp/" in result
def test_mktemp_d(env):
if env.resource_type == "disk":
pytest.skip("mktemp -d requires parent dirs on disk")
result = env.mirage("mktemp -d")
assert "/tmp/" in result
def test_mktemp_p(env):
result = env.mirage("mktemp -p /data")
assert "/data/" in result
+35
View File
@@ -0,0 +1,35 @@
# ========= 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. =========
def test_mv_v(env):
env.create_file("mv_src.txt", b"hello")
result = env.mirage("mv -v /data/mv_src.txt /data/mv_dst.txt")
assert "->" in result
def test_mv_n(env):
env.create_file("a.txt", b"aaa")
env.create_file("b.txt", b"bbb")
env.mirage("mv -n /data/a.txt /data/b.txt")
result = env.mirage("cat /data/b.txt")
assert "bbb" in result
def test_mv_f(env):
env.create_file("a.txt", b"aaa")
env.create_file("b.txt", b"bbb")
env.mirage("mv -f /data/a.txt /data/b.txt")
result = env.mirage("cat /data/b.txt")
assert "aaa" in result
+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. =========
def test_nl_default(env):
data = b"hello\nworld\n"
assert env.mirage("nl", stdin=data) == env.native("nl", stdin=data)
def test_nl_ba(env):
data = b"hello\n\nworld\n"
assert env.mirage("nl -b a", stdin=data) == env.native("nl -b a",
stdin=data)
def test_nl_file(env):
env.create_file("f.txt", b"aaa\nbbb\n")
assert env.mirage("nl /data/f.txt") == env.native("nl f.txt")
def test_nl_v(env):
data = b"a\nb\nc\n"
result = env.mirage("nl -v 10", stdin=data)
assert "10" in result
def test_nl_i(env):
data = b"a\nb\nc\n"
result = env.mirage("nl -i 2", stdin=data)
assert "1" in result and "3" in result
def test_nl_w(env):
data = b"a\nb\n"
result = env.mirage("nl -w 6", stdin=data)
assert " 1" in result or "1" in result
def test_nl_s(env):
data = b"a\nb\n"
result = env.mirage("nl -s '>> '", stdin=data)
assert ">>" in result
@@ -0,0 +1,21 @@
# ========= 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. =========
def test_nl_bp(env):
data = b"hello\nworld\nhello again\n"
result = env.mirage("nl -bp'hello'", stdin=data)
lines = result.strip().splitlines()
numbered = [ln for ln in lines if ln.strip() and ln.strip()[0].isdigit()]
assert len(numbered) == 2
@@ -0,0 +1,32 @@
# ========= 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. =========
def test_paste_two_files(env):
env.create_file("a.txt", b"1\n2\n3\n")
env.create_file("b.txt", b"a\nb\nc\n")
assert env.mirage("paste /data/a.txt /data/b.txt") == env.native(
"paste a.txt b.txt")
def test_paste_d(env):
env.create_file("a.txt", b"x\ny\n")
env.create_file("b.txt", b"1\n2\n")
assert env.mirage("paste -d , /data/a.txt /data/b.txt") == env.native(
"paste -d , a.txt b.txt")
def test_paste_stdin(env):
data = b"a\nb\nc\n"
assert env.mirage("paste -s", stdin=data) == "a\tb\tc\n"
@@ -0,0 +1,41 @@
# ========= 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. =========
def test_patch_N(env):
env.create_file("f.txt", b"hello\nworld\n")
patch_content = (b"--- a/f.txt\n"
b"+++ b/f.txt\n"
b"@@ -1,2 +1,2 @@\n"
b"-hello\n"
b"+goodbye\n"
b" world\n")
env.create_file("fix.patch", patch_content)
env.mirage("patch -N -p1 -i /data/fix.patch")
result = env.mirage("cat /data/f.txt")
assert "goodbye" in result
def test_patch_R(env):
env.create_file("f.txt", b"goodbye\nworld\n")
patch_content = (b"--- a/f.txt\n"
b"+++ b/f.txt\n"
b"@@ -1,2 +1,2 @@\n"
b"-hello\n"
b"+goodbye\n"
b" world\n")
env.create_file("fix.patch", patch_content)
env.mirage("patch -R -p1 -i /data/fix.patch")
result = env.mirage("cat /data/f.txt")
assert "hello" in result
+22
View File
@@ -0,0 +1,22 @@
# ========= 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. =========
def test_pwd_P(env):
assert env.mirage("pwd -P") == env.mirage("pwd")
def test_pwd_L(env):
result = env.mirage("pwd -L")
assert len(result.strip()) > 0
@@ -0,0 +1,30 @@
# ========= 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. =========
def test_readlink_n(env):
env.create_file("rl.txt", b"x")
result = env.mirage("readlink -n -f /data/rl.txt")
assert not result.endswith("\n")
def test_readlink_m(env):
result = env.mirage("readlink -m /data/nonexistent/path")
assert "/data/nonexistent/path" in result or "nonexistent" in result
def test_readlink_e(env):
env.create_file("f.txt", b"hello")
result = env.mirage("readlink -e /data/f.txt")
assert "f.txt" in result
@@ -0,0 +1,23 @@
# ========= 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. =========
def test_realpath_e_missing(env):
result = env.mirage("realpath -e /data/nonexistent")
assert result == ""
def test_realpath_m(env):
result = env.mirage("realpath -m /data/foo/../bar")
assert result.strip() == "/data/bar"
+23
View File
@@ -0,0 +1,23 @@
# ========= 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. =========
def test_rev_stdin(env):
data = b"hello\nworld\n"
assert env.mirage("rev", stdin=data) == env.native("rev", stdin=data)
def test_rev_file(env):
env.create_file("f.txt", b"abc\ndef\n")
assert env.mirage("rev /data/f.txt") == env.native("rev f.txt")
+51
View File
@@ -0,0 +1,51 @@
# ========= 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
def test_rm_d(env):
env.mirage("mkdir /data/emptydir")
env.mirage("rm -d /data/emptydir")
result = env.mirage("ls /data/")
assert "emptydir" not in result
def test_rm_r(env):
if env.resource_type == "s3":
pytest.skip("S3 cannot stat virtual directories for rm -r")
env.create_file("sub/a.txt", b"hello")
env.mirage("rm -r /data/sub")
result = env.mirage("find /data -name a.txt")
assert result.strip() == ""
def test_rm_f(env):
result = env.mirage("rm -f /data/nonexistent.txt")
assert result.strip() == ""
def test_rm_R(env):
if env.resource_type == "s3":
pytest.skip("S3 cannot stat virtual directories for rm -R")
env.create_file("sub/a.txt", b"hi")
env.mirage("rm -R /data/sub")
result = env.mirage("find /data -name a.txt")
assert result.strip() == ""
def test_rm_v(env):
env.create_file("f.txt", b"hello")
result = env.mirage("rm -v /data/f.txt")
assert "f.txt" in result
+255
View File
@@ -0,0 +1,255 @@
# ========= 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. =========
def test_sed_substitute(env):
data = b"hello world\n"
assert env.mirage("sed s/hello/bye/",
stdin=data) == env.native("sed s/hello/bye/", stdin=data)
def test_sed_global(env):
data = b"foo boo\n"
assert env.mirage("sed s/o/0/g", stdin=data) == env.native("sed s/o/0/g",
stdin=data)
def test_sed_first_only(env):
data = b"foo boo\n"
assert env.mirage("sed s/o/0/", stdin=data) == env.native("sed s/o/0/",
stdin=data)
def test_sed_delete_line(env):
data = b"a\nb\nc\n"
assert env.mirage("sed 2d", stdin=data) == env.native("sed 2d", stdin=data)
def test_sed_delete_regex(env):
data = b"foo\nbar\nfoo2\n"
assert env.mirage("sed /foo/d", stdin=data) == env.native("sed /foo/d",
stdin=data)
def test_sed_on_file(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("sed s/hello/bye/ /data/f.txt") == env.native(
"sed s/hello/bye/ f.txt")
def test_sed_n_suppress(env):
data = b"a\nb\nc\n"
assert env.mirage("sed -n p", stdin=data) == env.native("sed -n p",
stdin=data)
def test_sed_n_with_address(env):
data = b"a\nb\nc\n"
assert env.mirage("sed -n 2p", stdin=data) == env.native("sed -n 2p",
stdin=data)
def test_sed_n_range(env):
data = b"a\nb\nc\nd\ne\n"
assert env.mirage("sed -n 2,4p", stdin=data) == env.native("sed -n 2,4p",
stdin=data)
def test_sed_n_regex_address(env):
data = b"hello\nworld\nhello again\n"
assert env.mirage("sed -n /hello/p",
stdin=data) == env.native("sed -n /hello/p", stdin=data)
def test_sed_n_on_file(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("sed -n 2,3p /data/f.txt") == env.native(
"sed -n 2,3p f.txt")
def test_sed_E_extended(env):
data = b"foo123bar\nhello\n"
assert env.mirage("sed -E 's/[0-9]+/NUM/g'",
stdin=data) == env.native("sed -E 's/[0-9]+/NUM/g'",
stdin=data)
def test_sed_E_groups(env):
data = b"hello world\n"
assert env.mirage(r"sed -E 's/(hello) (world)/\2 \1/'",
stdin=data) == env.native(
r"sed -E 's/(hello) (world)/\2 \1/'", stdin=data)
def test_sed_nE_combined(env):
data = b"abc123\ndef\nghi456\n"
assert env.mirage("sed -nE '/[0-9]+/p'",
stdin=data) == env.native("sed -nE '/[0-9]+/p'",
stdin=data)
def test_sed_i(env):
env.create_file("f.txt", b"hello world\n")
env.mirage("sed -i s/hello/bye/ /data/f.txt")
result = env.mirage("cat /data/f.txt")
assert "bye" in result
def test_sed_e(env):
data = b"hello world\n"
result = env.mirage("sed -e s/hello/bye/", stdin=data)
assert "bye" in result
def test_sed_numeric_count(env):
data = b"oooo\n"
assert env.mirage("sed 's/o/O/2'",
stdin=data) == env.native("sed 's/o/O/2'", stdin=data)
def test_sed_p_flag(env):
data = b"hi\nbye\n"
assert env.mirage("sed 's/hi/HI/p'",
stdin=data) == env.native("sed 's/hi/HI/p'", stdin=data)
def test_sed_n_p_flag(env):
data = b"hi\nbye\n"
assert env.mirage("sed -n 's/hi/HI/p'",
stdin=data) == env.native("sed -n 's/hi/HI/p'",
stdin=data)
def test_sed_y_transliterate(env):
data = b"hello\n"
assert env.mirage("sed 'y/el/ip/'",
stdin=data) == env.native("sed 'y/el/ip/'", stdin=data)
def test_sed_c_single_address(env):
data = b"a\nb\nc\n"
assert env.mirage("sed '2c\\\nX'",
stdin=data) == env.native("sed '2c\\\nX'", stdin=data)
def test_sed_c_range(env):
data = b"a\nb\nc\nd\n"
assert env.mirage("sed '2,3c\\\nX'",
stdin=data) == env.native("sed '2,3c\\\nX'", stdin=data)
def test_sed_bre_group_backref(env):
data = b"foo\n"
assert env.mirage(r"sed 's/\(foo\)/[\1]/'",
stdin=data) == env.native(r"sed 's/\(foo\)/[\1]/'",
stdin=data)
def test_sed_bre_interval(env):
data = b"aaa\n"
assert env.mirage(r"sed 's/a\{2\}/X/'",
stdin=data) == env.native(r"sed 's/a\{2\}/X/'",
stdin=data)
def test_sed_bre_bare_plus_literal(env):
data = b"a+b\n"
assert env.mirage("sed 's/a+/X/'",
stdin=data) == env.native("sed 's/a+/X/'", stdin=data)
def test_sed_ere_group_plus(env):
data = b"foo\n"
assert env.mirage(r"sed -E 's/(foo)/[\1]/'",
stdin=data) == env.native(r"sed -E 's/(foo)/[\1]/'",
stdin=data)
def test_sed_ere_alternation(env):
data = b"dog\n"
assert env.mirage("sed -E 's/cat|dog/PET/'",
stdin=data) == env.native("sed -E 's/cat|dog/PET/'",
stdin=data)
def test_sed_r_alias(env):
data = b"aaab\n"
assert env.mirage("sed -r 's/a+/X/'",
stdin=data) == env.native("sed -r 's/a+/X/'", stdin=data)
def test_sed_multiple_e(env):
data = b"a\n"
assert env.mirage("sed -e 's/a/b/' -e 's/b/c/'",
stdin=data) == env.native("sed -e 's/a/b/' -e 's/b/c/'",
stdin=data)
def test_sed_e_with_file(env):
env.create_file("ef.txt", b"hello world\n")
assert env.mirage("sed -e s/hello/bye/ /data/ef.txt") == env.native(
"sed -e s/hello/bye/ ef.txt")
def test_sed_f_script_file(env):
env.create_file("prog.sed", b"s/hello/HI/\n")
env.create_file("inf.txt", b"hello world\n")
assert env.mirage("sed -f /data/prog.sed /data/inf.txt") == env.native(
"sed -f prog.sed inf.txt")
def test_sed_f_multiple_commands(env):
env.create_file("prog2.sed", b"s/hello/HI/\ns/world/EARTH/\n")
env.create_file("inf2.txt", b"hello world\n")
assert env.mirage("sed -f /data/prog2.sed /data/inf2.txt") == env.native(
"sed -f prog2.sed inf2.txt")
def test_sed_e_and_f_combined(env):
env.create_file("prog3.sed", b"s/world/EARTH/\n")
env.create_file("inf3.txt", b"hello world\n")
assert env.mirage(
"sed -e s/hello/HI/ -f /data/prog3.sed /data/inf3.txt") == env.native(
"sed -e s/hello/HI/ -f prog3.sed inf3.txt")
def test_sed_f_stdin(env):
env.create_file("prog4.sed", b"s/hello/HI/\n")
data = b"hello world\n"
assert env.mirage("sed -f /data/prog4.sed",
stdin=data) == env.native("sed -f prog4.sed", stdin=data)
def test_sed_negate_line(env):
data = b"a\nb\nc\n"
assert env.mirage("sed '2!d'", stdin=data) == env.native("sed '2!d'",
stdin=data)
def test_sed_negate_regex(env):
data = b"a\nb\nc\n"
assert env.mirage("sed '/b/!d'", stdin=data) == env.native("sed '/b/!d'",
stdin=data)
def test_sed_missing_final_newline(env):
data = b"foo"
assert env.mirage("sed 's/o/O/'", stdin=data) == env.native("sed 's/o/O/'",
stdin=data)
def test_sed_escaped_delimiter(env):
data = b"a/b\n"
assert env.mirage(r"sed 's/a\/b/c/'",
stdin=data) == env.native(r"sed 's/a\/b/c/'", stdin=data)
+37
View File
@@ -0,0 +1,37 @@
# ========= 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. =========
def test_seq_1arg(env):
assert env.mirage("seq 4") == env.native("seq 4")
def test_seq_2args(env):
assert env.mirage("seq 3 5") == env.native("seq 3 5")
def test_seq_3args(env):
assert env.mirage("seq 1 2 7") == env.native("seq 1 2 7")
def test_seq_s(env):
assert env.mirage("seq -s , 1 3").strip() == "1,2,3"
def test_seq_f(env):
assert env.mirage("seq -f '%.2f' 1 3") == env.native("seq -f '%.2f' 1 3")
def test_seq_w(env):
assert env.mirage("seq -w 1 10") == env.native("seq -w 1 10")
@@ -0,0 +1,21 @@
# ========= 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. =========
def test_sha256sum_c(env):
env.create_file("f.txt", b"hello\n")
checksums = env.mirage("sha256sum /data/f.txt")
env.create_file("sums.txt", checksums.encode())
result = env.mirage("sha256sum -c /data/sums.txt")
assert "OK" in result
+32
View File
@@ -0,0 +1,32 @@
# ========= 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. =========
def test_shuf_r(env):
data = b"a\nb\nc\n"
result = env.mirage("shuf -r -n 5", stdin=data)
lines = result.strip().splitlines()
assert len(lines) == 5
def test_shuf_e(env):
result = env.mirage("shuf -e a b c")
lines = [ln.strip().lstrip("/") for ln in result.strip().splitlines()]
assert sorted(lines) == ["a", "b", "c"]
def test_shuf_z(env):
data = b"a\x00b\x00c\x00"
result = env.mirage("shuf -z", stdin=data)
assert "\x00" in result or len(result) > 0
@@ -0,0 +1,23 @@
# ========= 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. =========
def test_create_and_cat(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("cat /data/f.txt") == env.native("cat f.txt")
def test_create_subdir_and_cat(env):
env.create_file("sub/f.txt", b"nested\n")
assert env.mirage("cat /data/sub/f.txt") == env.native("cat sub/f.txt")
+100
View File
@@ -0,0 +1,100 @@
# ========= 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. =========
def test_sort_default(env):
env.create_file("f.txt", b"cherry\napple\nbanana\n")
assert env.mirage("sort /data/f.txt") == env.native("sort f.txt")
def test_sort_r(env):
env.create_file("f.txt", b"a\nb\nc\n")
assert env.mirage("sort -r /data/f.txt") == env.native("sort -r f.txt")
def test_sort_n(env):
env.create_file("f.txt", b"10\n2\n1\n20\n")
assert env.mirage("sort -n /data/f.txt") == env.native("sort -n f.txt")
def test_sort_u(env):
env.create_file("f.txt", b"a\nb\na\nc\nb\n")
assert env.mirage("sort -u /data/f.txt") == env.native("sort -u f.txt")
def test_sort_nr(env):
env.create_file("f.txt", b"10\n2\n1\n20\n")
assert env.mirage("sort -nr /data/f.txt") == env.native("sort -nr f.txt")
def test_sort_k_t(env):
env.create_file("f.txt", b"b,3\na,1\nc,2\n")
assert env.mirage("sort -t , -k 2 -n /data/f.txt") == env.native(
"sort -t , -k 2 -n f.txt")
def test_sort_stdin(env):
data = b"cherry\napple\nbanana\n"
assert env.mirage("sort", stdin=data) == env.native("sort", stdin=data)
def test_sort_h(env):
env.create_file("f.txt", b"10K\n1M\n5G\n100\n2K\n")
assert env.mirage("sort -h /data/f.txt") == env.native("sort -h f.txt")
def test_sort_hr(env):
env.create_file("f.txt", b"10K\n1M\n5G\n100\n2K\n")
assert env.mirage("sort -hr /data/f.txt") == env.native("sort -hr f.txt")
def test_sort_h_stdin(env):
data = b"1G\n500M\n2T\n100K\n"
assert env.mirage("sort -h", stdin=data) == env.native("sort -h",
stdin=data)
def test_sort_V(env):
env.create_file("f.txt", b"v1.10\nv1.2\nv1.1\nv2.0\n")
assert env.mirage("sort -V /data/f.txt") == env.native("sort -V f.txt")
def test_sort_Vr(env):
env.create_file("f.txt", b"v1.10\nv1.2\nv1.1\nv2.0\n")
assert env.mirage("sort -Vr /data/f.txt") == env.native("sort -Vr f.txt")
def test_sort_V_stdin(env):
data = b"lib-2.1\nlib-1.10\nlib-1.2\nlib-3.0\n"
assert env.mirage("sort -V", stdin=data) == env.native("sort -V",
stdin=data)
def test_sort_s(env):
env.create_file("f.txt", b"b 2\na 1\nc 1\na 2\n")
assert env.mirage("sort -s -k 2 -t ' ' /data/f.txt") == env.native(
"sort -s -k 2 -t ' ' f.txt")
def test_sort_s_stdin(env):
data = b"b 2\na 1\nc 1\na 2\n"
assert env.mirage("sort -s -k 2 -t ' '",
stdin=data) == env.native("sort -s -k 2 -t ' '",
stdin=data)
def test_sort_f(env):
env.create_file("f.txt", b"B\na\nC\nb\n")
result = env.mirage("sort -f /data/f.txt")
assert "a" in result and "B" in result
@@ -0,0 +1,18 @@
# ========= 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. =========
def test_sort_M(env):
env.create_file("f.txt", b"Mar\nJan\nFeb\nDec\n")
assert env.mirage("sort -M /data/f.txt") == env.native("sort -M f.txt")
@@ -0,0 +1,42 @@
# ========= 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. =========
def test_split_d(env):
env.create_file("f.txt", b"a\nb\nc\nd\n")
env.mirage("split -d -l 2 /data/f.txt /data/part")
result = env.mirage("cat /data/part00")
assert "a" in result
def test_split_b(env):
env.create_file("f.txt", b"hello world this is a test\n")
env.mirage("split -b 10 /data/f.txt /data/chunk")
result = env.mirage("cat /data/chunkaa")
assert len(result) > 0
def test_split_a(env):
env.create_file("f.txt", b"a\nb\nc\nd\n")
env.mirage("split -d -a 3 -l 2 /data/f.txt /data/p")
result = env.mirage("ls /data")
assert "p000" in result
def test_split_n(env):
env.create_file("f.txt", b"abcdefghij")
env.mirage("split -n 2 /data/f.txt /data/chunk")
r1 = env.mirage("cat /data/chunkaa")
r2 = env.mirage("cat /data/chunkab")
assert len(r1) > 0 and len(r2) > 0
+25
View File
@@ -0,0 +1,25 @@
# ========= 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. =========
def test_stat_c(env):
env.create_file("f.txt", b"hello")
result = env.mirage("stat -c '%s' /data/f.txt")
assert result.strip() == "5"
def test_stat_f(env):
env.create_file("f.txt", b"hello")
result = env.mirage("stat -f '%s' /data/f.txt")
assert len(result.strip()) > 0
@@ -0,0 +1,20 @@
# ========= 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. =========
def test_strings_n(env):
data = b"\x00\x00hello world\x00\x00ab\x00"
result = env.mirage("strings -n 4", stdin=data)
assert "hello world" in result
assert "ab" not in result
+23
View File
@@ -0,0 +1,23 @@
# ========= 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. =========
def test_tac_stdin(env):
data = b"a\nb\nc\n"
assert env.mirage("tac", stdin=data) == env.native("tac", stdin=data)
def test_tac_file(env):
env.create_file("f.txt", b"1\n2\n3\n")
assert env.mirage("tac /data/f.txt") == env.native("tac f.txt")
+59
View File
@@ -0,0 +1,59 @@
# ========= 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. =========
def test_tail_default(env):
lines = "".join(f"line{i}\n" for i in range(1, 20))
env.create_file("f.txt", lines.encode())
assert env.mirage("tail /data/f.txt") == env.native("tail f.txt")
def test_tail_n3(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("tail -n 3 /data/f.txt") == env.native("tail -n 3 f.txt")
def test_tail_c5(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("tail -c 5 /data/f.txt") == env.native("tail -c 5 f.txt")
def test_tail_stdin(env):
data = b"a\nb\nc\nd\ne\n"
assert env.mirage("tail -n 3", stdin=data) == env.native("tail -n 3",
stdin=data)
def test_tail_plus_n(env):
env.create_file("f.txt", b"a\nb\nc\nd\ne\n")
assert env.mirage("tail -n +3 /data/f.txt") == env.native(
"tail -n +3 f.txt")
def test_tail_plus_n_stdin(env):
data = b"a\nb\nc\nd\ne\n"
assert env.mirage("tail -n +2", stdin=data) == env.native("tail -n +2",
stdin=data)
def test_tail_q(env):
env.create_file("a.txt", b"aaa\n")
result = env.mirage("tail -q /data/a.txt")
assert "aaa" in result
def test_tail_v(env):
env.create_file("a.txt", b"aaa\n")
result = env.mirage("tail -v /data/a.txt")
assert "aaa" in result
+72
View File
@@ -0,0 +1,72 @@
# ========= 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. =========
def test_tar_cz_tf(env):
env.create_file("a.txt", b"aaa\n")
env.create_file("b.txt", b"bbb\n")
env.mirage("tar -c -z -f /data/out.tar.gz /data/a.txt /data/b.txt")
listing = env.mirage("tar -t -f /data/out.tar.gz")
names = listing.strip().splitlines()
assert "a.txt" in " ".join(names)
assert "b.txt" in " ".join(names)
def test_tar_j_create_list(env):
env.create_file("a.txt", b"aaa\n")
env.create_file("b.txt", b"bbb\n")
env.mirage("tar -c -j -f /data/out.tar.bz2 /data/a.txt /data/b.txt")
listing = env.mirage("tar -t -f /data/out.tar.bz2")
names = listing.strip().splitlines()
assert "a.txt" in " ".join(names)
assert "b.txt" in " ".join(names)
def test_tar_J_create_list(env):
env.create_file("a.txt", b"aaa\n")
env.create_file("b.txt", b"bbb\n")
env.mirage("tar -c -J -f /data/out.tar.xz /data/a.txt /data/b.txt")
listing = env.mirage("tar -t -f /data/out.tar.xz")
names = listing.strip().splitlines()
assert "a.txt" in " ".join(names)
assert "b.txt" in " ".join(names)
def test_tar_strip_components(env):
env.create_file("a.txt", b"aaa\n")
env.mirage("tar -c -z -f /data/out.tar.gz /data/a.txt")
env.mirage(
"tar -x -z -f /data/out.tar.gz --strip-components 1 -C /data/extracted"
)
content = env.mirage("cat /data/extracted/a.txt")
assert "aaa" in content
def test_tar_exclude(env):
env.create_file("a.txt", b"aaa\n")
env.create_file("b.txt", b"bbb\n")
env.mirage(
"tar -c -z -f /data/out.tar.gz --exclude b.txt /data/a.txt /data/b.txt"
)
listing = env.mirage("tar -t -f /data/out.tar.gz")
names = listing.strip().splitlines()
assert "b.txt" not in " ".join(names)
assert "a.txt" in " ".join(names)
def test_tar_v(env):
env.create_file("a.txt", b"aaa\n")
env.mirage("tar -c -v -z -f /data/out.tar.gz /data/a.txt")
listing = env.mirage("tar -t -f /data/out.tar.gz")
assert "a.txt" in listing
+20
View File
@@ -0,0 +1,20 @@
# ========= 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. =========
def test_tee_a(env):
env.create_file("f.txt", b"first\n")
env.mirage("tee -a /data/f.txt", stdin=b"second\n")
result = env.mirage("cat /data/f.txt")
assert "first" in result and "second" in result
@@ -0,0 +1,47 @@
# ========= 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. =========
def test_touch_c_no_create(env):
env.mirage("touch -c /data/nonexistent.txt")
result = env.mirage("find /data -name nonexistent.txt")
assert result.strip() == ""
def test_touch_r(env):
env.create_file("ref.txt", b"ref")
env.mirage("touch /data/new.txt")
result = env.mirage("ls /data")
assert "new.txt" in result
def test_touch_d(env):
env.mirage("touch /data/dated.txt")
result = env.mirage("ls /data")
assert "dated.txt" in result
def test_touch_r_explicit(env):
env.create_file("ref.txt", b"ref")
env.create_file("new.txt", b"")
env.mirage("touch -r /data/ref.txt /data/new.txt")
result = env.mirage("ls /data")
assert "new.txt" in result
def test_touch_d_explicit(env):
env.create_file("dated.txt", b"")
env.mirage("touch -d '2024-01-01' /data/dated.txt")
result = env.mirage("ls /data")
assert "dated.txt" in result
+42
View File
@@ -0,0 +1,42 @@
# ========= 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. =========
def test_tr_basic(env):
data = b"hello\n"
assert env.mirage("tr h H", stdin=data) == env.native("tr h H", stdin=data)
def test_tr_d(env):
data = b"hello world\n"
assert env.mirage("tr -d aeiou", stdin=data) == env.native("tr -d aeiou",
stdin=data)
def test_tr_s(env):
data = b"baanaanaa\n"
assert env.mirage("tr -s a", stdin=data) == env.native("tr -s a",
stdin=data)
def test_tr_range(env):
data = b"hello\n"
assert env.mirage("tr a-z A-Z", stdin=data) == env.native("tr a-z A-Z",
stdin=data)
def test_tr_cd(env):
data = b"Hello World 123\n"
assert env.mirage("tr -cd a-z", stdin=data) == env.native("tr -cd a-z",
stdin=data)
+55
View File
@@ -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. =========
import pytest
def test_tree_d(env):
if env.resource_type == "s3":
pytest.skip("S3 tree cannot stat virtual directories")
env.create_file("sub/a.txt", b"hi")
result = env.mirage("tree -d /data")
assert "a.txt" not in result
assert "sub" in result
def test_tree_a(env):
env.create_file(".hidden", b"secret")
env.create_file("visible.txt", b"hi")
result = env.mirage("tree -a /data")
assert ".hidden" in result
def test_tree_L(env):
if env.resource_type == "s3":
pytest.skip("S3 tree cannot stat virtual directories")
env.create_file("sub/deep/a.txt", b"hi")
result = env.mirage("tree -L 1 /data")
assert "sub" in result
assert "a.txt" not in result
def test_tree_P(env):
env.create_file("hello.txt", b"hi")
env.create_file("world.txt", b"hi")
result = env.mirage("tree -P hello* /data")
assert "hello" in result
def test_tree_I(env):
env.create_file("keep.txt", b"hi")
env.create_file("skip.log", b"hi")
result = env.mirage("tree -I '*.log' /data")
assert "keep.txt" in result
assert "skip.log" not in result
@@ -0,0 +1,25 @@
# ========= 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. =========
def test_unexpand_a(env):
data = b" hello world\n"
result = env.mirage("unexpand -a", stdin=data)
assert "\t" in result
def test_unexpand_t(env):
data = b" hello\n"
result = env.mirage("unexpand -t 4", stdin=data)
assert "\t" 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. =========
def test_uniq_default(env):
env.create_file("f.txt", b"a\na\nb\nc\nc\n")
assert env.mirage("uniq /data/f.txt") == env.native("uniq f.txt")
def test_uniq_c(env):
env.create_file("f.txt", b"a\na\nb\nc\nc\nc\n")
m_lines = env.mirage("uniq -c /data/f.txt").strip().split("\n")
n_lines = env.native("uniq -c f.txt").strip().split("\n")
m_pairs = [(x.split()[0], x.split()[1]) for x in m_lines if x.strip()]
n_pairs = [(x.split()[0], x.split()[1]) for x in n_lines if x.strip()]
assert m_pairs == n_pairs
def test_uniq_d(env):
env.create_file("f.txt", b"a\na\nb\nc\nc\n")
assert env.mirage("uniq -d /data/f.txt") == env.native("uniq -d f.txt")
def test_uniq_u(env):
env.create_file("f.txt", b"a\na\nb\nc\nc\n")
assert env.mirage("uniq -u /data/f.txt") == env.native("uniq -u f.txt")
def test_uniq_stdin(env):
data = b"a\na\nb\n"
assert env.mirage("uniq", stdin=data) == env.native("uniq", stdin=data)
def test_uniq_i(env):
data = b"Hello\nhello\nWorld\n"
assert env.mirage("uniq -i", stdin=data) == env.native("uniq -i",
stdin=data)
def test_uniq_f(env):
data = b"a 1\nb 1\nc 2\n"
assert env.mirage("uniq -f 1", stdin=data) == env.native("uniq -f 1",
stdin=data)
def test_uniq_w(env):
data = b"abc\nabd\nxyz\n"
assert env.mirage("uniq -w 2", stdin=data) == "abc\nxyz\n"
def test_uniq_s(env):
data = b"xxhello\nyyhello\nzzworld\n"
assert env.mirage("uniq -s 2", stdin=data) == env.native("uniq -s 2",
stdin=data)
@@ -0,0 +1,49 @@
# ========= 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. =========
def test_unzip_q(env):
env.create_file("a.txt", b"hello")
env.mirage("zip /data/out.zip /data/a.txt")
result = env.mirage("unzip -q -d /data/ext /data/out.zip")
assert result.strip() == "" or "inflating" not in result
def test_unzip_t(env):
env.create_file("a.txt", b"hello")
env.mirage("zip /data/out.zip /data/a.txt")
result = env.mirage("unzip -t /data/out.zip")
assert "OK" in result or "ok" in result.lower() or "No errors" in result
def test_unzip_l(env):
env.create_file("a.txt", b"hello")
env.mirage("zip /data/out.zip /data/a.txt")
result = env.mirage("unzip -l /data/out.zip")
assert "a.txt" in result
def test_unzip_p(env):
env.create_file("a.txt", b"hello")
env.mirage("zip /data/out.zip /data/a.txt")
result = env.mirage("unzip -p /data/out.zip")
assert "hello" in result
def test_unzip_o(env):
env.create_file("a.txt", b"hello")
env.mirage("zip /data/out.zip /data/a.txt")
env.mirage("unzip -o /data/out.zip")
result = env.mirage("ls /data")
assert "a.txt" in result
+77
View File
@@ -0,0 +1,77 @@
# ========= 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. =========
def test_wc_l(env):
env.create_file("f.txt", b"a\nb\nc\n")
assert env.mirage("wc -l /data/f.txt").strip().split()[0] == env.native(
"wc -l f.txt").strip().split()[0]
def test_wc_w(env):
env.create_file("f.txt", b"hello world\nfoo\n")
assert env.mirage("wc -w /data/f.txt").strip().split()[0] == env.native(
"wc -w f.txt").strip().split()[0]
def test_wc_c(env):
env.create_file("f.txt", b"hello\n")
assert env.mirage("wc -c /data/f.txt").strip().split()[0] == env.native(
"wc -c f.txt").strip().split()[0]
def test_wc_stdin_l(env):
data = b"a\nb\nc\n"
assert env.mirage("wc -l",
stdin=data).strip() == env.native("wc -l",
stdin=data).strip()
def test_wc_default_counts(env):
env.create_file("f.txt", b"hello world\nfoo bar\n")
m_parts = env.mirage("wc /data/f.txt").strip().split()
n_parts = env.native("wc f.txt").strip().split()
assert m_parts[:3] == n_parts[:3]
def test_wc_L(env):
env.create_file("f.txt", b"short\na much longer line\nmed\n")
assert env.mirage("wc -L /data/f.txt").strip().split()[0] == env.native(
"wc -L f.txt").strip().split()[0]
def test_wc_L_stdin(env):
data = b"short\na much longer line\nmed\n"
assert env.mirage("wc -L",
stdin=data).strip() == env.native("wc -L",
stdin=data).strip()
def test_wc_L_empty(env):
env.create_file("f.txt", b"")
assert env.mirage("wc -L /data/f.txt").strip().split()[0] == env.native(
"wc -L f.txt").strip().split()[0]
def test_wc_L_single_line(env):
env.create_file("f.txt", b"hello world\n")
assert env.mirage("wc -L /data/f.txt").strip().split()[0] == env.native(
"wc -L f.txt").strip().split()[0]
def test_wc_m(env):
env.create_file("f.txt", b"hello\n")
result = env.mirage("wc -m /data/f.txt").strip().split()[0]
native = env.native("wc -m f.txt").strip().split()[0]
assert result == native
+57
View File
@@ -0,0 +1,57 @@
# ========= 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. =========
def test_xxd_u(env):
data = b"\xab\xcd"
result = env.mirage("xxd -u", stdin=data)
assert "AB" in result or "CD" in result
def test_xxd_r(env):
data = b"hello"
hex_out = env.mirage("xxd -p", stdin=data)
restored = env.mirage("xxd -r -p", stdin=hex_out.encode())
assert "hello" in restored
def test_xxd_p(env):
data = b"AB"
result = env.mirage("xxd -p", stdin=data)
assert "4142" in result or "4142" in result.lower()
def test_xxd_l(env):
data = b"hello world"
result = env.mirage("xxd -l 5", stdin=data)
assert "worl" not in result
def test_xxd_g(env):
data = b"ABCD"
result = env.mirage("xxd -g 4", stdin=data)
assert len(result.strip()) > 0
def test_xxd_c(env):
data = b"hello world"
result = env.mirage("xxd -c 4", stdin=data)
lines = result.strip().splitlines()
assert len(lines) >= 2
def test_xxd_s(env):
data = b"hello world"
result = env.mirage("xxd -s 5", stdin=data)
assert "6865" not in result.lower()
@@ -0,0 +1,114 @@
# ========= 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 gzip as gz
def test_zgrep_w(env):
env.create_file("f.txt", b"hello\nhelloworld\nhello there\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -w hello /data/f.txt.gz")
assert "helloworld" not in result
assert "hello" in result
def test_zgrep_i(env):
env.create_file("f.txt", b"Hello\nworld\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -i hello /data/f.txt.gz")
assert "Hello" in result
def test_zgrep_c(env):
env.create_file("f.txt", b"hello\nworld\nhello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -c hello /data/f.txt.gz")
assert "2" in result
def test_zgrep_v(env):
env.create_file("f.txt", b"hello\nworld\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -v hello /data/f.txt.gz")
assert "world" in result
assert "hello" not in result
def test_zgrep_n(env):
env.create_file("f.txt", b"hello\nworld\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -n hello /data/f.txt.gz")
assert "1:" in result or "1\t" in result
def test_zgrep_l(env):
env.create_file("f.txt", b"hello\nworld\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -l hello /data/f.txt.gz")
assert "f.txt" in result
def test_zgrep_e(env):
compressed = gz.compress(b"hello\nworld\n")
result = env.mirage("zgrep -e hello", stdin=compressed)
assert "hello" in result
def test_zgrep_E(env):
env.create_file("f.txt", b"foo\nbar\nbaz\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -E 'foo|bar' /data/f.txt.gz")
assert "foo" in result and "bar" in result
def test_zgrep_F(env):
env.create_file("f.txt", b"a.b\na*b\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -F 'a.b' /data/f.txt.gz")
assert "a.b" in result
def test_zgrep_o(env):
env.create_file("f.txt", b"hello world\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -o hello /data/f.txt.gz")
assert result.strip() == "hello"
def test_zgrep_m(env):
env.create_file("f.txt", b"a\na\na\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -m 1 a /data/f.txt.gz")
assert result.strip().count("a") == 1
def test_zgrep_q(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -q hello /data/f.txt.gz")
assert result.strip() == ""
def test_zgrep_H(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -H hello /data/f.txt.gz")
assert "f.txt" in result
def test_zgrep_h(env):
env.create_file("f.txt", b"hello\n")
env.mirage("gzip /data/f.txt")
result = env.mirage("zgrep -h hello /data/f.txt.gz")
assert "hello" in result
+34
View File
@@ -0,0 +1,34 @@
# ========= 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. =========
def test_zip_j(env):
env.create_file("sub/a.txt", b"hello")
env.mirage("zip -j /data/out.zip /data/sub/a.txt")
result = env.mirage("unzip -l /data/out.zip")
assert "a.txt" in result
assert "sub" not in result.replace("a.txt", "")
def test_zip_q(env):
env.create_file("a.txt", b"hello")
result = env.mirage("zip -q /data/out.zip /data/a.txt")
assert result.strip() == ""
def test_zip_r(env):
env.create_file("sub/a.txt", b"hello")
env.mirage("zip -r /data/out.zip /data/sub/a.txt")
result = env.mirage("unzip -l /data/out.zip")
assert "a.txt" in result