Skip to content

fix(cloud-registry): react to provider changes - #502

Merged
anuragxxd merged 5 commits into
devfrom
fix/cr-provider-changes
Oct 31, 2026
Merged

anuragxxd merged 5 commits into
devfrom
fix/cr-provider-changes

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Description

ecc-client-elixir-cloud-registry-service-create read provider only in firstUpdated(), and updated() replaced it with a REST provider whenever baseUrl changed. Apps that pass a custom provider (the pattern since #485, e.g. one that adds the user's bearer token) and rebuild it when the token changes kept submitting with the provider of the first render, i.e. with a stale token. The Cloud Registry UI works around this by rendering the form only once the user's roles are loaded, which doesn't help when the token changes later (elixir-cloud-aai/cloud-registry-ui#96 rebuilds the provider on every token change).

  • Whenever provider or baseUrl changes, the component uses provider, else a REST provider for baseUrl, and loads the service types from it. provider always takes precedence over baseUrl (before, a baseUrl change silently replaced a custom provider).
  • Types that a replaced provider returns late are dropped; its failures are not reported. If the current provider fails, or none is left, the types are cleared.
  • With only baseUrl, the types are loaded once on the first render (before: twice).
  • The form's input is kept.
  • No API change: same properties and events.
  • Docs: a note on replacing the provider, and React examples that create the provider once (each new provider object loads the types again).
  • Tests: the package's first tests (service-create.test.ts, 9 cases), and a test script for it. The shared web-test.runner-config.mjs gets the tsconfig option so esbuild compiles Lit's decorators, the same two lines as feat: add surface, font and dark mode controls #446.

Closes #448

How it was verified

  • npm run lint: 0 errors (warnings unchanged).
  • npm run build (cloud-registry and dependencies, and the docs site).
  • npx web-test-runner --group default in packages/ecc-client-elixir-cloud-registry with Chromium and Firefox: 9/9 pass. WebKit can't start on my machine (missing system libraries); CI runs all three. Without the fix, the tests for replacing the provider, the base URL precedence and late types fail.
  • wes tests still pass with the changed shared config.
  • CI: all checks pass (run 40769108348); the new tests pass in Chromium, Firefox and WebKit (9/9 each). Read the Docs preview built.

Checklist

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit, using the PR title as the commit message.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated the user-facing documentation to describe any new or changed behavior.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have not reduced the existing code coverage.

Comments

Declined review findings

  • ecc-service-create-validation-failed (no provider and no base URL) still fires on the first render only, also if an app sets the provider shortly after. Unchanged behaviour; apps that set the provider later can render the component once they have one.
  • No retry when the same provider object is set again after a failed load: a retry needs a new provider object (documented: each new object reloads). A reload() method can come with the form PR that shows the types.
  • test:watch (wtr --watch) still uses the package's own old config: unchanged, part of test: set up unit, integration and e2e tests #484.

🤖 Generated with Claude Code

Summary by Sourcery

Ensure the service creation component consistently uses the latest available provider and safely refreshes its service types when provider configuration changes.

Bug Fixes:

  • Update the service creation component to react to provider replacements and use the current provider for service-type loading and submissions, preventing stale provider credentials.
  • Ignore late results and failures from replaced providers while clearing types when the active provider fails or is unavailable.
  • Avoid duplicate service-type loading when using only a base URL.

Enhancements:

  • Preserve form input while switching providers and maintain provider precedence over base URL changes.

Documentation:

  • Document provider replacement behavior and advise React users to create provider instances only when their inputs change.

Tests:

  • Add nine provider-handling tests covering replacement, precedence, fallback, request races, failures, submission, and validation.
  • Add a package test script and configure the shared test runner for Lit decorator compilation.

uniqueg and others added 2 commits October 28, 2026 19:38
The create component read `provider` only in firstUpdated() and then
replaced it with a REST provider whenever `baseUrl` changed. Apps that
replace the provider, e.g. when the user's token changes, kept sending
requests with the old one.

Use `provider`, else a REST provider for `baseUrl`, whenever either
changes, reload the service types, and drop types of a replaced
provider that arrive late. Add the first tests of the package, and let
the shared test config compile Lit decorators (as in #446).

Closes #448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reset the service types when the current provider fails or none is
left, test the base URL paths, stale failures and the validation
event, and show React examples that create the provider once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR makes service-create provider selection reactive, ensuring token-refresh provider replacements take effect without stale submissions or stale asynchronous type results, adds comprehensive tests and test configuration, and documents provider precedence and React instantiation guidance.

Sequence diagram for reactive service provider replacement

sequenceDiagram
    participant Component as ServiceCreate
    participant Provider as CloudRegistryProvider
    participant OldProvider as ReplacedProvider

    Component->>Component: useProvider()
    Component->>Provider: getServiceTypes()
    Note over Component,Provider: provider takes precedence over baseUrl
    Component->>Component: provider changes
    Component->>Provider: getServiceTypes()
    OldProvider-->>Component: getServiceTypes() late
    Component->>Component: discard stale types
    Provider-->>Component: getServiceTypes()
    Component->>Component: keep current provider types
Loading

Flow diagram for provider precedence and reload behavior

flowchart TD
    A[provider or baseUrl changes] --> B{provider exists?}
    B -- Yes --> C[Use provider]
    B -- No --> D{baseUrl exists?}
    D -- Yes --> E[Create or reuse REST provider]
    D -- No --> F[Clear service types]
    C --> G["getServiceTypes()"]
    E --> G
    G --> H{Provider still current?}
    H -- Yes --> I[Store service types]
    H -- No --> J[Discard late result]
    G --> K{Load fails?}
    K -- Yes, current provider --> L[Clear types and emit ecc-service-create-failed]
Loading

File-Level Changes

Change Details Files
Track the effective provider reactively and protect service-type loading from stale asynchronous results.
  • Select the custom provider first, otherwise reuse or create the REST provider for baseUrl.
  • Reload service types when provider or baseUrl changes, including fallback when a provider is removed.
  • Ignore late successes and failures from replaced providers; clear types when the active provider fails or is absent.
  • Preserve existing form input while switching providers.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts
Add focused coverage for provider precedence, replacement, fallback, request deduplication, and asynchronous race handling.
  • Verify new providers handle subsequent submissions and baseUrl changes do not override custom providers.
  • Verify REST providers load once initially and reload for a new URL or after custom-provider removal.
  • Verify stale provider responses are ignored and current-provider failures clear types and emit the failure event.
  • Add the package test script and configure esbuild to use the package tsconfig for Lit decorators.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create.test.ts
packages/ecc-client-elixir-cloud-registry/package.json
web-test.runner-config.mjs
Document provider replacement behavior and React provider lifecycle guidance.
  • Explain that replacing a provider reloads service types and routes later requests through the replacement while retaining form input.
  • Document provider precedence over baseUrl and fallback behavior when the provider is removed.
  • Show providers created outside React render, with useMemo guidance when provider inputs change.
apps/documentation/pages/docs/cloud-registry/components/service-create.mdx
apps/documentation/pages/docs/cloud-registry/providers.mdx

Assessment against linked issues

Issue Objective Addressed Explanation
#448 React to changes in the provider property after the component has rendered, loading service types from the replacement provider and using it for subsequent requests. ✅
#448 Keep provider selection consistent when baseUrl also changes: prefer a supplied provider, and fall back to a REST provider for baseUrl when no custom provider is set. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

@uniqueg
uniqueg marked this pull request as ready for review October 28, 2026 21:19
@uniqueg
uniqueg requested a review from anuragxxd as a code owner October 28, 2026 21:19

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="150" />
<code_context>
-      this.serviceTypes = await this._provider.getServiceTypes();
+      const serviceTypes = await provider.getServiceTypes();
+      // the types of a provider that was replaced meanwhile are dropped
+      if (provider === this._provider) this.serviceTypes = serviceTypes;
     } catch (error) {
+      if (provider !== this._provider) return;
</code_context>
<issue_to_address>
**Stale type requests win**

When the component switches from provider A to another provider and back to the same A object before A's earlier type request settles, `loadServiceTypes()` checks only whether `provider === this._provider`, so the earlier request is accepted again: its success overwrites newer `serviceTypes`, or its catch clears newer types and reports an obsolete failure. The form shows stale types or emits a spurious failure.

Track the current type-load request with a generation or request token, and ignore both success and failure results from older requests.

Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:152`.
</issue_to_address>

### Comment 2
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="138" />
<code_context>
+    if (provider === this._provider) return;
+
+    // the types shown stay until those of the new provider are loaded
+    this._provider = provider;
+    if (provider) this.loadServiceTypes();
+    else this.serviceTypes = [];
</code_context>
<issue_to_address>
**Immediate submit uses old provider**

When a caller assigns `el.provider` and submits in the same JavaScript task, before Lit runs `updated()`, `updated()` has not synchronized `_provider` yet, so `handleSubmit()` uses the previous provider and sends the request with its credentials instead of the newly assigned provider's.

Resolve and use the effective provider synchronously when submission starts, or otherwise ensure a provider assignment updates the provider used by submissions immediately.
</issue_to_address>

### Comment 3
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create.test.ts" line_range="185" />
<code_context>
+    await el.updateComplete;
+    await waitUntil(() => internals(el).serviceTypes[0]?.artifact === "tes");
+
+    expect(typeRequests(fetchStub)).to.have.length(1);
+  });
+
</code_context>
<issue_to_address>
**Wrong fallback URL goes unnoticed**

When the provider is removed while `baseUrl` is set, but the fallback uses a different URL and still makes one `/types` request, the `uses the base URL once the provider is removed` test checks only that one `/types` request occurred, so a fallback provider aimed at a different registry still passes and the component can send later requests to the wrong registry.

Assert that the captured request URL is exactly `${BASE_URL}/services/types`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and if the component selects the wrong provider, a later form submission could create a service in the wrong registry. Reverting would stop future requests but would not remove that created record; it would need to be cleaned up in the registry.

Blocking findings: packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:150, packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:138, packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create.test.ts:185


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg uniqueg mentioned this pull request Oct 28, 2026
8 tasks done
uniqueg and others added 2 commits October 28, 2026 22:57
Turbo runs the packages' tests in parallel, and the wes tests use the
default port 8000, so the second runner failed with EADDRINUSE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Number the requests for service types, so that a late answer of a
provider that was replaced and set again is dropped, and submit with
the provider set just before, before the component updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@anuragxxd anuragxxd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, Alex. Approving; I'm merging this as soon as CI passes on the updated branch.

The same problem is in the other client components (service-registry services/service, WES runs/run/run-create, DRS, TRS, and the TRS and DRS filers). We reproduced it with tests for services, WES runs and run. Moving this PR's provider handling into a shared Lit controller in @elixir-cloud/design fixed all of those tests. I've opened #519 to fix it across all components, service-create included, with the details and a sketch of the controller. Could you take it on after the form PRs?

@anuragxxd
anuragxxd merged commit bf64a2a into dev Oct 31, 2026
12 checks passed
@anuragxxd
anuragxxd deleted the fix/cr-provider-changes branch October 31, 2026 06:35
anuragxxd added a commit that referenced this pull request Oct 31, 2026
#504 adds the reason to the error of a failed type load; the test from
#502 still expected the fixed message.
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflict in service-create.ts: keep the admin option and
use the provider from dev's provider handling (#502).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts: keep the type picker and
its type status and reloads, on dev's provider handling (#502) and
problem details (#504); drop the duplicate typesRequest field.

Adapt dev's new service-create tests to the type picker: fillForm
chooses "Add new service type", and the provider tests expect the
reload of the types after a create.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts: keep the configurable
environments; dev's provider handling (#502) now loads the
registration rules too, and resets them without a provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts: keep the form change
events and dirty state, on dev's provider handling (#502).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts and its docs: keep the
validation, environments and URL schemes; dev's provider handling (#502)
now loads the registration rules too, and resets them without a
provider. The event table takes dev's failure details (#504) and the
PR's validation details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

fix(cloud-registry): react to provider changes

2 participants