Repository navigation
fix(cloud-registry): react to provider changes - #502
Conversation
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>
Reviewer's GuideThe 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 replacementsequenceDiagram
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
Flow diagram for provider precedence and reload behaviorflowchart 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]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
|
There was a problem hiding this comment.
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
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
left a comment
There was a problem hiding this comment.
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?
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>
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>
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>
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>
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>
Description
ecc-client-elixir-cloud-registry-service-createreadprovideronly infirstUpdated(), andupdated()replaced it with a REST provider wheneverbaseUrlchanged. 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).providerorbaseUrlchanges, the component usesprovider, else a REST provider forbaseUrl, and loads the service types from it.provideralways takes precedence overbaseUrl(before, abaseUrlchange silently replaced a custom provider).baseUrl, the types are loaded once on the first render (before: twice).service-create.test.ts, 9 cases), and atestscript for it. The sharedweb-test.runner-config.mjsgets thetsconfigoption 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 defaultinpackages/ecc-client-elixir-cloud-registrywith 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.westests still pass with the changed shared config.Checklist
Comments
serviceTypes,formData,handleSubmit), because the form doesn't show the types and filling all inputs would test the form rather than the provider handling. This changes once test: set up unit, integration and e2e tests #484 settles the test approach.loadServiceTypes()'s error branch and add the same test config lines. I'll merge whichever lands second.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.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:
Enhancements:
Documentation:
Tests: