Skip to content

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Dec 8, 2025

Fixes #18

Adds a 'Duplicate' button to the contexts

@feloy feloy requested review from a team and benoitf as code owners December 8, 2025 14:47
@feloy feloy requested review from SoniaSandler and gastoner and removed request for a team December 8, 2025 14:47
@feloy feloy force-pushed the feat-18/duplicate-context branch from b209939 to a533976 Compare December 8, 2025 14:47
@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Warning

Rate limit exceeded

@feloy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d8f634c and 4812e46.

📒 Files selected for processing (6)
  • packages/channels/src/interface/contexts-api.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.ts (1 hunks)
  • packages/webview/src/component/ContextCard.spec.ts (3 hunks)
  • packages/webview/src/component/ContextCard.svelte (2 hunks)
  • packages/webview/src/component/actions/DuplicateContextAction.svelte (1 hunks)
📝 Walkthrough

Walkthrough

Adds a context-duplication feature: new duplicateContext method in the ContextsApi interface, implementation and helper in ContextsManager, a UI action component and ContextCard integration, and tests verifying duplicated context names with incremental suffixes.

Changes

Cohort / File(s) Summary
Interface Definition
packages/channels/src/interface/contexts-api.ts
Adds duplicateContext(contextName: string): Promise<void> to ContextsApi
Manager Implementation
packages/extension/src/manager/contexts-manager.ts
Adds findNewContextName(kubeConfig: KubeConfig, contextName: string): string and duplicateContext(contextName: string): Promise<void> to generate a non-conflicting name, clone the specified context (clusters/users/currentContext/contexts), update internal state, and persist kubeconfig
Manager Tests
packages/extension/src/manager/contexts-manager.spec.ts
Adds a test that duplicates a context twice, asserting new names context1-1 and context1-2 are created and total contexts increases
Webview UI
packages/webview/src/component/ContextCard.svelte, packages/webview/src/component/actions/DuplicateContextAction.svelte
Adds DuplicateContextAction.svelte (copy-icon button) and renders it inside ContextCard.svelte; action obtains contextsApi via Remote context and calls duplicateContext(name)
Webview Tests
packages/webview/src/component/ContextCard.spec.ts
Mocks DuplicateContextAction.svelte and extends assertions to expect it receives the current context name

Sequence Diagram

sequenceDiagram
    participant User
    participant ContextCard
    participant DuplicateAction
    participant ContextsApi
    participant ContextsManager
    participant KubeConfig

    User->>ContextCard: views context list
    ContextCard->>DuplicateAction: render(name)
    User->>DuplicateAction: click duplicate
    DuplicateAction->>ContextsApi: duplicateContext(name)
    ContextsApi->>ContextsManager: duplicateContext(name)
    ContextsManager->>KubeConfig: read current config
    ContextsManager->>ContextsManager: findNewContextName(config, name)
    ContextsManager->>ContextsManager: clone context, cluster, user entries with new name
    ContextsManager->>KubeConfig: update contexts/clusters/users/currentContext
    ContextsManager->>KubeConfig: persist (saveKubeConfig)
    ContextsManager-->>ContextsApi: resolve
    ContextsApi-->>DuplicateAction: success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review findNewContextName() for correct uniqueness logic and edge cases (empty contexts, name collisions).
  • Inspect duplicateContext() cloning to ensure deep copies and no shared references or accidental mutation of original entries.
  • Verify persistence path (saveKubeConfig() usage) and state update (update() call) ordering.
  • Confirm UI action obtains the proper API proxy and handles errors (click handler).

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat: duplicate contexts' clearly summarizes the main change—adding the ability to duplicate Kubernetes contexts.
Description check ✅ Passed The description mentions fixing issue #18 and adding a 'Duplicate' button to contexts, which directly relates to the changeset.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #18: it adds both UI action (DuplicateContextAction component) and backend logic (duplicateContext method in ContextsManager and ContextsApi interface).
Out of Scope Changes check ✅ Passed All changes are scoped to implementing context duplication functionality. No unrelated modifications to other features or system components were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/extension/src/manager/contexts-manager.ts (1)

77-86: Consider making findNewContextName private.

The method is only used internally by duplicateContext and doesn't need to be part of the public API. Making it private would better encapsulate the implementation detail.

Apply this diff:

-  findNewContextName(kubeConfig: KubeConfig, contextName: string): string {
+  #findNewContextName(kubeConfig: KubeConfig, contextName: string): string {
     let counter = 1;
     let newName = `${contextName}-${counter}`;
     // Keep creating new name by adding 1 to name until not existing name is found
     while (kubeConfig.contexts.find(context => context.name === newName)) {
       counter += 1;
       newName = `${contextName}-${counter}`;
     }
     return newName;
   }

And update line 91:

-    const newName = this.findNewContextName(kubeConfig, contextName);
+    const newName = this.#findNewContextName(kubeConfig, contextName);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15fc149 and a533976.

📒 Files selected for processing (5)
  • packages/channels/src/interface/contexts-api.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.ts (1 hunks)
  • packages/webview/src/component/ContextCard.svelte (2 hunks)
  • packages/webview/src/component/actions/DuplicateContextAction.svelte (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Build / ubuntu-24.04
packages/webview/src/component/actions/DuplicateContextAction.svelte

[failure] 14-14: src/component/ContextCard.spec.ts > ContextCard should render with no current context
TypeError: Cannot read properties of undefined (reading 'getProxy')

in <unknown>

❯ DuplicateContextAction src/component/actions/DuplicateContextAction.svelte:14:28
❯ ContextCard.add_svelte_meta.componentTag src/component/ContextCard.svelte:35:30
❯ ContextCard src/component/ContextCard.svelte:117:24


[failure] 14-14: src/component/ContextCard.spec.ts > ContextCard should render with current context
TypeError: Cannot read properties of undefined (reading 'getProxy')

in <unknown>

❯ DuplicateContextAction src/component/actions/DuplicateContextAction.svelte:14:28
❯ ContextCard.add_svelte_meta.componentTag src/component/ContextCard.svelte:35:30
❯ ContextCard src/component/ContextCard.svelte:117:24

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build extension OCI image
🔇 Additional comments (4)
packages/channels/src/interface/contexts-api.ts (1)

24-24: LGTM!

The new API method follows the existing interface pattern and integrates cleanly with the other context management methods.

packages/extension/src/manager/contexts-manager.spec.ts (1)

595-645: LGTM!

The test comprehensively validates the duplication behavior, including incremental name generation and context count verification.

packages/webview/src/component/ContextCard.svelte (1)

6-6: LGTM!

The integration of DuplicateContextAction is clean and follows the existing pattern. Rendering it unconditionally (unlike SetCurrentContextAction) makes sense since any context can be duplicated.

Also applies to: 35-35

packages/webview/src/component/actions/DuplicateContextAction.svelte (1)

1-21: Component implementation looks good.

The DuplicateContextAction component follows the same pattern as other action components (SetCurrentContextAction, DeleteContextAction) and correctly delegates to the API. Once the test failures are fixed, this component will work as expected.

@feloy feloy force-pushed the feat-18/duplicate-context branch 2 times, most recently from d8f634c to 5eea75f Compare December 8, 2025 14:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/webview/src/component/ContextCard.spec.ts (1)

36-90: Verify that tests are passing without the Remote context fix.

The past review flagged failing tests because the Remote context was not provided when rendering ContextCard. The suggested fix was to create a mock Remote object with getProxy and pass it via the context map. This fix has not been applied in the current version.

While the component is mocked at line 30 (which should prevent its code from executing), the previous build logs showed concrete test failures. Please verify whether the tests are passing now, or if the suggested fix still needs to be applied.

If tests are still failing, apply the fix from the previous review:

// Add this to test setup
const remote = {
  getProxy: vi.fn().mockReturnValue({
    duplicateContext: vi.fn(),
  }),
};

// Update render calls at lines 37 and 65
render(ContextCard, {
  context: new Map([[Remote, remote]]),
  props: {
    // ... existing props
  },
});

You can verify by running the tests:

#!/bin/bash
# Run the ContextCard tests to check for failures
cd packages/webview
npm test -- ContextCard.spec.ts
🧹 Nitpick comments (1)
packages/webview/src/component/actions/DuplicateContextAction.svelte (1)

16-18: Consider adding error handling for better user experience.

The duplicateContext function doesn't handle potential errors from the API call. If the duplication fails (e.g., due to invalid context name or persistence issues), the user receives no feedback.

Consider wrapping the call in a try-catch block to handle errors gracefully:

 async function duplicateContext(): Promise<void> {
-  await contextsApi.duplicateContext(name);
+  try {
+    await contextsApi.duplicateContext(name);
+  } catch (error) {
+    console.error('Failed to duplicate context:', error);
+    // Optionally show user notification
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a533976 and d8f634c.

📒 Files selected for processing (6)
  • packages/channels/src/interface/contexts-api.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.spec.ts (1 hunks)
  • packages/extension/src/manager/contexts-manager.ts (1 hunks)
  • packages/webview/src/component/ContextCard.spec.ts (3 hunks)
  • packages/webview/src/component/ContextCard.svelte (2 hunks)
  • packages/webview/src/component/actions/DuplicateContextAction.svelte (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/extension/src/manager/contexts-manager.ts
  • packages/webview/src/component/ContextCard.svelte
  • packages/extension/src/manager/contexts-manager.spec.ts
  • packages/channels/src/interface/contexts-api.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build / windows-2022
  • GitHub Check: Build extension OCI image
🔇 Additional comments (2)
packages/webview/src/component/actions/DuplicateContextAction.svelte (1)

1-21: Clean implementation following project patterns.

The component structure is well-organized and follows the established patterns for action buttons in this codebase. The use of Svelte 5's $props() rune and the Remote context pattern are appropriate.

packages/webview/src/component/ContextCard.spec.ts (1)

26-30: Test coverage for DuplicateContextAction integration looks good.

The tests appropriately verify that the DuplicateContextAction component is rendered with the correct context name prop in both test scenarios. The mocking approach and assertions follow the established patterns in this test file.

Also applies to: 61-61, 89-89

Signed-off-by: Philippe Martin <[email protected]>
@feloy feloy force-pushed the feat-18/duplicate-context branch from 5eea75f to 4812e46 Compare December 8, 2025 14:58
Copy link

@gastoner gastoner left a comment

Choose a reason for hiding this comment

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

LGTM on Linux

@feloy feloy merged commit 0d3c161 into podman-desktop:main Dec 9, 2025
8 checks passed
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.

Duplicate a context

2 participants