refactor: unify TUI tabs behind an entry interface; fix convention violations - #24
Open
lvlcn-t wants to merge 1 commit into
Open
refactor: unify TUI tabs behind an entry interface; fix convention violations#24lvlcn-t wants to merge 1 commit into
lvlcn-t wants to merge 1 commit into
Conversation
…olations The tabs were four near-identical types (browseTab, TenantsTab, ContextsTab, CredentialsTab) fed by a 12-method tabs.Manager interface no test ever mocked, with Tabs re-discriminating the selected item's concrete kind in four separate type-switches. That is a type-tag dispatch smell: a generic item routed through a switch on its kind. Replace it with real polymorphism: - entry interface (embeds list.Item + details.Item, adds name/blank/form/ save/remove): each item type (TenantItem, ContextItem, CredentialItem) carries its own CRUD behaviour as methods, with compile-time assertions. save switches on the submission intent internally, on the item. - activatable: the optional context-only "use" side-effect, type-asserted once (like io.WriterTo), replacing handleInteractiveSelect. - One Tab struct replaces the four tab types; Tabs holds a concrete *contexts.Manager (the tabs.Manager interface is deleted) and dispatches through entry methods with zero type-switches. Also fixes the convention violations found in the CRUD series: - contexts: RenameContext/DeleteContext and the tenant/credential delete path now wrap the existing ErrContext*/ErrTenant*/ErrCredential* sentinels with %w; renameAndRetarget takes the renameTarget struct instead of five params; entryTarget.deleteX renamed to remove. - form.Model stores the last validation error (not its text) and exposes Err(); tests assert errors.Is instead of message substrings. - tui/tabs tests drop every assert.Contains on View()/status/err.Error(); the pure validators are unit-tested with errors.Is/require.Error, and the duplicate-create rejection asserts contexts.ErrTenantExists via a lastErr accessor. - Domain error tests fold not-found singles into a table and use errors.Is. Net -219 lines; behaviour unchanged (verified by the CRUD flow tests and a CLI smoke test). Signed-off-by: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com>
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against 3b12559 |
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.
Why
The CRUD series left a type-tag dispatch smell: four near-identical tab
types (
browseTab,TenantsTab,ContextsTab,CredentialsTab) fed by a12-method
tabs.Managerinterface no test ever mocked, withTabsre-discriminating the selected item's concrete kind in four separate
type-switches. A generic
details.Itemrouted through aswitchon itskind is neither polymorphism nor concrete typing.
What
Real polymorphism, driven by the item types:
entryinterface (embedslist.Item+details.Item, addsname/blank/form/save/remove) — each item (TenantItem,ContextItem,CredentialItem) carries its own CRUD behaviour asmethods, with compile-time
var _ entryassertions.saveswitches onthe submission intent internally, on the item.
activatable— the context-only "use" side-effect, type-assertedonce (like
io.WriterTo), replacinghandleInteractiveSelect.Tabstruct replaces the four tab types.Tabsholds a concrete*contexts.Manager(tabs.Managerinterface deleted) and dispatchesthrough
entrymethods with zero type-switches.Net -219 lines.
Convention fixes (from the audit)
contexts:RenameContext/DeleteContextand the tenant/credentialdelete path wrap the existing
ErrContext*/ErrTenant*/ErrCredential*sentinels with
%w;renameAndRetargettakes therenameTargetstructinstead of 5 params;
entryTarget.deleteX→remove.form.Modelstores the last validation error (not its text), exposesErr(); form tests asserterrors.Is.tui/tabstests drop everyassert.ContainsonView()/status/err.Error(). Pure validators are unit-tested witherrors.Is/require.Error; duplicate-create rejection assertscontexts.ErrTenantExistsvia alastErraccessor.errors.Is.Verification
go test -race ./...,go vet, fullpre-commit— green.tabs.Managerinterface; no concrete-itemtype-switch outside item files; no message-substring assertions;
contextsstill a leaf;tuinever importscmd.tests.
Based on
feat/tui-crud-credentials(#23); reviewing the stack #20→#23first is recommended.