avyvar commited on
Commit
6083d40
·
verified ·
1 Parent(s): 8579f8a

Add Vite Selfbench 27-task evaluation (part 2)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. vite-pr-22269/solution/gold.patch +90 -0
  2. vite-pr-22269/solution/solve.sh +3 -0
  3. vite-pr-22269/task.toml +49 -0
  4. vite-pr-22269/tests/Dockerfile +42 -0
  5. vite-pr-22269/tests/repo.tar.gz +3 -0
  6. vite-pr-22269/tests/test.patch +53 -0
  7. vite-pr-22269/tests/test.sh +100 -0
  8. vite-server-port-zero/.selfbench-manifest.json +10 -0
  9. vite-server-port-zero/environment/Dockerfile +44 -0
  10. vite-server-port-zero/environment/repo.tar.gz +3 -0
  11. vite-server-port-zero/instruction.md +1 -0
  12. vite-server-port-zero/solution/gold.patch +104 -0
  13. vite-server-port-zero/solution/solve.sh +3 -0
  14. vite-server-port-zero/task.toml +49 -0
  15. vite-server-port-zero/tests/Dockerfile +42 -0
  16. vite-server-port-zero/tests/repo.tar.gz +3 -0
  17. vite-server-port-zero/tests/test.patch +30 -0
  18. vite-server-port-zero/tests/test.sh +100 -0
  19. vite-ssr-switch-case-scope/.selfbench-manifest.json +10 -0
  20. vite-ssr-switch-case-scope/environment/Dockerfile +44 -0
  21. vite-ssr-switch-case-scope/environment/repo.tar.gz +3 -0
  22. vite-ssr-switch-case-scope/instruction.md +3 -0
  23. vite-ssr-switch-case-scope/solution/gold.patch +59 -0
  24. vite-ssr-switch-case-scope/solution/solve.sh +3 -0
  25. vite-ssr-switch-case-scope/task.toml +49 -0
  26. vite-ssr-switch-case-scope/tests/Dockerfile +42 -0
  27. vite-ssr-switch-case-scope/tests/repo.tar.gz +3 -0
  28. vite-ssr-switch-case-scope/tests/test.patch +128 -0
  29. vite-ssr-switch-case-scope/tests/test.sh +100 -0
  30. vite-top-level-virtual-input/.selfbench-manifest.json +10 -0
  31. vite-top-level-virtual-input/environment/Dockerfile +44 -0
  32. vite-top-level-virtual-input/environment/repo.tar.gz +3 -0
  33. vite-top-level-virtual-input/instruction.md +1 -0
  34. vite-top-level-virtual-input/solution/gold.patch +271 -0
  35. vite-top-level-virtual-input/solution/solve.sh +3 -0
  36. vite-top-level-virtual-input/task.toml +49 -0
  37. vite-top-level-virtual-input/tests/Dockerfile +42 -0
  38. vite-top-level-virtual-input/tests/repo.tar.gz +3 -0
  39. vite-top-level-virtual-input/tests/test.patch +41 -0
  40. vite-top-level-virtual-input/tests/test.sh +100 -0
  41. vite-wasm-global-string-builtins/.selfbench-manifest.json +10 -0
  42. vite-wasm-global-string-builtins/environment/Dockerfile +44 -0
  43. vite-wasm-global-string-builtins/environment/repo.tar.gz +3 -0
  44. vite-wasm-global-string-builtins/instruction.md +3 -0
  45. vite-wasm-global-string-builtins/solution/gold.patch +307 -0
  46. vite-wasm-global-string-builtins/solution/solve.sh +3 -0
  47. vite-wasm-global-string-builtins/task.toml +49 -0
  48. vite-wasm-global-string-builtins/tests/Dockerfile +42 -0
  49. vite-wasm-global-string-builtins/tests/repo.tar.gz +3 -0
  50. vite-wasm-global-string-builtins/tests/test.patch +134 -0
vite-pr-22269/solution/gold.patch ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/server/environments/fullBundleEnvironment.ts b/packages/vite/src/node/server/environments/fullBundleEnvironment.ts
2
+ index 3f96a6428..4d5d86b0f 100644
3
+ --- a/packages/vite/src/node/server/environments/fullBundleEnvironment.ts
4
+ +++ b/packages/vite/src/node/server/environments/fullBundleEnvironment.ts
5
+ @@ -339,7 +339,16 @@ export class FullBundleDevEnvironment extends DevEnvironment {
6
+ code: typeof hmrOutput.code === 'string' ? '[code]' : hmrOutput.code,
7
+ })
8
+
9
+ - this.memoryFiles.set(hmrOutput.filename, { source: hmrOutput.code })
10
+ + this.memoryFiles.set(hmrOutput.filename, {
11
+ + // ensure that the generated hmr patch contains ESM syntax
12
+ + // this is to avoid attacks like GHSA-4v9v-hfq4-rm2v
13
+ + // https://github.com/webpack/webpack-dev-server/security/advisories/GHSA-4v9v-hfq4-rm2v
14
+ + // https://green.sapphi.red/blog/local-server-security-best-practices#_2-using-xssi-and-modifying-the-prototype
15
+ + // https://green.sapphi.red/blog/local-server-security-best-practices#properly-check-the-request-origin
16
+ + // we can also use `Cross-Origin Resource Policy` header instead of this
17
+ + // but we cannot use `Sec-Fetch-*` headers as they are only sent to potentially-trustworthy origins
18
+ + source: hmrOutput.code + '\n; export {}',
19
+ + })
20
+ if (hmrOutput.sourcemapFilename && hmrOutput.sourcemap) {
21
+ this.memoryFiles.set(hmrOutput.sourcemapFilename, {
22
+ source: hmrOutput.sourcemap,
23
+ diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts
24
+ index 1b2501b28..dc0b272bf 100644
25
+ --- a/packages/vite/src/node/server/index.ts
26
+ +++ b/packages/vite/src/node/server/index.ts
27
+ @@ -107,7 +107,6 @@ import type { DevEnvironment } from './environment'
28
+ import { hostValidationMiddleware } from './middlewares/hostCheck'
29
+ import { rejectInvalidRequestMiddleware } from './middlewares/rejectInvalidRequest'
30
+ import { memoryFilesMiddleware } from './middlewares/memoryFiles'
31
+ -import { rejectNoCorsRequestMiddleware } from './middlewares/rejectNoCorsRequest'
32
+
33
+ const usedConfigs = new WeakSet<ResolvedConfig>()
34
+
35
+ @@ -929,7 +928,6 @@ export async function _createServer(
36
+ }
37
+
38
+ middlewares.use(rejectInvalidRequestMiddleware())
39
+ - middlewares.use(rejectNoCorsRequestMiddleware())
40
+
41
+ // cors
42
+ const { cors } = serverConfig
43
+ diff --git a/packages/vite/src/node/server/middlewares/rejectNoCorsRequest.ts b/packages/vite/src/node/server/middlewares/rejectNoCorsRequest.ts
44
+ deleted file mode 100644
45
+ index a45de1748..000000000
46
+ --- a/packages/vite/src/node/server/middlewares/rejectNoCorsRequest.ts
47
+ +++ /dev/null
48
+ @@ -1,42 +0,0 @@
49
+ -import type { Connect } from '#dep-types/connect'
50
+ -
51
+ -/**
52
+ - * A middleware that rejects no-cors mode requests that are not same-origin.
53
+ - *
54
+ - * We should avoid untrusted sites to load the script to avoid attacks like GHSA-4v9v-hfq4-rm2v.
55
+ - * This is because:
56
+ - * - the path of HMR patch files / entry point files can be predictable
57
+ - * - the HMR patch files may not include ESM syntax
58
+ - * (if they include ESM syntax, loading as a classic script would fail)
59
+ - * - the HMR runtime in the browser has the list of all loaded modules
60
+ - *
61
+ - * https://github.com/webpack/webpack-dev-server/security/advisories/GHSA-4v9v-hfq4-rm2v
62
+ - * https://green.sapphi.red/blog/local-server-security-best-practices#_2-using-xssi-and-modifying-the-prototype
63
+ - * https://green.sapphi.red/blog/local-server-security-best-practices#properly-check-the-request-origin
64
+ - */
65
+ -export function rejectNoCorsRequestMiddleware(): Connect.NextHandleFunction {
66
+ - // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
67
+ - return function viteRejectNoCorsRequestMiddleware(req, res, next) {
68
+ - // While we can set Cross-Origin-Resource-Policy header instead of rejecting requests,
69
+ - // we choose to reject the request to be safer in case the request handler has any side-effects.
70
+ - if (
71
+ - req.headers['sec-fetch-mode'] === 'no-cors' &&
72
+ - req.headers['sec-fetch-site'] !== 'same-origin' &&
73
+ - // we only need to block classic script requests
74
+ - req.headers['sec-fetch-dest'] === 'script'
75
+ - ) {
76
+ - // Send a JavaScript code instead of 403 so that the error is shown in the devtools
77
+ - // If we send 403, the browser will avoid loading the body of the response
78
+ - // and just show "Failed to load" error without the detailed message.
79
+ - res.setHeader('Content-Type', 'text/javascript')
80
+ - res.end(
81
+ - `throw new Error(${JSON.stringify(
82
+ - '[Vite] Cross-origin requests for classic scripts must be made with CORS mode enabled.' +
83
+ - ' Make sure to set the "crossorigin" attribute on your <script> tag.',
84
+ - )});`,
85
+ - )
86
+ - return
87
+ - }
88
+ - return next()
89
+ - }
90
+ -}
vite-pr-22269/solution/solve.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ git -C /app apply --binary --whitespace=nowarn /solution/gold.patch
vite-pr-22269/task.toml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.4"
2
+ artifacts = ["/opt/selfbench/agent.patch"]
3
+
4
+ [task]
5
+ name = "selfbench/vite-pr-22269"
6
+ version = "1.0.0"
7
+ description = "Reproduce vite-pr-22269 from its authentic engineer request."
8
+ keywords = ["software-engineering", "private-swe", "selfbench", "medium"]
9
+
10
+ [metadata]
11
+ selfbench_task_id = "vite-pr-22269"
12
+ difficulty = "medium"
13
+ repo = "vitejs/vite"
14
+ base_commit = "3ec9cdaac7936ca32d0956c4cb1eb6e172945996"
15
+ workdir = "."
16
+ source_pr = 22269
17
+ compiler_revision = 23
18
+
19
+ [agent]
20
+ timeout_sec = 2400.0
21
+ user = "agent"
22
+ network_mode = "allowlist"
23
+ allowed_hosts = ["chatgpt.com", "*.chatgpt.com", "openai.com", "*.openai.com"]
24
+
25
+ [verifier]
26
+ timeout_sec = 1800.0
27
+ user = "root"
28
+ environment_mode = "separate"
29
+ network_mode = "public"
30
+
31
+ [[verifier.collect]]
32
+ service = "main"
33
+ user = "root"
34
+ timeout_sec = 300.0
35
+ command = "git --git-dir=/opt/selfbench/base.git --work-tree=/app add -A && git --git-dir=/opt/selfbench/base.git --work-tree=/app diff --cached --binary HEAD > /opt/selfbench/agent.patch"
36
+
37
+ [environment]
38
+ network_mode = "public"
39
+ build_timeout_sec = 1500.0
40
+ cpus = 4
41
+ memory_mb = 8192
42
+ storage_mb = 20480
43
+
44
+ [verifier.environment]
45
+ network_mode = "public"
46
+ build_timeout_sec = 1500.0
47
+ cpus = 4
48
+ memory_mb = 8192
49
+ storage_mb = 20480
vite-pr-22269/tests/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ COPY repo.tar.gz /tmp/repo.tar.gz
21
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
22
+ && git -C /app init -q \
23
+ && git -C /app config user.email selfbench@local \
24
+ && git -C /app config user.name selfbench \
25
+ && git -C /app add -A \
26
+ && git -C /app commit -qm base
27
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
28
+ && cd '/app/.' \
29
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.33.0 --activate && pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium && pnpm run build' \
30
+ && chmod -R a+rwX /opt/uv-cache
31
+
32
+ RUN useradd --create-home --shell /bin/bash verifier \
33
+ && chown -R verifier:verifier /app /opt/uv-cache \
34
+ && mkdir -p /opt/selfbench \
35
+ && chmod 700 /opt/selfbench \
36
+ && mkdir -p /home/verifier/.cache/uv \
37
+ && chown -R verifier:verifier /home/verifier/.cache
38
+ ENV UV_CACHE_DIR=/home/verifier/.cache/uv \
39
+ UV_NO_BUILD_ISOLATION=1
40
+ COPY test.patch test.sh /tests/
41
+ RUN chmod 700 /tests && chmod 600 /tests/test.patch && chmod +x /tests/test.sh
42
+ WORKDIR /app
vite-pr-22269/tests/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7293f9f3f608aa6bbc7daa076b9a778e9a1d8e309f4f222e8a155cf6f57e6196
3
+ size 12186692
vite-pr-22269/tests/test.patch ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/playground/fs-serve/__tests__/commonTests.ts b/playground/fs-serve/__tests__/commonTests.ts
2
+ index 06c58fae6..a5b3fb958 100644
3
+ --- a/playground/fs-serve/__tests__/commonTests.ts
4
+ +++ b/playground/fs-serve/__tests__/commonTests.ts
5
+ @@ -601,7 +601,7 @@ describe.runIf(!isServe)('preview HTML', () => {
6
+ })
7
+
8
+ test.runIf(isServe)(
9
+ - 'load script with no-cors mode from a different origin',
10
+ + 'serve regular scripts independently of cross-origin fetch metadata',
11
+ async () => {
12
+ const viteTestUrlUrl = new URL(viteTestUrl)
13
+
14
+ @@ -629,9 +629,7 @@ test.runIf(isServe)(
15
+ })
16
+ expect(res.statusCode).toBe(200)
17
+ const body = Buffer.concat(await ArrayFromAsync(res)).toString()
18
+ - expect(body).toContain(
19
+ - 'Cross-origin requests for classic scripts must be made with CORS mode enabled.',
20
+ - )
21
+ + expect(body).toContain('// code.js')
22
+ },
23
+ )
24
+
25
+ diff --git a/playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts b/playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts
26
+ index 0c78cb863..99dbdc527 100644
27
+ --- a/playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts
28
+ +++ b/playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts
29
+ @@ -95,14 +95,20 @@ if (isBuild) {
30
+ // BUNDLED -> GENERATING_HMR_PATCH -> BUNDLED
31
+ test('generate hmr patch', async () => {
32
+ await expect.poll(() => page.textContent('.hmr')).toBe('hello')
33
+ + const hmrPatchFileRes = page.waitForResponse(/\/hmr_patch_\d\.js$/)
34
+ editFile('hmr.js', (code) =>
35
+ code.replace("const foo = 'hello'", "const foo = 'hello1'"),
36
+ )
37
+ - await expect.poll(() => page.textContent('.hmr')).toBe('hello1')
38
+ + try {
39
+ + await expect.poll(() => page.textContent('.hmr')).toBe('hello1')
40
+
41
+ - editFile('hmr.js', (code) =>
42
+ - code.replace("const foo = 'hello1'", "const foo = 'hello'"),
43
+ - )
44
+ + const hmrPatch = await (await hmrPatchFileRes).text()
45
+ + expect(() => Function(hmrPatch)).toThrow(SyntaxError)
46
+ + } finally {
47
+ + editFile('hmr.js', (code) =>
48
+ + code.replace("const foo = 'hello1'", "const foo = 'hello'"),
49
+ + )
50
+ + }
51
+ await expect.poll(() => page.textContent('.hmr')).toContain('hello')
52
+ await expect.poll(() => page.textContent('.asset')).toMatch(assetUrl)
53
+ })
vite-pr-22269/tests/test.sh ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -uo pipefail
3
+ mkdir -p /logs/verifier
4
+ patch_applied=1
5
+ fail_to_pass=0
6
+ pass_to_pass=0
7
+ deterministic=0
8
+ setup_completed=0
9
+ fail_to_pass_exit_code=-1
10
+ fail_to_pass_repeat_exit_code=-1
11
+ pass_to_pass_exit_code=-1
12
+ verifier_cache=""
13
+
14
+ kill_verifier_processes() { pkill -KILL -u "$(id -u verifier)" 2>/dev/null || true; }
15
+ # Some toolchains fetch dependencies at test runtime (e.g. Next.js e2e installs),
16
+ # so a single registry connection reset must not be misread as a dead test. Retry
17
+ # only infrastructure-style failures with backoff; real assertion failures fail fast.
18
+ run_verifier_command() {
19
+ local logfile
20
+ logfile="$(mktemp /tmp/selfbench-verifier-command-XXXXXX.log)"
21
+ local attempt=1
22
+ local status=1
23
+ while [ "$attempt" -le 3 ]; do
24
+ : > "$logfile"
25
+ runuser -u verifier -- env PATH="/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" UV_CACHE_DIR="$verifier_cache" UV_NO_BUILD_ISOLATION=1 bash -lc "$1" >"$logfile" 2>&1
26
+ status=$?
27
+ if [ "$status" -eq 0 ]; then
28
+ break
29
+ fi
30
+ if [ "$attempt" -lt 3 ] && grep -qE 'ECONNRESET|ETIMEDOUT|ESOCKETTIMEDOUT|ENOTFOUND|EAI_AGAIN|META_FETCH_FAIL|FetchError|EPIPE|EPERM|registry\.npmjs' "$logfile"; then
31
+ sleep "$((10 * attempt))"
32
+ attempt=$((attempt + 1))
33
+ continue
34
+ fi
35
+ break
36
+ done
37
+ cat "$logfile"
38
+ rm -f "$logfile"
39
+ kill_verifier_processes
40
+ return "$status"
41
+ }
42
+ protect_held_out_path() {
43
+ local path="$1"
44
+ chown -R root:root -- "$path"
45
+ chmod -R a-w,go+rX -- "$path"
46
+ }
47
+
48
+ if [ ! -f /opt/selfbench/agent.patch ]; then
49
+ patch_applied=0
50
+ elif [ -s /opt/selfbench/agent.patch ]; then
51
+ git -C /app apply --binary --whitespace=nowarn --exclude='playground/fs-serve/__tests__/commonTests.ts' --exclude='playground/fs-serve/__tests__/commonTests.ts/*' --exclude='playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts' --exclude='playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts/*' /opt/selfbench/agent.patch || patch_applied=0
52
+ fi
53
+
54
+ if [ "$patch_applied" -eq 1 ]; then setup_completed=1; fi
55
+
56
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
57
+ kill_verifier_processes
58
+ for protected_path in 'playground/fs-serve/__tests__/commonTests.ts' 'playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts'; do
59
+ git -C /app restore --source=HEAD --staged --worktree -- "$protected_path" 2>/dev/null || true
60
+ git -C /app clean -fd -- "$protected_path" >/dev/null 2>&1 || true
61
+ done
62
+ git -C /app apply --binary --whitespace=nowarn /tests/test.patch || patch_applied=0
63
+ if [ "$patch_applied" -eq 1 ]; then
64
+ for protected_path in '/app/playground/fs-serve/__tests__/commonTests.ts' '/app/playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts'; do protect_held_out_path "$protected_path"; done
65
+ fi
66
+ rm -f /tests/test.patch
67
+ fi
68
+
69
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
70
+ cd '/app/.'
71
+ verifier_cache="$(mktemp -d /tmp/selfbench-verifier-uv-XXXXXX)"
72
+ cp -a /opt/uv-cache/. "$verifier_cache"/
73
+ chown -R verifier:verifier "$verifier_cache"
74
+ if run_verifier_command 'pnpm --filter vite run build-bundle && CI=1 pnpm run test-serve '"'"'playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts'"'"' '"'"'playground/fs-serve/__tests__/fs-serve.spec.ts'"'"''; then
75
+ fail_to_pass_exit_code=0
76
+ fail_to_pass=1
77
+ if run_verifier_command 'pnpm --filter vite run build-bundle && CI=1 pnpm run test-serve '"'"'playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts'"'"' '"'"'playground/fs-serve/__tests__/fs-serve.spec.ts'"'"''; then
78
+ fail_to_pass_repeat_exit_code=0
79
+ deterministic=1
80
+ else
81
+ fail_to_pass_repeat_exit_code=$?
82
+ fi
83
+ else
84
+ fail_to_pass_exit_code=$?
85
+ fi
86
+ if run_verifier_command 'pnpm --filter vite run build-bundle && CI=1 pnpm run test-serve '"'"'playground/assets-sanitize/__tests__/assets-sanitize.spec.ts'"'"''; then
87
+ pass_to_pass_exit_code=0
88
+ pass_to_pass=1
89
+ else
90
+ pass_to_pass_exit_code=$?
91
+ fi
92
+ rm -rf "$verifier_cache"
93
+ fi
94
+
95
+ reward=0
96
+ if [ "$patch_applied" -eq 1 ] && [ "$fail_to_pass" -eq 1 ] && [ "$pass_to_pass" -eq 1 ] && [ "$deterministic" -eq 1 ]; then reward=1; fi
97
+ cat > /logs/verifier/reward.json <<EOF
98
+ {"reward": $reward, "patch_applied": $patch_applied, "fail_to_pass": $fail_to_pass, "pass_to_pass": $pass_to_pass, "deterministic": $deterministic, "setup_completed": $setup_completed, "fail_to_pass_exit_code": $fail_to_pass_exit_code, "fail_to_pass_repeat_exit_code": $fail_to_pass_repeat_exit_code, "pass_to_pass_exit_code": $pass_to_pass_exit_code}
99
+ EOF
100
+ exit 0
vite-server-port-zero/.selfbench-manifest.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "generator": "selfbench",
3
+ "harborSchemaVersion": "1.4",
4
+ "compilerRevision": 23,
5
+ "taskId": "vite-server-port-zero",
6
+ "difficulty": "medium",
7
+ "definitionSha256": "f755005680ad7bfc2b439b24eba0b80c9f140b4afd69929d263d1cef1d8dd4d1",
8
+ "testPatchSha256": "957593f423db7a3a8cee81c45f55fcde423ffa34a2424f4294f18b73046f84dc",
9
+ "goldPatchSha256": "cb6329926fa06bf883fbe5108f4240e4c39efafeadbfa709e06b53bc51350b0d"
10
+ }
vite-server-port-zero/environment/Dockerfile ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ RUN useradd --create-home --shell /bin/bash agent
21
+ COPY repo.tar.gz /tmp/repo.tar.gz
22
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
23
+ && git -C /app init -q \
24
+ && git -C /app config user.email selfbench@local \
25
+ && git -C /app config user.name selfbench \
26
+ && git -C /app add -A \
27
+ && git -C /app commit -qm base
28
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
29
+ && cd '/app/.' \
30
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
31
+ && chmod -R a+rwX /opt/uv-cache
32
+ RUN git -C /app reset --hard -q HEAD \
33
+ && git -C /app clean -fdq \
34
+ && mkdir -p /opt/selfbench \
35
+ && cp -a /app/.git /opt/selfbench/base.git \
36
+ && chown -R agent:agent /app /home/agent /opt/uv-cache \
37
+ && chown -R root:root /opt/selfbench \
38
+ && chmod 700 /opt/selfbench \
39
+ && mkdir -p /home/agent/.cache/uv \
40
+ && chown -R agent:agent /home/agent/.cache
41
+ ENV UV_CACHE_DIR=/home/agent/.cache/uv \
42
+ UV_NO_BUILD_ISOLATION=1
43
+ USER agent
44
+ WORKDIR /app
vite-server-port-zero/environment/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c855310633b921fccc94a22085529a152071c2f0e25fdcf6c23e62defd19107f
3
+ size 12917035
vite-server-port-zero/instruction.md ADDED
@@ -0,0 +1 @@
 
 
1
+ Fix the dev server so `server.port = 0` retains Node's standard meaning. Starting a server with a numeric zero must ask the OS for an available ephemeral port instead of treating the value as missing and substituting Vite's default port. This must work through the public `createServer`/`listen` flow even when `strictPort` is enabled and the normal default port is occupied. After listening, consumers must be able to read the actual assigned non-zero port from the server's existing public HTTP server interface. Keep behavior for omitted ports and explicit non-zero ports unchanged, including current fallback and strict-port semantics.
vite-server-port-zero/solution/gold.patch ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts
2
+ index cc83504d3..50bb5ee88 100644
3
+ --- a/packages/vite/src/node/http.ts
4
+ +++ b/packages/vite/src/node/http.ts
5
+ @@ -164,6 +164,31 @@ async function readFileIfExists(value?: string | Buffer | any[]) {
6
+ return value
7
+ }
8
+
9
+ +// Let the OS select an ephemeral port on the first wildcard interface, then
10
+ +// verify that same concrete port is available on every remaining interface.
11
+ +async function getAvailableEphemeralPort(
12
+ + specifiedHost: string | undefined,
13
+ +): Promise<number | null> {
14
+ + for (let attempt = 0; attempt < 3; attempt++) {
15
+ + // Passing 0 asks the OS for a new candidate on every attempt.
16
+ + // We assume that the OS will return a different candidate on every attempt,
17
+ + // which does not always hold true, but it should be fine for most cases.
18
+ + let port = 0
19
+ + let available = true
20
+ + for (const host of [...wildcardHosts, specifiedHost]) {
21
+ + // Gracefully handle errors (e.g., IPv6 disabled on the system)
22
+ + const availablePort = await tryListen(port, host).catch(() => port)
23
+ + if (availablePort == null) {
24
+ + available = false
25
+ + break
26
+ + }
27
+ + port = availablePort
28
+ + }
29
+ + if (available) return port
30
+ + }
31
+ + return null
32
+ +}
33
+ +
34
+ // Check if a port is available on wildcard addresses (0.0.0.0, ::)
35
+ async function isPortAvailable(port: number): Promise<boolean> {
36
+ for (const host of wildcardHosts) {
37
+ @@ -174,14 +199,20 @@ async function isPortAvailable(port: number): Promise<boolean> {
38
+ return true
39
+ }
40
+
41
+ -function tryListen(port: number, host: string): Promise<boolean> {
42
+ +function tryListen(
43
+ + port: number,
44
+ + host: string | undefined,
45
+ +): Promise<number | null> {
46
+ return new Promise((resolve) => {
47
+ const server = net.createServer()
48
+ server.once('error', (e: NodeJS.ErrnoException) => {
49
+ - server.close(() => resolve(e.code !== 'EADDRINUSE'))
50
+ + server.close(() => resolve(e.code === 'EADDRINUSE' ? null : port))
51
+ })
52
+ server.once('listening', () => {
53
+ - server.close(() => resolve(true))
54
+ + const address = server.address()
55
+ + server.close(() =>
56
+ + resolve(typeof address === 'object' && address ? address.port : port),
57
+ + )
58
+ })
59
+ server.listen(port, host)
60
+ })
61
+ @@ -226,6 +257,23 @@ export async function httpServerStart(
62
+ ): Promise<number> {
63
+ const { port: startPort, strictPort, host, logger } = serverOptions
64
+
65
+ + if (startPort === 0) {
66
+ + const port = await getAvailableEphemeralPort(host)
67
+ + if (port == null) {
68
+ + throw new Error('No available ephemeral port found')
69
+ + }
70
+ +
71
+ + const result = await tryBindServer(httpServer, port, host)
72
+ + if (result.success) {
73
+ + return port
74
+ + }
75
+ + if (result.error.code !== 'EADDRINUSE') {
76
+ + throw result.error
77
+ + }
78
+ + // this can happen if the port was listened by other process between getAvailableEphemeralPort and tryBindServer
79
+ + throw new Error(`Port ${port} is already in use`)
80
+ + }
81
+ +
82
+ for (let port = startPort; port <= MAX_PORT; port++) {
83
+ // Pre-check port availability on wildcard addresses (0.0.0.0, ::)
84
+ // so that we avoid conflicts with other servers listening on all interfaces
85
+ diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts
86
+ index 84a8d567a..2dd71aa85 100644
87
+ --- a/packages/vite/src/node/server/index.ts
88
+ +++ b/packages/vite/src/node/server/index.ts
89
+ @@ -1110,11 +1110,11 @@ async function startServer(
90
+ const configPort = inlinePort ?? options.port
91
+ // When using non strict port for the dev server, the running port can be different from the config one.
92
+ // When restarting, the original port may be available but to avoid a switch of URL for the running
93
+ - // browser tabs, we enforce the previously used port, expect if the config port changed.
94
+ + // browser tabs, we enforce the previously used port, except if the config port changed.
95
+ const port =
96
+ - (!configPort || configPort === server._configServerPort
97
+ - ? server._currentServerPort
98
+ - : configPort) ?? DEFAULT_DEV_PORT
99
+ + configPort === server._configServerPort
100
+ + ? (server._currentServerPort ?? configPort)
101
+ + : configPort
102
+ server._configServerPort = configPort
103
+
104
+ const serverPort = await httpServerStart(httpServer, {
vite-server-port-zero/solution/solve.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ git -C /app apply --binary --whitespace=nowarn /solution/gold.patch
vite-server-port-zero/task.toml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.4"
2
+ artifacts = ["/opt/selfbench/agent.patch"]
3
+
4
+ [task]
5
+ name = "selfbench/vite-server-port-zero"
6
+ version = "1.0.0"
7
+ description = "Reproduce vite-server-port-zero from its authentic engineer request."
8
+ keywords = ["software-engineering", "private-swe", "selfbench", "medium"]
9
+
10
+ [metadata]
11
+ selfbench_task_id = "vite-server-port-zero"
12
+ difficulty = "medium"
13
+ repo = "vitejs/vite"
14
+ base_commit = "16944824fd5fae014101737ec0029ab6a58e774b"
15
+ workdir = "."
16
+ source_pr = 23158
17
+ compiler_revision = 23
18
+
19
+ [agent]
20
+ timeout_sec = 2400.0
21
+ user = "agent"
22
+ network_mode = "allowlist"
23
+ allowed_hosts = ["chatgpt.com", "*.chatgpt.com", "openai.com", "*.openai.com"]
24
+
25
+ [verifier]
26
+ timeout_sec = 1800.0
27
+ user = "root"
28
+ environment_mode = "separate"
29
+ network_mode = "public"
30
+
31
+ [[verifier.collect]]
32
+ service = "main"
33
+ user = "root"
34
+ timeout_sec = 300.0
35
+ command = "git --git-dir=/opt/selfbench/base.git --work-tree=/app add -A && git --git-dir=/opt/selfbench/base.git --work-tree=/app diff --cached --binary HEAD > /opt/selfbench/agent.patch"
36
+
37
+ [environment]
38
+ network_mode = "public"
39
+ build_timeout_sec = 1500.0
40
+ cpus = 4
41
+ memory_mb = 8192
42
+ storage_mb = 20480
43
+
44
+ [verifier.environment]
45
+ network_mode = "public"
46
+ build_timeout_sec = 1500.0
47
+ cpus = 4
48
+ memory_mb = 8192
49
+ storage_mb = 20480
vite-server-port-zero/tests/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ COPY repo.tar.gz /tmp/repo.tar.gz
21
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
22
+ && git -C /app init -q \
23
+ && git -C /app config user.email selfbench@local \
24
+ && git -C /app config user.name selfbench \
25
+ && git -C /app add -A \
26
+ && git -C /app commit -qm base
27
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
28
+ && cd '/app/.' \
29
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
30
+ && chmod -R a+rwX /opt/uv-cache
31
+
32
+ RUN useradd --create-home --shell /bin/bash verifier \
33
+ && chown -R verifier:verifier /app /opt/uv-cache \
34
+ && mkdir -p /opt/selfbench \
35
+ && chmod 700 /opt/selfbench \
36
+ && mkdir -p /home/verifier/.cache/uv \
37
+ && chown -R verifier:verifier /home/verifier/.cache
38
+ ENV UV_CACHE_DIR=/home/verifier/.cache/uv \
39
+ UV_NO_BUILD_ISOLATION=1
40
+ COPY test.patch test.sh /tests/
41
+ RUN chmod 700 /tests && chmod 600 /tests/test.patch && chmod +x /tests/test.sh
42
+ WORKDIR /app
vite-server-port-zero/tests/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c855310633b921fccc94a22085529a152071c2f0e25fdcf6c23e62defd19107f
3
+ size 12917035
vite-server-port-zero/tests/test.patch ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/__tests__/http.spec.ts b/packages/vite/src/node/__tests__/http.spec.ts
2
+ index 94ab9b6e8..fa1b646e5 100644
3
+ --- a/packages/vite/src/node/__tests__/http.spec.ts
4
+ +++ b/packages/vite/src/node/__tests__/http.spec.ts
5
+ @@ -48,6 +48,25 @@ describe('port detection', () => {
6
+ }
7
+
8
+ describe('port fallback', () => {
9
+ + test('uses an OS-assigned port when configured with port 0', async () => {
10
+ + await using _defaultPortServer = await createSimpleServer(
11
+ + 5173,
12
+ + 'localhost',
13
+ + )
14
+ +
15
+ + viteServer = await createServer({
16
+ + root: import.meta.dirname,
17
+ + optimizeDeps,
18
+ + logLevel: 'silent',
19
+ + server: { port: 0, strictPort: true, ws: false },
20
+ + })
21
+ + await viteServer.listen()
22
+ +
23
+ + const address = viteServer.httpServer!.address() as net.AddressInfo
24
+ + expect(address.port).toBeGreaterThan(0)
25
+ + expect(address.port).not.toBe(5173)
26
+ + })
27
+ +
28
+ test('detects port conflict', async () => {
29
+ await using _blockingServer = await createSimpleServer(
30
+ BASE_PORT,
vite-server-port-zero/tests/test.sh ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -uo pipefail
3
+ mkdir -p /logs/verifier
4
+ patch_applied=1
5
+ fail_to_pass=0
6
+ pass_to_pass=0
7
+ deterministic=0
8
+ setup_completed=0
9
+ fail_to_pass_exit_code=-1
10
+ fail_to_pass_repeat_exit_code=-1
11
+ pass_to_pass_exit_code=-1
12
+ verifier_cache=""
13
+
14
+ kill_verifier_processes() { pkill -KILL -u "$(id -u verifier)" 2>/dev/null || true; }
15
+ # Some toolchains fetch dependencies at test runtime (e.g. Next.js e2e installs),
16
+ # so a single registry connection reset must not be misread as a dead test. Retry
17
+ # only infrastructure-style failures with backoff; real assertion failures fail fast.
18
+ run_verifier_command() {
19
+ local logfile
20
+ logfile="$(mktemp /tmp/selfbench-verifier-command-XXXXXX.log)"
21
+ local attempt=1
22
+ local status=1
23
+ while [ "$attempt" -le 3 ]; do
24
+ : > "$logfile"
25
+ runuser -u verifier -- env PATH="/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" UV_CACHE_DIR="$verifier_cache" UV_NO_BUILD_ISOLATION=1 bash -lc "$1" >"$logfile" 2>&1
26
+ status=$?
27
+ if [ "$status" -eq 0 ]; then
28
+ break
29
+ fi
30
+ if [ "$attempt" -lt 3 ] && grep -qE 'ECONNRESET|ETIMEDOUT|ESOCKETTIMEDOUT|ENOTFOUND|EAI_AGAIN|META_FETCH_FAIL|FetchError|EPIPE|EPERM|registry\.npmjs' "$logfile"; then
31
+ sleep "$((10 * attempt))"
32
+ attempt=$((attempt + 1))
33
+ continue
34
+ fi
35
+ break
36
+ done
37
+ cat "$logfile"
38
+ rm -f "$logfile"
39
+ kill_verifier_processes
40
+ return "$status"
41
+ }
42
+ protect_held_out_path() {
43
+ local path="$1"
44
+ chown -R root:root -- "$path"
45
+ chmod -R a-w,go+rX -- "$path"
46
+ }
47
+
48
+ if [ ! -f /opt/selfbench/agent.patch ]; then
49
+ patch_applied=0
50
+ elif [ -s /opt/selfbench/agent.patch ]; then
51
+ git -C /app apply --binary --whitespace=nowarn --exclude='packages/vite/src/node/__tests__/http.spec.ts' --exclude='packages/vite/src/node/__tests__/http.spec.ts/*' /opt/selfbench/agent.patch || patch_applied=0
52
+ fi
53
+
54
+ if [ "$patch_applied" -eq 1 ]; then setup_completed=1; fi
55
+
56
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
57
+ kill_verifier_processes
58
+ for protected_path in 'packages/vite/src/node/__tests__/http.spec.ts'; do
59
+ git -C /app restore --source=HEAD --staged --worktree -- "$protected_path" 2>/dev/null || true
60
+ git -C /app clean -fd -- "$protected_path" >/dev/null 2>&1 || true
61
+ done
62
+ git -C /app apply --binary --whitespace=nowarn /tests/test.patch || patch_applied=0
63
+ if [ "$patch_applied" -eq 1 ]; then
64
+ for protected_path in '/app/packages/vite/src/node/__tests__/http.spec.ts'; do protect_held_out_path "$protected_path"; done
65
+ fi
66
+ rm -f /tests/test.patch
67
+ fi
68
+
69
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
70
+ cd '/app/.'
71
+ verifier_cache="$(mktemp -d /tmp/selfbench-verifier-uv-XXXXXX)"
72
+ cp -a /opt/uv-cache/. "$verifier_cache"/
73
+ chown -R verifier:verifier "$verifier_cache"
74
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/http.spec.ts'"'"''; then
75
+ fail_to_pass_exit_code=0
76
+ fail_to_pass=1
77
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/http.spec.ts'"'"''; then
78
+ fail_to_pass_repeat_exit_code=0
79
+ deterministic=1
80
+ else
81
+ fail_to_pass_repeat_exit_code=$?
82
+ fi
83
+ else
84
+ fail_to_pass_exit_code=$?
85
+ fi
86
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/constants.spec.ts'"'"''; then
87
+ pass_to_pass_exit_code=0
88
+ pass_to_pass=1
89
+ else
90
+ pass_to_pass_exit_code=$?
91
+ fi
92
+ rm -rf "$verifier_cache"
93
+ fi
94
+
95
+ reward=0
96
+ if [ "$patch_applied" -eq 1 ] && [ "$fail_to_pass" -eq 1 ] && [ "$pass_to_pass" -eq 1 ] && [ "$deterministic" -eq 1 ]; then reward=1; fi
97
+ cat > /logs/verifier/reward.json <<EOF
98
+ {"reward": $reward, "patch_applied": $patch_applied, "fail_to_pass": $fail_to_pass, "pass_to_pass": $pass_to_pass, "deterministic": $deterministic, "setup_completed": $setup_completed, "fail_to_pass_exit_code": $fail_to_pass_exit_code, "fail_to_pass_repeat_exit_code": $fail_to_pass_repeat_exit_code, "pass_to_pass_exit_code": $pass_to_pass_exit_code}
99
+ EOF
100
+ exit 0
vite-ssr-switch-case-scope/.selfbench-manifest.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "generator": "selfbench",
3
+ "harborSchemaVersion": "1.4",
4
+ "compilerRevision": 23,
5
+ "taskId": "vite-ssr-switch-case-scope",
6
+ "difficulty": "easy",
7
+ "definitionSha256": "1dc1ec1e4e9867a17dd44a2612da5f896aa483d65f66164326ae02654a287b31",
8
+ "testPatchSha256": "732a386380eec3d419ae04138735e75e90c91f6ad0bb29e652c95b3a80e83f21",
9
+ "goldPatchSha256": "ade5242b0f79481a7f4e40a6b7392e90ac0ed41b1811864b6e3a391f435c9ca7"
10
+ }
vite-ssr-switch-case-scope/environment/Dockerfile ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ RUN useradd --create-home --shell /bin/bash agent
21
+ COPY repo.tar.gz /tmp/repo.tar.gz
22
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
23
+ && git -C /app init -q \
24
+ && git -C /app config user.email selfbench@local \
25
+ && git -C /app config user.name selfbench \
26
+ && git -C /app add -A \
27
+ && git -C /app commit -qm base
28
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
29
+ && cd '/app/.' \
30
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
31
+ && chmod -R a+rwX /opt/uv-cache
32
+ RUN git -C /app reset --hard -q HEAD \
33
+ && git -C /app clean -fdq \
34
+ && mkdir -p /opt/selfbench \
35
+ && cp -a /app/.git /opt/selfbench/base.git \
36
+ && chown -R agent:agent /app /home/agent /opt/uv-cache \
37
+ && chown -R root:root /opt/selfbench \
38
+ && chmod 700 /opt/selfbench \
39
+ && mkdir -p /home/agent/.cache/uv \
40
+ && chown -R agent:agent /home/agent/.cache
41
+ ENV UV_CACHE_DIR=/home/agent/.cache/uv \
42
+ UV_NO_BUILD_ISOLATION=1
43
+ USER agent
44
+ WORKDIR /app
vite-ssr-switch-case-scope/environment/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:868cc9ca3631190662a4a6746c19e3e754426a60a267d3cf5e3301959adb7b30
3
+ size 12876284
vite-ssr-switch-case-scope/instruction.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Fix SSR import rewriting around JavaScript `switch` statements. When a case declares a binding directly in its body with the same name as an import, that declaration must obey module lexical scoping rather than making the import appear shadowed across the enclosing function.
2
+
3
+ Imported references before the switch, in the switch discriminant, from closures defined outside the switch, and after the switch must continue to resolve to the import. References within the switch that resolve to a case declaration must remain local, and all cases must share JavaScript's standard switch lexical environment, including temporal-dead-zone behavior. Cover lexical variable declarations as well as function and class declarations written directly in a case without additional braces, while preserving existing SSR transformation behavior.
vite-ssr-switch-case-scope/solution/gold.patch ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts
2
+ index 8ebaa63e8..65a5c67da 100644
3
+ --- a/packages/vite/src/node/ssr/ssrTransform.ts
4
+ +++ b/packages/vite/src/node/ssr/ssrTransform.ts
5
+ @@ -537,12 +537,8 @@ function walk(
6
+ onStatements(node.consequent)
7
+ }
8
+
9
+ - // track parent stack, skip for "else-if"/"else" branches as acorn nests
10
+ - // the ast within "if" nodes instead of flattening them
11
+ - if (
12
+ - parent &&
13
+ - !(parent.type === 'IfStatement' && node === parent.alternate)
14
+ - ) {
15
+ + // track parent stack
16
+ + if (parent && !isSkippedParent(node, parent)) {
17
+ parentStack.unshift(parent)
18
+ }
19
+
20
+ @@ -638,10 +634,7 @@ function walk(
21
+
22
+ leave(node: ESTree.Node, parent: ESTree.Node | null) {
23
+ // untrack parent stack from above
24
+ - if (
25
+ - parent &&
26
+ - !(parent.type === 'IfStatement' && node === parent.alternate)
27
+ - ) {
28
+ + if (parent && !isSkippedParent(node, parent)) {
29
+ parentStack.shift()
30
+ }
31
+
32
+ @@ -779,11 +772,26 @@ type FunctionNodes = ESTree.Node & {
33
+ | `${string}Function${'Expression' | 'Declaration'}`
34
+ | `${string}Method`
35
+ }
36
+ +/**
37
+ + * Children that must not see `parent` as an enclosing scope:
38
+ + * - "else-if"/"else" branches, as acorn nests the ast within "if" nodes
39
+ + * instead of flattening them.
40
+ + * - a `switch` discriminant, which is evaluated outside the case block:
41
+ + * in `switch (x) { case 1: let x }`, `x` is the outer binding.
42
+ + */
43
+ +function isSkippedParent(node: ESTree.Node, parent: ESTree.Node) {
44
+ + return (
45
+ + (parent.type === 'IfStatement' && node === parent.alternate) ||
46
+ + (parent.type === 'SwitchStatement' && node === parent.discriminant)
47
+ + )
48
+ +}
49
+ +
50
+ function isFunction(node: ESTree.Node): node is FunctionNodes {
51
+ return functionNodeTypeRE.test(node.type)
52
+ }
53
+
54
+ -const blockNodeTypeRE = /^BlockStatement$|^For(?:In|Of)?Statement$/
55
+ +const blockNodeTypeRE =
56
+ + /^BlockStatement$|^SwitchStatement$|^For(?:In|Of)?Statement$/
57
+ function isBlock(node: ESTree.Node) {
58
+ return blockNodeTypeRE.test(node.type)
59
+ }
vite-ssr-switch-case-scope/solution/solve.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ git -C /app apply --binary --whitespace=nowarn /solution/gold.patch
vite-ssr-switch-case-scope/task.toml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.4"
2
+ artifacts = ["/opt/selfbench/agent.patch"]
3
+
4
+ [task]
5
+ name = "selfbench/vite-ssr-switch-case-scope"
6
+ version = "1.0.0"
7
+ description = "Reproduce vite-ssr-switch-case-scope from its authentic engineer request."
8
+ keywords = ["software-engineering", "private-swe", "selfbench", "easy"]
9
+
10
+ [metadata]
11
+ selfbench_task_id = "vite-ssr-switch-case-scope"
12
+ difficulty = "easy"
13
+ repo = "vitejs/vite"
14
+ base_commit = "4bfe8bb0344a21d25134d8db06f3a8ae4a8ad69d"
15
+ workdir = "."
16
+ source_pr = 22893
17
+ compiler_revision = 23
18
+
19
+ [agent]
20
+ timeout_sec = 2400.0
21
+ user = "agent"
22
+ network_mode = "allowlist"
23
+ allowed_hosts = ["chatgpt.com", "*.chatgpt.com", "openai.com", "*.openai.com"]
24
+
25
+ [verifier]
26
+ timeout_sec = 1800.0
27
+ user = "root"
28
+ environment_mode = "separate"
29
+ network_mode = "public"
30
+
31
+ [[verifier.collect]]
32
+ service = "main"
33
+ user = "root"
34
+ timeout_sec = 300.0
35
+ command = "git --git-dir=/opt/selfbench/base.git --work-tree=/app add -A && git --git-dir=/opt/selfbench/base.git --work-tree=/app diff --cached --binary HEAD > /opt/selfbench/agent.patch"
36
+
37
+ [environment]
38
+ network_mode = "public"
39
+ build_timeout_sec = 1500.0
40
+ cpus = 4
41
+ memory_mb = 8192
42
+ storage_mb = 20480
43
+
44
+ [verifier.environment]
45
+ network_mode = "public"
46
+ build_timeout_sec = 1500.0
47
+ cpus = 4
48
+ memory_mb = 8192
49
+ storage_mb = 20480
vite-ssr-switch-case-scope/tests/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ COPY repo.tar.gz /tmp/repo.tar.gz
21
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
22
+ && git -C /app init -q \
23
+ && git -C /app config user.email selfbench@local \
24
+ && git -C /app config user.name selfbench \
25
+ && git -C /app add -A \
26
+ && git -C /app commit -qm base
27
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
28
+ && cd '/app/.' \
29
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
30
+ && chmod -R a+rwX /opt/uv-cache
31
+
32
+ RUN useradd --create-home --shell /bin/bash verifier \
33
+ && chown -R verifier:verifier /app /opt/uv-cache \
34
+ && mkdir -p /opt/selfbench \
35
+ && chmod 700 /opt/selfbench \
36
+ && mkdir -p /home/verifier/.cache/uv \
37
+ && chown -R verifier:verifier /home/verifier/.cache
38
+ ENV UV_CACHE_DIR=/home/verifier/.cache/uv \
39
+ UV_NO_BUILD_ISOLATION=1
40
+ COPY test.patch test.sh /tests/
41
+ RUN chmod 700 /tests && chmod 600 /tests/test.patch && chmod +x /tests/test.sh
42
+ WORKDIR /app
vite-ssr-switch-case-scope/tests/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:868cc9ca3631190662a4a6746c19e3e754426a60a267d3cf5e3301959adb7b30
3
+ size 12876284
vite-ssr-switch-case-scope/tests/test.patch ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts b/packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts
2
+ new file mode 100644
3
+ index 000000000..cef9e69d2
4
+ --- /dev/null
5
+ +++ b/packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts
6
+ @@ -0,0 +1,122 @@
7
+ +import { expect, test } from 'vitest'
8
+ +import { moduleRunnerTransform } from '../..'
9
+ +
10
+ +async function evaluateSsrModule(
11
+ + source: string,
12
+ + modules: Record<string, Record<string, unknown>>,
13
+ +) {
14
+ + const transformed = await moduleRunnerTransform(
15
+ + source,
16
+ + null,
17
+ + 'entry.js',
18
+ + source,
19
+ + )
20
+ + expect(transformed).not.toBeNull()
21
+ +
22
+ + const exported = new Map<string, () => unknown>()
23
+ + const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
24
+ + const execute = new AsyncFunction(
25
+ + '__vite_ssr_import__',
26
+ + '__vite_ssr_exportName__',
27
+ + `"use strict";\n${transformed!.code}`,
28
+ + )
29
+ +
30
+ + await execute(
31
+ + async (id: string) => modules[id],
32
+ + (name: string, getter: () => unknown) => exported.set(name, getter),
33
+ + )
34
+ +
35
+ + return Object.fromEntries(
36
+ + Array.from(exported, ([name, getter]) => [name, getter()]),
37
+ + )
38
+ +}
39
+ +
40
+ +test('switch case bindings preserve imported references outside the switch scope', async () => {
41
+ + const importCalls: unknown[] = []
42
+ + const exports = await evaluateSsrModule(
43
+ + `import { createObjectProperty as o } from './ast'
44
+ +export function buildProps(node) {
45
+ + const marker = () => o('ref_for')
46
+ + const values = []
47
+ + switch (o(node.type)) {
48
+ + case 1:
49
+ + let o = node.value
50
+ + values.push(o)
51
+ + break
52
+ + }
53
+ + return [marker(), ...values, o('after')]
54
+ +}`,
55
+ + {
56
+ + './ast': {
57
+ + createObjectProperty(value: unknown) {
58
+ + importCalls.push(value)
59
+ + return typeof value === 'number' ? value : `import:${value}`
60
+ + },
61
+ + },
62
+ + },
63
+ + )
64
+ +
65
+ + const buildProps = exports.buildProps as (node: {
66
+ + type: number
67
+ + value: string
68
+ + }) => unknown
69
+ + expect(buildProps({ type: 1, value: 'case-local' })).toEqual([
70
+ + 'import:ref_for',
71
+ + 'case-local',
72
+ + 'import:after',
73
+ + ])
74
+ + expect(importCalls).toEqual([1, 'ref_for', 'after'])
75
+ +})
76
+ +
77
+ +test('all cases use the switch lexical environment', async () => {
78
+ + const exports = await evaluateSsrModule(
79
+ + `import { value } from './dependency'
80
+ +export function readCase(selected) {
81
+ + switch (selected) {
82
+ + case 0:
83
+ + return value
84
+ + case 1:
85
+ + let value = 'case-local'
86
+ + return value
87
+ + }
88
+ +}`,
89
+ + { './dependency': { value: 'imported' } },
90
+ + )
91
+ +
92
+ + const readCase = exports.readCase as (selected: number) => string
93
+ + expect(readCase(1)).toBe('case-local')
94
+ + expect(() => readCase(0)).toThrow(ReferenceError)
95
+ +})
96
+ +
97
+ +test('case function and class declarations do not shadow imports after the switch', async () => {
98
+ + class ImportedClass {
99
+ + kind = 'imported class'
100
+ + }
101
+ +
102
+ + const exports = await evaluateSsrModule(
103
+ + `import { f, C } from './dependency'
104
+ +export function run(selected) {
105
+ + let locals
106
+ + switch (selected) {
107
+ + case 1:
108
+ + function f() { return 'local function' }
109
+ + class C { kind = 'local class' }
110
+ + locals = [f(), new C().kind]
111
+ + break
112
+ + }
113
+ + return { locals, imports: [f(), new C().kind] }
114
+ +}`,
115
+ + {
116
+ + './dependency': {
117
+ + f: () => 'imported function',
118
+ + C: ImportedClass,
119
+ + },
120
+ + },
121
+ + )
122
+ +
123
+ + const run = exports.run as (selected: number) => unknown
124
+ + expect(run(1)).toEqual({
125
+ + locals: ['local function', 'local class'],
126
+ + imports: ['imported function', 'imported class'],
127
+ + })
128
+ +})
vite-ssr-switch-case-scope/tests/test.sh ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -uo pipefail
3
+ mkdir -p /logs/verifier
4
+ patch_applied=1
5
+ fail_to_pass=0
6
+ pass_to_pass=0
7
+ deterministic=0
8
+ setup_completed=0
9
+ fail_to_pass_exit_code=-1
10
+ fail_to_pass_repeat_exit_code=-1
11
+ pass_to_pass_exit_code=-1
12
+ verifier_cache=""
13
+
14
+ kill_verifier_processes() { pkill -KILL -u "$(id -u verifier)" 2>/dev/null || true; }
15
+ # Some toolchains fetch dependencies at test runtime (e.g. Next.js e2e installs),
16
+ # so a single registry connection reset must not be misread as a dead test. Retry
17
+ # only infrastructure-style failures with backoff; real assertion failures fail fast.
18
+ run_verifier_command() {
19
+ local logfile
20
+ logfile="$(mktemp /tmp/selfbench-verifier-command-XXXXXX.log)"
21
+ local attempt=1
22
+ local status=1
23
+ while [ "$attempt" -le 3 ]; do
24
+ : > "$logfile"
25
+ runuser -u verifier -- env PATH="/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" UV_CACHE_DIR="$verifier_cache" UV_NO_BUILD_ISOLATION=1 bash -lc "$1" >"$logfile" 2>&1
26
+ status=$?
27
+ if [ "$status" -eq 0 ]; then
28
+ break
29
+ fi
30
+ if [ "$attempt" -lt 3 ] && grep -qE 'ECONNRESET|ETIMEDOUT|ESOCKETTIMEDOUT|ENOTFOUND|EAI_AGAIN|META_FETCH_FAIL|FetchError|EPIPE|EPERM|registry\.npmjs' "$logfile"; then
31
+ sleep "$((10 * attempt))"
32
+ attempt=$((attempt + 1))
33
+ continue
34
+ fi
35
+ break
36
+ done
37
+ cat "$logfile"
38
+ rm -f "$logfile"
39
+ kill_verifier_processes
40
+ return "$status"
41
+ }
42
+ protect_held_out_path() {
43
+ local path="$1"
44
+ chown -R root:root -- "$path"
45
+ chmod -R a-w,go+rX -- "$path"
46
+ }
47
+
48
+ if [ ! -f /opt/selfbench/agent.patch ]; then
49
+ patch_applied=0
50
+ elif [ -s /opt/selfbench/agent.patch ]; then
51
+ git -C /app apply --binary --whitespace=nowarn --exclude='packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts' --exclude='packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts/*' /opt/selfbench/agent.patch || patch_applied=0
52
+ fi
53
+
54
+ if [ "$patch_applied" -eq 1 ]; then setup_completed=1; fi
55
+
56
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
57
+ kill_verifier_processes
58
+ for protected_path in 'packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts'; do
59
+ git -C /app restore --source=HEAD --staged --worktree -- "$protected_path" 2>/dev/null || true
60
+ git -C /app clean -fd -- "$protected_path" >/dev/null 2>&1 || true
61
+ done
62
+ git -C /app apply --binary --whitespace=nowarn /tests/test.patch || patch_applied=0
63
+ if [ "$patch_applied" -eq 1 ]; then
64
+ for protected_path in '/app/packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts'; do protect_held_out_path "$protected_path"; done
65
+ fi
66
+ rm -f /tests/test.patch
67
+ fi
68
+
69
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
70
+ cd '/app/.'
71
+ verifier_cache="$(mktemp -d /tmp/selfbench-verifier-uv-XXXXXX)"
72
+ cp -a /opt/uv-cache/. "$verifier_cache"/
73
+ chown -R verifier:verifier "$verifier_cache"
74
+ if run_verifier_command 'pnpm test-unit '"'"'packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts'"'"''; then
75
+ fail_to_pass_exit_code=0
76
+ fail_to_pass=1
77
+ if run_verifier_command 'pnpm test-unit '"'"'packages/vite/src/node/ssr/__tests__/switchCaseScope.spec.ts'"'"''; then
78
+ fail_to_pass_repeat_exit_code=0
79
+ deterministic=1
80
+ else
81
+ fail_to_pass_repeat_exit_code=$?
82
+ fi
83
+ else
84
+ fail_to_pass_exit_code=$?
85
+ fi
86
+ if run_verifier_command 'true'; then
87
+ pass_to_pass_exit_code=0
88
+ pass_to_pass=1
89
+ else
90
+ pass_to_pass_exit_code=$?
91
+ fi
92
+ rm -rf "$verifier_cache"
93
+ fi
94
+
95
+ reward=0
96
+ if [ "$patch_applied" -eq 1 ] && [ "$fail_to_pass" -eq 1 ] && [ "$pass_to_pass" -eq 1 ] && [ "$deterministic" -eq 1 ]; then reward=1; fi
97
+ cat > /logs/verifier/reward.json <<EOF
98
+ {"reward": $reward, "patch_applied": $patch_applied, "fail_to_pass": $fail_to_pass, "pass_to_pass": $pass_to_pass, "deterministic": $deterministic, "setup_completed": $setup_completed, "fail_to_pass_exit_code": $fail_to_pass_exit_code, "fail_to_pass_repeat_exit_code": $fail_to_pass_repeat_exit_code, "pass_to_pass_exit_code": $pass_to_pass_exit_code}
99
+ EOF
100
+ exit 0
vite-top-level-virtual-input/.selfbench-manifest.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "generator": "selfbench",
3
+ "harborSchemaVersion": "1.4",
4
+ "compilerRevision": 23,
5
+ "taskId": "vite-top-level-virtual-input",
6
+ "difficulty": "hard",
7
+ "definitionSha256": "2f859f0c0376eb18e4ac8825c2951fd8d992e204e3af1a045d1b9c829a601e5e",
8
+ "testPatchSha256": "fecc8f3ae1585ef5b4515654b09dcc949e6d9e2330aab1728445d04daeaeb1e3",
9
+ "goldPatchSha256": "1806d439ece22a69997ca4950955ec9ebe0417375791f53aef008e576ee5b8f6"
10
+ }
vite-top-level-virtual-input/environment/Dockerfile ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ RUN useradd --create-home --shell /bin/bash agent
21
+ COPY repo.tar.gz /tmp/repo.tar.gz
22
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
23
+ && git -C /app init -q \
24
+ && git -C /app config user.email selfbench@local \
25
+ && git -C /app config user.name selfbench \
26
+ && git -C /app add -A \
27
+ && git -C /app commit -qm base
28
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
29
+ && cd '/app/.' \
30
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
31
+ && chmod -R a+rwX /opt/uv-cache
32
+ RUN git -C /app reset --hard -q HEAD \
33
+ && git -C /app clean -fdq \
34
+ && mkdir -p /opt/selfbench \
35
+ && cp -a /app/.git /opt/selfbench/base.git \
36
+ && chown -R agent:agent /app /home/agent /opt/uv-cache \
37
+ && chown -R root:root /opt/selfbench \
38
+ && chmod 700 /opt/selfbench \
39
+ && mkdir -p /home/agent/.cache/uv \
40
+ && chown -R agent:agent /home/agent/.cache
41
+ ENV UV_CACHE_DIR=/home/agent/.cache/uv \
42
+ UV_NO_BUILD_ISOLATION=1
43
+ USER agent
44
+ WORKDIR /app
vite-top-level-virtual-input/environment/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b8a4a24054e8b3f2de83d043d73952a9fb92260a7522009ba3e3775f65777e9
3
+ size 12904260
vite-top-level-virtual-input/instruction.md ADDED
@@ -0,0 +1 @@
 
 
1
+ Support virtual modules in Vite's top-level `input` option. When a configured plugin can resolve and load the specified input ID, Vite must use that module as the entry instead of treating the ID as a path under the project root. Preserve existing behavior for ordinary file-based inputs and the default entry.
vite-top-level-virtual-input/solution/gold.patch ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts
2
+ index 80d27ce34..15c402285 100644
3
+ --- a/packages/vite/src/node/build.ts
4
+ +++ b/packages/vite/src/node/build.ts
5
+ @@ -621,9 +621,7 @@ export function resolveRolldownOptions(
6
+ : typeof options.ssr === 'string'
7
+ ? resolve(options.ssr)
8
+ : options.rolldownOptions.input ||
9
+ - (topLevelInput != null
10
+ - ? topLevelInput // top-level `input` is already resolved in resolveConfig
11
+ - : resolve('index.html'))
12
+ + (topLevelInput ?? resolve('index.html'))
13
+
14
+ if (ssr && typeof input === 'string' && input.endsWith('.html')) {
15
+ throw new Error(
16
+ diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts
17
+ index 79371b377..f3defc59d 100644
18
+ --- a/packages/vite/src/node/config.ts
19
+ +++ b/packages/vite/src/node/config.ts
20
+ @@ -923,27 +923,21 @@ const configDefaults = Object.freeze({
21
+ appType: 'spa',
22
+ } satisfies UserConfig)
23
+
24
+ -function resolveInput(
25
+ +function normalizeInput(
26
+ input: InputOption | undefined,
27
+ - root: string,
28
+ ): InputOption | undefined {
29
+ if (input === undefined) {
30
+ return undefined
31
+ }
32
+ if (typeof input === 'string') {
33
+ - const unescapedInput = unescapeGlobCharacters(input)
34
+ - return normalizePath(path.resolve(root, unescapedInput))
35
+ + return unescapeGlobCharacters(input)
36
+ }
37
+ if (Array.isArray(input)) {
38
+ - return input.map((inp) => {
39
+ - const unescapedInput = unescapeGlobCharacters(inp)
40
+ - return normalizePath(path.resolve(root, unescapedInput))
41
+ - })
42
+ + return input.map(unescapeGlobCharacters)
43
+ }
44
+ const resolved: Record<string, string> = {}
45
+ for (const key in input) {
46
+ - const unescapedInput = unescapeGlobCharacters(input[key])
47
+ - resolved[key] = normalizePath(path.resolve(root, unescapedInput))
48
+ + resolved[key] = unescapeGlobCharacters(input[key])
49
+ }
50
+ return resolved
51
+ }
52
+ @@ -996,7 +990,6 @@ function resolveEnvironmentOptions(
53
+ options: EnvironmentOptions,
54
+ alias: Alias[],
55
+ preserveSymlinks: boolean,
56
+ - root: string,
57
+ forceOptimizeDeps: boolean | undefined,
58
+ logger: Logger,
59
+ environmentName: string,
60
+ @@ -1044,7 +1037,7 @@ function resolveEnvironmentOptions(
61
+ isSsrTargetWebworkerEnvironment,
62
+ )
63
+ return {
64
+ - input: resolveInput(options.input, root),
65
+ + input: normalizeInput(options.input),
66
+ define: options.define,
67
+ resolve,
68
+ keepProcessEnv:
69
+ @@ -1727,7 +1720,6 @@ export async function resolveConfig(
70
+ config.environments[environmentName],
71
+ resolvedDefaultResolve.alias,
72
+ resolvedDefaultResolve.preserveSymlinks,
73
+ - resolvedRoot,
74
+ inlineConfig.forceOptimizeDeps,
75
+ logger,
76
+ environmentName,
77
+ @@ -1865,13 +1857,8 @@ export async function resolveConfig(
78
+ )
79
+ : ''
80
+
81
+ - const input = resolveInput(config.input, resolvedRoot)
82
+ - const server = await resolveServerOptions(
83
+ - resolvedRoot,
84
+ - config.server,
85
+ - input,
86
+ - logger,
87
+ - )
88
+ + const input = normalizeInput(config.input)
89
+ + const server = await resolveServerOptions(resolvedRoot, config.server, logger)
90
+
91
+ const builder = resolveBuilderOptions(config.builder)
92
+
93
+ diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts
94
+ index 1f2844b80..812db8498 100644
95
+ --- a/packages/vite/src/node/optimizer/scan.ts
96
+ +++ b/packages/vite/src/node/optimizer/scan.ts
97
+ @@ -214,19 +214,13 @@ async function computeEntries(environment: ScanEnvironment) {
98
+ let entries: string[] = []
99
+
100
+ const explicitEntryPatterns = environment.config.optimizeDeps.entries
101
+ - const buildInput =
102
+ + const input =
103
+ environment.config.input ?? environment.config.build.rolldownOptions.input
104
+
105
+ if (explicitEntryPatterns) {
106
+ entries = await globEntries(explicitEntryPatterns, environment)
107
+ - } else if (buildInput) {
108
+ + } else if (input) {
109
+ const resolvePath = async (p: string) => {
110
+ - if (environment.config.input) {
111
+ - // input is already resolved in resolveConfig
112
+ - return p
113
+ - }
114
+ - // `build.rollupOptions.input` is resolved from the root (not `process.cwd()`)
115
+ - // by the build, so resolve it from the root here too by not passing an importer.
116
+ const id = (
117
+ await environment.pluginContainer.resolveId(p, undefined, {
118
+ isEntry: true,
119
+ @@ -240,12 +234,12 @@ async function computeEntries(environment: ScanEnvironment) {
120
+ }
121
+ return id
122
+ }
123
+ - if (typeof buildInput === 'string') {
124
+ - entries = [await resolvePath(buildInput)]
125
+ - } else if (Array.isArray(buildInput)) {
126
+ - entries = await Promise.all(buildInput.map(resolvePath))
127
+ - } else if (isObject(buildInput)) {
128
+ - entries = await Promise.all(Object.values(buildInput).map(resolvePath))
129
+ + if (typeof input === 'string') {
130
+ + entries = [await resolvePath(input)]
131
+ + } else if (Array.isArray(input)) {
132
+ + entries = await Promise.all(input.map(resolvePath))
133
+ + } else if (isObject(input)) {
134
+ + entries = await Promise.all(Object.values(input).map(resolvePath))
135
+ } else {
136
+ throw new Error('invalid rolldownOptions.input value.')
137
+ }
138
+ diff --git a/packages/vite/src/node/server/environment.ts b/packages/vite/src/node/server/environment.ts
139
+ index d74657109..a08b4e11a 100644
140
+ --- a/packages/vite/src/node/server/environment.ts
141
+ +++ b/packages/vite/src/node/server/environment.ts
142
+ @@ -1,3 +1,4 @@
143
+ +import path from 'node:path'
144
+ import colors from 'picocolors'
145
+ import type { FetchFunctionOptions, FetchResult } from 'vite/module-runner'
146
+ import type { FSWatcher } from '#dep-types/chokidar'
147
+ @@ -16,7 +17,7 @@ import {
148
+ createExplicitDepsOptimizer,
149
+ } from '../optimizer/optimizer'
150
+ import { ERR_OUTDATED_OPTIMIZED_DEP } from '../../shared/constants'
151
+ -import { promiseWithResolvers } from '../../shared/utils'
152
+ +import { cleanUrl, promiseWithResolvers } from '../../shared/utils'
153
+ import type { ViteDevServer } from '../server'
154
+ import { EnvironmentModuleGraph } from './moduleGraph'
155
+ import type { EnvironmentModuleNode } from './moduleGraph'
156
+ @@ -220,6 +221,47 @@ export class DevEnvironment extends BaseEnvironment {
157
+ )
158
+ }
159
+
160
+ + /** @internal */
161
+ + async _registerInputsAsSafeModules(): Promise<void> {
162
+ + const input = this.config.input
163
+ + const entries =
164
+ + input == null
165
+ + ? ['index.html']
166
+ + : typeof input === 'string'
167
+ + ? [input]
168
+ + : Array.isArray(input)
169
+ + ? input
170
+ + : Object.values(input)
171
+ +
172
+ + const resolveEntries = async () => {
173
+ + const resolvedEntries = await Promise.all(
174
+ + entries.map((entry) =>
175
+ + this.pluginContainer.resolveId(entry, undefined, {
176
+ + isEntry: true,
177
+ + // Avoid a deadlock when the dependency scanner triggers the first
178
+ + // buildStart. Normal resolution waits for the scan to finish,
179
+ + // while the scan is waiting for buildStart to finish.
180
+ + scan: true,
181
+ + }),
182
+ + ),
183
+ + )
184
+ + for (const resolved of resolvedEntries) {
185
+ + if (resolved && !resolved.external) {
186
+ + const resolvedId = cleanUrl(resolved.id)
187
+ + if (path.isAbsolute(resolvedId)) {
188
+ + this.getTopLevelConfig().safeModulePaths.add(resolvedId)
189
+ + }
190
+ + }
191
+ + }
192
+ + }
193
+ +
194
+ + if (input == null) {
195
+ + await resolveEntries().catch(() => {})
196
+ + } else {
197
+ + await resolveEntries()
198
+ + }
199
+ + }
200
+ +
201
+ /**
202
+ * When the dev server is restarted, the methods are called in the following order:
203
+ * - new instance `init`
204
+ diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts
205
+ index fa2c551af..84a8d567a 100644
206
+ --- a/packages/vite/src/node/server/index.ts
207
+ +++ b/packages/vite/src/node/server/index.ts
208
+ @@ -14,7 +14,7 @@ import chokidar from 'chokidar'
209
+ import launchEditorMiddleware from 'launch-editor-middleware'
210
+ import { determineAgent } from '@vercel/detect-agent'
211
+ import { disableCache } from '@voidzero-dev/vite-task-client'
212
+ -import type { InputOption, SourceMap } from 'rolldown'
213
+ +import type { SourceMap } from 'rolldown'
214
+ import type { ModuleRunner } from 'vite/module-runner'
215
+ import type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
216
+ import type { Connect } from '#dep-types/connect'
217
+ @@ -1214,7 +1214,6 @@ const RESERVED_ALLOWED_HOSTS_CHARACTERS_RE = /[\\"']/
218
+ export async function resolveServerOptions(
219
+ root: string,
220
+ raw: ServerOptions | undefined,
221
+ - input: InputOption | undefined,
222
+ logger: Logger,
223
+ ): Promise<ResolvedServerOptions> {
224
+ const _server = mergeWithDefaults(
225
+ @@ -1244,7 +1243,6 @@ export async function resolveServerOptions(
226
+ }
227
+
228
+ let allowDirs = server.fs.allow
229
+ - allowDirs.push(...getInputPaths(root, input))
230
+
231
+ const cwd = searchForPackageRoot(root)
232
+ if (process.versions.pnp) {
233
+ @@ -1345,12 +1343,6 @@ export async function resolveServerOptions(
234
+ return server
235
+ }
236
+
237
+ -function getInputPaths(root: string, input: ResolvedConfig['input']): string[] {
238
+ - if (input == null) return [path.resolve(root, 'index.html')]
239
+ - if (typeof input === 'string') return [input]
240
+ - return Array.isArray(input) ? input : Object.values(input)
241
+ -}
242
+ -
243
+ async function restartServer(server: ViteDevServer) {
244
+ global.__vite_start_time = performance.now()
245
+
246
+ diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts
247
+ index e14d5c613..081b57d44 100644
248
+ --- a/packages/vite/src/node/server/pluginContainer.ts
249
+ +++ b/packages/vite/src/node/server/pluginContainer.ts
250
+ @@ -334,7 +334,7 @@ class EnvironmentPluginContainer<Env extends Environment = Environment> {
251
+ }
252
+ this._started = true
253
+ const config = this.environment.getTopLevelConfig()
254
+ - this._buildStartPromise = this.handleHookPromise(
255
+ + const hookPromise = this.handleHookPromise(
256
+ this.hookParallel(
257
+ 'buildStart',
258
+ (plugin) => this._getPluginContext(plugin),
259
+ @@ -345,6 +345,12 @@ class EnvironmentPluginContainer<Env extends Environment = Environment> {
260
+ plugin.perEnvironmentStartEndDuringDev,
261
+ ),
262
+ ) as Promise<void>
263
+ + this._buildStartPromise = (async () => {
264
+ + await hookPromise
265
+ + if (this.environment.mode === 'dev') {
266
+ + await this.environment._registerInputsAsSafeModules()
267
+ + }
268
+ + })()
269
+ await this._buildStartPromise
270
+ this._buildStartPromise = undefined
271
+ }
vite-top-level-virtual-input/solution/solve.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ git -C /app apply --binary --whitespace=nowarn /solution/gold.patch
vite-top-level-virtual-input/task.toml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.4"
2
+ artifacts = ["/opt/selfbench/agent.patch"]
3
+
4
+ [task]
5
+ name = "selfbench/vite-top-level-virtual-input"
6
+ version = "1.0.0"
7
+ description = "Reproduce vite-top-level-virtual-input from its authentic engineer request."
8
+ keywords = ["software-engineering", "private-swe", "selfbench", "hard"]
9
+
10
+ [metadata]
11
+ selfbench_task_id = "vite-top-level-virtual-input"
12
+ difficulty = "hard"
13
+ repo = "vitejs/vite"
14
+ base_commit = "fa005d19af5d847931c6dbefc63841c137383e6c"
15
+ workdir = "."
16
+ source_pr = 23101
17
+ compiler_revision = 23
18
+
19
+ [agent]
20
+ timeout_sec = 2400.0
21
+ user = "agent"
22
+ network_mode = "allowlist"
23
+ allowed_hosts = ["chatgpt.com", "*.chatgpt.com", "openai.com", "*.openai.com"]
24
+
25
+ [verifier]
26
+ timeout_sec = 1800.0
27
+ user = "root"
28
+ environment_mode = "separate"
29
+ network_mode = "public"
30
+
31
+ [[verifier.collect]]
32
+ service = "main"
33
+ user = "root"
34
+ timeout_sec = 300.0
35
+ command = "git --git-dir=/opt/selfbench/base.git --work-tree=/app add -A && git --git-dir=/opt/selfbench/base.git --work-tree=/app diff --cached --binary HEAD > /opt/selfbench/agent.patch"
36
+
37
+ [environment]
38
+ network_mode = "public"
39
+ build_timeout_sec = 1500.0
40
+ cpus = 4
41
+ memory_mb = 8192
42
+ storage_mb = 20480
43
+
44
+ [verifier.environment]
45
+ network_mode = "public"
46
+ build_timeout_sec = 1500.0
47
+ cpus = 4
48
+ memory_mb = 8192
49
+ storage_mb = 20480
vite-top-level-virtual-input/tests/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ COPY repo.tar.gz /tmp/repo.tar.gz
21
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
22
+ && git -C /app init -q \
23
+ && git -C /app config user.email selfbench@local \
24
+ && git -C /app config user.name selfbench \
25
+ && git -C /app add -A \
26
+ && git -C /app commit -qm base
27
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
28
+ && cd '/app/.' \
29
+ && bash -lc 'corepack enable && corepack prepare pnpm@10.34.5 --activate && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pnpm install --frozen-lockfile && pnpm run build' \
30
+ && chmod -R a+rwX /opt/uv-cache
31
+
32
+ RUN useradd --create-home --shell /bin/bash verifier \
33
+ && chown -R verifier:verifier /app /opt/uv-cache \
34
+ && mkdir -p /opt/selfbench \
35
+ && chmod 700 /opt/selfbench \
36
+ && mkdir -p /home/verifier/.cache/uv \
37
+ && chown -R verifier:verifier /home/verifier/.cache
38
+ ENV UV_CACHE_DIR=/home/verifier/.cache/uv \
39
+ UV_NO_BUILD_ISOLATION=1
40
+ COPY test.patch test.sh /tests/
41
+ RUN chmod 700 /tests && chmod 600 /tests/test.patch && chmod +x /tests/test.sh
42
+ WORKDIR /app
vite-top-level-virtual-input/tests/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b8a4a24054e8b3f2de83d043d73952a9fb92260a7522009ba3e3775f65777e9
3
+ size 12904260
vite-top-level-virtual-input/tests/test.patch ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts
2
+ index e956370b4..16e885348 100644
3
+ --- a/packages/vite/src/node/__tests__/build.spec.ts
4
+ +++ b/packages/vite/src/node/__tests__/build.spec.ts
5
+ @@ -112,6 +112,36 @@ describe('build', () => {
6
+ expect(chunk?.code).toContain('from-top-level-input')
7
+ })
8
+
9
+ + test('top-level input can be a virtual module for build', async () => {
10
+ + const input = 'virtual:entry'
11
+ + const resolvedInput = `\0${input}`
12
+ + const result = (await build({
13
+ + root: resolve(dirname, 'packages/build-project'),
14
+ + logLevel: 'silent',
15
+ + input,
16
+ + build: {
17
+ + write: false,
18
+ + },
19
+ + plugins: [
20
+ + {
21
+ + name: 'virtual-entry',
22
+ + resolveId(id) {
23
+ + if (id === input) {
24
+ + return resolvedInput
25
+ + }
26
+ + },
27
+ + load(id) {
28
+ + if (id === resolvedInput) {
29
+ + return `console.log('from-virtual-top-level-input')`
30
+ + }
31
+ + },
32
+ + },
33
+ + ],
34
+ + })) as RolldownOutput
35
+ + const chunk = result.output.find((o) => o.type === 'chunk')
36
+ + expect(chunk?.code).toContain('from-virtual-top-level-input')
37
+ + })
38
+ +
39
+ test('file hash should change when pure css chunk changes', async () => {
40
+ const buildProject = async (cssColor: string) => {
41
+ return (await build({
vite-top-level-virtual-input/tests/test.sh ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -uo pipefail
3
+ mkdir -p /logs/verifier
4
+ patch_applied=1
5
+ fail_to_pass=0
6
+ pass_to_pass=0
7
+ deterministic=0
8
+ setup_completed=0
9
+ fail_to_pass_exit_code=-1
10
+ fail_to_pass_repeat_exit_code=-1
11
+ pass_to_pass_exit_code=-1
12
+ verifier_cache=""
13
+
14
+ kill_verifier_processes() { pkill -KILL -u "$(id -u verifier)" 2>/dev/null || true; }
15
+ # Some toolchains fetch dependencies at test runtime (e.g. Next.js e2e installs),
16
+ # so a single registry connection reset must not be misread as a dead test. Retry
17
+ # only infrastructure-style failures with backoff; real assertion failures fail fast.
18
+ run_verifier_command() {
19
+ local logfile
20
+ logfile="$(mktemp /tmp/selfbench-verifier-command-XXXXXX.log)"
21
+ local attempt=1
22
+ local status=1
23
+ while [ "$attempt" -le 3 ]; do
24
+ : > "$logfile"
25
+ runuser -u verifier -- env PATH="/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" UV_CACHE_DIR="$verifier_cache" UV_NO_BUILD_ISOLATION=1 bash -lc "$1" >"$logfile" 2>&1
26
+ status=$?
27
+ if [ "$status" -eq 0 ]; then
28
+ break
29
+ fi
30
+ if [ "$attempt" -lt 3 ] && grep -qE 'ECONNRESET|ETIMEDOUT|ESOCKETTIMEDOUT|ENOTFOUND|EAI_AGAIN|META_FETCH_FAIL|FetchError|EPIPE|EPERM|registry\.npmjs' "$logfile"; then
31
+ sleep "$((10 * attempt))"
32
+ attempt=$((attempt + 1))
33
+ continue
34
+ fi
35
+ break
36
+ done
37
+ cat "$logfile"
38
+ rm -f "$logfile"
39
+ kill_verifier_processes
40
+ return "$status"
41
+ }
42
+ protect_held_out_path() {
43
+ local path="$1"
44
+ chown -R root:root -- "$path"
45
+ chmod -R a-w,go+rX -- "$path"
46
+ }
47
+
48
+ if [ ! -f /opt/selfbench/agent.patch ]; then
49
+ patch_applied=0
50
+ elif [ -s /opt/selfbench/agent.patch ]; then
51
+ git -C /app apply --binary --whitespace=nowarn --exclude='packages/vite/src/node/__tests__/build.spec.ts' --exclude='packages/vite/src/node/__tests__/build.spec.ts/*' /opt/selfbench/agent.patch || patch_applied=0
52
+ fi
53
+
54
+ if [ "$patch_applied" -eq 1 ]; then setup_completed=1; fi
55
+
56
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
57
+ kill_verifier_processes
58
+ for protected_path in 'packages/vite/src/node/__tests__/build.spec.ts'; do
59
+ git -C /app restore --source=HEAD --staged --worktree -- "$protected_path" 2>/dev/null || true
60
+ git -C /app clean -fd -- "$protected_path" >/dev/null 2>&1 || true
61
+ done
62
+ git -C /app apply --binary --whitespace=nowarn /tests/test.patch || patch_applied=0
63
+ if [ "$patch_applied" -eq 1 ]; then
64
+ for protected_path in '/app/packages/vite/src/node/__tests__/build.spec.ts'; do protect_held_out_path "$protected_path"; done
65
+ fi
66
+ rm -f /tests/test.patch
67
+ fi
68
+
69
+ if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then
70
+ cd '/app/.'
71
+ verifier_cache="$(mktemp -d /tmp/selfbench-verifier-uv-XXXXXX)"
72
+ cp -a /opt/uv-cache/. "$verifier_cache"/
73
+ chown -R verifier:verifier "$verifier_cache"
74
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/build.spec.ts'"'"''; then
75
+ fail_to_pass_exit_code=0
76
+ fail_to_pass=1
77
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/build.spec.ts'"'"''; then
78
+ fail_to_pass_repeat_exit_code=0
79
+ deterministic=1
80
+ else
81
+ fail_to_pass_repeat_exit_code=$?
82
+ fi
83
+ else
84
+ fail_to_pass_exit_code=$?
85
+ fi
86
+ if run_verifier_command 'pnpm run test-unit '"'"'packages/vite/src/node/__tests__/logger.spec.ts'"'"' '"'"'packages/vite/src/node/__tests__/constants.spec.ts'"'"''; then
87
+ pass_to_pass_exit_code=0
88
+ pass_to_pass=1
89
+ else
90
+ pass_to_pass_exit_code=$?
91
+ fi
92
+ rm -rf "$verifier_cache"
93
+ fi
94
+
95
+ reward=0
96
+ if [ "$patch_applied" -eq 1 ] && [ "$fail_to_pass" -eq 1 ] && [ "$pass_to_pass" -eq 1 ] && [ "$deterministic" -eq 1 ]; then reward=1; fi
97
+ cat > /logs/verifier/reward.json <<EOF
98
+ {"reward": $reward, "patch_applied": $patch_applied, "fail_to_pass": $fail_to_pass, "pass_to_pass": $pass_to_pass, "deterministic": $deterministic, "setup_completed": $setup_completed, "fail_to_pass_exit_code": $fail_to_pass_exit_code, "fail_to_pass_repeat_exit_code": $fail_to_pass_repeat_exit_code, "pass_to_pass_exit_code": $pass_to_pass_exit_code}
99
+ EOF
100
+ exit 0
vite-wasm-global-string-builtins/.selfbench-manifest.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "generator": "selfbench",
3
+ "harborSchemaVersion": "1.4",
4
+ "compilerRevision": 23,
5
+ "taskId": "vite-wasm-global-string-builtins",
6
+ "difficulty": "easy",
7
+ "definitionSha256": "93a683cbd3457845ec9099d155b83e307dae985fa2243c947c91c726d08d9d01",
8
+ "testPatchSha256": "c82d090c5528e366925ef44945b3ec5b925d2520522a2ebc0dbdf2469d3027aa",
9
+ "goldPatchSha256": "a51bc68b215be7c753d9a0c91d1932aa7a155b11d9771b7e8e58614b719af9b3"
10
+ }
vite-wasm-global-string-builtins/environment/Dockerfile ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ RUN useradd --create-home --shell /bin/bash agent
21
+ COPY repo.tar.gz /tmp/repo.tar.gz
22
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
23
+ && git -C /app init -q \
24
+ && git -C /app config user.email selfbench@local \
25
+ && git -C /app config user.name selfbench \
26
+ && git -C /app add -A \
27
+ && git -C /app commit -qm base
28
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
29
+ && cd '/app/.' \
30
+ && bash -lc 'corepack enable && pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium && pnpm run build' \
31
+ && chmod -R a+rwX /opt/uv-cache
32
+ RUN git -C /app reset --hard -q HEAD \
33
+ && git -C /app clean -fdq \
34
+ && mkdir -p /opt/selfbench \
35
+ && cp -a /app/.git /opt/selfbench/base.git \
36
+ && chown -R agent:agent /app /home/agent /opt/uv-cache \
37
+ && chown -R root:root /opt/selfbench \
38
+ && chmod 700 /opt/selfbench \
39
+ && mkdir -p /home/agent/.cache/uv \
40
+ && chown -R agent:agent /home/agent/.cache
41
+ ENV UV_CACHE_DIR=/home/agent/.cache/uv \
42
+ UV_NO_BUILD_ISOLATION=1
43
+ USER agent
44
+ WORKDIR /app
vite-wasm-global-string-builtins/environment/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c86ffe35eda3dd43cb9d4db9f36b182e80f919caf9cb5f50027fe0d8eacbf51
3
+ size 12882301
vite-wasm-global-string-builtins/instruction.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Enhance Vite's WebAssembly ESM integration. Direct `.wasm` imports must expose exported `WebAssembly.Global` values to JavaScript as their normal JS values (for example, an i32 global is imported as a number), rather than as `WebAssembly.Global` objects. At the same time, wasm-to-wasm imports must continue receiving the actual live global cell: a module may import another wasm module's global, and mutations from the exporting module must be visible to the consumer.
2
+
3
+ Enable the WebAssembly JS String Builtins and Imported String Constants proposals for the compilation and instantiation paths used by Vite's wasm support, consistent with the specification and Node.js behavior. Engine-provided builtin and string-constant imports must not be treated as ordinary JavaScript module imports. Preserve existing direct `.wasm` imports and `?init` behavior.
vite-wasm-global-string-builtins/solution/gold.patch ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/packages/vite/src/node/plugins/wasm.ts b/packages/vite/src/node/plugins/wasm.ts
2
+ index 77fe1301f..ae28b242a 100644
3
+ --- a/packages/vite/src/node/plugins/wasm.ts
4
+ +++ b/packages/vite/src/node/plugins/wasm.ts
5
+ @@ -12,8 +12,31 @@ const wasmHelperId = '\0vite/wasm-helper.js'
6
+ const wasmInitRE = /(?<![?#].*)\.wasm\?init/
7
+ const wasmDirectRE = /(?<![?#].*)\.wasm$/
8
+
9
+ +// Lower "instance" layer of a directly imported `.wasm` module that exports a
10
+ +// WebAssembly.Global. It owns the WebAssembly.Instance and exposes exports
11
+ +// verbatim (globals stay WebAssembly.Global objects), so that wasm-to-wasm
12
+ +// global imports receive the actual Global. The user-facing `.wasm` module is a
13
+ +// thin wrapper around this layer that unwraps globals for JS consumers.
14
+ +const wasmInstanceSuffix = '?vite-wasm-instance'
15
+ +const wasmInstanceRE = /[?&]vite-wasm-instance(?:&|$)/
16
+ +
17
+ const wasmInitUrlRE: RegExp = /__VITE_WASM_INIT__([\w$]+)__/g
18
+
19
+ +// Enabled per spec
20
+ +const wasmCompileOptions = {
21
+ + builtins: ['js-string'],
22
+ + importedStringConstants: 'wasm:js/string-constants',
23
+ +}
24
+ +
25
+ +// Modules satisfied by the engine when the above proposals are enabled. They
26
+ +// must never surface as JS imports in the generated glue. The host Node running
27
+ +// `parseWasm` may not support these proposals yet (older versions), in which
28
+ +// case `WebAssembly.Module.imports` still reports them, so we filter explicitly.
29
+ +const wasmReservedModules = new Set<string>([
30
+ + ...wasmCompileOptions.builtins.map((name) => `wasm:${name}`),
31
+ + wasmCompileOptions.importedStringConstants,
32
+ +])
33
+ +
34
+ const wasmHelper = async (opts = {}, url: string) => {
35
+ let result
36
+ if (url.startsWith('data:')) {
37
+ @@ -32,7 +55,7 @@ const wasmHelper = async (opts = {}, url: string) => {
38
+ 'Failed to decode base64-encoded data URL, Buffer and atob are not supported',
39
+ )
40
+ }
41
+ - result = await WebAssembly.instantiate(bytes, opts)
42
+ + result = await WebAssembly.instantiate(bytes, opts, wasmCompileOptions)
43
+ } else {
44
+ result = await instantiateFromUrl(url, opts)
45
+ }
46
+ @@ -53,10 +76,10 @@ const instantiateFromUrl = async (url: string, opts?: WebAssembly.Imports) => {
47
+ 'instantiateStreaming' in WebAssembly &&
48
+ contentType.startsWith('application/wasm')
49
+ ) {
50
+ - return WebAssembly.instantiateStreaming(response, opts)
51
+ + return WebAssembly.instantiateStreaming(response, opts, wasmCompileOptions)
52
+ } else {
53
+ const buffer = await response.arrayBuffer()
54
+ - return WebAssembly.instantiate(buffer, opts)
55
+ + return WebAssembly.instantiate(buffer, opts, wasmCompileOptions)
56
+ }
57
+ }
58
+
59
+ @@ -69,7 +92,7 @@ const instantiateFromFile = async (
60
+ const { readFile } = await import('node:fs/promises')
61
+ const fileUrl = new URL(fileUrlString, /** #__KEEP__ */ import.meta.url)
62
+ const buffer = await readFile(fileUrl)
63
+ - return WebAssembly.instantiate(buffer, opts)
64
+ + return WebAssembly.instantiate(buffer, opts, wasmCompileOptions)
65
+ }
66
+
67
+ const instantiateFromFileCode = instantiateFromFile.toString()
68
+ @@ -87,19 +110,43 @@ export const wasmHelperPlugin = (): Plugin => {
69
+ },
70
+
71
+ load: {
72
+ - filter: { id: [exactRegex(wasmHelperId), wasmInitRE, wasmDirectRE] },
73
+ + filter: {
74
+ + id: [
75
+ + exactRegex(wasmHelperId),
76
+ + wasmInitRE,
77
+ + wasmDirectRE,
78
+ + wasmInstanceRE,
79
+ + ],
80
+ + },
81
+ async handler(id) {
82
+ const ssr = this.environment.config.consumer === 'server'
83
+
84
+ if (id === wasmHelperId) {
85
+ return `
86
+ +const wasmCompileOptions = ${JSON.stringify(wasmCompileOptions)}
87
+ const instantiateFromUrl = ${ssr ? instantiateFromFileCode : instantiateFromUrlCode}
88
+ export default ${wasmHelperCode}
89
+ `
90
+ }
91
+
92
+ const isInit = wasmInitRE.test(id)
93
+ - const cleanedId = id.split('?')[0]
94
+ + const isInstance = wasmInstanceRE.test(id)
95
+ + const cleanedId = isInstance ? cleanUrl(id) : id.split('?')[0]
96
+ +
97
+ + // Direct .wasm import (WASM ESM Integration)
98
+ + let wasmInfo: WasmInfo | undefined
99
+ + if (!isInit) {
100
+ + wasmInfo = await parseWasm(cleanedId)
101
+ + // The user-facing module of a wasm that exports a global is a thin
102
+ + // wrapper that re-exports the instance layer, unwrapping globals for JS.
103
+ + if (!isInstance && wasmInfo.hasGlobalExport) {
104
+ + return generateWrapperGlue(
105
+ + wasmInfo,
106
+ + cleanedId + wasmInstanceSuffix,
107
+ + )
108
+ + }
109
+ + }
110
+ +
111
+ let url = await fileToUrl(this, cleanedId, ssr)
112
+ assetUrlRE.lastIndex = 0
113
+ if (ssr && assetUrlRE.test(url)) {
114
+ @@ -113,9 +160,7 @@ export default ${wasmHelperCode}
115
+ `
116
+ }
117
+
118
+ - // Direct .wasm import (WASM ESM Integration)
119
+ - const wasmInfo = await parseWasm(cleanedId)
120
+ - const glueCode = generateGlueCode(wasmInfo, {
121
+ + const glueCode = generateInstanceGlue(wasmInfo!, {
122
+ initWasm: '__vite__initWasm',
123
+ wasmUrl: '__vite__wasmUrl',
124
+ })
125
+ @@ -179,33 +224,41 @@ ${glueCode}
126
+ })
127
+ }
128
+
129
+ +interface WasmName {
130
+ + name: string
131
+ + isGlobal: boolean
132
+ +}
133
+ +
134
+ interface WasmInfo {
135
+ imports: {
136
+ from: string
137
+ - names: string[]
138
+ + names: WasmName[]
139
+ }[]
140
+ - exports: string[]
141
+ + exports: WasmName[]
142
+ + hasGlobalExport: boolean
143
+ }
144
+
145
+ async function parseWasm(wasmFilePath: string): Promise<WasmInfo> {
146
+ try {
147
+ const wasmBinary = await fsp.readFile(wasmFilePath)
148
+ - const wasmModule = await WebAssembly.compile(wasmBinary)
149
+ - const importMap: Record<string, string[]> = Object.create(null)
150
+ + const wasmModule = await WebAssembly.compile(wasmBinary, wasmCompileOptions)
151
+ + const importMap = new Map<string, WasmName[]>()
152
+ for (const item of WebAssembly.Module.imports(wasmModule)) {
153
+ - importMap[item.module] ??= []
154
+ - importMap[item.module].push(item.name)
155
+ + if (wasmReservedModules.has(item.module)) continue
156
+ + let names = importMap.get(item.module)
157
+ + if (!names) importMap.set(item.module, (names = []))
158
+ + names.push({ name: item.name, isGlobal: item.kind === 'global' })
159
+ }
160
+ - const imports = Object.entries(importMap).map(([from, names]) => ({
161
+ - from,
162
+ - names,
163
+ - }))
164
+ + const imports = [...importMap].map(([from, names]) => ({ from, names }))
165
+
166
+ - const exports = WebAssembly.Module.exports(wasmModule).map(
167
+ - (item) => item.name,
168
+ - )
169
+ + let hasGlobalExport = false
170
+ + const exports = WebAssembly.Module.exports(wasmModule).map((item) => {
171
+ + const isGlobal = item.kind === 'global'
172
+ + if (isGlobal) hasGlobalExport = true
173
+ + return { name: item.name, isGlobal }
174
+ + })
175
+
176
+ - return { imports, exports }
177
+ + return { imports, exports, hasGlobalExport }
178
+ } catch (e) {
179
+ throw new Error(
180
+ `Failed to parse WASM file "${wasmFilePath}": ${(e as Error).message}`,
181
+ @@ -214,25 +267,43 @@ async function parseWasm(wasmFilePath: string): Promise<WasmInfo> {
182
+ }
183
+ }
184
+
185
+ -function generateGlueCode(
186
+ +// Instantiates the wasm module and re-exports its exports verbatim. Globals stay
187
+ +// WebAssembly.Global objects so wasm-to-wasm global imports get the live cell.
188
+ +function generateInstanceGlue(
189
+ wasmInfo: WasmInfo,
190
+ names: { initWasm: string; wasmUrl: string },
191
+ ): string {
192
+ - const importStatements = wasmInfo.imports.map(({ from }, i) => {
193
+ - return `import * as __vite__wasmImport_${i} from ${JSON.stringify(from)};`
194
+ - })
195
+ -
196
+ + const importStatements: string[] = []
197
+ const importObject: SimpleObject = wasmInfo.imports.map(
198
+ ({ from, names: importNames }, i) => {
199
+ - return {
200
+ - key: JSON.stringify(from),
201
+ - value: importNames.map((name) => {
202
+ - return {
203
+ + const value: SimpleObject = []
204
+ + const globals = importNames.filter((n) => n.isGlobal)
205
+ + const others = importNames.filter((n) => !n.isGlobal)
206
+ + if (others.length > 0) {
207
+ + const ns = `__vite__wasmImport_${i}`
208
+ + importStatements.push(`import * as ${ns} from ${JSON.stringify(from)};`)
209
+ + for (const { name } of others) {
210
+ + value.push({
211
+ key: JSON.stringify(name),
212
+ - value: `__vite__wasmImport_${i}[${JSON.stringify(name)}]`,
213
+ - }
214
+ - }),
215
+ + value: `${ns}[${JSON.stringify(name)}]`,
216
+ + })
217
+ + }
218
+ + }
219
+ + if (globals.length > 0) {
220
+ + // Wasm global imports need the WebAssembly.Global object, so import them
221
+ + // from the exporter's instance layer instead of its JS-unwrapped value.
222
+ + const ns = `__vite__wasmImportInstance_${i}`
223
+ + importStatements.push(
224
+ + `import * as ${ns} from ${JSON.stringify(from + wasmInstanceSuffix)};`,
225
+ + )
226
+ + for (const { name } of globals) {
227
+ + value.push({
228
+ + key: JSON.stringify(name),
229
+ + value: `${ns}[${JSON.stringify(name)}]`,
230
+ + })
231
+ + }
232
+ }
233
+ + return { key: JSON.stringify(from), value }
234
+ },
235
+ )
236
+
237
+ @@ -244,7 +315,7 @@ function generateGlueCode(
238
+
239
+ const exportStatements: string[] = []
240
+ const nameMap = new Map<string, string>()
241
+ - for (const [index, name] of wasmInfo.exports.entries()) {
242
+ + for (const [index, { name }] of wasmInfo.exports.entries()) {
243
+ if (isValidJsDeclareName(name)) {
244
+ exportStatements.push(` ${name},`)
245
+ } else {
246
+ @@ -258,7 +329,7 @@ function generateGlueCode(
247
+ exportStatements.unshift(`const {`)
248
+ exportStatements.push(`} = __vite__wasmModule;`)
249
+ exportStatements.push(`export {`)
250
+ - for (const name of wasmInfo.exports) {
251
+ + for (const { name } of wasmInfo.exports) {
252
+ const localName = nameMap.get(name)
253
+ if (localName) {
254
+ exportStatements.push(` ${localName} as ${JSON.stringify(name)},`)
255
+ @@ -275,6 +346,52 @@ function generateGlueCode(
256
+ return [...importStatements, initCode, ...exportStatements].join('\n')
257
+ }
258
+
259
+ +// User-facing module of a wasm that exports a global. Re-exports the instance
260
+ +// layer and overrides each global with its unwrapped JS value.
261
+ +function generateWrapperGlue(wasmInfo: WasmInfo, instanceId: string): string {
262
+ + const instanceIdLiteral = JSON.stringify(instanceId)
263
+ + const lines = [`export * from ${instanceIdLiteral};`]
264
+ +
265
+ + // `export *` skips `default`, so re-export it explicitly when present.
266
+ + if (wasmInfo.exports.some((e) => e.name === 'default')) {
267
+ + lines.push(`export { default } from ${instanceIdLiteral};`)
268
+ + }
269
+ +
270
+ + const imports: string[] = []
271
+ + const bindings: string[] = []
272
+ + const unwraps: string[] = []
273
+ + const reExports: string[] = []
274
+ + for (const [index, { name, isGlobal }] of wasmInfo.exports.entries()) {
275
+ + if (!isGlobal || name === 'default') continue
276
+ + const alias = `__vite__wasmGlobal_${index}`
277
+ + imports.push(`${codegenModuleExportName(name)} as ${alias}`)
278
+ + // Use the export name as the binding directly; only non-identifier names
279
+ + // need a separate aliased local.
280
+ + const binding = isValidJsDeclareName(name)
281
+ + ? name
282
+ + : `__vite__wasmGlobalValue_${index}`
283
+ + bindings.push(binding)
284
+ + // v128 globals throw in GetGlobalValue and have no JS value, so stay undefined.
285
+ + unwraps.push(`try { ${binding} = ${alias}.value; } catch {}`)
286
+ + reExports.push(
287
+ + binding === name ? name : `${binding} as ${JSON.stringify(name)}`,
288
+ + )
289
+ + }
290
+ +
291
+ + if (bindings.length > 0) {
292
+ + lines.push(`import { ${imports.join(', ')} } from ${instanceIdLiteral};`)
293
+ + lines.push(`let ${bindings.join(', ')};`)
294
+ + lines.push(...unwraps)
295
+ + lines.push(`export { ${reExports.join(', ')} };`)
296
+ + }
297
+ +
298
+ + return lines.join('\n')
299
+ +}
300
+ +
301
+ +function codegenModuleExportName(name: string): string {
302
+ + return isValidJsDeclareName(name) ? name : JSON.stringify(name)
303
+ +}
304
+ +
305
+ type SimpleObject = SimpleObjectKeyValue[]
306
+
307
+ interface SimpleObjectKeyValue {
vite-wasm-global-string-builtins/solution/solve.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ git -C /app apply --binary --whitespace=nowarn /solution/gold.patch
vite-wasm-global-string-builtins/task.toml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.4"
2
+ artifacts = ["/opt/selfbench/agent.patch"]
3
+
4
+ [task]
5
+ name = "selfbench/vite-wasm-global-string-builtins"
6
+ version = "1.0.0"
7
+ description = "Reproduce vite-wasm-global-string-builtins from its authentic engineer request."
8
+ keywords = ["software-engineering", "private-swe", "selfbench", "easy"]
9
+
10
+ [metadata]
11
+ selfbench_task_id = "vite-wasm-global-string-builtins"
12
+ difficulty = "easy"
13
+ repo = "vitejs/vite"
14
+ base_commit = "6319827116c5be2a19c1b91c84ba3d38ad26a41c"
15
+ workdir = "."
16
+ source_pr = 22674
17
+ compiler_revision = 23
18
+
19
+ [agent]
20
+ timeout_sec = 2400.0
21
+ user = "agent"
22
+ network_mode = "allowlist"
23
+ allowed_hosts = ["chatgpt.com", "*.chatgpt.com", "openai.com", "*.openai.com"]
24
+
25
+ [verifier]
26
+ timeout_sec = 1800.0
27
+ user = "root"
28
+ environment_mode = "separate"
29
+ network_mode = "public"
30
+
31
+ [[verifier.collect]]
32
+ service = "main"
33
+ user = "root"
34
+ timeout_sec = 300.0
35
+ command = "git --git-dir=/opt/selfbench/base.git --work-tree=/app add -A && git --git-dir=/opt/selfbench/base.git --work-tree=/app diff --cached --binary HEAD > /opt/selfbench/agent.patch"
36
+
37
+ [environment]
38
+ network_mode = "public"
39
+ build_timeout_sec = 1500.0
40
+ cpus = 4
41
+ memory_mb = 8192
42
+ storage_mb = 20480
43
+
44
+ [verifier.environment]
45
+ network_mode = "public"
46
+ build_timeout_sec = 1500.0
47
+ cpus = 4
48
+ memory_mb = 8192
49
+ storage_mb = 20480
vite-wasm-global-string-builtins/tests/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+ ENV DEBIAN_FRONTEND=noninteractive \
3
+ UV_LINK_MODE=copy \
4
+ UV_CACHE_DIR=/opt/uv-cache \
5
+ UV_PYTHON_INSTALL_DIR=/usr/local/share/uv/python \
6
+ UV_PYTHON_BIN_DIR=/usr/local/bin \
7
+ RUSTUP_HOME=/usr/local/rustup \
8
+ CARGO_HOME=/usr/local/cargo \
9
+ COREPACK_HOME=/opt/corepack \
10
+ PATH=/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ bash build-essential ca-certificates curl git jq passwd pkg-config procps unzip xz-utils \
13
+ && rm -rf /var/lib/apt/lists/*
14
+ ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
15
+ RUN mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" && chmod 755 "$PLAYWRIGHT_BROWSERS_PATH" \
16
+ && arch="$(dpkg --print-architecture)" && case "$arch" in arm64) node_arch=arm64 ;; amd64) node_arch=x64 ;; *) exit 1 ;; esac \
17
+ && curl -fsSL "https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-${node_arch}.tar.xz" | tar -C /usr/local --strip-components=1 -xJ \
18
+ && mkdir -p /opt/corepack && chmod 755 /opt/corepack \
19
+ && corepack enable
20
+ COPY repo.tar.gz /tmp/repo.tar.gz
21
+ RUN mkdir -p /app && tar -xzf /tmp/repo.tar.gz -C /app && rm /tmp/repo.tar.gz \
22
+ && git -C /app init -q \
23
+ && git -C /app config user.email selfbench@local \
24
+ && git -C /app config user.name selfbench \
25
+ && git -C /app add -A \
26
+ && git -C /app commit -qm base
27
+ RUN mkdir -p /opt/uv-cache && chmod 777 /opt/uv-cache \
28
+ && cd '/app/.' \
29
+ && bash -lc 'corepack enable && pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium && pnpm run build' \
30
+ && chmod -R a+rwX /opt/uv-cache
31
+
32
+ RUN useradd --create-home --shell /bin/bash verifier \
33
+ && chown -R verifier:verifier /app /opt/uv-cache \
34
+ && mkdir -p /opt/selfbench \
35
+ && chmod 700 /opt/selfbench \
36
+ && mkdir -p /home/verifier/.cache/uv \
37
+ && chown -R verifier:verifier /home/verifier/.cache
38
+ ENV UV_CACHE_DIR=/home/verifier/.cache/uv \
39
+ UV_NO_BUILD_ISOLATION=1
40
+ COPY test.patch test.sh /tests/
41
+ RUN chmod 700 /tests && chmod 600 /tests/test.patch && chmod +x /tests/test.sh
42
+ WORKDIR /app
vite-wasm-global-string-builtins/tests/repo.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c86ffe35eda3dd43cb9d4db9f36b182e80f919caf9cb5f50027fe0d8eacbf51
3
+ size 12882301
vite-wasm-global-string-builtins/tests/test.patch ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/playground/wasm/__tests__/wasm.spec.ts b/playground/wasm/__tests__/wasm.spec.ts
2
+ index 86cb015b8..a43a75b1b 100644
3
+ --- a/playground/wasm/__tests__/wasm.spec.ts
4
+ +++ b/playground/wasm/__tests__/wasm.spec.ts
5
+ @@ -41,3 +41,27 @@ test('direct wasm import with wasm imports', async () => {
6
+ .poll(() => page.textContent('.direct-wasm-with-imports .result'))
7
+ .toMatch('42')
8
+ })
9
+ +
10
+ +test('direct wasm import unwraps exported WebAssembly.Global', async () => {
11
+ + await expect
12
+ + .poll(() => page.textContent('.direct-wasm-global .result'))
13
+ + .toMatch('42 number')
14
+ +})
15
+ +
16
+ +test('wasm importing a global from another wasm', async () => {
17
+ + await expect
18
+ + .poll(() => page.textContent('.direct-wasm-global-import .result'))
19
+ + .toMatch('43')
20
+ +})
21
+ +
22
+ +test('wasm reading a mutable global mutated by another wasm', async () => {
23
+ + await expect
24
+ + .poll(() => page.textContent('.direct-wasm-mutable-global-import .result'))
25
+ + .toMatch('9')
26
+ +})
27
+ +
28
+ +test('wasm using js-string builtins and imported string constants', async () => {
29
+ + await expect
30
+ + .poll(() => page.textContent('.direct-wasm-string-builtins .result'))
31
+ + .toMatch('5')
32
+ +})
33
+ diff --git a/playground/wasm/global-consumer.wasm b/playground/wasm/global-consumer.wasm
34
+ new file mode 100644
35
+ index 0000000000000000000000000000000000000000..7d925265a5794f06c45f7fe32b7124701c54d3ab
36
+ GIT binary patch
37
+ literal 131
38
+ zcmZQbEY4+QU|?WmWlUgTtY@-h;?>hn&&f|p%+V_c%CRNp6_=+LG1oJoiu2``mLw+S
39
+ zq&nx9=9Pft8JU@x7#P@<m;};OOB}(P0&+@={qs^87`Tg46H}ln85p_vnAjPV85|k2
40
+ KxLFvK8My)aBO%KG
41
+
42
+ literal 0
43
+ HcmV?d00001
44
+
45
+ diff --git a/playground/wasm/global.wasm b/playground/wasm/global.wasm
46
+ new file mode 100644
47
+ index 0000000000000000000000000000000000000000..769dfda95bca8f547101dca8d6062f7dfd72cae0
48
+ GIT binary patch
49
+ literal 108
50
+ zcmXZUF$#k~5CzcxXM;-|NRtZ)v9ie-7BAw8HsWefmy~mLEo@)$5cfm?ETt1OS_e2M
51
+ zV4-3NjT(bj|9up3+5h9_@JjiJ{XDj7UXBas;xGW(=k&Yn+TP+(q2i=Zd>A;@)Dw|E
52
+ B71RI#
53
+
54
+ literal 0
55
+ HcmV?d00001
56
+
57
+ diff --git a/playground/wasm/index.html b/playground/wasm/index.html
58
+ index f2d3c226c..378e9fe9e 100644
59
+ --- a/playground/wasm/index.html
60
+ +++ b/playground/wasm/index.html
61
+ @@ -38,6 +38,31 @@
62
+ <span class="result"></span>
63
+ </div>
64
+
65
+ +<div class="direct-wasm-global">
66
+ + <h3>Direct wasm import of a global, result should be 42 (number)</h3>
67
+ + <span class="result"></span>
68
+ +</div>
69
+ +
70
+ +<div class="direct-wasm-global-import">
71
+ + <h3>wasm importing a global from another wasm, result should be 43</h3>
72
+ + <span class="result"></span>
73
+ +</div>
74
+ +
75
+ +<div class="direct-wasm-mutable-global-import">
76
+ + <h3>
77
+ + wasm reading a mutable global mutated by another wasm, result should be 9
78
+ + </h3>
79
+ + <span class="result"></span>
80
+ +</div>
81
+ +
82
+ +<div class="direct-wasm-string-builtins">
83
+ + <h3>
84
+ + wasm using js-string builtins and imported string constants, result should
85
+ + be 5
86
+ + </h3>
87
+ + <span class="result"></span>
88
+ +</div>
89
+ +
90
+ <script type="module">
91
+ import light from './light.wasm?init'
92
+ import heavy from './heavy.wasm?init'
93
+ @@ -45,6 +70,10 @@
94
+ import { add } from './add.wasm'
95
+ import { exported_func } from './light-with-imports.wasm'
96
+ import { getResult } from './imports.js'
97
+ + import { answer } from './global.wasm'
98
+ + import { getAnswerPlusOne, readCounter } from './global-consumer.wasm'
99
+ + import { bumpCounter } from './global.wasm'
100
+ + import { helloLength } from './string-constants.wasm'
101
+
102
+ const w = new myWorker()
103
+ w.addEventListener('message', (ev) => {
104
+ @@ -56,6 +85,19 @@
105
+ exported_func()
106
+ text('.direct-wasm-with-imports .result', getResult())
107
+
108
+ + text('.direct-wasm-global .result', `${answer} ${typeof answer}`)
109
+ + text('.direct-wasm-global-import .result', getAnswerPlusOne())
110
+ +
111
+ + // The mutable global is a single live cell shared between the two wasm
112
+ + // modules: mutating it from one is observed by the other (7 + 2 = 9).
113
+ + bumpCounter()
114
+ + bumpCounter()
115
+ + text('.direct-wasm-mutable-global-import .result', readCounter())
116
+ +
117
+ + // 'hello'.length, where 'hello' is an engine-provided imported string constant
118
+ + // and `length` is a js-string builtin.
119
+ + text('.direct-wasm-string-builtins .result', helloLength())
120
+ +
121
+ async function testWasm(init, resultElement) {
122
+ const { exported_func } = await init({
123
+ imports: {
124
+ diff --git a/playground/wasm/string-constants.wasm b/playground/wasm/string-constants.wasm
125
+ new file mode 100644
126
+ index 0000000000000000000000000000000000000000..fa6d4db73d01f6c12ffd5d3453be25ed2944ee31
127
+ GIT binary patch
128
+ literal 112
129
+ zcmXZT%L+h17>42R8#zQ_X>ToiZox&6<j|NY|CFU$CoJEmUJSAm0AtnD^6J4$wJJRy
130
+ wZ#JpK9jloGJ(<}pK=FJ1c{N%iZZJ;#WzyPu7M>!*jLF;Gw=s?wphS-32B-ubApigX
131
+
132
+ literal 0
133
+ HcmV?d00001
134
+