Skip to content

Update typing in the s3 uploader#2

Merged
mshriver merged 1 commit intoibutsu:mainfrom
mshriver:test-fix-and-release
Nov 21, 2025
Merged

Update typing in the s3 uploader#2
mshriver merged 1 commit intoibutsu:mainfrom
mshriver:test-fix-and-release

Conversation

@mshriver
Copy link
Contributor

@mshriver mshriver commented Nov 21, 2025

Summary by Sourcery

Adjust S3 uploader tests to use more precise typings for mocked file system reads.

Enhancements:

  • Refine Jest spy typings for fs.promises.readdir in S3 uploader tests to match the string[] overload.

Tests:

  • Simplify mocked readdir return type in S3 uploader tests by returning a string array directly instead of casting to Dirent[].

Copilot AI review requested due to automatic review settings November 21, 2025 13:59
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 21, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refines Jest mocking in the S3 uploader tests by giving readdir spies precise promise and argument typings and returning a correctly typed file name array, improving type safety and readability.

File-Level Changes

Change Details Files
Tightened Jest spy typing for fs.promises.readdir in S3Uploader tests to match the string[] overload and simplified the mocked return value.
  • Cast the jest.spyOn call for fs.promises.readdir to a SpyInstance that returns Promise<string[]> with a single PathLike argument to satisfy TypeScript overload resolution.
  • Updated the mocked resolved value for readdir from an fs.Dirent[]-cast array to a plain string[] of file names, matching the selected overload’s return type.
  • Enhanced the comment on the mock to clarify that the spy is explicitly cast to the string[] overload of readdir.
test/s3-uploader.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The custom typing on the jest.spyOn(fs.promises, 'readdir') spy narrows the signature to [path: fs.PathLike], which omits the optional options parameter used in some readdir overloads; consider reflecting the full function type (e.g., via jest.MockedFunction<typeof fs.promises.readdir>) so tests stay aligned with the real API surface.
  • Instead of casting through unknown to jest.SpyInstance<Promise<string[]>, [fs.PathLike]>, consider defining a small typed helper or using a generic spyOn<typeof fs.promises.readdir> pattern to avoid brittle type assertions and make the intent clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The custom typing on the `jest.spyOn(fs.promises, 'readdir')` spy narrows the signature to `[path: fs.PathLike]`, which omits the optional `options` parameter used in some `readdir` overloads; consider reflecting the full function type (e.g., via `jest.MockedFunction<typeof fs.promises.readdir>`) so tests stay aligned with the real API surface.
- Instead of casting through `unknown` to `jest.SpyInstance<Promise<string[]>, [fs.PathLike]>`, consider defining a small typed helper or using a generic `spyOn<typeof fs.promises.readdir>` pattern to avoid brittle type assertions and make the intent clearer.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@5f4460e). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #2   +/-   ##
=======================================
  Coverage        ?   92.21%           
=======================================
  Files           ?        4           
  Lines           ?      244           
  Branches        ?       64           
=======================================
  Hits            ?      225           
  Misses          ?       19           
  Partials        ?        0           
Flag Coverage Δ
unittests 92.21% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f4460e...415bff5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR corrects the typing for the fs.promises.readdir mock in the S3 uploader tests to accurately reflect the actual implementation's behavior.

Key Changes:

  • Updated the Jest spy typing to explicitly specify the string[] return type overload
  • Removed the incorrect as unknown as fs.Dirent[] cast from the mock resolved value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mshriver mshriver force-pushed the test-fix-and-release branch 2 times, most recently from ec91fa9 to f33ff7e Compare November 21, 2025 14:07
@mshriver mshriver force-pushed the test-fix-and-release branch from f33ff7e to 415bff5 Compare November 21, 2025 14:12
@mshriver mshriver merged commit 3958848 into ibutsu:main Nov 21, 2025
7 checks passed
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.

2 participants