M4: lens linters, tests, triage, watch, freshness (closes #27 #28 #29 #30 #31 #32 #33 #34)
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-09-30 14:13:13 +00:00
1 parent 9b8cf48e21
commit 1637d9274b
12 files changed
+1339 -65

No files matched your search

Executable
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
# Full local check: fmt, clippy, unit tests, all e2e scripts.
cd "$(dirname "$0")/.."
export PATH="$HOME/.local/bin:$PATH"
set -e
cargo fmt --all --check
cargo clippy -q --workspace --all-targets -- -D warnings
log=$(mktemp)
cargo test -q --workspace >"$log" 2>&1 || { grep -E 'FAILED|panicked' -A4 "$log"; exit 1; }
grep -oE 'ok. [0-9]+ passed' "$log" | awk '{s+=$2} END {print s" unit tests ok"}'
cargo build -q
sh tests/e2e.sh
python3 tests/tui_smoke.py | grep -q FAIL && { echo "tui smoke FAIL"; exit 1; } || echo "tui smoke ok"
sh tests/lens_e2e.sh
sh tests/m4_e2e.sh
+66
View File
@@ -0,0 +1,66 @@
"""M4 e2e fake model (python project):
turn 1: write badly formatted p.py with an unused import -> expect ruff F401 in lens report, file formatted
turn 2: edit p.py (must not be blocked by the formatter's change: read-guard refreshed)
turn 3: diag_mark the remaining finding as false positive
turn 4: finish; report what it saw
Usage: python3 tests/fake_m4.py PORT
"""
import http.server, json, sys
LOG = []
def sse(ev, d):
return f"event: {ev}\ndata: {json.dumps(d)}\n\n".encode()
def texts(msg):
out = []
for b in msg["content"]:
if b.get("type") == "text":
out.append(b["text"])
if b.get("type") == "tool_result":
out.append(("ERR:" if b.get("is_error") else "OK:") + b["content"])
return "\n".join(out)
class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def do_POST(self):
body = json.loads(self.rfile.read(int(self.headers["content-length"])))
LOG.append(texts(body["messages"][-1]))
n = len(LOG)
if n == 1:
turn = ("Write", {"path": "p.py", "content": "import os\nx = 1\nprint( x )\n"})
elif n == 2:
turn = ("Edit", {"path": "p.py", "old_string": "x = 1", "new_string": "x = 2"})
elif n == 3:
turn = ("diag_mark", {"path": "p.py", "line": 1, "mark": "false_positive", "reason": "needed for side effects"})
else:
turn = None
self.send_response(200)
self.send_header("content-type", "text/event-stream")
self.end_headers()
w = self.wfile.write
w(sse("message_start", {"message": {"usage": {"input_tokens": 1, "output_tokens": 1}}}))
if turn is None:
w(sse("content_block_start", {"index": 0, "content_block": {"type": "text", "text": ""}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "text_delta", "text": "FINISHED"}}))
stop = "end_turn"
else:
w(sse("content_block_start", {"index": 0, "content_block": {"type": "tool_use", "id": f"t{n}", "name": turn[0], "input": {}}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "input_json_delta", "partial_json": json.dumps(turn[1])}}))
stop = "tool_use"
w(sse("content_block_stop", {"index": 0}))
w(sse("message_delta", {"delta": {"stop_reason": stop}, "usage": {"output_tokens": 1}}))
w(sse("message_stop", {}))
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(LOG).encode())
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
# M4 e2e: ruff lint findings reach the model, ruff-format runs without tripping the read-guard,
# diag_mark persists and hides the finding.
set -eu
command -v ruff >/dev/null || { echo "skip: ruff not installed"; exit 0; }
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
port=$((20000 + $$ % 20000))
python3 "$root/tests/fake_m4.py" $port & srv=$!
mkdir -p "$tmp/home/.hx" "$tmp/repo"
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
# ruff.toml enables ruff-format (formatters only run when configured)
echo 'line-length = 100' > "$tmp/repo/ruff.toml"
printf '[lsp]\ndisable = ["pyright"]\n' > "$tmp/home/.hx/config.toml"
sleep 0.5
cd "$tmp/repo"
HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p "go" > "$tmp/out" 2> "$tmp/err" || { cat "$tmp/err"; exit 1; }
log="$tmp/log.json"
curl -s "http://127.0.0.1:$port/" > "$log"
fail() { echo "FAIL: $1"; echo "--- log"; python3 -m json.tool < "$log"; echo "--- err"; cat "$tmp/err"; exit 1; }
chk() { python3 -c "import json,sys; l=json.load(open(sys.argv[1])); $1" "$log"; }
grep -q FINISHED "$tmp/out" || fail "no finish"
# turn 2 request carries lens report with ruff F401
chk 'assert "[F401]" in l[1] and "(ruff)" in l[1], l[1]' || fail "no ruff finding"
# formatter applied, and the following edit was not blocked
grep -qx "x = 2" p.py && grep -qx "print(x)" p.py || fail "format/edit: $(cat p.py)"
chk 'assert l[2].startswith("OK:edited"), l[2]' || fail "edit blocked"
# diag_mark succeeded and persisted
chk 'assert "OK:marked FalsePositive" in l[3], l[3]' || fail "mark"
grep -q F401 "$tmp"/home/.hx/projects/*/triage.json || fail "triage not persisted"
[ -s "$tmp/home/.hx/latency.log" ] || fail "no latency log"
echo "m4 e2e ok"