Skip to content

test: add unit tests for getUriParts utility#36

Closed
zknpr wants to merge 1 commit intomainfrom
jules-test-geturiparts-3659151931186356262
Closed

test: add unit tests for getUriParts utility#36
zknpr wants to merge 1 commit intomainfrom
jules-test-geturiparts-3659151931186356262

Conversation

@zknpr
Copy link
Copy Markdown
Owner

@zknpr zknpr commented Feb 7, 2026

Improved testing for getUriParts in src/helpers.ts.

Changes:

  • Implemented unit tests covering various scenarios for URI parsing.
  • Setup a test configuration to mock vscode module without affecting the main build.
  • Fixed a runtime crash in cryptoShim.ts when running in Node.js environment.
  • Verified all tests pass.

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

- Added `tests/unit/helpers.test.ts` to test `getUriParts`.
- Created `tests/mocks/vscode.ts` to mock VS Code API for tests.
- Created `tsconfig.test.json` to configure path mapping for tests.
- Updated `package.json` to use `tsconfig.test.json` for tests.
- Fixed `src/platform/cryptoShim.ts` to use optional chaining for `import.meta.env` to prevent crashes in Node.js test environment.

Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
@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.

@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:22pm

@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 significantly improves the testing landscape by introducing new unit tests for the getUriParts utility, ensuring its robustness across different URI formats. It also establishes a more isolated and controlled testing environment through vscode module mocking and a dedicated TypeScript configuration for tests. A critical runtime stability issue in cryptoShim.ts affecting Node.js environments has also been addressed.

Highlights

  • Unit Test Coverage: Added comprehensive unit tests for the getUriParts utility function in src/helpers.ts, covering various URI parsing scenarios including strings, vscode.Uri objects, files without extensions, root files, and paths with special characters.
  • Testing Infrastructure: Introduced a dedicated test configuration (tsconfig.test.json) and a mock implementation for the vscode module (tests/mocks/vscode.ts) to enable isolated and reliable unit testing without requiring a full VS Code environment.
  • Runtime Stability Fix: Implemented a fix in src/platform/cryptoShim.ts by adding optional chaining to import.meta.env, preventing a potential runtime crash when the code is executed in certain Node.js environments.
  • Test Script Update: Modified the test script in package.json to utilize the newly created tsconfig.test.json for test execution, ensuring the correct test environment setup.

🧠 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
  • package.json
    • Updated the 'test' script to use 'npx tsx --tsconfig tsconfig.test.json --test tests/unit/*.test.ts', pointing to a new test-specific TypeScript configuration.
  • src/platform/cryptoShim.ts
    • Modified 'import.meta.env.VSCODE_BROWSER_EXT' to 'import.meta.env?.VSCODE_BROWSER_EXT' to safely access 'VSCODE_BROWSER_EXT' and prevent runtime errors in Node.js environments.
  • tests/mocks/vscode.ts
    • Added a new file providing a mock implementation for the 'vscode' module, including 'env', 'Uri', 'ColorThemeKind', and 'UIKind', to facilitate isolated unit testing.
  • tests/unit/helpers.test.ts
    • Added a new file containing unit tests for the 'getUriParts' function, covering various scenarios like parsing file paths, URIs, files without extensions, root files, and paths with special characters.
  • tsconfig.test.json
    • Added a new TypeScript configuration file that extends 'tsconfig.json' and configures path mapping to redirect 'vscode' imports to the mock implementation in 'tests/mocks/vscode.ts'.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 adds valuable unit tests for the getUriParts utility, which is a great improvement for code quality and maintainability. The setup of a dedicated test configuration and the fix for the runtime crash in cryptoShim.ts are also excellent additions. My review focuses on a correctness issue in getUriParts that the new tests have helped uncover, and some improvements to the new vscode mock to make it more robust for future testing.

it('should parse simple file path URI', () => {
const uri = vsc.Uri.file('/home/user/test.txt');
const parts = getUriParts(uri);
assert.strictEqual(parts.dirname, 'file:///home/user/'); // Regex matches from uri.toString() which returns file://...
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This test reveals a correctness issue with the getUriParts implementation. The function's documentation states it "Extract[s] path components from a URI", but as your test and comment correctly note, it includes the URI scheme (file://) in the dirname when passed a vscode.Uri object. This is because it operates on uri.toString() instead of the uri.path property, which can lead to unexpected behavior.

To fix this, getUriParts should be modified to use the .path property when it receives a vscode.Uri object.

Here is a suggested change for src/helpers.ts:

export function getUriParts(uri: string | vsc.Uri): { /* ... */ } {
  const pathString = typeof uri === 'string' ? uri : uri.path;
  const match = pathString.match(uriPathPattern);
  // ... the rest of the function
}

With this change in getUriParts, this test assertion should be updated to expect '/home/user/'.

Comment thread tests/mocks/vscode.ts
Comment on lines +8 to +12
parse: (value: string) => ({
toString: () => value,
path: value,
scheme: 'file'
}),
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 path property in this mock for Uri.parse is incorrect. It returns the entire URI string, whereas it should return only the path component. For example, for a URI file:///foo/bar.txt, path should be /foo/bar.txt.

This is inconsistent with the file() mock and could cause issues in future tests that rely on uri.path. This becomes more important if getUriParts is changed to use uri.path as suggested in another comment.

Consider making the mock more accurate to prevent future issues.

Suggested change
parse: (value: string) => ({
toString: () => value,
path: value,
scheme: 'file'
}),
parse: (value: string) => ({
toString: () => value,
path: value.startsWith('file://') ? new URL(value).pathname : value,
scheme: 'file'
}),

Comment thread tests/mocks/vscode.ts
Comment on lines +13 to +17
file: (path: string) => ({
toString: () => `file://${path}`,
path,
scheme: 'file'
})
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

This mock for Uri.file doesn't handle Windows paths correctly. For a path like C:\\Users\\test.txt, toString() would produce file://C:\\Users\\test.txt, which is not a valid URI. A valid file URI for a Windows path should look like file:///C:/Users/test.txt.

While the current tests only use POSIX-style paths, making the mock cross-platform compatible would make it more robust for future tests.

  file: (path: string) => {
    // Handle Windows paths to create valid file URIs.
    const posixPath = path.replace(/\\/g, '/');
    const uriPath = /^[a-zA-Z]:\//.test(posixPath) ? `/${posixPath}` : posixPath;
    return {
      toString: () => `file://${uriPath}`,
      path: uriPath,
      scheme: 'file'
    };
  }

@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. I am glad the changes are merged.

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