Fixes hang in async-iterator-stream tests for Response bodies with async generators.
## Root Cause
When `new Response(async generator)` is created:
1. Response constructor stores stream in GC cache (weak ref)
2. Body's `readable.Ref` is set to `.Response` (relies on GC cache)
3. RequestContext receives Response and protects the JSValue
4. BUT: Between Response creation and RequestContext using it, GC could collect the stream
5. When RequestContext calls `.get()`, it returns `null` → hangs waiting for stream
## Fix
**RequestContext.zig:1833-1836** - Upgrade Ref to `.strong` before using
- Call `.get()` to retrieve the stream
- Call `.upgrade()` to convert Ref to `.strong` (prevents GC)
- Subsequent `.get()` calls succeed with strong reference
**ReadableStream.zig:124** - Fix upgrade() bug (pre-existing)
- Changed `current.value` to `current.*`
- `Strong.init()` expects full ReadableStream struct, not just JSValue
## Results
async-iterator-stream tests:
- ✅ 45 tests pass (was 0)
- ⚠️ 41 Request body tests still timeout (different issue)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The issue was that when Request.getBody() or Response.getBody() is called
without a valid JSValue owner (e.g., owner.Request == .zero), the code was
trying to store streams in the GC cache, which failed silently, leading to
null reference panics and hanging tests.
Changes:
1. **Body.zig:443-456** - When converting blob to stream in toReadableStream()
- Check if owner has valid JSValue
- Use .strong ref if JSValue is .zero or owner is .empty
- Only set GC cache if owner has valid JSValue
2. **Body.zig:502-519** - When creating stream from drain in toReadableStream()
- Same logic: use .strong if no valid owner JSValue
- Fixes panics from unwrapping null on lines 504/507
3. **ReadableStream.zig:127-142** - Fix Ref.init() for empty/strong owners
- Return .empty instead of trying to create .strong without a stream
- Caller should use .set() to populate
This fixes the body-stream.test.ts hang. The tests now pass but the full
suite (4,883 tests) takes a very long time (~3s/test for large streaming
tests = ~4 hours total). Individual test subsets all pass correctly.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit fixes several issues with the new ReadableStream.Ref system
that caused body-stream tests to hang:
1. **Body.zig:1020** - Fixed owner mismatch when setting stream after draining
- Was using `.strong` owner when should use actual owner (Request/Response)
- This caused Ref.get() to fail since Ref type didn't match owner type
2. **Body.zig:964,1026** - Set proper Ref type for cloned bodies
- When tee() returns streams via array, cloned body gets proper Ref type
- Ensures cloned body can access its stream via GC cache
3. **Request.zig:819** - Fixed stream assignment in doClone
- Stream[0] should go to original request, not cloned request
4. **ReadableStream.zig:108** - Always update original Ref after tee()
- Original body's Ref must point to its tee'd stream
5. **body-stream.test.ts** - Fixed test discovery hang
- Changed from eager to lazy array creation using factory function
- Prevents creating hundreds of 2MB arrays during test discovery
- Arrays now created on-demand when each test runs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>