Skip to content

test: add remote-signing-service coverage#279

Draft
Dexploarer wants to merge 1 commit intodevelopfrom
jules-6223555680832473089-686870ff
Draft

test: add remote-signing-service coverage#279
Dexploarer wants to merge 1 commit intodevelopfrom
jules-6223555680832473089-686870ff

Conversation

@Dexploarer
Copy link
Owner

What:
Added missing test file src/services/remote-signing-service.test.ts to cover RemoteSigningService.

Why:
The service handles critical security operations like transaction signing, audit logging, and human approval flow. Having missing tests here is a security and reliability risk.

Verification:
Ran bun test src/services/remote-signing-service.test.ts and all 10 tests passed successfully.

Result:
Increased confidence in RemoteSigningService behavior without altering any production code.


PR created automatically by Jules for task 6223555680832473089 started by @Dexploarer

@google-labs-jules
Copy link

👋 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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 260b5070-ebcc-46b3-9ed9-b984b9434c28

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-6223555680832473089-686870ff
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@github-actions github-actions bot added the tests label Mar 20, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 of the RemoteSigningService by introducing a dedicated test suite. Given the service's role in handling sensitive security operations, this addition mitigates potential risks and boosts confidence in its behavior without altering any production code.

Highlights

  • Test Coverage: Added comprehensive unit tests for the RemoteSigningService to ensure the reliability and security of critical transaction signing, audit logging, and human approval flows.

🧠 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.

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.

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.

Comment on lines +131 to +152
it("should expire pending approvals", async () => {
const request: SigningRequest = {
requestId: "req-5",
chainId: 1,
to: "0x123",
value: "20000000000000000",
data: "0x",
createdAt: Date.now(),
};

await service.submitSigningRequest(request);

// Simulate time passing beyond timeout
vi.spyOn(Date, "now").mockReturnValue(Date.now() + 2000);

const result = await service.approveRequest("req-5");
expect(result.success).toBe(false);
expect(result.error).toBe("Approval expired");
expect(service.getPendingApprovals()).toHaveLength(0);

vi.restoreAllMocks();
});

Choose a reason for hiding this comment

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

The test for expiring pending approvals manipulates Date.now() after the createdAt field is set using the real time. This can lead to non-deterministic test results if there is a delay between these calls. To ensure deterministic behavior, mock Date.now() before constructing the request and setting createdAt, so both the request and the approval logic use the same reference time.

Recommended solution:

vi.spyOn(Date, "now").mockReturnValue(1000000);
const request: SigningRequest = { ... createdAt: Date.now(), ... };
// ...
vi.spyOn(Date, "now").mockReturnValue(1000000 + 2000);

This ensures both the request and the approval use the mocked time, making the test reliable.

Comment on lines +196 to +207
it("should update policy", () => {
const newPolicy = service.getPolicy();
newPolicy.requireHumanConfirmation = true;

service.updatePolicy(newPolicy);

const updatedPolicy = service.getPolicy();
expect(updatedPolicy.requireHumanConfirmation).toBe(true);
expect(mockAuditLog.record).toHaveBeenCalledWith(
expect.objectContaining({ type: "policy_decision" })
);
});

Choose a reason for hiding this comment

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

The test for updating the policy mutates the object returned by service.getPolicy() directly. If getPolicy() returns a reference to the internal policy object, this could cause unintended side effects, especially if other tests or code rely on the original policy. To avoid this, always clone the policy object before mutating it in tests.

Recommended solution:

const newPolicy = { ...service.getPolicy() };
newPolicy.requireHumanConfirmation = true;
service.updatePolicy(newPolicy);

This ensures test isolation and prevents accidental mutation of shared state.

Copy link

@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 much-needed test coverage for the RemoteSigningService, which is critical for security and reliability. The tests cover a good range of scenarios, including successful signing, policy enforcement, human approval flows, and error handling. I've identified a couple of areas for improvement in the tests to make them more robust and complete. Specifically, I've suggested using fake timers for time-dependent tests and adding a test case for the cleanup logic in getPendingApprovals. Overall, this is a valuable addition.

Comment on lines +131 to +152
it("should expire pending approvals", async () => {
const request: SigningRequest = {
requestId: "req-5",
chainId: 1,
to: "0x123",
value: "20000000000000000",
data: "0x",
createdAt: Date.now(),
};

await service.submitSigningRequest(request);

// Simulate time passing beyond timeout
vi.spyOn(Date, "now").mockReturnValue(Date.now() + 2000);

const result = await service.approveRequest("req-5");
expect(result.success).toBe(false);
expect(result.error).toBe("Approval expired");
expect(service.getPendingApprovals()).toHaveLength(0);

vi.restoreAllMocks();
});

Choose a reason for hiding this comment

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

medium

While this test works, using vi.spyOn(Date, 'now') for time-based tests can be fragile and less readable. The recommended approach in vitest is to use fake timers. This provides more deterministic control over time and makes the test's intent clearer. Consider refactoring this test to use vi.useFakeTimers() and vi.advanceTimersByTime().

  it("should expire pending approvals", async () => {
    vi.useFakeTimers();

    const request: SigningRequest = {
      requestId: "req-5",
      chainId: 1,
      to: "0x123",
      value: "20000000000000000",
      data: "0x",
      createdAt: Date.now(),
    };

    await service.submitSigningRequest(request);

    // Simulate time passing beyond timeout
    vi.advanceTimersByTime(2000);

    const result = await service.approveRequest("req-5");
    expect(result.success).toBe(false);
    expect(result.error).toBe("Approval expired");
    expect(service.getPendingApprovals()).toHaveLength(0);

    vi.useRealTimers();
  });

expect.objectContaining({ type: "policy_decision" })
);
});
});

Choose a reason for hiding this comment

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

medium

The test coverage for RemoteSigningService is great! One small improvement would be to add a test case specifically for the cleanup logic within getPendingApprovals(). The current expiration test (should expire pending approvals) covers the expiration check inside approveRequest, but not the lazy cleanup that happens when getPendingApprovals() is called. Adding a test for this would ensure all paths of the expiration logic are covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant