Skip to content

test(puppeteer): upload test files from the Browser Run download directory - #264

Merged
ruifigueira merged 1 commit into
mainfrom
rfigueira/upload-download-dir
Nov 24, 2026
Merged

ruifigueira merged 1 commit into
mainfrom
rfigueira/upload-download-dir

Conversation

@ruifigueira

Copy link
Copy Markdown
Collaborator

Problem

The full test run on main failed in 5 input tests:

ProtocolError: Protocol error (DOM.setFileInputFiles): 'DOM.setFileInputFiles' only accepts files under /tmp/browser-run-downloads

Failed run: https://github.com/cloudflare/browser-run/actions/runs/45219961719/job/137852100909

Browser Run accepts DOM.setFileInputFiles paths only under /tmp/browser-run-downloads. The upstream input tests use client-side paths, so Browser Run refuses them.

Change

The test build (utils/generate_worker_tests.js) rewrites the paths in input.test.ts:

  • FILE_TO_UPLOAD becomes /tmp/browser-run-downloads/file-to-upload.txt.
  • path.relative(process.cwd(), FILE_TO_UPLOAD) becomes FILE_TO_UPLOAD, so the path stays absolute.
  • 'file-does-not-exist.txt' becomes /tmp/browser-run-downloads/file-does-not-exist.txt.

The files do not need to exist. These tests only check the name, type and events of the File that the page gets. They passed before with paths that did not exist in the browser container. The 2 tests that read the file contents stay in the skip list.

Tests fixed

  • ElementHandle.uploadFile > should upload the file
  • FileChooser.accept > should accept single file
  • FileChooser.accept > should be able to reset selected files with empty file list
  • FileChooser.accept > should succeed even for non-existent files
  • FileChooser.accept > should error on read of non-existent files

The other 5 tests in that run were flaky. Browser Run returned 410 Browser not running (state: unhealthy) and one test timed out. All 5 passed on retry. This PR does not change them.

beep-boop-🤖

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of dd42283c.

This review, of 865d4476

💬 Approved with comments — A clean, narrowly scoped test-build change. The only note is an optional suggestion about string rewrites that fail silently.

Findings: 1 suggestion (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 suggestion

One optional robustness note. The new plugin matches the pattern of the existing tracing plugin.

Recommendation: 💬 Optional Nits

  • [SUGGESTION] The .replace/.replaceAll rewrites in uploadDirectoryPlugin do nothing, and say nothing, if the upstream test text changes (packages/puppeteer-cloudflare/utils/generate_worker_tests.js:141)
View full review
  • packages/puppeteer-cloudflare/utils/generate_worker_tests.js:140-147: the first .replace matches an exact multi-line string, newlines and indentation included. If the upstream input.test.ts changes its formatting, the rewrite silently does nothing and the DOM.setFileInputFiles protocol error comes back, with no hint that the plugin is the cause. This is optional, because the tests would still fail visibly. tracingTempDirectoryPlugin works the same way.

✅ All other checks passed

🔒 Security: ✅ LGTM

The change only touches test-build tooling. It rewrites constant paths in input.test.ts and takes no external input.


📝 Documentation: ✅ LGTM

The inline comment explains why the plugin exists and why the files do not need to exist.


Reviewed commit: 865d4476

transform(code, id) {
if (!id.endsWith('/input.test.ts')) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💬 SUGGESTION · Code Quality

The .replace/.replaceAll rewrites in uploadDirectoryPlugin do nothing, and say nothing, if the upstream test text changes

This replacement matches an exact multi-line string, including newlines and two-space indentation. If upstream input.test.ts reformats the FILE_TO_UPLOAD declaration, nothing gets rewritten and the tests fail again with the DOM.setFileInputFiles protocol error, with no hint that this plugin is the cause. You could throw when the transformed code still contains '/../assets/file-to-upload.txt', or use a regex that tolerates whitespace, so that drift shows up at build time.

@ruifigueira ruifigueira Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

beep-boop-rui-agent-🤖 Fixed in cc553dc. Each rewrite in uploadDirectoryPlugin now throws if its pattern is not in input.test.ts. If upstream changes this text, the test build fails with the missing pattern.

I did not add the suggested check for '/../assets/file-to-upload.txt'. The upstream test "should not accept multiple files for single-file input" uses this path on purpose, so the check would always fail. A test with a changed pattern made the build fail with this message:

upload-directory: "'file-does-not-exist.txt'" not found in .../submodules/puppeteer/test/src/input.test.ts

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

@cloudflare/puppeteer preview for commit cc553dc

npm i https://pkg.pr.new/cloudflare/browser-run/@cloudflare/puppeteer@cc553dc13cbcc9ab99beae7f739d7ab885d92b36

Published by this workflow run. New pushes and reruns update this comment.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of cc553dc1.

This review, of dd42283c

✅ Approved — This is a small change to the test build only. The one earlier suggestion is fixed, and no new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

This only changes the test build tooling. It rewrites constant paths in a test file and takes no external input.


📋 Code Quality: ✅ LGTM

The earlier suggestion is resolved. Each rewrite in uploadDirectoryPlugin in packages/puppeteer-cloudflare/utils/generate_worker_tests.js now throws if its pattern is missing from input.test.ts. Not checking '/../assets/file-to-upload.txt' is reasonable, because an upstream test uses that path on purpose.


📝 Documentation: ✅ LGTM

The inline comments explain why the plugin exists and why it fails when a pattern is missing.


Reviewed commit: dd42283c

…ctory

Browser Run accepts DOM.setFileInputFiles paths only under
/tmp/browser-run-downloads. The input tests used client-side paths, so
5 tests failed with a protocol error.

The test build now rewrites the paths in input.test.ts to this
directory. The files do not need to exist. The tests only check the
name, type and events of the File that the page gets.

Each rewrite throws if its pattern is not in input.test.ts. If upstream
changes this text, the test build fails with the missing pattern.

beep-boop-🤖
@ruifigueira
ruifigueira force-pushed the rfigueira/upload-download-dir branch from dd42283 to cc553dc Compare November 24, 2026 09:16

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — This is a small change to the test build only. The one earlier suggestion is fixed, and no new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

This only changes the test build tooling. It rewrites constant paths in a test file and takes no external input.


📋 Code Quality: ✅ LGTM

The earlier suggestion is resolved. Each rewrite in uploadDirectoryPlugin in packages/puppeteer-cloudflare/utils/generate_worker_tests.js now throws if its pattern is missing from input.test.ts. Not checking '/../assets/file-to-upload.txt' is reasonable, because an upstream test uses that path on purpose.


📝 Documentation: ✅ LGTM

The inline comments explain why the plugin exists and why it fails when a pattern is missing.


Reviewed commit: cc553dc1 — same changes as dd42283c, so this is that commit's review (no new review was run; line numbers are as of dd42283c)

@ruifigueira
ruifigueira merged commit 9beba9b into main Nov 24, 2026
5 of 6 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.

1 participant