Repository navigation
Expand file tree
/
Copy pathdev
More file actions
executable file
·114 lines (108 loc) · 6.28 KB
/
Copy pathdev
File metadata and controls
executable file
·114 lines (108 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
"""Shared pilot adapters. Run from a configured product checkout."""
import argparse
import datetime
import json
import os
from pathlib import Path
import subprocess
import sys
import tomllib
ENVIRONMENT_ROOT = Path(__file__).resolve().parent
PINS = json.loads((ENVIRONMENT_ROOT / "toolchains.json").read_text())
def commands(profile, operation):
if operation == "setup":
return ([["npm", "ci", "--prefix", "bindings/node"],
["npm", "ci", "--prefix", "bindings/wasm"],
["cargo", "dfv", "build"]] if profile == "core" else
[["uv", "sync", "--frozen", "--group", "dev", "--group", "ci"]])
if profile == "core":
return [["cargo", "fmt", "--all", "--check"],
["cargo", "clippy", "--workspace", "--all-targets", "--all-features", "--", "-D", "warnings"],
["cargo", "test", "--workspace", "--all-features"],
["cargo", "dfv", "check", "--json"],
["cargo", "dfv", "parity", "--json"],
["cargo", "dfv", "eval", "--json"],
["cargo", "dfv", "smoke", "--json"],
["cargo", "dfv", "parity", "--live", "--json"],
["cargo", "dfv", "parity", "--workspace", "--json"]]
return [["uv", "run", "--frozen", *args] for args in
(["ruff", "check", "."], ["ruff", "format", "--check", "."],
["mypy"], ["pyright"], ["pytest"])]
def validate_repo(root, profile):
if profile == "core":
toolchain = tomllib.loads((root / "rust-toolchain.toml").read_text())["toolchain"]
if toolchain["channel"] != PINS["rust"]:
raise ValueError("Core Rust pin differs from FogMachine; select a compatible environment")
if int((root / ".nvmrc").read_text().strip()) != PINS["node_major"]:
raise ValueError("Core Node pin differs from FogMachine")
packages = tomllib.loads((root / "Cargo.lock").read_text())["package"]
versions = {p["version"] for p in packages if p["name"] == "wasm-bindgen"}
if versions != {PINS["wasm_bindgen"]}:
raise ValueError("Core wasm-bindgen pin differs from FogMachine")
browser = json.loads((root / "bindings/wasm/package.json").read_text())
if browser["devDependencies"]["playwright"] != PINS["playwright"]:
raise ValueError("Core Playwright pin differs from FogMachine")
elif (root / ".python-version").read_text().strip() != PINS["python"]:
raise ValueError("MCP Python pin differs from FogMachine")
def doctor_commands():
# Assertions make a mismatch fail instead of merely displaying versions.
return [["python3", "-c", f"import sys; assert '.'.join(map(str,sys.version_info[:2])) == {PINS['python']!r}"],
["bash", "-c", f"test \"$(rustc --version | cut -d' ' -f2)\" = {PINS['rust']}"],
["node", "-e", f"if (+process.versions.node.split('.')[0] !== {PINS['node_major']}) process.exit(1)"],
["bash", "-c", f"test \"$(uv --version | cut -d' ' -f2)\" = {PINS['uv']}"],
["bash", "-c", f"test \"$(maturin --version | cut -d' ' -f2)\" = {PINS['maturin']}"],
["bash", "-c", f"test \"$(wasm-bindgen --version | cut -d' ' -f2)\" = {PINS['wasm_bindgen']}"],
["node", "--input-type=module", "-e", "import {chromium} from '/opt/fogmachine/browser/node_modules/playwright/index.mjs'; const browser=await chromium.launch(); console.log(await browser.version()); await browser.close();"]]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("operation", choices=["doctor", "setup", "check"])
parser.add_argument("--profile", choices=["core", "mcp"])
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
root = Path.cwd()
try:
profile = args.profile or json.loads((root / ".fogmachine.json").read_text())["profile"]
if profile not in ("core", "mcp"):
raise ValueError(f"Unsupported profile: {profile}")
validate_repo(root, profile)
except (OSError, ValueError, KeyError) as error:
parser.exit(1, f"FogMachine configuration: {error}\n")
steps = doctor_commands() if args.operation == "doctor" else commands(profile, args.operation)
if args.dry_run:
print(json.dumps(steps, indent=2))
return 0
evidence = root / ".fogmachine-runs" / (datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%dT%H%M%S%fZ") + f"-{args.operation}")
evidence.mkdir(parents=True)
def git(*arguments):
return subprocess.check_output(["git", *arguments], cwd=root, text=True).strip()
versions = {}
for tool, command in {"python": ["python3", "--version"], "rust": ["rustc", "--version"], "node": ["node", "--version"], "uv": ["uv", "--version"], "maturin": ["maturin", "--version"], "wasm_bindgen": ["wasm-bindgen", "--version"]}.items():
try:
result = subprocess.run(command, capture_output=True, text=True)
versions[tool] = {"exit_code": result.returncode, "output": (result.stdout + result.stderr).strip()}
except OSError as error:
versions[tool] = {"error": str(error)}
report = {"tool_versions": versions, "profile": profile, "operation": args.operation, "source_sha": git("rev-parse", "HEAD"),
"source_diff": git("diff", "--binary", "HEAD"), "git_status": git("status", "--porcelain"),
"image": os.environ.get("FOGMACHINE_IMAGE", "unrecorded"), "requirements": PINS, "steps": []}
status = 0
try:
for index, command in enumerate(steps):
print("+ " + " ".join(command), flush=True)
with (evidence / f"{index}.log").open("w") as output:
result = subprocess.run(command, stdout=output, stderr=subprocess.STDOUT, cwd=root)
report["steps"].append({"command": command, "exit_code": result.returncode})
if result.returncode:
status = result.returncode
print((evidence / f"{index}.log").read_text(), file=sys.stderr)
break
except OSError as error:
report["error"] = str(error)
status = 1
report["pass"] = status == 0
(evidence / "report.json").write_text(json.dumps(report, indent=2) + "\n")
print(f"Evidence: {evidence}")
return status
if __name__ == "__main__":
sys.exit(main())