Files
wehub-resource-sync bcbd1bdb22
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
chore: import upstream snapshot with attribution
2026-07-13 12:30:44 +08:00

233 lines
9.6 KiB
Python

# ========= 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 json
import os
from dotenv import load_dotenv
from mirage import MountMode, Workspace
from mirage.resource.oci import OCIConfig, OCIResource
load_dotenv(".env.development")
config = OCIConfig(
bucket=os.environ["OCI_BUCKET"],
namespace=os.environ["OCI_NAMESPACE"],
region=os.environ["OCI_REGION"],
endpoint_url=os.environ.get("OCI_ENDPOINT_URL"),
access_key_id=os.environ["OCI_ACCESS_KEY_ID"],
secret_access_key=os.environ["OCI_SECRET_ACCESS_KEY"],
)
backend = OCIResource(config)
ws = Workspace({"/oci/": backend}, mode=MountMode.READ)
def ops_summary() -> str:
records = ws.ops.records
total = sum(r.bytes for r in records)
return f"{len(records)} ops, {total} bytes transferred"
async def main():
print("=== PLAN ESTIMATES ===\n")
dr = await ws.execute("grep mirage /oci/data/example.jsonl",
provision=True)
print("--- plan: grep mirage /oci/data/example.jsonl ---")
print(f" network_read: {dr.network_read}, cache_read: {dr.cache_read}")
print(f" read_ops: {dr.read_ops}, precision: {dr.precision}")
dr = await ws.execute("grep mirage /oci/data/example.jsonl | head -n 3",
provision=True)
print("\n--- plan: grep mirage ... | head -n 3 ---")
print(f" op: {dr.op}, children: {len(dr.children)}")
print(f" network_read: {dr.network_read}, cache_read: {dr.cache_read}")
print(f" precision: {dr.precision}")
for c in dr.children:
net, cache = c.network_read, c.cache_read
print(f" {c.command}: net={net}, cache={cache}, {c.precision}")
dr = await ws.execute("grep mirage /oci/data/example.jsonl && echo found",
provision=True)
print("\n--- plan: grep ... && echo found ---")
print(f" op: {dr.op}, network_read: {dr.network_read}")
for c in dr.children:
print(f" {c.command}: net={c.network_read}, {c.precision}")
print(f"\n Stats after plans (should be 0): {ops_summary()}")
print("\n--- caching: cat /oci/data/example.jsonl | wc -l ---")
result = await ws.execute("cat /oci/data/example.jsonl | wc -l")
print(f" lines: {(await result.stdout_str()).strip()}")
print(f" Stats after caching: {ops_summary()}")
dr = await ws.execute("grep mirage /oci/data/example.jsonl",
provision=True)
print("\n--- plan after cache: grep mirage ... ---")
print(f" network_read: {dr.network_read}, cache_read: {dr.cache_read}")
print(f" cache_hits: {dr.cache_hits}, read_ops: {dr.read_ops}")
print("\n=== ACTUAL EXECUTION ===\n")
print("--- grep mirage /oci/data/example.jsonl ---")
output = await (
await ws.execute("grep mirage /oci/data/example.jsonl")).stdout_str()
lines = output.strip().splitlines() if output.strip() else []
print(f" Matches: {len(lines)}")
if lines:
print(f" First: {lines[0][:80]}...")
print(f" Stats: {ops_summary()}")
print("\n--- grep -m 1 mirage /oci/data/example.jsonl ---")
output = await (
await
ws.execute("grep -m 1 mirage /oci/data/example.jsonl")).stdout_str()
lines = output.strip().splitlines() if output.strip() else []
print(f" Matches: {len(lines)}")
print(f" Stats: {ops_summary()}")
print("\n--- grep mirage /oci/data/example.jsonl | wc -l ---")
result = await ws.execute("grep mirage /oci/data/example.jsonl | wc -l")
print(f" Count: {(await result.stdout_str()).strip()}")
print(f" Exit code: {result.exit_code}")
print(f" Stats: {ops_summary()}")
print("\n--- grep mirage /oci/data/example.jsonl | head -n 3 ---")
result = await ws.execute("grep mirage /oci/data/example.jsonl | head -n 3"
)
lines = (await result.stdout_str()).strip().splitlines()
print(f" Lines: {len(lines)}")
for ln in lines:
print(f" {ln[:80]}...")
print(f" Stats: {ops_summary()}")
print("\n--- cat /oci/data/example.jsonl"
" | grep queue-operation | sort | uniq ---")
result = await ws.execute(
"cat /oci/data/example.jsonl | grep queue-operation | sort | uniq")
lines = ((await result.stdout_str()).strip().splitlines() if
(await result.stdout_str()).strip() else [])
print(f" Unique lines: {len(lines)}")
print(f" Stats: {ops_summary()}")
print("\n--- rg queue-operation /oci/data/example.jsonl"
" | head -n 5 | cut -d , -f 2 ---")
result = await ws.execute("rg queue-operation /oci/data/example.jsonl | "
"head -n 5 | cut -d , -f 2")
print(f" Fields:\n {(await result.stdout_str()).strip()}")
print(f" Stats: {ops_summary()}")
print("\n--- grep -m 1 mirage /oci/data/example.jsonl"
" && echo 'found mirage' ---")
result = await ws.execute(
"grep -m 1 mirage /oci/data/example.jsonl && echo found")
print(f" Exit code: {result.exit_code}")
print(
f" Stdout ends with: ...{(await result.stdout_str()).strip()[-30:]}")
print(f" Stats: {ops_summary()}")
print("\n--- grep NONEXISTENT /oci/data/example.jsonl"
" || echo 'not found' ---")
result = await ws.execute(
"grep NONEXISTENT /oci/data/example.jsonl || echo not_found")
print(f" Exit code: {result.exit_code}")
print(f" Output: {(await result.stdout_str()).strip()}")
print(f" Stats: {ops_summary()}")
print("\n--- (grep queue-operation /oci/data/example.jsonl"
" | sort | uniq) | wc -l ---")
result = await ws.execute(
"(grep queue-operation /oci/data/example.jsonl | sort | uniq) | wc -l")
print(f" Unique queue ops: {(await result.stdout_str()).strip()}")
print(f" Stats: {ops_summary()}")
print("\n--- head -n 1 /oci/data/example.jsonl"
" ; wc -l /oci/data/example.jsonl ---")
result = await ws.execute(
"head -n 1 /oci/data/example.jsonl ; wc -l /oci/data/example.jsonl")
print(f" Output: {(await result.stdout_str()).strip()}")
print(f" Stats: {ops_summary()}")
print("\n--- lazy multi-pipe: grep | grep -v | head | cut ---")
result = await ws.execute("grep queue-operation /oci/data/example.jsonl"
" | grep -v error | head -n 2 | cut -d , -f 1")
print(f" Output:\n {(await result.stdout_str()).strip()}")
result_full = await ws.execute(
"grep queue-operation /oci/data/example.jsonl"
" | grep -v error | cut -d , -f 1")
full_lines = (await result_full.stdout_str()).strip().splitlines()
print(f" Without head: {len(full_lines)} lines (full OCI download)")
print("\n--- rg -l mirage /oci/data ---")
output = await (await ws.execute("rg -l mirage /oci/data")).stdout_str()
lines = output.strip().splitlines() if output.strip() else []
print(f" Files: {lines}")
print(f" Stats: {ops_summary()}")
print("\n=== JQ QUERIES ===\n")
print("--- jq .metadata ---")
result = await ws.execute("jq .metadata /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: all team names (nested [] iterator) ---")
result = await ws.execute(
"jq \".departments[].teams[].name\" /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: all employee names ---")
result = await ws.execute("jq \".departments[].teams[].members[].name\""
" /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: senior engineers on platform ---")
result = await ws.execute("jq \".departments[0].teams[0].members"
" | map(select(.level == \\\"senior\\\"))"
" | map(.name)\" /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: all active project names ---")
result = await ws.execute("jq \".departments[].teams[].projects"
" | map(select(.status == \\\"active\\\"))"
" | map(.name)\" /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: mirage project metrics ---")
result = await ws.execute("jq .departments[0].teams[0].projects[0].metrics"
" /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: total budget ---")
result = await ws.execute(
"jq .metadata.total_budget /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: compact JSON row ---")
result = await ws.execute("jq -c .metadata /oci/data/example.json")
print(f" {(await result.stdout_str()).strip()}")
print("\n--- jq: departments pretty json ---")
result = await ws.execute("jq .departments /oci/data/example.json")
parsed = json.loads(await result.stdout_str())
print(f" departments: {len(parsed)}")
print(f" first team: {parsed[0]['teams'][0]['name']}")
if __name__ == "__main__":
asyncio.run(main())