Drafter hardening: reverse lookup by location + the write-path trigger #79

Merged
bvandeusen merged 8 commits from dev into main 2026-07-28 10:12:48 -04:00
Showing only changes of commit fc9c8119a2 - Show all commits
+13 -11
View File
@@ -228,19 +228,21 @@ def test_snippet_fields_falls_back_to_the_body_when_data_is_absent():
def test_data_and_body_round_trip_to_the_same_fields(): def test_data_and_body_round_trip_to_the_same_fields():
"""The two representations must agree — they're written together, and a """The two representations must agree — they're written together, and a
disagreement would make a snippet read one way and query another.""" disagreement would make a snippet read one way and query another."""
fields = dict(name="debounce", when_to_use="rate-limit a callback", name, when, sig, lang = ("debounce", "rate-limit a callback",
signature="debounce(fn, ms)", language="ts") "debounce(fn, ms)", "ts")
locs = [{"repo": "web", "path": "src/util.ts", "symbol": "debounce"}] locs = [{"repo": "web", "path": "src/util.ts", "symbol": "debounce"}]
from_body = s.snippet_fields(_Note( # compose_body takes no `name` — the name lives in the title — so the two
title=s.compose_title(fields["name"], fields["when_to_use"]), # serializers get their own argument lists rather than a shared spread.
body=s.compose_body(code="const x = 1", locations=locs, **fields), title = s.compose_title(name, when)
tags=s.compose_tags(fields["language"]), body = s.compose_body(code="const x = 1", language=lang, signature=sig,
)) when_to_use=when, locations=locs)
tags = s.compose_tags(lang)
from_body = s.snippet_fields(_Note(title=title, body=body, tags=tags))
from_data = s.snippet_fields(_Note( from_data = s.snippet_fields(_Note(
title=s.compose_title(fields["name"], fields["when_to_use"]), title=title, body=body, tags=tags,
body=s.compose_body(code="const x = 1", locations=locs, **fields), data=s.compose_data(name=name, when_to_use=when, signature=sig,
tags=s.compose_tags(fields["language"]), language=lang, locations=locs),
data=s.compose_data(locations=locs, **fields),
)) ))
for key in ("name", "when_to_use", "signature", "language", "locations", for key in ("name", "when_to_use", "signature", "language", "locations",
"repo", "path", "symbol", "code"): "repo", "path", "symbol", "code"):