Repository navigation
ai slop #30550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ai slop #30550
Changes from 24 commits
96fb9b5
163086c
9c4d47a
65204af
83bfe97
c5dbf87
ac6a48f
02d29d4
74e6c01
86a6b53
3d1d4fb
a9eaadd
697f3ce
00d9af4
c77625d
bf80823
869011f
df4722b
089836a
ac682b4
c73ed66
45e007b
d450552
c760dc4
d2c591c
90eeeda
d46737c
0e0554f
7d338d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -513,42 +513,7 @@ impl Stdio { | |
| } | ||
|
|
||
| if let Some(stream_) = webcore::ReadableStream::from_js(value, global)? { | ||
| let mut stream = stream_; | ||
| if let Some(blob) = stream.to_any_blob(global) { | ||
| return out_stdio.extract_blob(global, blob, i); | ||
| } | ||
|
|
||
| let name: &'static [u8] = match i { | ||
| 0 => b"stdin", | ||
| 1 => b"stdout", | ||
| 2 => b"stderr", | ||
| _ => { | ||
| return Err(global.throw_invalid_arguments(format_args!( | ||
| "ReadableStream cannot be used for stdio[{i}] yet" | ||
| ))); | ||
| } | ||
| }; | ||
|
|
||
| if is_sync { | ||
| return Err(global.throw_invalid_arguments(format_args!( | ||
| "'{}' ReadableStream cannot be used in sync mode", | ||
| bstr::BStr::new(name), | ||
| ))); | ||
| } | ||
|
|
||
| if stream.is_disturbed(global) { | ||
| return Err(global | ||
| .err( | ||
| jsc::ErrorCode::INVALID_STATE, | ||
| format_args!( | ||
| "'{}' ReadableStream has already been used", | ||
| bstr::BStr::new(name), | ||
| ), | ||
| ) | ||
| .throw()); | ||
| } | ||
| *out_stdio = Stdio::ReadableStream(stream); | ||
| return Ok(()); | ||
| return out_stdio.extract_readable_stream(global, stream_, i, is_sync); | ||
| } | ||
|
|
||
| if let Some(array_buffer) = value.as_array_buffer(global) { | ||
|
|
@@ -575,6 +540,70 @@ impl Stdio { | |
| ))) | ||
| } | ||
|
|
||
| /// Validate a `ReadableStream` destined for a spawned process's stdio and | ||
| /// store it. Shared by `Bun.spawn`'s option extraction and the shell's | ||
| /// `cmd < ${stream}` redirect so the two cannot drift. | ||
| /// | ||
| /// Streams that are really an already-complete Blob/File take the blob | ||
| /// fast-path. Disturbed (already read from) and locked (a reader is held) | ||
| /// streams are rejected up front: `assignToStream` could not pump either, | ||
| /// and that failure would otherwise surface only asynchronously, after the | ||
| /// child is already running with an empty stdin. | ||
| pub fn extract_readable_stream( | ||
| &mut self, | ||
| global: &JSGlobalObject, | ||
| stream: webcore::ReadableStream, | ||
| i: i32, | ||
| is_sync: bool, | ||
| ) -> JsResult<()> { | ||
| let mut stream = stream; | ||
| if let Some(blob) = stream.to_any_blob(global) { | ||
| return self.extract_blob(global, blob, i); | ||
| } | ||
|
|
||
| let name: &'static [u8] = match i { | ||
| 0 => b"stdin", | ||
| 1 => b"stdout", | ||
| 2 => b"stderr", | ||
| _ => { | ||
| return Err(global.throw_invalid_arguments(format_args!( | ||
| "ReadableStream cannot be used for stdio[{i}] yet" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two reasons:
The one behavior change for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we unify the implementation then?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 7d338d6. Two behavior changes fall out of the unification, both visible in the error messages:
One thing I did not touch: |
||
| ))); | ||
| } | ||
| }; | ||
|
|
||
| if is_sync { | ||
| return Err(global.throw_invalid_arguments(format_args!( | ||
| "'{}' ReadableStream cannot be used in sync mode", | ||
| bstr::BStr::new(name), | ||
| ))); | ||
| } | ||
|
|
||
| if stream.is_disturbed(global) { | ||
| return Err(global | ||
| .err( | ||
| jsc::ErrorCode::INVALID_STATE, | ||
| format_args!( | ||
| "'{}' ReadableStream has already been used", | ||
| bstr::BStr::new(name), | ||
| ), | ||
| ) | ||
| .throw()); | ||
| } | ||
|
|
||
| if stream.is_locked(global) { | ||
| return Err(global | ||
| .err( | ||
| jsc::ErrorCode::INVALID_STATE, | ||
| format_args!("'{}' ReadableStream is locked", bstr::BStr::new(name)), | ||
| ) | ||
| .throw()); | ||
| } | ||
|
|
||
| *self = Stdio::ReadableStream(stream); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn extract_blob( | ||
| &mut self, | ||
| global: &JSGlobalObject, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -744,6 +744,28 @@ impl Builtin { | |
| if redirect.stderr() { | ||
| me.stderr = BuiltinIO::ArrayBuf { buf: mk(), i: 0 }; | ||
| } | ||
| } else if match crate::webcore::ReadableStream::from_js(jsval, global) { | ||
| Ok(Some(_)) => true, | ||
| Ok(None) => false, | ||
| // from_js threw (e.g. a hostile Symbol.asyncIterator getter); | ||
| // propagate instead of continuing with a pending exception. | ||
| Err(_) => return Some(Yield::failed()), | ||
| } { | ||
| if redirect.stdin() { | ||
| // Builtins read stdin synchronously from a buffer/blob; piping an | ||
| // async ReadableStream into a builtin would require buffering the | ||
| // whole stream first. Reject with a clear error instead of crashing. | ||
| let _ = global.throw_invalid_arguments(format_args!( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the original issue's headline example platform-divergent. await Bun.$`cat < ${stream}`
// POSIX: external /bin/cat → works (the new Cmd.rs path)
// Windows: builtin → throws "ReadableStream cannot be redirected to a builtin command ('cat')"The added test's own comment works around exactly this ("Use a spawned bun process (not the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Went with the "deliberate divergence, tested" option (45e007b): a new |
||
| "ReadableStream cannot be redirected to a builtin command ('{}'). \ | ||
| Use an external command or buffer the stream first", | ||
| kind.as_str() | ||
| )); | ||
| } else { | ||
| let _ = global.throw_invalid_arguments(format_args!( | ||
| "ReadableStream can only be redirected to stdin" | ||
| )); | ||
| } | ||
| return Some(Yield::failed()); | ||
| } else if let Some(body) = | ||
| crate::webcore::body::Value::from_request_or_response(jsval) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change, correct or not, strictly required for landing this PR? If not, can we throw it into another PR? We would want to derisk changes like this if it's only tangential.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. The behavior is required for the PR (without it
cat < ${new ReadableStream({ type: "direct" })}never gives the child EOF, so the command hangs, and the never-started controller's GC destructor releases a ref it does not own), but it does not have to live in the generic builtin. Done in d46737c:readDirectStreamis back to exactly what main has, andFileSink::assign_to_streamnow runs the same terminal as a fulfilled pump (handle_resolve_stream: detach plus close the writer, both idempotent) whenassignToStreamreturns synchronously with no promise, which is precisely the no-pull/ pull-ended-inline case. That scopes the change to the sinks this PR is about (spawn stdin, the shell redirect,Bun.write(file, stream)). Both no-pullregression tests still pass, plus a new one for a direct stream whosepullwrites and ends inline. Other sink types given a pull-less direct stream still have the underlying issue on main; happy to send thereadDirectStreamone-liner with its own tests as a follow-up PR.