Skip to content

🧪 Improve testing for WebviewCollection#35

Closed
zknpr wants to merge 1 commit intomainfrom
testing-webview-collection-6092940338158183239
Closed

🧪 Improve testing for WebviewCollection#35
zknpr wants to merge 1 commit intomainfrom
testing-webview-collection-6092940338158183239

Conversation

@zknpr
Copy link
Copy Markdown
Owner

@zknpr zknpr commented Feb 7, 2026

🎯 What: add tests for WebviewCollection
📊 Coverage: add, get, getByWebviewId, has and panel disposal logic
Result: The WebviewCollection class is now unit-testable and fully covered.


PR created automatically by Jules for task 6092940338158183239 started by @zknpr

- Extracted `WebviewCollection` class to `src/webview-collection.ts` to isolate it from `vscode` module dependency.
- Updated `src/helpers.ts` to re-export `WebviewCollection`.
- Added comprehensive unit tests in `tests/unit/webview_collection.test.ts`.

Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sq-lite-explorer Ready Ready Preview, Comment Feb 7, 2026 1:21pm

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @zknpr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the robustness and maintainability of the webview management system by extracting the WebviewCollection class into its own module and implementing a thorough suite of unit tests. This refactoring improves code organization and ensures the reliable operation of webview panel tracking and lifecycle management.

Highlights

  • Refactoring: The WebviewCollection class has been moved from src/helpers.ts to its own dedicated file, src/webview-collection.ts, improving modularity and separation of concerns.
  • Unit Testing: Comprehensive unit tests have been introduced for the WebviewCollection class in a new file, tests/unit/webview_collection.test.ts.
  • Test Coverage: The new tests ensure full coverage for key functionalities of WebviewCollection, including add, get, getByWebviewId, has methods, and the crucial panel disposal logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/helpers.ts
    • Removed the WebviewCollection class definition from this file.
    • Added an export statement to re-export WebviewCollection from its new module.
  • src/webview-collection.ts
    • A new file was created to house the WebviewCollection class, promoting better separation of concerns.
  • tests/unit/webview_collection.test.ts
    • A new unit test file has been added, containing tests for WebviewCollection's core functionalities, including adding, retrieving, checking existence, and handling panel disposal.
    • Includes mock implementations for Uri and WebviewPanel to facilitate isolated testing.
Activity
  • The pull request was automatically generated by Jules for task 6092940338158183239.
  • The primary objective is to add and improve testing for the WebviewCollection class to ensure it is unit-testable and fully covered.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a solid improvement. It refactors the WebviewCollection class into its own dedicated file, which enhances modularity and makes the code easier to maintain. The addition of a comprehensive unit test suite for this class is excellent, as it significantly boosts confidence in its functionality and future changes. I have one suggestion to improve the performance of the WebviewCollection by optimizing its internal data structures for faster lookups.

Comment thread src/webview-collection.ts
Comment on lines +9 to +72
export class WebviewCollection {
/** Internal storage for URI to panel mappings */
private readonly entries = new Set<{
readonly uriString: string;
readonly panel: WebviewPanel;
}>();

/** Map from webview ID to panel for direct lookup */
private readonly idLookup = new Map<string, WebviewPanel>();

/**
* Iterate all panels associated with a document URI.
*
* @param uri - Document URI to look up
* @yields WebviewPanel instances for this URI
*/
public *get(uri: Uri): IterableIterator<WebviewPanel> {
const targetKey = uri.toString();
for (const entry of this.entries) {
if (entry.uriString === targetKey) {
yield entry.panel;
}
}
}

/**
* Find a panel by its unique webview ID.
*
* @param webviewId - Unique identifier for the webview
* @returns Panel if found, undefined otherwise
*/
public getByWebviewId(webviewId: string): WebviewPanel | undefined {
return this.idLookup.get(webviewId);
}

/**
* Check if any panels exist for a document URI.
*
* @param uri - Document URI to check
* @returns True if at least one panel exists
*/
public has(uri: Uri): boolean {
return !this.get(uri).next().done;
}

/**
* Register a new webview panel.
*
* @param uri - Associated document URI
* @param panel - Webview panel instance
* @param webviewId - Unique identifier for this webview
*/
public add(uri: Uri, panel: WebviewPanel, webviewId: string): void {
const entry = { uriString: uri.toString(), panel };
this.entries.add(entry);
this.idLookup.set(webviewId, panel);

// Auto-cleanup on panel disposal
panel.onDidDispose(() => {
this.entries.delete(entry);
this.idLookup.delete(webviewId);
});
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation of WebviewCollection uses a Set to store all panel entries. This leads to O(N) complexity for get(uri) and has(uri) operations, where N is the total number of webview panels. This could become a performance bottleneck if a large number of panels are open.

To improve performance, I recommend using a Map to group panels by their URI string. This would change the lookup complexity to O(1), making it much more efficient.

Below is a suggested refactoring of the class that implements this change.

export class WebviewCollection {
  /** Map from URI string to a set of panels */
  private readonly uriLookup = new Map<string, Set<WebviewPanel>>();

  /** Map from webview ID to panel for direct lookup */
  private readonly idLookup = new Map<string, WebviewPanel>();

  /**
   * Iterate all panels associated with a document URI.
   *
   * @param uri - Document URI to look up
   * @yields WebviewPanel instances for this URI
   */
  public *get(uri: Uri): IterableIterator<WebviewPanel> {
    const panels = this.uriLookup.get(uri.toString());
    if (panels) {
      yield* panels;
    }
  }

  /**
   * Find a panel by its unique webview ID.
   *
   * @param webviewId - Unique identifier for the webview
   * @returns Panel if found, undefined otherwise
   */
  public getByWebviewId(webviewId: string): WebviewPanel | undefined {
    return this.idLookup.get(webviewId);
  }

  /**
   * Check if any panels exist for a document URI.
   *
   * @param uri - Document URI to check
   * @returns True if at least one panel exists
   */
  public has(uri: Uri): boolean {
    const panels = this.uriLookup.get(uri.toString());
    return !!panels && panels.size > 0;
  }

  /**
   * Register a new webview panel.
   *
   * @param uri - Associated document URI
   * @param panel - Webview panel instance
   * @param webviewId - Unique identifier for this webview
   */
  public add(uri: Uri, panel: WebviewPanel, webviewId: string): void {
    const uriString = uri.toString();
    let panels = this.uriLookup.get(uriString);
    if (!panels) {
      panels = new Set();
      this.uriLookup.set(uriString, panels);
    }

    panels.add(panel);
    this.idLookup.set(webviewId, panel);

    // Auto-cleanup on panel disposal
    panel.onDidDispose(() => {
      const panelsForUri = this.uriLookup.get(uriString);
      if (panelsForUri) {
        panelsForUri.delete(panel);
        if (panelsForUri.size === 0) {
          this.uriLookup.delete(uriString);
        }
      }
      this.idLookup.delete(webviewId);
    });
  }
}

@zknpr
Copy link
Copy Markdown
Owner Author

zknpr commented Feb 7, 2026

Merged as part of v1.3.0 release in PR #65

@zknpr zknpr closed this Feb 7, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

Merged as part of v1.3.0 release in PR #65

Acknowledged. Thank you for the update.

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.

1 participant