ci / check (push) Canceled after 0s
- seq log: monotonic project/file seq with change source - minimal LSP JSON-RPC client (no lsp-types): framing, requests with timeout, server->client requests, publishDiagnostics with versions, $/progress + rust-analyzer serverStatus busy tracking - manager: built-in table (rust-analyzer, tsserver, pyright, gopls, clangd), outermost-root detection, lazy spawn, idle eviction, crash restart with 2-failure breaker, degradation notes, ContentModified retry, session-start warmup, config overrides/disable - turn-end hook: diagnostics for files changed this turn, errors first, per-file cap, total cap, unchanged findings not repeated, one 'no problems' after a fix; agent_end/off modes - lsp tool: diagnostics, definition, references, hover, symbols - tests: real rust-analyzer + pyright (skipped if absent); tests/lens_e2e.sh proves an introduced type error is surfaced and fixed without prompting Closes #21, closes #22, closes #23, closes #24, closes #25, closes #26
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
"""Lens e2e: fake model writes a Rust type error; hx must inject rust-analyzer diagnostics at turn end;
|
|
the fake model only fixes the file if it sees the error in the next request.
|
|
Usage: python3 tests/fake_lens.py PORT
|
|
"""
|
|
import http.server, json, sys
|
|
|
|
LOG = []
|
|
|
|
|
|
def sse(ev, d):
|
|
return f"event: {ev}\ndata: {json.dumps(d)}\n\n".encode()
|
|
|
|
|
|
def last_user_text(body):
|
|
m = body["messages"][-1]
|
|
return "\n".join(b.get("text", "") for b in m["content"] if b.get("type") == "text")
|
|
|
|
|
|
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(body)
|
|
n = len(LOG)
|
|
lens = last_user_text(body)
|
|
if n == 1:
|
|
turn = ("tool", "Write", {"path": "src/lib.rs", "content": "pub fn f() -> u32 {\n \"oops\"\n}\n"})
|
|
elif "[lens]" in lens and "error" in lens:
|
|
turn = ("tool", "Write", {"path": "src/lib.rs", "content": "pub fn f() -> u32 {\n 42\n}\n"})
|
|
else:
|
|
turn = ("text", "FINISHED lens=" + ("clean" if "no problems" in lens else "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[0] == "text":
|
|
w(sse("content_block_start", {"index": 0, "content_block": {"type": "text", "text": ""}}))
|
|
w(sse("content_block_delta", {"index": 0, "delta": {"type": "text_delta", "text": turn[1]}}))
|
|
stop = "end_turn"
|
|
else:
|
|
w(sse("content_block_start", {"index": 0, "content_block": {"type": "tool_use", "id": f"t{n}", "name": turn[1], "input": {}}}))
|
|
w(sse("content_block_delta", {"index": 0, "delta": {"type": "input_json_delta", "partial_json": json.dumps(turn[2])}}))
|
|
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()
|