Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(diagnose,eval): attach the report to the registry, and exit non-zero when the attach fails (#1683)

Alpamys Makazhanb403d87365a2
diff --git a/changelog.d/0.75.1/1683.fixed.md b/changelog.d/0.75.1/1683.fixed.md
new file mode 100644
index 00000000..bcf80694
--- /dev/null
+++ b/changelog.d/0.75.1/1683.fixed.md
@@ -0,0 +1,11 @@
+- `soup diagnose --attach-to-registry` and `soup eval unlearning --attach-to-registry`
+ attach the report. Both called the registry helper with arguments it does not take, so
+ the attach raised a `TypeError` on every run, the report was never linked to the entry,
+ and the command printed the error as a warning and exited 0. The `--output` file is now
+ stored on the entry (as `diagnose_report` / `eval_results`), and a requested attach is
+ part of the command's success, as it already is for `soup bom emit`, `soup attest emit`
+ and `soup eval custom`: a failed attach (unknown or ambiguous entry, unreadable
+ registry) prints an error and exits 1 with the report left on disk, and
+ `--attach-to-registry` without `--output` is refused before anything runs (exit 3 for
+ `soup diagnose`, exit 2 for `soup eval unlearning`) instead of being skipped with a
+ warning (#1683).
diff --git a/docs/evaluation.md b/docs/evaluation.md
index 1a56bd11..2b34d1ad 100644
--- a/docs/evaluation.md
+++ b/docs/evaluation.md
@@ -344,6 +344,12 @@ soup diagnose my-run-id --base-model HuggingFaceTB/SmolLM2-135M --allow-not-run
soup diagnose my-run-id --output diag.json --attach-to-registry abc123
```
+**Registry attach.** `--attach-to-registry <id>` links the `--output` file to that entry as a
+`diagnose_report` artifact; `<id>` is an entry id, a unique id prefix, `name:tag` or
+`registry://<id>`. A requested attach is part of the command's success: `soup diagnose` exits 1
+when it fails (unknown or ambiguous entry, unreadable registry), with the report left on disk,
+and exits 3 before anything runs when the flag is given without `--output`.
+
**Live runners (v0.71.7).** With `--base-model` the six probes run against the loaded model
(+ optional `--adapter` LoRA path, `--dataset` for format / memorization / citation probes,
`--holdout` for the forgetting probe using the first 12 usable rows and falling back to built-in general prompts if unset,
diff --git a/src/soup_cli/commands/_eval_v0610.py b/src/soup_cli/commands/_eval_v0610.py
index 5660f9f4..9c895338 100644
--- a/src/soup_cli/commands/_eval_v0610.py
+++ b/src/soup_cli/commands/_eval_v0610.py
@@ -49,8 +49,9 @@ def register(app: typer.Typer, console: Console) -> None:
attach_to_registry: Optional[str] = typer.Option(
None, "--attach-to-registry",
help=(
- "Optional registry entry id to attach the report as an "
- "eval_results artifact (mirrors v0.55.0 eval lock policy)."
+ "Registry entry id to attach the --output report to as an "
+ "eval_results artifact (needs --output). Exits 1 when the "
+ "attach fails."
),
),
) -> None:
@@ -68,6 +69,15 @@ def register(app: typer.Typer, console: Console) -> None:
console.print(f"[red]Invalid benchmark:[/] {for_terminal(exc)}")
raise typer.Exit(2) from exc
+ # The attach links the --output file, so without one nothing can be
+ # attached: refuse before the eval runs.
+ if attach_to_registry is not None and output is None:
+ console.print(
+ "[red]--attach-to-registry requires --output[/] "
+ "(nothing written to attach)."
+ )
+ raise typer.Exit(2)
+
evidence_data = None
if evidence is not None:
try:
@@ -131,27 +141,24 @@ def register(app: typer.Typer, console: Console) -> None:
raise typer.Exit(2) from exc
console.print(f"Wrote report -> {for_terminal(output)}")
- # Optional registry attach.
+ # Optional registry attach. Once requested it is part of the command's
+ # success: a failure exits 1, with the report already on disk.
if attach_to_registry is not None:
- if output is None:
- console.print(
- "[yellow]--attach-to-registry requires --output;[/] skipping attach."
+ assert output is not None # narrowed by the early arg-check
+ try:
+ from soup_cli.registry.attach import attach_artifact
+
+ attach_artifact(
+ entry_id=attach_to_registry,
+ path=output,
+ kind="eval_results",
)
- else:
- try:
- from soup_cli.registry.attach import attach_artifact
- attach_artifact(
- entry_id=attach_to_registry,
- artifact_path=output,
- kind="eval_results",
- )
- console.print(
- f"Attached eval_results -> registry {for_terminal(attach_to_registry)}"
- )
- except Exception as exc: # noqa: BLE001
- console.print(
- f"[yellow]Registry attach failed:[/] {for_terminal(exc)}"
- )
+ except Exception as exc: # noqa: BLE001
+ console.print(f"[red]Registry attach failed:[/] {for_terminal(exc)}")
+ raise typer.Exit(1) from exc
+ console.print(
+ f"Attached eval_results -> registry {for_terminal(attach_to_registry)}"
+ )
# Exit code: 0 on OK / MINOR; 2 on MAJOR (matches v0.56.0 diagnose
# gate convention so CI scripts can chain `soup train` → `soup
diff --git a/src/soup_cli/commands/diagnose.py b/src/soup_cli/commands/diagnose.py
index 4e7aed3c..5198513f 100644
--- a/src/soup_cli/commands/diagnose.py
+++ b/src/soup_cli/commands/diagnose.py
@@ -5,7 +5,7 @@ Top-level CLI command (NOT a sub-group) — operators type:
soup diagnose <run-id>
soup diagnose <run-id> --output diagnose.json
soup diagnose <run-id> --badge diagnose.svg
- soup diagnose <run-id> --attach-to-registry <id>
+ soup diagnose <run-id> --output diagnose.json --attach-to-registry <id>
Since v0.71.7 (#165) the six probe runners (forgetting / refusal / format /
mode_collapse / memorization / contamination) run LIVE when ``--base-model``
@@ -197,25 +197,25 @@ def _write_badge(badge_path: str, svg: str) -> None:
def _attach_to_registry(report: FailureReport, registry_id: str, output: str) -> None:
+ """Attach the written report to a registry entry as ``diagnose_report``.
+
+ A requested attach is part of the command's success: when it does not
+ happen the command exits 1, with the report already on disk.
+ """
try:
from soup_cli.registry.attach import attach_artifact
- except Exception as exc: # noqa: BLE001 — registry is optional
- console.print(
- f"[yellow]Warning:[/] could not import registry attach helper: "
- f"{escape(type(exc).__name__)}"
- )
- return
- try:
- attach_artifact(registry_id, "diagnose_report", output)
- console.print(
- f"[green]Attached[/] diagnose_report to registry entry "
- f"[bold]{for_terminal(registry_id)}[/]"
- )
+
+ attach_artifact(registry_id, path=output, kind="diagnose_report")
except Exception as exc: # noqa: BLE001
console.print(
- f"[yellow]Warning:[/] could not attach to registry: "
+ f"[red]Error:[/] could not attach to registry: "
f"{escape(type(exc).__name__)}: {for_terminal(exc)}"
)
+ raise typer.Exit(code=1) from exc
+ console.print(
+ f"[green]Attached[/] diagnose_report to registry entry "
+ f"[bold]{for_terminal(registry_id)}[/]"
+ )
def _emit_report(
@@ -251,12 +251,9 @@ def _emit_report(
)
raise typer.Exit(code=1) from exc
- if attach_to_registry and output:
+ if attach_to_registry is not None:
+ assert output # narrowed by the early arg-check in diagnose()
_attach_to_registry(report, attach_to_registry, output)
- elif attach_to_registry and not output:
- console.print(
- "[yellow]Warning:[/] --attach-to-registry needs --output (skipped)."
- )
def diagnose(
@@ -275,7 +272,12 @@ def diagnose(
None, "--badge", help="Write an SVG badge to this path."
),
attach_to_registry: Optional[str] = typer.Option(
- None, "--attach-to-registry", help="Attach the report to a registry entry id."
+ None,
+ "--attach-to-registry",
+ help=(
+ "Attach the --output report to a registry entry id (needs --output). "
+ "Exits 1 when the attach fails."
+ ),
),
base_model: Optional[str] = typer.Option(
None,
@@ -355,6 +357,15 @@ def diagnose(
)
raise typer.Exit(code=2) from exc
+ # The attach links the --output file, so without one nothing can be
+ # attached: say so before a live run loads a model.
+ if attach_to_registry is not None and not output:
+ console.print(
+ "[red]Error:[/] --attach-to-registry needs --output "
+ "(nothing written to attach)."
+ )
+ raise typer.Exit(code=EXIT_USAGE_ERROR)
+
if base_model is not None:
from soup_cli.utils.diagnose import _common
from soup_cli.utils.diagnose.live import run_live_diagnose
diff --git a/tests/test_diagnose_evidence_terminal_output.py b/tests/test_diagnose_evidence_terminal_output.py
index ab35588c..9f3ad8f3 100644
--- a/tests/test_diagnose_evidence_terminal_output.py
+++ b/tests/test_diagnose_evidence_terminal_output.py
@@ -295,7 +295,12 @@ def test_badge_error_shows_the_exception_text_literally(monkeypatch, tmp_path):
def test_attached_line_shows_the_registry_id_literally(monkeypatch, tmp_path):
- monkeypatch.setattr(attach_mod, "attach_artifact", lambda entry_id, kind, path: None)
+ # The stand-ins take the helper's own keyword-only signature, so a call the
+ # real attach_artifact would refuse fails here too.
+ def _attached(entry_id, *, path, kind, enforce_cwd=True):
+ return 1
+
+ monkeypatch.setattr(attach_mod, "attach_artifact", _attached)
result, out = _run(
monkeypatch, tmp_path, "run1", "--output", "report.json", "--attach-to-registry", FILE_TEXT
)
@@ -304,15 +309,15 @@ def test_attached_line_shows_the_registry_id_literally(monkeypatch, tmp_path):
_assert_shown_literally(out)
-def test_attach_warning_shows_the_exception_text_literally(monkeypatch, tmp_path):
- def _missing(entry_id, kind, path):
+def test_attach_error_shows_the_exception_text_literally(monkeypatch, tmp_path):
+ def _missing(entry_id, *, path, kind, enforce_cwd=True):
raise ValueError(f"registry entry not found: {entry_id}")
monkeypatch.setattr(attach_mod, "attach_artifact", _missing)
result, out = _run(
monkeypatch, tmp_path, "run1", "--output", "report.json", "--attach-to-registry", FILE_TEXT
)
- _ok(result)
+ assert result.exit_code == 1, (result.output, repr(result.exception))
assert "could not attach to registry: ValueError: registry entry not found:" in out
_assert_shown_literally(out)
diff --git a/tests/test_diagnose_unlearning_attach_to_registry.py b/tests/test_diagnose_unlearning_attach_to_registry.py
new file mode 100644
index 00000000..7d64d9af
--- /dev/null
+++ b/tests/test_diagnose_unlearning_attach_to_registry.py
@@ -0,0 +1,398 @@
+"""``--attach-to-registry`` on the two report commands attaches, or fails loudly.
+
+``soup diagnose`` and ``soup eval unlearning`` write a JSON report and can link
+it to a Model Registry entry. Both called the shared helper
+``soup_cli.registry.attach.attach_artifact`` with arguments it does not take
+(three positionals in one command, an ``artifact_path=`` keyword in the other),
+printed the resulting ``TypeError`` as a warning and exited 0: the report was
+never attached, and the shell was told the command had succeeded.
+
+A requested attach is part of the command's success, as it already is for
+``soup bom emit``, ``soup attest emit`` and ``soup eval custom``:
+
+* the report is stored on the entry;
+* an attach that fails exits 1 and names the problem, with the report on disk;
+* ``--attach-to-registry`` without ``--output`` is refused before the run.
+
+Every test drives the real command line against a real registry store in a
+throwaway SQLite file (``SOUP_REGISTRY_DB_PATH``) and asserts on the rows the
+store holds, with the real ``attach_artifact`` in between: a stand-in with a
+looser signature is what let the wrong call through.
+"""
+
+from __future__ import annotations
+
+import hashlib
+import json
+import os
+from pathlib import Path
+
+import pytest
+from typer.testing import CliRunner
+
+import soup_cli.utils.diagnose.live as live_mod
+import soup_cli.utils.unlearning_eval as unlearning_eval
+from soup_cli.cli import app
+from soup_cli.registry.store import RegistryStore
+from soup_cli.utils.diagnose.report import FAILURE_MODES
+from soup_cli.utils.diagnose.runner import build_report, neutral_score
+from soup_cli.utils.exit_codes import EXIT_GATE_FAILED, EXIT_USAGE_ERROR
+from tests.conftest import strip_ansi
+
+runner = CliRunner()
+
+DB_NAME = "registry.db"
+
+
+def _plain(text: str) -> str:
+ """ANSI-stripped, whitespace-collapsed CLI output, safe to substring-match.
+
+ Rich colours flag names, quoted strings and numbers on a colour terminal
+ and wraps at the terminal width, so a raw substring check is flaky.
+ """
+ return " ".join(strip_ansi(text).split())
+
+
+def _ok(result) -> None:
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+
+
+def _exits(result, code: int) -> None:
+ assert result.exit_code == code, (result.output, repr(result.exception))
+
+
+def workdir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
+ """An empty cwd whose registry is ``./registry.db`` (never ``~/.soup``)."""
+ monkeypatch.setenv("SOUP_REGISTRY_DB_PATH", str(tmp_path / DB_NAME))
+ monkeypatch.chdir(tmp_path)
+ return tmp_path
+
+
+def _push(workdir: Path, name: str = "demo", tag: str = "v1") -> str:
+ with RegistryStore(db_path=workdir / DB_NAME) as store:
+ return store.push(
+ name=name,
+ tag=tag,
+ base_model="tiny-base",
+ task="sft",
+ run_id="run-1",
+ config={"base": "tiny-base"},
+ )
+
+
+def _artifacts(workdir: Path, entry_id: str) -> list[dict]:
+ with RegistryStore(db_path=workdir / DB_NAME) as store:
+ return store.get_artifacts(entry_id)
+
+
+def _assert_stored(workdir: Path, entry_id: str, kind: str, written: Path) -> None:
+ """The entry holds exactly one artifact: ``written``, as ``kind``."""
+ rows = _artifacts(workdir, entry_id)
+ assert [row["kind"] for row in rows] == [kind], rows
+ assert os.path.samefile(rows[0]["path"], written), rows
+ assert rows[0]["sha256"] == hashlib.sha256(written.read_bytes()).hexdigest()
+ assert rows[0]["size_bytes"] == written.stat().st_size
+
+
+def _major_evidence(workdir: Path) -> str:
+ (workdir / "ev.json").write_text(
+ json.dumps({"scores": {"forgetting": {"score": 0.1, "evidence": "regressed"}}}),
+ encoding="utf-8",
+ )
+ return "ev.json"
+
+
+# ---------------------------------------------------------------------------
+# soup diagnose
+# ---------------------------------------------------------------------------
+
+
+class TestDiagnoseAttachesTheReport:
+ @pytest.mark.parametrize(
+ "output",
+ ["report.json", "reports/nested/diag.json", "ABSOLUTE"],
+ ids=["relative", "nested", "absolute"],
+ )
+ def test_the_report_is_stored_on_the_entry(self, workdir, output):
+ entry_id = _push(workdir)
+ target = workdir / "abs.json" if output == "ABSOLUTE" else workdir / output
+ output_arg = str(target) if output == "ABSOLUTE" else output
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--output", output_arg, "--attach-to-registry", entry_id],
+ )
+
+ _ok(result)
+ _assert_stored(workdir, entry_id, "diagnose_report", target)
+ out = _plain(result.output)
+ assert f"Attached diagnose_report to registry entry {entry_id}" in out
+ assert "could not attach" not in out
+
+ @pytest.mark.parametrize("spelling", ["full-id", "id-prefix", "registry-url", "name-tag"])
+ def test_every_spelling_of_the_entry_reference_attaches(self, workdir, spelling):
+ entry_id = _push(workdir, name="demo", tag="v1")
+ reference = {
+ "full-id": entry_id,
+ "id-prefix": entry_id[:-4],
+ "registry-url": f"registry://{entry_id}",
+ "name-tag": "demo:v1",
+ }[spelling]
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--output", "report.json", "--attach-to-registry", reference],
+ )
+
+ _ok(result)
+ _assert_stored(workdir, entry_id, "diagnose_report", workdir / "report.json")
+
+ def test_a_live_report_is_attached_too(self, workdir, monkeypatch):
+ entry_id = _push(workdir)
+
+ def _live(**kwargs):
+ return build_report(
+ run_id=kwargs["run_id"],
+ base=kwargs["base"],
+ adapter="",
+ scores={mode: neutral_score(mode, "stub") for mode in FAILURE_MODES},
+ soup_version="0",
+ )
+
+ monkeypatch.setattr(live_mod, "run_live_diagnose", _live)
+ result = runner.invoke(
+ app,
+ [
+ "diagnose", "run-1", "--base-model", "org/m",
+ "--output", "live.json", "--attach-to-registry", entry_id,
+ ],
+ )
+
+ _ok(result)
+ _assert_stored(workdir, entry_id, "diagnose_report", workdir / "live.json")
+
+ def test_a_major_report_is_attached_and_still_exits_two(self, workdir):
+ """The verdict exit code is unchanged, and a MAJOR report is still linked."""
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app,
+ [
+ "diagnose", "run-1", "--evidence", _major_evidence(workdir),
+ "--output", "report.json", "--attach-to-registry", entry_id,
+ ],
+ )
+
+ _exits(result, EXIT_GATE_FAILED)
+ _assert_stored(workdir, entry_id, "diagnose_report", workdir / "report.json")
+
+
+class TestDiagnoseAttachFailureIsNotSuccess:
+ def test_an_unknown_entry_exits_one_and_names_it(self, workdir):
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app,
+ [
+ "diagnose", "run-1", "--output", "report.json",
+ "--attach-to-registry", "no-such-entry",
+ ],
+ )
+
+ _exits(result, 1)
+ out = _plain(result.output)
+ assert (
+ "Error: could not attach to registry: ValueError: "
+ "registry entry not found: no-such-entry" in out
+ ), out
+ assert "Attached" not in out
+ assert _artifacts(workdir, entry_id) == []
+ # The report itself was written before the attach was tried.
+ written = json.loads((workdir / "report.json").read_text(encoding="utf-8"))
+ assert written["run_id"] == "run-1"
+
+ def test_an_ambiguous_prefix_exits_one_and_attaches_to_neither(self, workdir):
+ first = _push(workdir, name="first")
+ second = _push(workdir, name="second")
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--output", "report.json", "--attach-to-registry", "reg_"],
+ )
+
+ _exits(result, 1)
+ out = _plain(result.output)
+ assert "Error: could not attach to registry: AmbiguousRefError:" in out, out
+ assert "matches 2 entries" in out, out
+ assert _artifacts(workdir, first) == []
+ assert _artifacts(workdir, second) == []
+
+ def test_an_empty_entry_id_exits_one(self, workdir):
+ """``--attach-to-registry "$ID"`` with ``ID`` unset must not pass silently."""
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--output", "report.json", "--attach-to-registry", ""],
+ )
+
+ _exits(result, 1)
+ out = _plain(result.output)
+ assert "Error: could not attach to registry: ValueError: registry entry not found:" in out
+ assert _artifacts(workdir, entry_id) == []
+
+ def test_an_unreadable_registry_exits_one(self, tmp_path, monkeypatch):
+ """A failure that is not a lookup miss is reported the same way."""
+ (tmp_path / "not-a-database").mkdir()
+ monkeypatch.setenv("SOUP_REGISTRY_DB_PATH", str(tmp_path / "not-a-database"))
+ monkeypatch.chdir(tmp_path)
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--output", "report.json", "--attach-to-registry", "any"],
+ )
+
+ _exits(result, 1)
+ out = _plain(result.output)
+ assert "Error: could not attach to registry: OperationalError:" in out, out
+ assert (tmp_path / "report.json").is_file()
+
+ def test_a_failed_attach_outranks_the_verdict(self, workdir):
+ """Like a failed ``--output`` write: exit 1, not the MAJOR exit 2."""
+ _push(workdir)
+
+ result = runner.invoke(
+ app,
+ [
+ "diagnose", "run-1", "--evidence", _major_evidence(workdir),
+ "--output", "report.json", "--attach-to-registry", "no-such-entry",
+ ],
+ )
+
+ _exits(result, 1)
+ assert "could not attach to registry" in _plain(result.output)
+
+
+class TestDiagnoseAttachNeedsOutput:
+ @pytest.mark.parametrize("output_args", [[], ["--output", ""]], ids=["absent", "empty"])
+ def test_it_is_refused_before_the_report_is_built(self, workdir, output_args):
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app, ["diagnose", "run-1", *output_args, "--attach-to-registry", entry_id]
+ )
+
+ _exits(result, EXIT_USAGE_ERROR)
+ out = _plain(result.output)
+ assert "Error: --attach-to-registry needs --output (nothing written to attach)." in out
+ assert "soup diagnose:" not in out, out
+ assert _artifacts(workdir, entry_id) == []
+
+ def test_it_is_refused_before_a_live_run_loads_the_model(self, workdir, monkeypatch):
+ entry_id = _push(workdir)
+ monkeypatch.setattr(
+ live_mod,
+ "run_live_diagnose",
+ lambda **kwargs: pytest.fail("the model must not load when nothing can be attached"),
+ )
+
+ result = runner.invoke(
+ app,
+ ["diagnose", "run-1", "--base-model", "org/m", "--attach-to-registry", entry_id],
+ )
+
+ _exits(result, EXIT_USAGE_ERROR)
+ assert "--attach-to-registry needs --output" in _plain(result.output)
+
+
+class TestDiagnoseWithoutTheFlag:
+ @pytest.mark.parametrize(
+ "output_args", [[], ["--output", "report.json"]], ids=["bare", "output"]
+ )
+ def test_the_registry_is_never_opened(self, workdir, output_args):
+ result = runner.invoke(app, ["diagnose", "run-1", *output_args])
+
+ _ok(result)
+ out = _plain(result.output)
+ assert "registry" not in out.lower(), out
+ assert not (workdir / DB_NAME).exists()
+ if output_args:
+ assert "Wrote report.json" in out
+ assert (workdir / "report.json").is_file()
+
+ def test_an_existing_entry_gains_no_artifact(self, workdir):
+ entry_id = _push(workdir)
+
+ result = runner.invoke(app, ["diagnose", "run-1", "--output", "report.json"])
+
+ _ok(result)
+ assert _artifacts(workdir, entry_id) == []
+
+
+# ---------------------------------------------------------------------------
+# soup eval unlearning: the same defect, in its own copy of the call
+# ---------------------------------------------------------------------------
+
+
+class TestEvalUnlearningAttach:
+ def test_the_report_is_stored_on_the_entry(self, workdir):
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app,
+ [
+ "eval", "unlearning", "run-1",
+ "--output", "unlearn.json", "--attach-to-registry", entry_id,
+ ],
+ )
+
+ _ok(result)
+ _assert_stored(workdir, entry_id, "eval_results", workdir / "unlearn.json")
+ out = _plain(result.output)
+ assert f"Attached eval_results -> registry {entry_id}" in out
+ assert "Registry attach failed" not in out
+
+ def test_an_unknown_entry_exits_one_and_names_it(self, workdir):
+ entry_id = _push(workdir)
+
+ result = runner.invoke(
+ app,
+ [
+ "eval", "unlearning", "run-1",
+ "--output", "unlearn.json", "--attach-to-registry", "no-such-entry",
+ ],
+ )
+
+ _exits(result, 1)
+ out = _plain(result.output)
+ assert "Registry attach failed: registry entry not found: no-such-entry" in out, out
+ assert "Attached" not in out
+ assert _artifacts(workdir, entry_id) == []
+ assert (workdir / "unlearn.json").is_file()
+
+ def test_without_output_it_is_refused_before_the_eval_runs(self, workdir, monkeypatch):
+ entry_id = _push(workdir)
+ monkeypatch.setattr(
+ unlearning_eval,
+ "run_unlearn_eval",
+ lambda **kwargs: pytest.fail("the eval must not run when nothing can be attached"),
+ )
+
+ result = runner.invoke(
+ app, ["eval", "unlearning", "run-1", "--attach-to-registry", entry_id]
+ )
+
+ _exits(result, 2)
+ out = _plain(result.output)
+ assert "--attach-to-registry requires --output (nothing written to attach)." in out, out
+ assert _artifacts(workdir, entry_id) == []
+
+ def test_without_the_flag_the_registry_is_never_opened(self, workdir):
+ result = runner.invoke(app, ["eval", "unlearning", "run-1", "--output", "unlearn.json"])
+
+ _ok(result)
+ out = _plain(result.output)
+ assert "Wrote report -> unlearn.json" in out
+ assert "registry" not in out.lower(), out
+ assert not (workdir / DB_NAME).exists()
diff --git a/tests/test_eval_unlearning_terminal_output.py b/tests/test_eval_unlearning_terminal_output.py
index 8ba41934..d69a84ad 100644
--- a/tests/test_eval_unlearning_terminal_output.py
+++ b/tests/test_eval_unlearning_terminal_output.py
@@ -283,7 +283,12 @@ def test_write_error_shows_the_exception_text_literally(monkeypatch, tmp_path):
def test_attached_line_shows_the_registry_id_literally(monkeypatch, tmp_path):
- monkeypatch.setattr(attach_mod, "attach_artifact", lambda **kwargs: None)
+ # The stand-ins take the helper's own keyword-only signature, so a call the
+ # real attach_artifact would refuse fails here too.
+ def _attached(entry_id, *, path, kind, enforce_cwd=True):
+ return 1
+
+ monkeypatch.setattr(attach_mod, "attach_artifact", _attached)
result, out = _run(
monkeypatch, tmp_path, "run1", "--output", "report.json", "--attach-to-registry", FILE_TEXT
)
@@ -293,14 +298,14 @@ def test_attached_line_shows_the_registry_id_literally(monkeypatch, tmp_path):
def test_attach_failure_shows_the_exception_text_literally(monkeypatch, tmp_path):
- def _missing(**kwargs):
- raise ValueError(f"registry entry not found: {kwargs['entry_id']}")
+ def _missing(entry_id, *, path, kind, enforce_cwd=True):
+ raise ValueError(f"registry entry not found: {entry_id}")
monkeypatch.setattr(attach_mod, "attach_artifact", _missing)
result, out = _run(
monkeypatch, tmp_path, "run1", "--output", "report.json", "--attach-to-registry", FILE_TEXT
)
- _exit(result, 0)
+ _exit(result, 1)
assert "Registry attach failed: registry entry not found:" in out
_assert_shown_literally(out)
diff --git a/tests/test_v0560.py b/tests/test_v0560.py
index 934e4a70..c178e791 100644
--- a/tests/test_v0560.py
+++ b/tests/test_v0560.py
@@ -634,14 +634,16 @@ class TestCli:
)
assert result.exit_code == 1
- def test_diagnose_attach_to_registry_without_output_warns(
+ def test_diagnose_attach_to_registry_without_output_is_refused(
self, tmp_path: Path
) -> None:
+ # A requested attach that cannot happen is an input error, not a
+ # warning with exit 0.
os.chdir(tmp_path)
result = runner.invoke(
app, ["diagnose", "myrun", "--attach-to-registry", "abc"]
)
- assert result.exit_code == 0
+ assert result.exit_code == 3, (result.output, repr(result.exception))
assert "needs --output" in _strip_ansi(result.output)
def test_diagnose_run_id_oversize(self, tmp_path: Path) -> None: