fix(8321): a .grimoire marker that disagrees with the repo's binding is named at session start
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Failing after 1m58s
CI & Build / integration (push) Successful in 1m58s
CI & Build / Build & push image (push) Skipped

A marker copied along with a repo outlived the project it was written for:
the Throne folder's marker still named project 38 after the split, so every
hook held the session to Cartographer and writes to Throne stopped on the
project fence, with nothing saying why.

The SessionStart hook now sends the remote beside a marker's project_id. The
marker still decides the project; /context also resolves the remote's binding,
and when it names a different project the context says which project each
names and how to fix the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 13:22:50 -05:00
co-authored by Claude Opus 5.5
parent 9de0e80531
commit f4d6486255
6 changed files with 113 additions and 3 deletions
+53
View File
@@ -136,6 +136,59 @@ async def test_build_session_context_includes_project_when_scoped():
assert "Reflex:" not in out["context"]
@pytest.mark.parametrize("repo_project_id, says", [(43, True), (38, False), (0, False)])
async def test_a_marker_that_disagrees_with_the_repo_binding_is_named(repo_project_id, says):
"""A `.grimoire` marker names project 38 while the repo's remote is bound
to 43: the marker wins, and the session is told which project each names
and how to fix the file. Agreeing, or no binding to compare, says nothing."""
projects = {38: MagicMock(id=38, title="Cartographer", goal="", design_system_id=None),
43: MagicMock(id=43, title="Throne", goal="", design_system_id=None)}
async def get_project(_uid, pid):
return projects.get(pid)
with patch("grimoire.services.plugin_context.projects_svc.get_project", get_project), \
patch("grimoire.services.plugin_context.notes_svc.list_notes",
AsyncMock(return_value=([], 0))):
from grimoire.services.plugin_context import build_session_context
out = await build_session_context(user_id=7, project_id=38, repo_project_id=repo_project_id)
assert out["project"] == {"id": 38, "title": "Cartographer"}
ctx = out["context"]
assert ("overrides its repo binding" in ctx) is says
if says:
assert "names Cartographer (id 38)" in ctx and "bound to Throne (id 43)" in ctx
assert "delete the file" in ctx
@pytest.mark.parametrize("query, resolves, passed", [
({"project_id": "38", "repo": "https://git.example.com/o/r.git"}, 43, 43),
({"project_id": "38"}, 43, 0),
({"repo": "https://git.example.com/o/r.git"}, 43, 0),
])
async def test_the_route_looks_up_the_remote_beside_a_marker(query, resolves, passed):
"""With a marker's project_id AND the remote, the route resolves the
remote's binding too and hands it on; the project stays the marker's.
With only one key there is nothing to compare."""
import inspect
from types import SimpleNamespace
from quart import Quart, g
from grimoire.routes import plugin as routes
build = AsyncMock(return_value={"context": "", "project": None})
app = Quart(__name__)
async with app.test_request_context("/api/plugin/context", query_string=query):
g.user = SimpleNamespace(id=7)
with patch.object(routes.repo_bindings_svc, "resolve_project", AsyncMock(return_value=resolves)), \
patch.object(routes.plugin_ctx_svc, "build_session_context", build):
await inspect.unwrap(routes.session_context)()
args, kwargs = build.await_args
assert args[1] == (38 if "project_id" in query else resolves)
assert kwargs["repo_project_id"] == passed
def test_a_short_goal_is_shown_whole():
from grimoire.services.plugin_context import _goal_line
assert _goal_line("ship it", 2) == "Goal: ship it"
+19
View File
@@ -52,3 +52,22 @@ def test_the_fallback_is_a_first_step_not_an_option(tmp_path):
def test_a_marker_names_the_exact_call(tmp_path):
out = run_hook(tmp_path, DEAD, marker_project=31)
assert "Start by calling `enter_project(31)`" in out
def test_a_marker_sends_the_remote_beside_it_so_a_disagreement_can_be_said(tmp_path):
"""The marker decides the project, but a marker copied along with a repo
can outlive the project it was written for. The remote goes too, so the
server can compare it with the repo's binding; a folder outside any repo
sends the marker alone."""
from tests.helpers import http_sink
need_tools("bash", "curl", "awk", "git")
subprocess.run(["git", "init", "-q", str(tmp_path)], check=True)
subprocess.run(["git", "-C", str(tmp_path), "remote", "add", "origin",
"https://git.example.com/owner/split-off.git"], check=True)
with http_sink(b'{"context":"","project":null}') as (port, seen):
url = f"http://127.0.0.1:{port}"
run_hook(tmp_path, url, marker_project=38)
ask = seen[0]
assert ask["project_id"] == ["38"]
assert ask["repo"] == ["https://git.example.com/owner/split-off.git"]