fix(6252): a prompt that names nothing gets no notes menu
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / integration (push) Successful in 1m3s
CI & Build / Python tests (push) Failing after 1m26s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / integration (push) Successful in 1m3s
CI & Build / Python tests (push) Failing after 1m26s
CI & Build / Build & push image (push) Skipped
"keep going", "yes please do", "is it deployed?": with no word of its own the
auto-inject query was the previous reply's tail alone, and the menu handed
back the records that reply was built from. In a sample of 59 logged calls,
28 came from short prompts; those with a subject of their own ("continue into
DRY 14", "fix the Windows gate") led with the record meant, while the ones
without were finished tasks already in context, with an open on 2 of about 15.
_has_subject checks the operator's words against a list of words that name
nothing; without one, the ranked menu is skipped and records named by number
are still shown. The prompt rule arm is unchanged and still searches with the
tail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from grimoire.services.plugin_context import (
|
||||
_AUTOINJECT_CONTEXT_MAX,
|
||||
_AUTOINJECT_CONTEXT_PROMPT_MAX,
|
||||
_autoinject_query,
|
||||
_has_subject,
|
||||
_menu_name,
|
||||
_menu_passage,
|
||||
)
|
||||
@@ -56,6 +57,50 @@ def test_context_is_cut_from_the_end_of_the_reply():
|
||||
assert tail.endswith("TAIL") and "HEAD" not in tail
|
||||
|
||||
|
||||
# --- a prompt that names nothing ----------------------------------------------
|
||||
|
||||
@pytest.mark.parametrize("prompt", [
|
||||
"keep going", "yes please do", "1. yes 2. yes 3. yes", "start step 6",
|
||||
"is it deployed?", "awesome, what's next?", "go ahead",
|
||||
"is there anything else open in this project?",
|
||||
"please commit and let me know when it passes CI",
|
||||
])
|
||||
def test_a_turn_of_the_conversation_names_no_subject(prompt):
|
||||
assert not _has_subject(prompt)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prompt", [
|
||||
"now fix the filter", "keep steward, it's our own app",
|
||||
"continue into DRY 14", "I've added a maintenance plan",
|
||||
"fix the Windows gate first, then step 2",
|
||||
])
|
||||
def test_one_word_of_its_own_is_a_subject(prompt):
|
||||
assert _has_subject(prompt)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_prompt_with_no_subject_gets_no_menu_and_no_search():
|
||||
"""Its query would be the previous reply's tail alone, and the menu would
|
||||
hand back what that reply was built from."""
|
||||
from grimoire.services import plugin_context as pc
|
||||
|
||||
search = AsyncMock(return_value=[(0.9, fake_note(id=11, title="the reply's own record", user_id=1))])
|
||||
retrieval = MagicMock()
|
||||
with patch.object(pc, "get_autoinject_config",
|
||||
AsyncMock(return_value={"enabled": True, "threshold": 0.55, "top_k": 3})), \
|
||||
patch.object(pc, "semantic_search_notes", search), \
|
||||
patch.object(pc, "record_retrieval", retrieval), \
|
||||
patch.object(pc, "record_surfaced", MagicMock()):
|
||||
out = await pc.build_autoinject_hint(
|
||||
1, "yes please do", project_id=2,
|
||||
context="I'll move the library filters into the side column.",
|
||||
)
|
||||
|
||||
assert out["context"] == "" and out["note_ids"] == []
|
||||
search.assert_not_called()
|
||||
retrieval.assert_not_called()
|
||||
|
||||
|
||||
# --- what the hook extracts --------------------------------------------------
|
||||
|
||||
def _rec(role: str, blocks: list[dict], sidechain: bool = False) -> str:
|
||||
|
||||
@@ -139,7 +139,7 @@ async def test_a_named_record_comes_first_and_is_not_repeated_as_a_match():
|
||||
other = fake_note(id=11, title="something that matched the words", user_id=1)
|
||||
hits = [(0.80, named), (0.78, other)]
|
||||
out, surfaced, retrieval = await _hint(
|
||||
"go ahead with 4448", hits=hits, records={4448: named},
|
||||
"go ahead with the filing fix in 4448", hits=hits, records={4448: named},
|
||||
)
|
||||
|
||||
ctx = out["context"]
|
||||
@@ -156,6 +156,23 @@ async def test_a_named_record_comes_first_and_is_not_repeated_as_a_match():
|
||||
assert row["suppressed"] == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_prompt_with_no_subject_still_shows_what_it_names():
|
||||
""""go ahead with 4448" names a record and nothing else: the record is
|
||||
looked up and shown, and no ranked menu is searched for."""
|
||||
rec = _task(4448, "the named one")
|
||||
other = fake_note(id=11, title="what the reply was about", user_id=1)
|
||||
out, surfaced, retrieval = await _hint(
|
||||
"go ahead with 4448", hits=[(0.8, other)], records={4448: rec},
|
||||
context="I'll start on the importer next.",
|
||||
)
|
||||
|
||||
assert out["note_ids"] == [4448]
|
||||
assert "Possibly relevant" not in out["context"]
|
||||
assert "auto_inject" not in surfaced
|
||||
retrieval.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_named_record_already_shown_is_a_pointer():
|
||||
rec = _task(4448, "the named one", "a long body that is already in context")
|
||||
|
||||
@@ -127,7 +127,7 @@ async def test_injected_menu_attributes_another_users_note():
|
||||
patch.object(plugin_context, "record_retrieval", MagicMock()), \
|
||||
patch.object(plugin_context, "owner_names_for",
|
||||
AsyncMock(return_value={9: "alex"})):
|
||||
out = await plugin_context.build_autoinject_hint(7, "anything")
|
||||
out = await plugin_context.build_autoinject_hint(7, "debounce helper")
|
||||
|
||||
lines = out["context"].splitlines()
|
||||
theirs_line = next(ln for ln in lines if "#2" in ln)
|
||||
@@ -160,7 +160,7 @@ async def test_injected_menu_labels_the_record_kind():
|
||||
AsyncMock(return_value={"enabled": True, "threshold": 0.5,
|
||||
"top_k": 5})), \
|
||||
patch.object(plugin_context, "record_retrieval", MagicMock()):
|
||||
out = await plugin_context.build_autoinject_hint(7, "anything")
|
||||
out = await plugin_context.build_autoinject_hint(7, "debounce helper")
|
||||
|
||||
lines = out["context"].splitlines()
|
||||
by_id = {n: next(ln for ln in lines if f"#{n} " in ln) for n in (1, 2, 3, 4, 5)}
|
||||
|
||||
Reference in New Issue
Block a user