Skip to content

Reorg introduce api package containing Entry interface#401

Merged
steiler merged 29 commits intomainfrom
reorgIntroduceAPI
Apr 16, 2026
Merged

Reorg introduce api package containing Entry interface#401
steiler merged 29 commits intomainfrom
reorgIntroduceAPI

Conversation

@steiler
Copy link
Copy Markdown
Collaborator

@steiler steiler commented Feb 19, 2026

Reorganizes the tree package by introducing a new pkg/tree/api surface and a pkg/tree/consts package, then updates the codebase to use those exported interfaces, types, and constants.

  • Adds a dedicated API layer (pkg/tree/api) with Entry, LeafVariants, delete-path types, and non-revertive tracking; introduces pkg/tree/ops helpers (e.g., GetByOwner) and an ops interface.
  • Moves tree constants to pkg/tree/consts and replaces many direct tree.RunningIntentName/RunningValuesPrio/Replace* usages with consts equivalents across datastore, targets, server, and tests.
  • Refactors core tree implementation to use the new API types: method visibility changes (e.g., ShouldDelete, GetOrCreateChilds, ToJsonInternal), LeafVariants accessors, and TreeContext now exposing SchemaClient, ExplicitDeletes, and NonRevertiveInfo.
  • Updates mocks and generated code to reflect new API package paths and added interface methods; adds a new mock for SdcpbPath.
  • Adjusts update/path handling with SdcpbPath() and updates callers, plus broad test updates to match new APIs and constants.

@steiler steiler requested a review from a team as a code owner February 19, 2026 14:24
Copy link
Copy Markdown
Contributor

@faebr faebr left a comment

Choose a reason for hiding this comment

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

I really like the interface separation from the stateless ops. I always struggled to fully understand sharedEntryAttributes and this breaks it down! I assume the commented out functions in entry.go are the ones you will still implement right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should the leaf_variants also be parts of the api / interface package or would it make sense to take this implementation into another package so to only have the interface definitions in the api package?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

possible... lets add an issue to investigate that. Nothing I would want to also squeeze into this PR.

Comment thread pkg/tree/ops/deletebranch.go Outdated
Comment thread go.mod Outdated
Comment thread pkg/datastore/types/transaction_intent.go
Comment thread pkg/datastore/deviations.go Outdated
Comment thread pkg/datastore/sync.go Outdated
Comment thread pkg/tree/ops/getschemakeys.go Outdated
Comment thread pkg/tree/ops/getdeletes.go Outdated
Comment thread pkg/tree/ops/getdeviations.go Outdated
Comment thread pkg/tree/ops/proto.go
Comment thread pkg/tree/sharedEntryAttributes_test.go
steiler added 3 commits March 13, 2026 11:38
…centralize dispatch

- extract entry validators into dedicated files (range, length, pattern, mandatory, min/max-elements)
- keep validate package entrypoint focused on orchestration/result aggregation
- introduce dedicated validator dispatch/registry file with shared ValidationFunc signature
- precompute active validators once from config and pass through recursive processor tasks
- simplify recursive validation path by executing only active validator functions per entry
@steiler steiler force-pushed the reorgIntroduceAPI branch from e2324c9 to eddffb1 Compare March 13, 2026 15:54
Comment thread pkg/tree/ops/validation/validation_dispatch.go
Comment thread pkg/tree/ops/validation/validation_entry_pattern.go Outdated
Comment thread pkg/tree/api/adapter/intentresponse.go
@steiler steiler force-pushed the reorgIntroduceAPI branch from 8e2dcbd to e90c167 Compare March 20, 2026 10:05
Comment thread pkg/datastore/deviations.go Outdated
Copy link
Copy Markdown
Contributor

@alexandernorth alexandernorth left a comment

Choose a reason for hiding this comment

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

much prefer this approach :)

Comment thread pkg/tree/processors/processor_explicit_delete.go Outdated
Comment thread pkg/tree/processors/processor_blame_config.go
Comment thread pkg/tree/processors/processor_mark_owner_delete.go
Comment thread pkg/tree/processors/processor_mark_owner_delete.go
Comment thread pkg/tree/processors/processor_mark_owner_delete.go
Copy link
Copy Markdown
Contributor

@alexandernorth alexandernorth left a comment

Choose a reason for hiding this comment

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

lgtm

steiler added 4 commits March 31, 2026 13:29
…tions

Summary:
Replace ad-hoc child creation with a canonical get-or-create API (`AddOrGetChild`) on the `Entry` interface and in `ChildMap`. Callers are updated to use the canonical `Entry` returned by the API so concurrent creators do not overwrite canonical children. Also add interactive path-completion support via `pkg/tree/ops/GetPathCompletions` and its integration test.

Why:
Previous usage assumed the caller's `Entry` instance becomes the canonical child. Concurrent creators could create duplicate or overwritten children. Centralizing canonicalization avoids subtle concurrency bugs and ensures a single canonical child entry per path name.

API changes:
- `pkg/tree/api/entry.go`: replace `AddChild(context.Context, Entry) error` with `AddOrGetChild(context.Context, Entry) (Entry, error)`; `NewEntry` now returns `api.Entry`.

Implementation changes:
- `pkg/tree/api/childMap.go`: add `AddOrGet` which acquires the lock and returns the canonical `Entry` if present, otherwise inserts and returns the new entry.
- `pkg/tree/sharedEntryAttributes.go`: implement `AddOrGetChild` and use `childs.AddOrGet` so we don't overwrite an existing canonical entry. Update callers to use the returned `Entry` where appropriate.
- Update ops to use the new API (`pkg/tree/ops/getorcreatechilds.go`, `pkg/tree/ops/checkandcreatekeysasleafs.go`, etc.).

New feature:
- `pkg/tree/ops/getpathcompletions.go` (new): provides path and key completions for interactive XPath-like paths.
- `pkg/tree/getpathcompletions_test.go` (new): integration tests covering completion behavior.
GetIntentResponse with yet missing attributes
Comment thread pkg/tree/ops/getpathcompletions.go Outdated
Comment thread pkg/tree/ops/getpathcompletions.go
Comment thread pkg/tree/ops/getpathcompletions.go
@alexandernorth
Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@henderiw
Copy link
Copy Markdown
Contributor

LGTM

@steiler steiler merged commit e195d5d into main Apr 16, 2026
5 of 6 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants