Repository navigation
feat(web): add bounded buffered file uploads - #1407
purplelight wants to merge 2 commits into
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
Thanks for the PR. The integration control is good: it shows Chromium leaving disk-backed file bytes out of route.request().postDataBuffer(), so the underlying problem is real. Before the code questions, there is a product question.
For the maintainer
- No issue is linked, and I found no issue where we agreed on this feature. Under the community policy, a new
web()option needs agreement on an issue first. #954 and #958 deal with upload buttons and file choosers, which is a different problem. - I don't think we have an in-repo caller that hits the problem. The public
WebRoute(packages/web/src/browser.ts:80) exposespostDataas a string, and it has nofetch.continue()with no overrides already forwards the original body, file bytes included. Losing bytes requires raw Playwright throughsurfaceOf()plusroute.fetch()or a replayed body, which is exactly what the integration test does. Should we add an engine-wide mode for that consumer? - Playwright parity: Playwright solves this per call.
setInputFilesaccepts{ name, mimeType, buffer }payloads. Ourlocator.setInputFiles(packages/e2e/src/types.ts:540) only takes paths. If we want this at all, payload support onsetInputFilesis the Playwright-shaped primitive. The globalfileUploads: 'buffered'switch is not.
Must fix (if the feature is accepted)
upload-files.ts:67refuses any.pdffile that does not start with%PDF-. That check guesses validity from the file extension, and it breaks a common test: uploading a malformed PDF to check that the app rejects it. Your own unit testnot-a-pdf.pdfshows the refusal. Please remove it.upload-files.ts:43,48,61-63add a second file policy inside the engine: no symlinks, regular files only, and dev/ino/size/mtime/ctime compared across 3 stats. Core already decides which files may be uploaded (packages/e2e/src/agent/upload-paths.ts: inside the project root, symlinks resolved, regular files only). Path mode follows symlinks, so switching modes changes which files are allowed. Reading the file once and refusing it only when the byte count differs fromstat.sizeis enough.upload-files.ts:24uses one fixed message for count, size, symlink, changed file, PDF and I/O failures alike. A user has no way to tell which limit they hit. Paths stay out of observations if you name the cause without the path, e.g. "buffered upload exceeds 2000000 bytes" or "buffered upload allows at most 32 files".surface.ts:869-888plusactions.ts:109-110add a mutableuploadDispatchedclosure flag, anonUploadDispatchcallback threaded positionally throughdispatchLocatorAction, and a special case in the error classifier, all so that a timeout during preparation does not count asACTION_MAY_HAVE_COMMITTED. A simpler approach: prepare the payloads inperformbeforethis.guard(...), then pass the readyfilesto the action. A preparation failure then never enters the action guard, and the flag, the callback and the classifier branch can all go.surface.tsis already 1142 lines on main, so please don't add special cases to it.- The timeout budget is applied twice.
actions.ts:168wraps the work inwithConnectionBudget, andprepareUploadFileswraps it again atupload-files.ts:35. Keep one. Also drop themodeparameter and the'path'branch (upload-files.ts:33). The caller already branches on the mode, so that branch is reached only by tests, and dropping it also removes thestring[] | BufferedFile[]return union. upload-files.ts:74:handle.close().catch(() => { throw refused(); })insidefinallyreplaces the real error, and it fails an upload whose read already succeeded if only the close fails. Let close errors through, or ignore them.pnpm checkfails becausepackages/web/tests/types/upload-files.tsis never reached from an entry point (fallow reports it as an unused file). Add it toentryin.fallowrc.jsonnext to the otherpackages/web/tests/types/*files.- Integration tests: only the first case (
upload('buffered')) runs the engine change. I checked this by switching the engine back to path mode: that case failed and the other three still passed. ThenativeChoosercases callprepareUploadFilesandchooser.setFilesdirectly. The redirect case checks the test's ownroute.fetch({ maxRedirects: 0 }), which no code in this PR can affect. Please drive the cases throughsurface.perform, drop the redirect case, and write the shared setup as ordinary multi-line code instead of the 80-line function with boolean flags and several statements per line.
Nits
docs/reference/web.mdx:378-399describes Chromium internals, a "future native chooser implementation" and "redirect and request admission policy". Keep only what a user needs: what the option does, the limits, and thelastModifiedchange. Trim the setup.md row the same way.engine.ts:84validates inline. The other options usevalidate*helpers. Also,fileUploadswas added first inWEB_OPTION_KEYSandWebOptions, which reorders the existing unknown-key error message. Add it at the end.- Please name the 2,000,000-byte and 32-file limits in the docs, and say why those numbers. As written they look arbitrary.
This was an automated review.
|
Thanks for this I'm closing this because we're solving it per call instead of with an engine-wide mode. #1883 is adding in-memory payloads to If #1883 doesn't cover your case once it lands, please open an issue describing the test you're writing and we'll look at what's missing. |
web({ fileUploads: 'buffered' })for tests that inspect multipart request bytes before forwarding. Chromium can omit disk-backed file bytes from intercepted request bodies; replaying that body can truncate the upload.lastModifiedfollows Playwright's current-time behavior, documented as opt-in.The common preparation helper can also serve the preferred button-upload path in #958. This PR contains none of the closed #1386 chooser-node workflow. It grants no upload destination or mutation permission and changes no redirect policy.
Issue
Related to the native upload work in #954 and #958. This addresses the separate file-byte omission seen when a guarded caller inspects and replays multipart bodies.
Verified
Ran it locally: yes, deterministic Chromium and owned loopback HTTP, Playwright1.64.1 and Node24.19.0.
pnpm --filter @e2e-dev/web exec vitest run tests/unit/upload-files.test.ts tests/unit/actions.test.ts tests/unit/protected-app-options.test.ts tests/integration/buffered-upload.test.ts: 72 checks passed in independent review. The server verifies the selected binary file's exact bytes, name, size and SHA. The page receives200, and a307 response is not followed.These are native protocol and source checks, not a real-agent or production-application pass. Full CLI/testbed/benchmark and model verification have not run for this change; no model or production call was made. A separate real-agent loopback allocation is planned before any application opts in. The complete application upload failures remain retained.