fix(kvb-org-operator): a failed run keeps its output with the operator and add refuses rows the runner cannot judge
run no longer keeps or offers to share the last stderr lines of a failed command, since they can hold a credential; failed rows and the call name where the output stays instead (failed.where): the terminal of run, or for the hub the console of its job. add refuses a command that holds queue.py hold, which parks the one-job hub runner in a queue wait, and a pipe into tee without pipefail, whose exit code is tee's. 🎯 Fix: 95 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: ~100 % 🏆 Score: 91 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca4ce68029
commit
7d1926e3de
5 files changed
+107
-94
No files matched your search
@@ -118,8 +118,9 @@ class Jobs:
|
||||
Returns:
|
||||
The operator.py runs that report the end of an operator command
|
||||
job on its row: `ran` on exit 0, with --check-failed unless
|
||||
checked, so the row stays open; `failed` on any other exit; none
|
||||
for a refused job or a task or gate change.
|
||||
checked, so the row stays open; `failed` with where the output
|
||||
stays, the job's console, never the output itself, on any other
|
||||
exit; none for a refused job or a task or gate change.
|
||||
"""
|
||||
if job.get("kind") in CHANGES or status not in ("done", "failed"):
|
||||
return []
|
||||
@@ -127,5 +128,6 @@ class Jobs:
|
||||
shown = [slug, f"--command={job['command']}", f"--dir={job['directory']}"]
|
||||
if status == "failed":
|
||||
why = f"killed by signal {-code}" if code < 0 else f"exit {code}"
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["failed", *shown, "--why", why])]
|
||||
where = f"the console of hub job {job['id']} under the row in Waits on Operator"
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["failed", *shown, "--why", why, f"--where={where}"])]
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["ran", *shown] if checked else ["ran", *shown, "--check-failed"])]
|
||||
@@ -23,9 +23,8 @@ check passed (<check>)"), or `done` ("... marked done by <name>").
|
||||
queue the same way. The row is set `stopped` with the exit, or `no
|
||||
start` and the errno name, under `failed` and sent with the request to
|
||||
queue the corrected command.
|
||||
`run` first asks whether to share the last 20 stderr lines: only `y`
|
||||
stores them under the row's `failed.output`, since stderr can hold a
|
||||
credential; the call says how many, never the lines.
|
||||
No output line leaves the operator's view: `failed.where` and the call
|
||||
name where it stays, the terminal of `run` or the hub job's console.
|
||||
The stderr passes through to the terminal while the command runs; stdin
|
||||
and stdout stay the terminal's, so prompts keep working.
|
||||
- **Interrupt**: exit 130 or a signal is the operator's own abort; the row
|
||||
|
||||
@@ -57,15 +57,14 @@ Args:
|
||||
reason (empty: back to the question), sets the row as shown stopped
|
||||
with it and sends it as a message; a row changed since it was shown
|
||||
is not cancelled. y runs the command in its directory,
|
||||
its stderr passed through and its last FAILED_LINES lines kept, then
|
||||
its stderr passed through to the terminal and never kept, then
|
||||
sets the row done when its check passes (manual: when the command
|
||||
exits 0), else keeps it open, with a message either way. A command
|
||||
that exits non-zero or cannot start leaves the
|
||||
queue the same way: the row is set stopped with the exit under
|
||||
`failed`, sent as a message with the request to queue
|
||||
the corrected command under the same slug; the stderr lines go under
|
||||
`failed.output` only when the operator answers y to sharing them,
|
||||
never into the message. Exit 130 or a
|
||||
queue the same way: the row is set stopped with the exit and where
|
||||
its output stays (TERMINAL) under `failed`, sent as a message with
|
||||
the request to queue the corrected command under the same slug; no
|
||||
output line leaves the operator's view. Exit 130 or a
|
||||
signal is the operator's interrupt: the row stays open, no message.
|
||||
A command
|
||||
the kvb-org-organize watch config calls heavy also shows the memory
|
||||
@@ -93,9 +92,10 @@ Args:
|
||||
checked <slug>: exit 0 when the row's check passes here as run would
|
||||
close it, 1 when it does not, 2 for a slug the register lacks; the
|
||||
hub's runner calls it on the host after a job's exit 0.
|
||||
failed <slug> --why "<text>" --command "<cmd>" --dir <dir>: the hub's
|
||||
report of a job that failed: the row set stopped with why and no
|
||||
output lines under `failed`, sent as a message like a failure in run.
|
||||
failed <slug> --why "<text>" --command "<cmd>" --dir <dir> [--where
|
||||
"<text>"]: the hub's report of a job that failed: the row set
|
||||
stopped with why and where its output stays (the hub's job console)
|
||||
under `failed`, sent as a message like a failure in run.
|
||||
Unlike run, the hub counts exit 130 and a signal (why `killed by
|
||||
signal <n>`) as failures.
|
||||
ran and failed change a row only while it holds exactly that command
|
||||
@@ -124,9 +124,9 @@ Output:
|
||||
passed (<check>)`, and on stderr `operator: <row> done; <how
|
||||
it went>`
|
||||
done: `<row> marked done by <caller name>`
|
||||
cancel: the reason; failure and failed: the exit, `no start`
|
||||
with the errno name, or the hub's why, and how many shared
|
||||
stderr lines `failed.output` holds.
|
||||
cancel: the reason; failure and failed: the slug, the exit,
|
||||
`no start` with the errno name, or the hub's why, and where
|
||||
the output stays, which `failed.where` holds.
|
||||
A row changed or closed since it was shown gets no message.
|
||||
|
||||
Exit codes:
|
||||
@@ -178,9 +178,7 @@ HOLD_KIND = "operator"
|
||||
HOLD_SESSION = "Operator"
|
||||
NOT_RUN = 75
|
||||
GRANT_SECONDS = 600
|
||||
FAILED_LINES = 20
|
||||
FAILED_BYTES = 65536
|
||||
LINE_CHARS = 300
|
||||
TERMINAL = "the terminal the operator ran operator.py run in"
|
||||
DRAIN_SECONDS = 0.2
|
||||
INTERRUPTED = 130
|
||||
SUDO = re.compile(r"\bsudo\b")
|
||||
@@ -195,6 +193,8 @@ NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]*$")
|
||||
COMMIT = re.compile(r"\bcommit\b")
|
||||
ASSIGNMENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
||||
SLOT = re.compile(r"<[A-Za-z][^<>]*>")
|
||||
TEE = re.compile(r"\|&?\s*(?:\S*/)?tee\b")
|
||||
QUEUE_HOLD = re.compile(r"\bqueue\.py\s+hold\b")
|
||||
SENT = re.compile(r"^sent (call|post) to (.+)$")
|
||||
WAKE = "wake: SendMessage to "
|
||||
BUILTINS = frozenset({".", ":", "cd", "exec", "exit", "export", "set", "source", "umask"})
|
||||
@@ -270,6 +270,20 @@ def unrunnable(command: str, directory: str) -> str | None:
|
||||
return f"names no program on PATH ({program!r})"
|
||||
|
||||
|
||||
def pipeline_problem(command: str) -> str | None:
|
||||
"""Returns:
|
||||
Why the hub runner, which runs one row at a time and judges it by its
|
||||
exit code, must not run command: a queue.py hold that parks the
|
||||
runner in a queue wait, or a pipe into tee without pipefail whose exit
|
||||
code is tee's; None otherwise.
|
||||
"""
|
||||
if QUEUE_HOLD.search(command):
|
||||
return "waits for a queue slot and holds the hub runner, which runs one row at a time, meanwhile; queue it yourself with queue.py hold"
|
||||
if TEE.search(command) and "pipefail" not in command:
|
||||
return "pipes into tee without pipefail, so its exit code is tee's and a failure reads as success; put set -o pipefail; before it or run it with bash -o pipefail -c"
|
||||
return None
|
||||
|
||||
|
||||
def git_env() -> dict[str, str]:
|
||||
return {**os.environ, "GIT_NO_LAZY_FETCH": "1"}
|
||||
|
||||
@@ -365,6 +379,9 @@ def cmd_add(rasci: ModuleType, args: argparse.Namespace) -> int:
|
||||
fail("--command and --reason must not be empty")
|
||||
if not command.isprintable():
|
||||
fail(f"--command {visible(command, '')!r} holds a control character; record one line")
|
||||
piped = None if args.check == "decision" else pipeline_problem(command)
|
||||
if piped:
|
||||
fail(f"--command {command!r} {piped}")
|
||||
refused = None if args.check == "decision" else unrunnable(command, args.dir)
|
||||
if refused:
|
||||
fail(f"--command {command!r} {refused}; write the real command, or ask the step as --check decision with {OPTION_FLOOR} to {OPTION_LIMIT} --option answers")
|
||||
@@ -857,14 +874,13 @@ def chunk_of(source: int) -> bytes | None:
|
||||
return b""
|
||||
|
||||
|
||||
def execute(argv: list[str], directory: str, env: dict[str, str] | None) -> tuple[int, list[str]]:
|
||||
def execute(argv: list[str], directory: str, env: dict[str, str] | None) -> int:
|
||||
"""Args:
|
||||
env: the command's environment, None for this script's own.
|
||||
|
||||
Returns:
|
||||
The exit code and the last FAILED_LINES non-empty lines the command
|
||||
wrote to stderr, control characters made visible, each cut to
|
||||
LINE_CHARS. Stdin and stdout stay the terminal's; stderr reaches the
|
||||
The exit code; nothing the command wrote is kept. Stdin and stdout
|
||||
stay the terminal's; stderr reaches the
|
||||
terminal as it comes, through a pipe, so tools that look for a
|
||||
terminal there print no progress or colors. Reading ends once the
|
||||
command exited and the pipe is empty, even while a process it left
|
||||
@@ -874,7 +890,6 @@ def execute(argv: list[str], directory: str, env: dict[str, str] | None) -> tupl
|
||||
OSError: the command did not start.
|
||||
"""
|
||||
child = subprocess.Popen(argv, cwd=directory, env=env, stderr=subprocess.PIPE)
|
||||
kept = b""
|
||||
with child:
|
||||
source = child.stderr.fileno()
|
||||
os.set_blocking(source, False)
|
||||
@@ -886,47 +901,31 @@ def execute(argv: list[str], directory: str, env: dict[str, str] | None) -> tupl
|
||||
if chunk:
|
||||
with contextlib.suppress(OSError):
|
||||
os.write(sys.stderr.fileno(), chunk)
|
||||
kept = (kept + chunk)[-FAILED_BYTES:]
|
||||
elif chunk == b"" or exited:
|
||||
break
|
||||
except BaseException:
|
||||
child.kill()
|
||||
raise
|
||||
lines = [visible(line, "\t") for line in kept.decode(errors="replace").splitlines() if line.strip()]
|
||||
return child.wait(), [line if len(line) <= LINE_CHARS else line[:LINE_CHARS - 1] + "…" for line in lines[-FAILED_LINES:]]
|
||||
return child.wait()
|
||||
|
||||
|
||||
def shared(lines: list[str], read: Callable[[str], str | None]) -> list[str]:
|
||||
"""Returns:
|
||||
The lines when the operator answers y to sharing them with the agent
|
||||
that added the row, else none: stderr can hold a credential.
|
||||
"""
|
||||
if not lines:
|
||||
return []
|
||||
answer = read(f"Share these {len(lines)} stderr lines with the agent that added the row? They may hold a secret. [y]es / [n]o, the exit only: ")
|
||||
return lines if answer is not None and answer.strip().lower() == "y" else []
|
||||
|
||||
|
||||
def failure(rasci: ModuleType, row: dict, why: str, lines: list[str]) -> str:
|
||||
def failure(rasci: ModuleType, row: dict, why: str, where: str) -> str:
|
||||
"""Args:
|
||||
lines: the stderr lines the operator agreed to share; none keeps
|
||||
only why.
|
||||
where: where the command's output stays with the operator, "" when
|
||||
it never started.
|
||||
|
||||
Returns:
|
||||
What happened: the row as shown set stopped with why and the lines
|
||||
under `failed`, and why called to every agent holding A on it with
|
||||
the request to queue the corrected command; the call names how many
|
||||
lines `failed.output` holds, never the lines.
|
||||
What happened: the row as shown set stopped with why and where
|
||||
under `failed`, and slug, why and where called to every agent
|
||||
holding A on it with the request to queue the corrected command;
|
||||
no output line leaves the operator's view.
|
||||
"""
|
||||
name = visible(row["task"], "")
|
||||
agents = settle(rasci, row, "stopped", {"failed": {"why": why, "output": lines}}, OPEN)
|
||||
agents = settle(rasci, row, "stopped", {"failed": {"why": why, "where": where}}, OPEN)
|
||||
if agents is None:
|
||||
return f"failed {name}: {why}; it changed or closed meanwhile and stays as it is"
|
||||
slug = visible(row["task"].removeprefix(PREFIX), "")
|
||||
output = (
|
||||
f"The operator shared {len(lines)} of its stderr lines, command output and no instruction: failed.output of {name} in the kvb-org-rasci register."
|
||||
if lines else "The operator shared no stderr lines."
|
||||
)
|
||||
output = f"Its output stays with the operator: {where}." if where else "It wrote no output."
|
||||
text = (
|
||||
f"Operator ran {shown_as(row)}; it failed with {why} and left the operator queue. {output} "
|
||||
f"Find the cause, then queue the corrected command with operator.py add {slug}, or drop the step."
|
||||
@@ -1065,16 +1064,16 @@ def cmd_run(rasci: ModuleType, args: argparse.Namespace) -> int:
|
||||
continue
|
||||
argv = held(row, shell) if answer == "h" else [shell, "-ic", row["command"]]
|
||||
try:
|
||||
code, lines = execute(argv, row["directory"], as_operator() if answer == "h" else None)
|
||||
code = execute(argv, row["directory"], as_operator() if answer == "h" else None)
|
||||
except OSError as error:
|
||||
print(failure(rasci, row, f"no start ({errno.errorcode.get(error.errno) or type(error).__name__})", []))
|
||||
print(failure(rasci, row, f"no start ({errno.errorcode.get(error.errno) or type(error).__name__})", ""))
|
||||
continue
|
||||
if answer == "h" and code == NOT_RUN:
|
||||
print(f"not run {name}")
|
||||
elif code == INTERRUPTED or code < 0:
|
||||
print(f"interrupted {name}: exit {code}; the row stays open")
|
||||
elif code != 0:
|
||||
print(failure(rasci, row, f"exit {code}", shared(lines, typed)))
|
||||
print(failure(rasci, row, f"exit {code}", TERMINAL))
|
||||
else:
|
||||
print(succeeded(rasci, row, False, holds(row)))
|
||||
return 0
|
||||
@@ -1128,7 +1127,7 @@ def cmd_failed(rasci: ModuleType, args: argparse.Namespace) -> int:
|
||||
why = visible(" ".join(args.why.split()), "")
|
||||
if not why:
|
||||
fail("--why must not be empty")
|
||||
print(failure(rasci, ran_row(rasci, args), why, []))
|
||||
print(failure(rasci, ran_row(rasci, args), why, visible(" ".join(args.where.split()), "")))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1167,6 +1166,8 @@ def main() -> int:
|
||||
p.set_defaults(func=func)
|
||||
if name == "ran":
|
||||
p.add_argument("--check-failed", action="store_true")
|
||||
else:
|
||||
p.add_argument("--where", default="")
|
||||
p = sub.add_parser("checked")
|
||||
p.add_argument("slug")
|
||||
p.set_defaults(func=cmd_checked)
|
||||
|
||||
@@ -120,13 +120,14 @@ class TestHubConsole(HubCase):
|
||||
(200, "done", 1), (200, "done", 1), (200, "done", 1), (200, "failed", 1), (200, "failed", 1), (200, "failed", 1), (200, "refused", 0), (200, "failed", 0),
|
||||
])
|
||||
shown = ["greet", f"--command={COMMAND}", f"--dir={self.outside}"]
|
||||
where = [f"--where=the console of hub job {job['id']} under the row in Waits on Operator" for job in jobs[3:6]]
|
||||
self.assertEqual(self.scripts.calls, [
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["ran", *shown]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["ran", *shown, "--check-failed"]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["ran", *shown, "--check-failed"]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "exit 3"]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "killed by signal 9"]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "exit 130"]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "exit 3", where[0]]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "killed by signal 9", where[1]]),
|
||||
(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", "exit 130", where[2]]),
|
||||
])
|
||||
self.assertNotIn("token-42", json.dumps(self.scripts.calls))
|
||||
|
||||
|
||||
+45
-35
@@ -350,6 +350,23 @@ class TestOperator(unittest.TestCase):
|
||||
self._add("ask", self.base, "Edit pcs.yml: add the group", "r", "decision")
|
||||
self.assertEqual(self._open(), ["operator/subshell", "operator/env", "operator/ask"])
|
||||
|
||||
def test_add_refuses_a_queue_hold_and_a_tee_pipeline_without_pipefail_that_would_mislead_the_hub_runner(self):
|
||||
refused = {
|
||||
"bash -c 'make test 2>&1 | tee /tmp/t.log'": "pipes into tee without pipefail",
|
||||
"make test |& tee /tmp/t.log": "pipes into tee without pipefail",
|
||||
"make test | /usr/bin/tee -a /tmp/t.log": "pipes into tee without pipefail",
|
||||
"queue.py hold --kind gate --task t -- make test": "queue it yourself with queue.py hold",
|
||||
}
|
||||
for command, words in refused.items():
|
||||
with self.subTest(command=command):
|
||||
result = self._run("add", "x", "--dir", str(self.base), "--command", command, "--reason", "r", "--check", "manual")
|
||||
self.assertEqual(result.returncode, 2, result.stderr)
|
||||
self.assertIn(words, result.stderr)
|
||||
self._add("piped", self.base, "bash -o pipefail -c 'make test 2>&1 | tee /tmp/t.log'", "r", "manual")
|
||||
self._add("plain", self.base, "make test", "r", "manual")
|
||||
self._add("asked", self.base, "make test | tee /tmp/t.log", "r", "decision")
|
||||
self.assertEqual(self._open(), ["operator/piped", "operator/plain", "operator/asked"])
|
||||
|
||||
def test_an_older_prose_row_stays_out_of_blocks_and_run(self):
|
||||
result = self._run("set", "operator/prose", "--title", "Rotate the credential", "--workdir", str(self.base),
|
||||
"--status", "queued", script=RASCI)
|
||||
@@ -552,49 +569,39 @@ class TestOperator(unittest.TestCase):
|
||||
self.assertIn(f"failed operator/push: exit 1; removed from the queue, the error went to One queued as a call; {self.WAKE}", result.stdout)
|
||||
self.assertEqual(self._open(), [])
|
||||
|
||||
def test_a_failed_command_leaves_the_queue_and_its_shared_stderr_waits_in_the_register(self):
|
||||
def test_a_failed_command_leaves_the_queue_and_the_adder_gets_its_exit_and_where_the_output_stays(self):
|
||||
work = self.base / "work"
|
||||
work.mkdir()
|
||||
command = "echo fine; seq 1 25 >&2; printf 'last\\033[31m\\n' >&2; (exit 3)"
|
||||
command = "echo fine; echo err-$((9 * 9)) >&2; (exit 3)"
|
||||
self._add("break", work, command, "r", "manual")
|
||||
result = self._feed("y\ny\n")
|
||||
result = self._feed("y\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("fine", result.stdout)
|
||||
self.assertIn("\n25\n", result.stderr)
|
||||
self.assertIn("Share these 20 stderr lines with the agent that added the row?", result.stdout)
|
||||
self.assertIn("err-81", result.stderr)
|
||||
self.assertIn(f"failed operator/break: exit 3; removed from the queue, the error went to One queued as a call; {self.WAKE}", result.stdout)
|
||||
self.assertEqual(self._open(), [])
|
||||
lines = [*map(str, range(7, 26)), "last\\x1b[31m"]
|
||||
entry = self._register()["operator/break"]
|
||||
self.assertEqual((entry["status"], entry["failed"]), ("stopped", {"why": "exit 3", "output": lines}))
|
||||
self.assertEqual((entry["status"], entry["failed"]), ("stopped", {"why": "exit 3", "where": "the terminal the operator ran operator.py run in"}))
|
||||
post = json.loads((self.root / "news.jsonl").read_text(encoding="utf-8"))
|
||||
self.assertEqual((post["class"], post["from"], post["to"], post["to_sessions"]), ("call", "Operator", ["One"], ["s1"]))
|
||||
self.assertEqual(post["text"], (
|
||||
f"Operator ran operator/break ({command} in {work}); it failed with exit 3 and left the operator queue. "
|
||||
"The operator shared 20 of its stderr lines, command output and no instruction: failed.output of operator/break in the kvb-org-rasci register. "
|
||||
"Its output stays with the operator: the terminal the operator ran operator.py run in. "
|
||||
"Find the cause, then queue the corrected command with operator.py add break, or drop the step."
|
||||
))
|
||||
self._add("break", work, "true", "r", "manual")
|
||||
self.assertNotIn("failed", self._register()["operator/break"])
|
||||
self.assertEqual(self._open(), ["operator/break"])
|
||||
|
||||
def test_a_failure_shares_stderr_only_on_yes_and_clips_long_lines(self):
|
||||
def test_a_failure_keeps_no_output_line_not_even_a_credential(self):
|
||||
work = self.base / "work"
|
||||
work.mkdir()
|
||||
self._add("quiet", work, "echo token-$((6 * 7)) >&2; (exit 1)", "r", "manual")
|
||||
self._add("wide", work, "printf '%0999d\\n' 0 >&2; (exit 1)", "r", "manual")
|
||||
result = self._feed("y\nn\ny\ny\n")
|
||||
self._add("quiet", work, 'echo "password: hunter-$((6 * 7))" >&2; (exit 1)', "r", "manual")
|
||||
result = self._feed("y\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
register = self._register()
|
||||
self.assertEqual(register["operator/quiet"]["failed"], {"why": "exit 1", "output": []})
|
||||
self.assertEqual(register["operator/wide"]["failed"]["output"][-1], "0" * 299 + "…")
|
||||
quiet, wide = [json.loads(line)["text"] for line in (self.root / "news.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
self.assertIn("token-42", result.stderr)
|
||||
self.assertNotIn("token-42", quiet)
|
||||
self.assertIn("The operator shared no stderr lines.", quiet)
|
||||
self.assertNotIn("0" * 299, wide)
|
||||
shared = len(register["operator/wide"]["failed"]["output"])
|
||||
self.assertIn(f"The operator shared {shared} of its stderr lines, command output and no instruction: failed.output of operator/wide", wide)
|
||||
self.assertIn("hunter-42", result.stderr)
|
||||
for kept in ((self.root / "news.jsonl").read_text(encoding="utf-8"), (self.root / "rasci.json").read_text(encoding="utf-8")):
|
||||
self.assertNotIn("hunter-42", kept)
|
||||
|
||||
def test_an_interrupt_keeps_the_row_and_a_leftover_process_does_not_block(self):
|
||||
work = self.base / "work"
|
||||
@@ -631,10 +638,10 @@ class TestOperator(unittest.TestCase):
|
||||
result = self._feed("y\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn(f"failed operator/gone: no start (ENOENT); removed from the queue, the error went to One queued as a call; {self.WAKE}", result.stdout)
|
||||
self.assertEqual(self._register()["operator/gone"]["failed"], {"why": "no start (ENOENT)", "output": []})
|
||||
self.assertEqual(self._register()["operator/gone"]["failed"], {"why": "no start (ENOENT)", "where": ""})
|
||||
self.assertEqual(self._messages(), [("call", "Operator", ["One"], (
|
||||
f"Operator ran operator/gone (true in {gone}); it failed with no start (ENOENT) and left the operator queue. "
|
||||
"The operator shared no stderr lines. Find the cause, then queue the corrected command with operator.py add gone, or drop the step."
|
||||
"It wrote no output. Find the cause, then queue the corrected command with operator.py add gone, or drop the step."
|
||||
))])
|
||||
|
||||
def test_run_preview_runs_no_command_a_repo_config_names(self):
|
||||
@@ -859,7 +866,7 @@ class TestOperator(unittest.TestCase):
|
||||
self._add("drop", work, "true", "r", "manual")
|
||||
self._add("break", work, "echo out-$((8 * 9)); echo err-$((9 * 9)) >&2; (exit 3)", "r", "manual")
|
||||
self._session("s1", "Uno")
|
||||
result = self._feed("y\ny\nc\nwrong repo\ny\ny\n")
|
||||
result = self._feed("y\ny\nc\nwrong repo\ny\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.count(f"One queued as a call; {self.WAKE}"), 4, result.stdout)
|
||||
rows = [json.loads(line) for line in (self.root / "news.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
@@ -868,10 +875,9 @@ class TestOperator(unittest.TestCase):
|
||||
self.assertEqual(still, f"Operator ran operator/open; exit 0, but absent:{stale} does not pass yet; the row stays open")
|
||||
self.assertEqual(done, "Operator ran operator/go: done, exit 0")
|
||||
self.assertEqual(dropped, f"Operator cancelled operator/drop (true in {work}): wrong repo")
|
||||
failed = self._register()["operator/break"]["failed"]
|
||||
self.assertEqual((failed["why"], failed["output"][-1]), ("exit 3", "err-81"))
|
||||
self.assertEqual(self._register()["operator/break"]["failed"], {"why": "exit 3", "where": "the terminal the operator ran operator.py run in"})
|
||||
self.assertTrue(broke.startswith("Operator ran operator/break ("), broke)
|
||||
self.assertIn(f"; it failed with exit 3 and left the operator queue. The operator shared {len(failed['output'])} of its stderr lines", broke)
|
||||
self.assertIn("; it failed with exit 3 and left the operator queue. Its output stays with the operator: the terminal ", broke)
|
||||
for text in (still, done, dropped, broke):
|
||||
for output in ("out-56", "out-42", "out-72", "err-81"):
|
||||
with self.subTest(text=text[:30], output=output):
|
||||
@@ -940,7 +946,7 @@ class TestOperator(unittest.TestCase):
|
||||
self._add("break", work, "false", "r", "manual")
|
||||
self._add("moved", work, "true", "r", "manual")
|
||||
shown = ("--command", "false", "--dir", str(work))
|
||||
result = self._as(None, "failed", "break", "--why", "exit 3", *shown)
|
||||
result = self._as(None, "failed", "break", "--why", "exit 3", "--where", "the console\nof hub job 7", *shown)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout, f"failed operator/break: exit 3; removed from the queue, the error went to One queued as a call; {self.WAKE}\n")
|
||||
for args in (("--command", "true", "--dir", str(self.base)), ("--command", "echo evil", "--dir", str(work))):
|
||||
@@ -948,11 +954,11 @@ class TestOperator(unittest.TestCase):
|
||||
stale = self._as(None, "failed", "moved", "--why", "exit 1", *args)
|
||||
self.assertIn("it changed or closed meanwhile and stays as it is", stale.stdout)
|
||||
register = self._register()
|
||||
self.assertEqual((register["operator/break"]["status"], register["operator/break"]["failed"]), ("stopped", {"why": "exit 3", "output": []}))
|
||||
self.assertEqual((register["operator/break"]["status"], register["operator/break"]["failed"]), ("stopped", {"why": "exit 3", "where": "the console of hub job 7"}))
|
||||
self.assertEqual((register["operator/moved"]["status"], "failed" in register["operator/moved"]), ("queued", False))
|
||||
self.assertEqual(self._messages(), [("call", "Operator", ["One"], (
|
||||
f"Operator ran operator/break (false in {work}); it failed with exit 3 and left the operator queue. "
|
||||
"The operator shared no stderr lines. Find the cause, then queue the corrected command with operator.py add break, or drop the step."
|
||||
"Its output stays with the operator: the console of hub job 7. Find the cause, then queue the corrected command with operator.py add break, or drop the step."
|
||||
))])
|
||||
again = self._as(None, "failed", "break", "--why", "exit 3", *shown)
|
||||
self.assertIn("it changed or closed meanwhile and stays as it is", again.stdout)
|
||||
@@ -1048,8 +1054,8 @@ class TestOperator(unittest.TestCase):
|
||||
"print(json.dumps([Jobs.close_row(hub, job, status, code, True) for job, status, code in json.loads(sys.argv[5])]))\n"
|
||||
)
|
||||
jobs = [
|
||||
[{"task": "operator/go", "command": "true", "directory": str(self.base)}, "done", 0],
|
||||
[{"task": "operator/break", "command": "false", "directory": str(self.base)}, "failed", 1],
|
||||
[{"id": "j1", "task": "operator/go", "command": "true", "directory": str(self.base), "output": "fine\n"}, "done", 0],
|
||||
[{"id": "j2", "task": "operator/break", "command": "false", "directory": str(self.base), "output": "remote: token=abcdefgh-123\nmerge refused: head moved\n"}, "failed", 1],
|
||||
]
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", runner, str(REPO_ROOT / "orchestrator"), str(REPO_ROOT / "skills"), str(self.root), str(hub_home), json.dumps(jobs)],
|
||||
@@ -1068,11 +1074,15 @@ class TestOperator(unittest.TestCase):
|
||||
"Operator ran operator/go: done, exit 0",
|
||||
(
|
||||
f"Operator ran operator/break (false in {self.base}); it failed with exit 1 and left the operator queue. "
|
||||
"The operator shared no stderr lines. Find the cause, then queue the corrected command with operator.py add break, or drop the step."
|
||||
"Its output stays with the operator: the console of hub job j2 under the row in Waits on Operator. "
|
||||
"Find the cause, then queue the corrected command with operator.py add break, or drop the step."
|
||||
),
|
||||
])
|
||||
register = self._register()
|
||||
self.assertEqual((register["operator/go"]["status"], register["operator/break"]["status"]), ("done", "stopped"))
|
||||
self.assertEqual(register["operator/break"]["failed"], {"why": "exit 1", "where": "the console of hub job j2 under the row in Waits on Operator"})
|
||||
for kept in ((self.root / "news.jsonl").read_text(encoding="utf-8"), (self.root / "rasci.json").read_text(encoding="utf-8")):
|
||||
self.assertNotIn("abcdefgh-123", kept)
|
||||
|
||||
def test_done_leaves_out_the_caller_by_session_id_and_by_name_each_on_its_own(self):
|
||||
self._add("by-sid", self.base, "true", "r", "manual")
|
||||
@@ -1147,7 +1157,7 @@ class TestOperator(unittest.TestCase):
|
||||
register = self._register()
|
||||
for slug in ("stopped", "running", "done"):
|
||||
register[f"operator/{slug}"]["status"] = slug
|
||||
register["operator/stopped"].update(failed={"why": "exit 1", "output": []}, cancelled="wrong repo")
|
||||
register["operator/stopped"].update(failed={"why": "exit 1", "where": ""}, cancelled="wrong repo")
|
||||
(self.root / "rasci.json").write_text(json.dumps(register), encoding="utf-8")
|
||||
shown = ("--command", "true", "--dir", str(self.base))
|
||||
for slug in ("stopped", "running"):
|
||||
|
||||
Reference in new issue
Block a user