Skip to content

Converge default-template name search into one tier-1 primitive#47

Merged
david-w-t merged 4 commits into
davidwt-com:mainfrom
david-w-t:develop
Jun 23, 2026
Merged

Converge default-template name search into one tier-1 primitive#47
david-w-t merged 4 commits into
davidwt-com:mainfrom
david-w-t:develop

Conversation

@david-w-t

Copy link
Copy Markdown
Contributor

Summary

Behaviour-preserving DRY refactor in graphdb_class. The same template
name-search walk (downward_children_by_arc/3 + lists:search for a
kind=template child whose name matches) was carried verbatim in two
functions. This slice extracts the shared body into one exported tier-1
in-transaction primitive and points both callers at it.

  • New: 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/1 now delegates with ?DEFAULT_TEMPLATE_NAME.
  • do_find_template_by_name/2 now wraps one graphdb_mgr:transaction/1
    around the primitive, preserving its {error,_} -> not_found swallow.

No externally observable change. do_templates_for_class/1,
do_default_template/1, and docs/Architecture.md are intentionally
untouched.

Closes the deferred "Converge default-template name search" item in
TASKS.md (left behind by the atomic-add_relationship work, PRs #44#45).

Behaviour preservation

  • graphdb_mgr:transaction/1 maps {atomic,R}->{ok,R} / {aborted,R}->{error,R},
    so the wrapper's {ok,{ok,Nref}} / {ok,not_found} / {error,_} match
    surfaces the same {ok,Nref} / not_found as before.
  • default_template_in_txn/1 returns identical values and still aborts the
    enclosing transaction on a mnesia read error (the bare-mnesia walk
    propagates errors; no try/catch added).

Tests

+3 direct CT cases in graphdb_class_SUITE for the new primitive (invoked
via 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 = template guard's reject branch is unreachable through the
public 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

david-w-t and others added 4 commits June 22, 2026 21:10
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

@david-w-t david-w-t left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@david-w-t david-w-t merged commit 45c79ca into davidwt-com:main Jun 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant