Conversation
Cover isHexStrict, toBigintOrThrow, stableStringify, bigintReplacer, signalTimeout, and signalAny — all previously had zero dedicated tests. https://claude.ai/code/session_01CwAhCXrYxQAdL7Vdy6DW7U
Summary of ChangesHello, 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 enhances the robustness and reliability of several core utility functions by introducing dedicated unit tests. These tests cover various edge cases and expected behaviors for functions related to hexadecimal validation, BigInt conversion and serialization, stable JSON stringification, and AbortSignal management, ensuring their correct operation and preventing future regressions. Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds much-needed unit tests for several utility functions, significantly improving code coverage. The new tests are generally well-structured. I've identified a few areas for improvement in the tests themselves to make them more robust and accurately reflect the behavior they are testing. Additionally, I've found a potential memory leak in the signalAny polyfill that the new tests are for. My detailed comments provide suggestions for these points.
| it('aborts when any input signal aborts', () => { | ||
| const c1 = new AbortController(); | ||
| const c2 = new AbortController(); | ||
| const combined = signalAny([c1.signal, c2.signal]); | ||
| expect(combined).toBeDefined(); | ||
| expect(combined!.aborted).toBe(false); | ||
|
|
||
| c1.abort(new Error('first')); | ||
| expect(combined!.aborted).toBe(true); | ||
| }); |
There was a problem hiding this comment.
While this test correctly verifies that the combined signal aborts, it doesn't cover a potential memory leak in the signalAny polyfill. The current implementation does not remove event listeners from the other source signals after one has aborted. This can lead to memory leaks if signalAny is used frequently with signals that have longer lifecycles.
A more robust implementation would clean up all listeners once the combined signal is aborted. While this is difficult to test without mocking, it's a significant issue in the underlying implementation that these tests are covering.
| it('includes field name in error message', () => { | ||
| try { | ||
| toBigintOrThrow('bad', ctx); | ||
| } catch (err) { | ||
| expect(err).toBeInstanceOf(SdkError); | ||
| expect((err as SdkError).message).toContain('amount'); | ||
| expect((err as SdkError).code).toBe('CONFIG'); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Using a try...catch block to assert on thrown errors can be brittle. If toBigintOrThrow('bad', ctx) doesn't throw, this test will pass silently, which is incorrect. It's better to use vitest's expect().toThrow() with an error object matcher for a more robust and concise test.
it('includes field name in error message', () => {
expect(() => toBigintOrThrow('bad', ctx)).toThrow(
expect.objectContaining({
message: expect.stringContaining('amount'),
code: 'CONFIG',
}),
);
});| it('handles nested objects with sorted keys', () => { | ||
| const result = stableStringify({ b: { d: 1, c: 2 }, a: 3 }); | ||
| const keys = Object.keys(JSON.parse(result)); | ||
| expect(keys).toEqual(['a', 'b']); | ||
| }); |
There was a problem hiding this comment.
This test case only verifies that the top-level keys are sorted. It doesn't check if the keys of nested objects are also sorted, which is part of the function's intended behavior. To properly test this, you should compare the stringified output of objects with differently ordered nested keys or assert against the exact expected string output.
| it('handles nested objects with sorted keys', () => { | |
| const result = stableStringify({ b: { d: 1, c: 2 }, a: 3 }); | |
| const keys = Object.keys(JSON.parse(result)); | |
| expect(keys).toEqual(['a', 'b']); | |
| }); | |
| it('handles nested objects with sorted keys', () => { | |
| const a = stableStringify({ b: { d: 1, c: 2 }, a: 3 }); | |
| const b = stableStringify({ a: 3, b: { c: 2, d: 1 } }); | |
| expect(a).toBe(b); | |
| expect(a).toBe('{"a":3,"b":{"c":2,"d":1}}'); | |
| }); |
Cover isHexStrict, toBigintOrThrow, stableStringify, bigintReplacer,
signalTimeout, and signalAny — all previously had zero dedicated tests.
https://claude.ai/code/session_01CwAhCXrYxQAdL7Vdy6DW7U