Follow url metadata redirects#133
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 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 |
… and follow the redirects in fetchAsBotStream
… from tests related to fetchAsBotStream
|
So as you suggested, I used stream factory to detect redirects and repeat the stream with the redirected url along the error-detection. I have some pin points and questions. Pin points:
Questions:
|
Nope, it's only a closure if it references a local variable inside of the function it's declared within. You could ensure it doesn't create a closure by moving it to a top-level function and passing it in as a value.
I have no idea! I don't think it would make a big difference which one is used TBH
Yeah, it would be good to return an error if the redirect can't be resolved (the same as we return an error for a non-200 status) |
…ceptors and cleanup in afterEach
…ppercase method names
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/worker/src/utils/fetchAsBot.ts (1)
146-192: Consider using a shared no-op Writable instead ofcreateWriteStream(devNull).Each call to
createWriteStream(devNull)opens a new file descriptor. While the FDs are closed when the stream ends and redirects are bounded byfollowRedirects, a singleton no-op Writable would avoid the overhead entirely.♻️ Optional: Use a shared no-op Writable
+import { Writable } from "stream"; + +const noopWritable = new Writable({ + write(_chunk, _encoding, callback) { + callback(); + }, +}); + const fetchAsBotStreamFactory: Dispatcher.StreamFactory< FetchAsBotStreamFactoryOpaque > = ({ opaque, statusCode, headers }) => { // ... - return createWriteStream(devNull); + return noopWritable; // ... (apply to all three return statements) };Note: This is a minor optimization and the current implementation is functionally correct.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/worker/src/utils/fetchAsBot.ts` around lines 146 - 192, The stream factory fetchAsBotStreamFactory currently calls createWriteStream(devNull) multiple times (opening FDs) when handling redirects or non-2xx statuses; replace those repeated calls with a single shared no-op Writable singleton (e.g., a module-scoped DevNullWritable) and return that instance instead of calling createWriteStream(devNull) so you avoid opening multiple file descriptors; keep existing behavior for setting opaque.error and opaque.redirect and ensure the singleton is used wherever createWriteStream(devNull) currently appears in fetchAsBotStreamFactory.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/worker/src/utils/fetchAsBot.ts`:
- Around line 146-192: The stream factory fetchAsBotStreamFactory currently
calls createWriteStream(devNull) multiple times (opening FDs) when handling
redirects or non-2xx statuses; replace those repeated calls with a single shared
no-op Writable singleton (e.g., a module-scoped DevNullWritable) and return that
instance instead of calling createWriteStream(devNull) so you avoid opening
multiple file descriptors; keep existing behavior for setting opaque.error and
opaque.redirect and ensure the singleton is used wherever
createWriteStream(devNull) currently appears in fetchAsBotStreamFactory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e2dee141-b1c2-4fe6-b848-30caa48a378d
📒 Files selected for processing (3)
apps/worker/src/utils/fetchAsBot.test.tsapps/worker/src/utils/fetchAsBot.tsapps/worker/test-utils/server.ts
Closes #34
The reason why I didn't (and couldn't) use the
onInfomethod is that it only runs the callback for responses with1xxstatus code.Todo:
fetchAsBotStreamfunctionfetchAsBotandfetchAsBotStreamUnrelated Todo:
disableNetConnect) for mocks to make sure there is no real request to the net.Summary by CodeRabbit
Release Notes
New Features
Improvements