feat(8565,8566,8567,8568): promoting a family idea lifts it onto a family record with no project
CI & Build / TypeScript typecheck (push) Successful in 14s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Python tests (push) Failing after 1m55s
CI & Build / integration (push) Failing after 2m33s
CI & Build / Build & push image (push) Skipped

Canon now belongs to the family. Promotion moves an idea off the project
record it was written on and onto a note with no project (owned by the same
person, arose_from_id naming the project record), carrying its state,
platforms, references, ledger and decision log. The project record stays its
own; a snippet becomes a reference implementation. Revising the idea or
folding a conflict into it now edits the family record, never a project's.
The project record's id still names the idea in every family call
(family.idea_key).

- A project that owns a reference snippet and has not answered the idea is
  answered adopted by the system, naming the snippet, unless its shapes
  already speak for it (on promotion and on set_family_references).
- The family record takes the project record's shares and its project's
  shares, so whoever could read the idea still can.
- An owed task still finds its Systems through the project record the idea
  was lifted from.
- Migration 0141 lifts every idea promoted before this, the same way.
- The Family page shows where each idea lives and its reference
  implementations; the skill, tool descriptions, model docstring and
  features doc describe the family record. Plugin minted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 14:44:56 -05:00
co-authored by Claude Opus 5.5
parent 0d9fe5d3c5
commit 6c0481ef9c
13 changed files with 788 additions and 19 deletions
+120 -2
View File
@@ -112,6 +112,9 @@ async def _promote(f, **overrides):
async def _ledger(note_id: int) -> dict[int, str]:
# Promotion lifts the idea onto a family record; the project's record id
# still names it.
note_id = await family_svc.idea_key(note_id)
async with async_session() as s:
rows = (await s.execute(
select(FamilyAdoption.project_id, FamilyAdoption.status)
@@ -121,6 +124,7 @@ async def _ledger(note_id: int) -> dict[int, str]:
async def _idea(note_id: int) -> FamilyIdea:
note_id = await family_svc.idea_key(note_id)
async with async_session() as s:
return await s.get(FamilyIdea, note_id)
@@ -167,13 +171,127 @@ async def test_someone_who_cannot_write_the_note_cannot_promote_it(family):
)
# --- the family record ----------------------------------------------------------------
async def test_promotion_lifts_the_idea_onto_a_family_record_and_leaves_the_projects_record_alone(family):
async with async_session() as s:
s.add(FamilyIdea(note_id=family["note"], status="candidate"))
await s.flush()
s.add(FamilyDecision(idea_id=family["note"], action="propose", reason="repeated",
decided_via="system", user_id=family["owner"]))
await s.commit()
out = await _promote(family)
lifted = out["idea"]["note_id"]
assert lifted != family["note"]
assert out["lifted"] == {"family_record": lifted, "from": family["note"],
"note": out["lifted"]["note"]}
async with async_session() as s:
record = await s.get(Note, lifted)
origin = await s.get(Note, family["note"])
assert await s.get(FamilyIdea, family["note"]) is None
moved = (await s.execute(select(FamilyDecision.action).where(
FamilyDecision.idea_id == lifted).order_by(FamilyDecision.id))).scalars().all()
# The family record has no project, belongs to the same person, and names
# where it came from; the project's record is unchanged.
assert record.project_id is None and record.user_id == family["owner"]
assert record.arose_from_id == family["note"] and record.title == origin.title
assert f"#{family['note']}" in record.body
assert origin.project_id == family["a"]
assert origin.body == "One keystore, two channels, in-place update."
# Its whole history moved with it, the proposal included.
assert moved == ["propose", "promote"]
assert out["decision"]["evidence"]["lifted_from"] == family["note"]
# The project's record still names the idea everywhere an id is taken.
assert await family_svc.idea_key(family["note"]) == lifted
assert (await family_svc.get_idea(family["owner"], family["note"]))["note_id"] == lifted
with pytest.raises(ValueError, match="already canon"):
await _promote(family)
async def test_a_snippet_stays_in_its_project_as_a_reference_and_its_project_is_answered_adopted(family):
async with async_session() as s:
snippet = Note(user_id=family["owner"], project_id=family["a"], note_type="snippet",
title="ReleaseSigner", body="fun sign(apk: File) = ...",
data={"language": "kotlin"})
s.add(snippet)
await s.commit()
await s.refresh(snippet)
out = await family_svc.promote(
family["owner"], snippet.id, applies_when="any Android app that ships its own APK",
platforms=["android-app"], criteria=CRITERIA, evidence=["CI green"], reason="proven",
)
lifted = out["idea"]["note_id"]
async with async_session() as s:
record = await s.get(Note, lifted)
# The code stays in the project's snippet; the family record carries the idea.
assert record.note_type == "note"
refs = await family_svc._reference_ids(lifted)
assert refs == {snippet.id}
# The project that wrote the reference has built the idea; the other
# member project still owes an answer.
assert await _ledger(lifted) == {family["a"]: "adopted", family["b"]: "unassessed"}
assert [a["project_id"] for a in out["answered"]] == [family["a"]]
async with async_session() as s:
answer = (await s.execute(select(FamilyDecision).where(
FamilyDecision.idea_id == lifted, FamilyDecision.project_id == family["a"]))).scalars().one()
assert answer.decided_via == "system" and answer.evidence["source"] == "reference"
async def test_an_answer_somebody_gave_is_not_overwritten_by_the_reference(family):
from grimoire.services import family_adoption
async with async_session() as s:
snippet = Note(user_id=family["owner"], project_id=family["b"], note_type="snippet",
title="Signer", body="...", data={"language": "kotlin"})
s.add(snippet)
await s.commit()
await s.refresh(snippet)
out = await _promote(family)
lifted = out["idea"]["note_id"]
async with async_session() as s:
row = (await s.execute(select(FamilyAdoption).where(
FamilyAdoption.idea_id == lifted, FamilyAdoption.project_id == family["b"]))).scalars().one()
row.status, row.reason, row.canon_version, row.decided_via = "exempt", "store-installed", 1, "agent"
await s.commit()
await family_adoption.set_references(family["owner"], lifted, [snippet.id])
assert (await _ledger(lifted))[family["b"]] == "exempt"
async def test_whoever_could_read_the_idea_through_its_project_can_read_the_family_record(family):
from grimoire.models.share import ProjectShare
from grimoire.services import access
async with async_session() as s:
s.add(ProjectShare(project_id=family["a"], shared_with_user_id=family["outsider"],
permission="viewer", invited_by=family["owner"]))
await s.commit()
out = await _promote(family)
lifted = out["idea"]["note_id"]
assert await access.get_note_permission(family["outsider"], lifted) == "viewer"
async def test_a_repeat_of_a_lifted_record_says_it_is_canon_and_opens_nothing_new(family):
out = await _promote(family)
repeat = await _note_in(family["b"], family["owner"], "One keystore, two channels.")
async with async_session() as s:
original = await s.get(Note, family["note"])
with patch("grimoire.services.embeddings.semantic_search_notes",
AsyncMock(return_value=[(0.86, original)])):
hint = await family_svc.repeat_trigger(family["owner"], repeat)
assert hint and "already" in hint and "family canon" in hint
async with async_session() as s:
ideas = (await s.execute(select(FamilyIdea.note_id))).scalars().all()
assert family["note"] not in ideas and out["idea"]["note_id"] in ideas
# --- undo and retirement ------------------------------------------------------------
async def test_undoing_a_promotion_restores_the_prior_state_and_keeps_judged_rows(family):
out = await _promote(family)
async with async_session() as s:
row = (await s.execute(select(FamilyAdoption).where(
FamilyAdoption.idea_id == family["note"],
FamilyAdoption.idea_id == out["idea"]["note_id"],
FamilyAdoption.project_id == family["a"]))).scalars().one()
row.status, row.canon_version, row.decided_via = "adopted", 1, "agent"
await s.commit()
@@ -218,7 +336,7 @@ async def test_an_undo_names_what_it_reversed_as_its_precedent(family):
assert undo["decision"]["precedent_ids"] == [out["decision"]["id"]]
async with async_session() as s:
actions = (await s.execute(select(FamilyDecision.action).where(
FamilyDecision.idea_id == family["note"]).order_by(FamilyDecision.id))).scalars().all()
FamilyDecision.idea_id == out["idea"]["note_id"]).order_by(FamilyDecision.id))).scalars().all()
assert actions == ["promote", "undo"]