Conversation
- Create `src/services/remote-signing-service.test.ts` - Cover happy paths, policy rejection, human confirmation, audit logging, and error handling - Mock `SignerBackend` and `SandboxAuditLog` - Use `vitest` framework features (fake timers, mocks)
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @Dexploarer, 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 stability and trustworthiness of the 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
|
| vi.useFakeTimers(); | ||
| policy.requireHumanConfirmation = true; | ||
| service.updatePolicy(policy); | ||
|
|
||
| const request = makeRequest(); | ||
| await service.submitSigningRequest(request); | ||
|
|
||
| // Advance time past expiration (1000ms set in beforeEach) | ||
| vi.advanceTimersByTime(1500); | ||
|
|
||
| const result = await service.approveRequest(request.requestId); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| expect(result.error).toContain("Approval expired"); | ||
| expect(service.getPendingApprovals()).toHaveLength(0); | ||
|
|
||
| vi.useRealTimers(); | ||
| }); |
There was a problem hiding this comment.
The use of vi.useFakeTimers() in the 'should fail if approval expired' test is not paired with a vi.useRealTimers() in a finally block or afterEach hook. If an error occurs before vi.useRealTimers() is called, subsequent tests may run with fake timers, leading to unpredictable behavior and flaky tests.
Recommended solution:
Wrap the test body in a try/finally block to ensure vi.useRealTimers() is always called, or use an afterEach hook to reset timers after each test that uses fake timers:
it("should fail if approval expired", async () => {
vi.useFakeTimers();
try {
// ...test body...
} finally {
vi.useRealTimers();
}
});| it("should return false if request not found", () => { | ||
| const removed = service.rejectRequest("non-existent"); | ||
| expect(removed).toBe(false); | ||
| }); |
There was a problem hiding this comment.
The test 'should return false if request not found' for rejectRequest does not assert that the audit log is not called when a non-existent request is rejected. This is important to ensure that no misleading audit entries are created for failed rejections.
Recommended solution:
Add an assertion to verify that mockAuditLog.record is not called in this scenario:
expect(mockAuditLog.record).not.toHaveBeenCalled();There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of unit tests for the RemoteSigningService, covering critical paths like auto-signing, policy enforcement, human confirmation workflows, and error handling. The tests are well-structured and use mocks effectively. I have a couple of suggestions to enhance test determinism and clean up the test setup.
| function makeRequest(overrides: Partial<SigningRequest> = {}): SigningRequest { | ||
| return { | ||
| requestId: `req-${Date.now()}-${Math.random()}`, | ||
| chainId: 1, | ||
| to: "0x1234567890abcdef1234567890abcdef12345678", | ||
| value: "1000000000000000", // 0.001 ETH | ||
| data: "0x", | ||
| createdAt: Date.now(), | ||
| ...overrides, | ||
| }; | ||
| } |
There was a problem hiding this comment.
To improve test determinism and make debugging easier, it's best to avoid Math.random() for generating test data like requestId. Using a simple counter is a more robust approach.
Note: You'll need to reset requestCounter = 0; inside your beforeEach block to ensure test isolation.
let requestCounter = 0;
function makeRequest(overrides: Partial<SigningRequest> = {}): SigningRequest {
requestCounter++;
return {
requestId: `req-test-${requestCounter}`,
chainId: 1,
to: "0x1234567890abcdef1234567890abcdef12345678",
value: "1000000000000000", // 0.001 ETH
data: "0x",
createdAt: Date.now(),
...overrides,
};
}| mockSigner = { | ||
| getAddress: vi.fn().mockResolvedValue("0xsigner"), | ||
| signMessage: vi.fn().mockResolvedValue("0xsignature"), | ||
| signTransaction: vi.fn().mockImplementation(async (tx: UnsignedTransaction) => { | ||
| return "0xsignedtx"; | ||
| }), | ||
| }; |
There was a problem hiding this comment.
The signMessage method on the mock signer is defined but is not used in any of the tests for RemoteSigningService, as the service under test does not expose this functionality. This line can be removed to simplify the test setup and avoid confusion.
mockSigner = {
getAddress: vi.fn().mockResolvedValue("0xsigner"),
signTransaction: vi.fn().mockImplementation(async (tx: UnsignedTransaction) => {
return "0xsignedtx";
}),
};
Added comprehensive unit tests for
RemoteSigningServiceinsrc/services/remote-signing-service.test.ts.This service handles critical security operations (transaction signing), policy enforcement, and approval workflows.
The tests cover:
The tests use
vitestmocks and fake timers to ensure determinism and isolation.PR created automatically by Jules for task 4635356540678650487 started by @Dexploarer