mirror of
https://github.com/morluto/rea.git
synced 2026-11-09 00:07:18 +00:00
* test: focus configuration diagnostics on their owners Preserve shape errors, selected paths, recovery guidance, and unchanged-file behavior across parser, setup, and uninstall boundaries. * test: focus artifact and evidence checks on behavior Retain format, identity, malformed-input, and cleanup coverage while removing fixed prose and closing the admitted test source. * refactor(debugger): use configured session admission limits * test: focus evidence and diagnostics on behavior * fix(test): restore verifier export and formatting * test(config): verify debugger limit ranges * test(rizin): keep fixture executable authoritative * test(rizin): isolate debugger fixture environment
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import type { Interface } from "node:readline";
|
|
|
|
import type { SessionRequest } from "./DesktopApplicationSession.js";
|
|
|
|
const QUEUE_PAUSE = 16;
|
|
const QUEUE_RESUME = 4;
|
|
|
|
/**
|
|
* `stop` ends the session. An empty line, `checkpoint` or `checkpoint <name>`
|
|
* requests a checkpoint; any other line names one.
|
|
*/
|
|
const parseSessionRequest = (line: string): SessionRequest => {
|
|
const text = line.trim();
|
|
if (text === "stop") return { kind: "stop" };
|
|
const name = text.replace(/^checkpoint(?:\s+|$)/u, "");
|
|
return { kind: "checkpoint", name: name.length === 0 ? undefined : name };
|
|
};
|
|
|
|
/**
|
|
* Requests read line by line. The end of input counts as `stop`, so a driver
|
|
* must keep its input open between checkpoints. Reading pauses while many
|
|
* requests are queued, so a fast driver cannot grow the queue without bound.
|
|
*/
|
|
export class SessionRequestQueue {
|
|
readonly #requests: SessionRequest[] = [];
|
|
#paused = false;
|
|
|
|
constructor(readonly lines: Interface) {
|
|
lines.on("line", (line) => {
|
|
this.#requests.push(parseSessionRequest(line));
|
|
if (!this.#paused && this.#requests.length >= QUEUE_PAUSE) {
|
|
this.#paused = true;
|
|
lines.pause();
|
|
}
|
|
});
|
|
lines.once("close", () => {
|
|
this.#requests.push({ kind: "stop" });
|
|
});
|
|
}
|
|
|
|
next(): SessionRequest | undefined {
|
|
const request = this.#requests.shift();
|
|
if (this.#paused && this.#requests.length <= QUEUE_RESUME) {
|
|
this.#paused = false;
|
|
this.lines.resume();
|
|
}
|
|
return request;
|
|
}
|
|
|
|
close(): void {
|
|
this.lines.close();
|
|
}
|
|
}
|