refactor(sdk/go): unify functional-option handling with shared applier - #3232
Open
rhuss wants to merge 2 commits into
Open
refactor(sdk/go): unify functional-option handling with shared applier#3232rhuss wants to merge 2 commits into
rhuss wants to merge 2 commits into
Conversation
Signed-off-by: Roland Huß <rhuss@redhat.com>
Introduce a single generic applier, options.Apply[T any, O ~func(*T)], in a new leaf package openshell/v1/internal/options, and route all option-application sites through it. Nil option entries are now ignored uniformly instead of panicking; non-nil options still apply in order, and each site keeps its existing pre-seeding and defaulting. - Add internal/options package with Apply and unit tests - Route the 15 application sites (root, types, oidc, fake, gateway, edge) through options.Apply; exported types.Apply*Options keep their signatures and delegate to it - Add one nil-handling test per affected package - Document the nil-option rule in README.md and the docs book No public API signature changes. Closes NVIDIA#3213 Signed-off-by: Roland Huß <rhuss@redhat.com>
rhuss
requested review from
a team,
derekwaynecarr,
mrunalp and
sjenning
as code owners
September 9, 2026 07:17
4 tasks
elezar
reviewed
Sep 9, 2026
elezar
reviewed
Sep 9, 2026
elezar
reviewed
Sep 9, 2026
Comment on lines
86
to
99
| fc.sandboxes = sandboxes | ||
| fc.templateCreate = sandboxes | ||
| fc.templates = newFakeSandboxTemplateClient(fc.templateStore, fc.isClosed) | ||
| fc.providers = newFakeProviderClient(fc.providerStore, fc.isClosed) | ||
| fc.services = newFakeServiceClient(fc.isClosed) | ||
| fc.exec = newFakeExecClient(fc.isClosed) | ||
| fc.files = newFakeFileClient(fc.isClosed) | ||
| fc.health = newFakeHealthClient(nil, fc.isClosed) | ||
| fc.ssh = newFakeSSHClient(fc.isClosed) | ||
| fc.tcp = newFakeTCPClient(fc.isClosed) | ||
| fc.cfg = newFakeConfigClient(fc.isClosed) | ||
| fc.policy = newFakePolicyClient(fc.isClosed) | ||
| fc.workspaces = newFakeWorkspaceClient(fc.workspaceStore, fc.memberStore, fc.isClosed) | ||
| fc.inference = newFakeInferenceClient(fc.isClosed) |
Member
There was a problem hiding this comment.
out of scope: Instead of applying these directly, should we also model them as ClientOptions?
elezar
reviewed
Sep 9, 2026
Comment on lines
+41
to
42
| options.Apply(cfg, opts) | ||
| cfg.applyDefaults() |
Member
There was a problem hiding this comment.
Also out of scope: Why do we apply defaults after applying the inputs? Does this mean that user inputs could be overridden?
elezar
reviewed
Sep 9, 2026
Comment on lines
+239
to
+247
|
|
||
| # spex: generated/local files (only constitution is committed) | ||
| **/.claude/ | ||
| **/.agents/ | ||
| **/.codex/ | ||
| **/.specify/** | ||
| !**/.specify/spex.json | ||
| !**/.specify/memory/ | ||
| !**/.specify/memory/constitution.md |
Member
There was a problem hiding this comment.
Is this change related to this PR? Note that the .agents folder in this repo is explicitly used for contributor workflows.
Contributor
Author
There was a problem hiding this comment.
sorry, this slipped in from my SDD flow (but I'm getting there, already was able to reliably exclude the main SDD artefacts). Going to remove this change.
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
The Go SDK applied functional options with hand-copied
for _, o := range opts { o(&cfg) }loops at 15 sites across six areas. None guarded against a nil option, so a nil entry in an option list panicked everywhere. This unifies option application behind a single generic helper and adopts one rule: nil options are ignored.Related Issue
Closes #3213
Changes
openshell/v1/internal/options(new leaf package) withApply[T any, O ~func(*T)](target *T, opts []O)— skips nil entries, applies the rest in order.types,oidc,fake,gateway,edge)through
options.Apply. Exportedtypes.Apply*Optionshelpers keep their signatures and delegate.applyDefaults()ordering; only nil handling changes.sdk/go/README.mdand the docs book (docs/src/architecture.md).No public API signature changes; consumers compile unchanged.
Testing
mise run go:cigreen: build,golangci-lint,gofmt, fullgo test, proto-check, docs-check.Checklist