Converge default-template name search into one tier-1 primitive#47
Merged
Conversation
Design for extracting the duplicated template name-search walk in graphdb_class into one exported tier-1 in-transaction primitive (find_template_by_name_in_txn/2), funnelling do_find_template_by_name/2 and default_template_in_txn/1 through it. Behaviour-preserving, single module. Tracked as the deferred TASKS.md "Converge default-template name search" item. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF
Implementation plan (2 tasks: extract+converge primitive with 3 CT cases; docs) plus a design-doc amendment swapping the third test case from the unreachable kind-filter trap to a public-API name-discrimination case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF
…tive
Extract the duplicated downward_children_by_arc + name-match walk shared by
do_find_template_by_name/2 and default_template_in_txn/1 into an exported
tier-1 primitive find_template_by_name_in_txn/2. default_template_in_txn/1
delegates with ?DEFAULT_TEMPLATE_NAME; do_find_template_by_name/2 wraps one
graphdb_mgr:transaction/1 and preserves its {error,_}->not_found swallow.
Behaviour-preserving; +3 direct CT cases for the new primitive.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF
CLAUDE.md tier-1 primitive bullet lists find_template_by_name_in_txn/2; TASKS.md "Converge default-template name search" flipped to IMPLEMENTED. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Behaviour-preserving DRY refactor in
graphdb_class. The same templatename-search walk (
downward_children_by_arc/3+lists:searchfor akind=templatechild whose name matches) was carried verbatim in twofunctions. This slice extracts the shared body into one exported tier-1
in-transaction primitive and points both callers at it.
graphdb_class:find_template_by_name_in_txn(ClassNref, Name) -> {ok, Nref} | not_found— tier-1 in-transaction primitive (bare mnesia, never opens its own
transaction), exported in the tier-1 primitive group.
default_template_in_txn/1now delegates with?DEFAULT_TEMPLATE_NAME.do_find_template_by_name/2now wraps onegraphdb_mgr:transaction/1around the primitive, preserving its
{error,_} -> not_foundswallow.No externally observable change.
do_templates_for_class/1,do_default_template/1, anddocs/Architecture.mdare intentionallyuntouched.
Closes the deferred "Converge default-template name search" item in
TASKS.md(left behind by the atomic-add_relationshipwork, PRs #44–#45).Behaviour preservation
graphdb_mgr:transaction/1maps{atomic,R}->{ok,R}/{aborted,R}->{error,R},so the wrapper's
{ok,{ok,Nref}}/{ok,not_found}/{error,_}matchsurfaces the same
{ok,Nref}/not_foundas before.default_template_in_txn/1returns identical values and still aborts theenclosing transaction on a mnesia read error (the bare-mnesia walk
propagates errors; no try/catch added).
Tests
+3 direct CT cases in
graphdb_class_SUITEfor the new primitive (invokedvia
graphdb_mgr:transaction/1): found-by-name, discriminates-by-name(proves the name selects the right template, not first-match), and
name-not-found.
Full suite green: 455 CT + 105 EUnit = 560 tests, zero warnings.
The
kind = templateguard's reject branch is unreachable through thepublic API (composition children of a class with arc 26 are templates by
construction; subclasses attach via a taxonomy arc and are filtered out
before the guard runs); the guard stays in the code for behaviour
preservation but is not covered by an artificial injected-state test. See
docs/designs/converge-default-template-name-search-design.md.🤖 Generated with Claude Code