Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
fix: inspect search() for he talk scoped-chat flags
Frankie-Xu6d855f2305e9
diff --git a/hyperextract/cli/cli.py b/hyperextract/cli/cli.pyindex 4eef923..c21cbb8 100644--- a/hyperextract/cli/cli.py+++ b/hyperextract/cli/cli.py@@ -1253,15 +1253,27 @@ def talk(if scope_kwargs:import inspect+ # Inspect search() for ledger support — same rule as `he search`.+ # Do not inspect chat() alone: BaseAutoType.chat always accepts+ # source_ids/tags, so AutoList/AutoModel would silently ignore --source.+ search_params = inspect.signature(type(ka).search).parameterschat_params = inspect.signature(type(ka).chat).parametersfor flag, key in (("--source", "source_ids"), ("--tag", "tags")):- if key in scope_kwargs and key not in chat_params:+ if key not in scope_kwargs:+ continue+ if key not in search_params:console.print(f"[red]Error:[/red] Scoped chat ({flag}) is not "f"supported by {type(ka).__name__} knowledge ""abstracts (no source ledger).")raise typer.Exit(1)+ if key not in chat_params:+ console.print(+ f"[red]Error:[/red] Scoped chat ({flag}) is not "+ f"supported by {type(ka).__name__} knowledge abstracts."+ )+ raise typer.Exit(1)if interactive:chat_loop(ka, ka_path, top_k=top_k, **scope_kwargs)diff --git a/tests/cli/test_talk.py b/tests/cli/test_talk.pyindex 8b55257..4f77123 100644--- a/tests/cli/test_talk.py+++ b/tests/cli/test_talk.py@@ -1,13 +1,16 @@"""Tests for the interactive `he talk` chat loop and scoped chat flags."""+import inspectimport jsonfrom pathlib import Pathfrom unittest.mock import patch+from pydantic import BaseModelfrom typer.testing import CliRunnerimport hyperextract.cli.cli as climodfrom hyperextract.cli.cli import app+from hyperextract.types import AutoListrunner = CliRunner()@@ -54,6 +57,9 @@ def test_talk_forwards_source_and_tag(tmp_path):def load(self, path):pass+ def search(self, query, top_k=3, *, source_ids=None, tags=None):+ return []+def chat(self, query, top_k=3, *, source_ids=None, tags=None):recorded["query"] = queryrecorded["source_ids"] = source_ids@@ -85,18 +91,61 @@ def test_talk_forwards_source_and_tag(tmp_path):assert recorded["tags"] == ["t1"]-def test_talk_scope_rejected_without_ledger(tmp_path):- class _ListChatKA:+class _ListItem(BaseModel):+ name: str+++def test_talk_scope_rejected_on_autolist(tmp_path, llm_client, embedder):+ """Production AutoList inherits base.chat(source_ids=...), but search() has no ledger.++ A stub whose chat() omits those kwargs hid the bug: inspecting chat() then+ lets `he talk --source` through and silently ignores the filter.+ """+ ka = AutoList(+ item_schema=_ListItem,+ llm_client=llm_client,+ embedder=embedder,+ )+ assert "source_ids" in inspect.signature(type(ka).chat).parameters+ assert "source_ids" not in inspect.signature(type(ka).search).parameters++ ka_dir = _ka_dir(tmp_path)+ with (+ patch("hyperextract.cli.cli.validate_config"),+ patch("hyperextract.cli.cli.Template.create", return_value=ka),+ patch.object(ka, "load"),+ ):+ result = runner.invoke(+ app,+ ["talk", str(ka_dir), "-q", "hello", "--source", "s1"],+ )++ assert result.exit_code == 1+ assert "AutoList" in result.output+ assert "source ledger" in result.output+ assert "scoped chat" in result.output.lower() or "Scoped chat" in result.output+++def test_talk_scope_rejected_when_chat_does_not_forward(tmp_path):+ """search() can scope, but chat() does not yet accept the kwargs (Cog_RAG pre-#171)."""++ class _SearchScopedChatPlain:def load(self, path):pass+ def search(self, query, top_k=3, *, source_ids=None, tags=None):+ return []+def chat(self, query, top_k=3):return type("_Resp", (), {"content": "ok", "additional_kwargs": {}})()ka_dir = _ka_dir(tmp_path)with (patch("hyperextract.cli.cli.validate_config"),- patch("hyperextract.cli.cli.Template.create", return_value=_ListChatKA()),+ patch(+ "hyperextract.cli.cli.Template.create",+ return_value=_SearchScopedChatPlain(),+ ),):result = runner.invoke(app,@@ -104,5 +153,4 @@ def test_talk_scope_rejected_without_ledger(tmp_path):)assert result.exit_code == 1- assert "source ledger" in result.output- assert "scoped chat" in result.output.lower() or "Scoped chat" in result.output+ assert "Scoped chat" in result.output or "scoped chat" in result.output.lower()