fix(cli): align ingest CLI with unified ingest dispatcher

This commit is contained in:
Sameer6305
2026-05-31 20:21:23 +05:30
parent 98da904a06
commit b22c93e9ec
2 changed files with 46 additions and 4 deletions
+3 -3
View File
@@ -661,9 +661,9 @@ def ingest(
_dry(cli_ctx, "ingest", json_out=_is_json(cli_ctx, local_json),
source=source, type=ingestor_type, format=fmt)
return
kwargs: Dict[str, Any] = {"source": source, "batch_size": batch_size}
kwargs: Dict[str, Any] = {"batch_size": batch_size}
if ingestor_type:
kwargs["ingestor_type"] = ingestor_type
kwargs["source_type"] = ingestor_type
if fmt:
kwargs["format"] = fmt
if recursive:
@@ -674,7 +674,7 @@ def ingest(
kwargs["output"] = output
try:
from .ingest import ingest as _ingest
result = _ingest(**kwargs)
result = _ingest(source, **kwargs)
except ImportError as exc:
raise click.ClickException(f"Ingest module not available: {exc}") from exc
if _is_json(cli_ctx, local_json):
+43 -1
View File
@@ -272,11 +272,53 @@ class TestIngest:
result = runner.invoke(main, ["ingest", "data.pdf", "--dry-run"])
_ok(result, substr="Dry run")
def test_runtime_path_passes_source_positionally(self, runner, monkeypatch):
captured = {}
def fake_ingest_file(sources, **kwargs):
captured["sources"] = sources
captured["kwargs"] = kwargs
return [{"path": sources}]
monkeypatch.setattr("semantica.ingest.methods.ingest_file", fake_ingest_file)
result = runner.invoke(
main,
["ingest", "README.md", "--type", "file", "--format", "csv", "--json"],
)
_ok(result)
data = _json_output(result)
assert data["files"] == [{"path": "README.md"}]
assert captured["sources"] == "README.md"
assert captured["kwargs"]["method"] == "file"
assert captured["kwargs"]["batch_size"] == 500
assert captured["kwargs"]["format"] == "csv"
def test_runtime_path_passes_source_positionally_with_auto_detection(self, runner, monkeypatch):
captured = {}
def fake_ingest_file(sources, **kwargs):
captured["sources"] = sources
captured["kwargs"] = kwargs
return [{"path": sources}]
monkeypatch.setattr("semantica.ingest.methods.ingest_file", fake_ingest_file)
result = runner.invoke(main, ["ingest", "README.md", "--json"])
_ok(result)
data = _json_output(result)
assert data["files"] == [{"path": "README.md"}]
assert captured["sources"] == "README.md"
assert captured["kwargs"]["method"] == "file"
def test_import_error_is_clean(self, runner, monkeypatch):
monkeypatch.setattr(cli_module, "__import__", _import_side_effect, raising=False)
original_import = __import__
with patch("builtins.__import__", side_effect=lambda n, *a, **k: (
(_ for _ in ()).throw(ImportError(n))
if n.startswith("semantica.ingest") else __import__(n, *a, **k)
if n.startswith("semantica.ingest") else original_import(n, *a, **k)
)):
result = runner.invoke(main, ["ingest", "data.pdf"])
assert result.exit_code != 0