Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/docs/features/builtin-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Hiding is an output filter; registered subcommands remain reachable via `<cli> a

Rationale: these three flags only have meaning when apcore-cli performs its own filesystem discovery. In embedded mode — where the integrator has pre-built the `registry` and passes it programmatically — the flags are inert (do nothing) and pollute `--help --all-options` output. Omitting them entirely in embedded mode results in cleaner help and an explicit "unknown option" error if a user attempts them.

When Python starts the standalone CLI with `--commands-dir` or `--binding`,
it reports each failed Toolkit registration by module ID and cause. Startup
exits with code 47 before dispatching a command if any registration fails.

**Under `apcli` group:**

| Subcommand | Source | Notes |
Expand Down
18 changes: 10 additions & 8 deletions cli/python/src/apcore_cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ def _apply_toolkit_integration(

Toolkit symbols are imported statically at module top — the package
is a required runtime dep (``pyproject.toml`` pins
``apcore-toolkit>=0.7.0``). Operational failures inside scanner /
loader / writer calls still degrade to a WARNING.
``apcore-toolkit>=0.7.0``). Scan and load errors are logged. Any reported
registration failure aborts CLI startup after the writer has processed the batch.
"""
if commands_dir is None and binding_path is None:
return
Expand Down Expand Up @@ -754,12 +754,14 @@ def _apply_toolkit_integration(
except Exception as e:
logger.warning("DisplayResolver failed: %s", e)

try:
writer = RegistryWriter()
writer.write(scanned, registry, allowed_prefixes=allowed_prefixes)
logger.info("RegistryWriter: registered %d toolkit-sourced module(s)", len(scanned))
except Exception as e:
logger.warning("RegistryWriter failed: %s", e)
results = RegistryWriter().write(scanned, registry, allowed_prefixes=allowed_prefixes)
failures = [result for result in results if not result.verified]
if failures:
details = "\n".join(
f" {result.module_id} — {result.verification_error or 'Registration failed'}" for result in failures
)
raise RuntimeError(f"Toolkit could not register the following modules\n{details}")
logger.info("RegistryWriter: registered %d toolkit-sourced module(s)", len(results))


# ---------------------------------------------------------------------------
Expand Down
34 changes: 34 additions & 0 deletions cli/python/tests/test_toolkit_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,40 @@ def test_binding_only_writes_to_registry(self, tmp_path):
# allowed_prefixes propagated end-to-end.
assert fake_writer.write.call_args.kwargs["allowed_prefixes"] == ["sandbox"]

def test_standalone_rejects_failed_binding_registration(self, tmp_path, monkeypatch, capsys):
from apcore_toolkit import ScannedModule

from apcore_cli.__main__ import main
from apcore_cli.exit_codes import EXIT_CONFIG_NOT_FOUND

binding = tmp_path / "bad.binding.yaml"
scanned = ScannedModule(
module_id="broken.task",
description="Fixture module with no importable target",
input_schema={"type": "object"},
output_schema={"type": "object"},
tags=[],
target="unimportable_apcore_binding_fixture:run",
)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(
"sys.argv",
["apcore-cli", "--extensions-dir", str(tmp_path), "--binding", str(binding), "apcli", "list"],
)
with (
patch("apcore_cli.factory.BindingLoader") as loader,
patch("apcore_cli.factory.DisplayResolver") as resolver,
):
loader.return_value.load.return_value = [scanned]
resolver.return_value.resolve.return_value = [scanned]
with pytest.raises(SystemExit) as exc:
main()

assert exc.value.code == EXIT_CONFIG_NOT_FOUND
captured = capsys.readouterr()
assert "broken.task" in captured.err
assert "unimportable_apcore_binding_fixture" in captured.err


class TestCommandsDirReadmeExampleE2E:
"""README.md's "Zero-import way" (`--commands-dir`) example, exercised
Expand Down
Loading