Skip to content

improve(loaders): add getClusterForTopic() helper - #3444

Draft
Dave Shoup (shouples) wants to merge 1 commit into
mainfrom
djs/issue-1694-get-cluster-for-topic
Draft

improve(loaders): add getClusterForTopic() helper#3444
Dave Shoup (shouples) wants to merge 1 commit into
mainfrom
djs/issue-1694-get-cluster-for-topic

Conversation

@shouples

Copy link
Copy Markdown
Contributor

Summary of Changes

Consolidates how the extension looks up the Kafka cluster a topic belongs to. Two commands previously hand-rolled the same getKafkaClustersForEnvironmentId(...).find(...) lookup; both now call a new ResourceLoader.getClusterForTopic(topic) helper instead, which returns the cluster (or undefined if none matches) and works for Confluent Cloud, local, and direct-connection topics alike.

  • New getClusterForTopic() on the abstract ResourceLoader base, mirroring the existing sibling getTopicSubjectGroups() (same connection-id guard, same lookup by topic.environmentId).
  • resourceScaffoldProjectCommand (project scaffolding) and deleteTopic now route through the helper instead of inlining the lookup.
  • Scaffolding logs to Sentry via logError() when a topic can't be resolved to a cluster, so we learn if that unexpected condition ever happens in the wild.

Closes #1694.

Click-testing instructions

This is internal plumbing with no user-visible change on the happy path. To confirm nothing regressed:

  1. Right-click a Kafka topic (try both a Confluent Cloud topic and a direct-connection topic) and run Create Project / scaffold. The generated template should pre-fill the cluster's bootstrap server (and schema registry URL, if the environment has one) exactly as before.
  2. Delete a topic and confirm the Topics view refreshes afterward (the topicChanged event still fires for the parent cluster).

Optional: Any additional details or context that should be provided?

  • The original connection-unaware ResourceManager.getClusterForTopic() referenced in Implement ResourceLoader.getClusterForTopic(topic: KafkaTopic): KafkaCluster | undefined #1694 was already removed in a prior change; this adds the connection-aware replacement on the loader and wires the remaining callers to it.
  • Deferred: several loader methods repeat the same connectionId mismatch guard verbatim; extracting a shared assertSameConnection() helper is out of scope here and left as a follow-up.

Pull request checklist

Please check if your PR fulfills the following (if applicable):

Tests

  • Added new
  • Updated existing
  • Deleted existing

Release notes

  • Does anything in this PR need to be mentioned in the user-facing CHANGELOG? No user-facing behavior change.

The old ResourceManager lookup was connection-unaware and failed for
direct-connection topics. Route the scaffold and delete-topic commands
through the new method, and log to Sentry when a topic's cluster can't
be resolved during scaffolding.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 26, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates “topic → Kafka cluster” resolution behind a new ResourceLoader.getClusterForTopic() helper, and updates the project-scaffolding and topic-deletion commands to use it. This aligns cluster lookup behavior across Confluent Cloud, local, and direct connections, and adds Sentry logging for an unexpected “topic can’t resolve to cluster” condition during scaffolding.

Changes:

  • Added ResourceLoader.getClusterForTopic(topic) helper with a connection-id guard and environment-scoped cluster lookup.
  • Refactored project scaffolding and topic deletion to call the helper instead of inlining getKafkaClustersForEnvironmentId(...).find(...).
  • Updated unit tests to cover the helper and scaffolding’s new Sentry logging path.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/loaders/resourceLoader.ts Adds getClusterForTopic() helper on the loader base class.
src/loaders/resourceLoader.test.ts Adds unit tests for getClusterForTopic().
src/commands/scaffold.ts Uses getClusterForTopic() and logs to Sentry when a topic can’t resolve to a cluster.
src/commands/scaffold.test.ts Updates scaffolding tests to stub getClusterForTopic() and assert Sentry logging.
src/commands/kafkaClusters.ts Uses getClusterForTopic() when firing topicChanged after deletion.
src/commands/kafkaClusters.test.ts Updates the “topic deleted” test to stub getClusterForTopic().
Suppressed comments (2)

src/loaders/resourceLoader.test.ts:500

  • Test name doesn’t follow the project’s convention of using a "should …" prefix (CodingGuidelineID 1000004).
  it("Returns the cluster matching the topic's clusterId", async () => {

src/loaders/resourceLoader.test.ts:510

  • Test name doesn’t follow the project’s convention of using a "should …" prefix (CodingGuidelineID 1000004).
  it("Returns undefined when no cluster in the environment matches the topic's clusterId", async () => {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

sandbox.restore();
});

it("Raises error for a topic from a mismatched connection", async () => {
Comment on lines 453 to +455
it("should fire the topicChanged event with change='deleted' after successful deletion", async () => {
showInputBoxStub.resolves(TEST_CCLOUD_KAFKA_TOPIC.name);
stubbedLoader.getKafkaClustersForEnvironmentId.resolves([TEST_CCLOUD_KAFKA_CLUSTER]);
stubbedLoader.getClusterForTopic.resolves(TEST_CCLOUD_KAFKA_CLUSTER);
@sonarqube-confluent

Copy link
Copy Markdown

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.

Implement ResourceLoader.getClusterForTopic(topic: KafkaTopic): KafkaCluster | undefined

2 participants