feat(serve): Add server-side handlers for Test262 tests [pt 2/5]#56841
feat(serve): Add server-side handlers for Test262 tests [pt 2/5]#56841jcscottiii merged 8 commits intomasterfrom
Conversation
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
ad5fa6b to
72ff9c7
Compare
16aa645 to
d5eb82e
Compare
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
DanielRyanSmith
left a comment
There was a problem hiding this comment.
This suggestion came from a Gemini code review:
File: tools/serve/serve.py
Code: with open(path, encoding='ISO-8859-1') as f:
Criticism: Using ISO-8859-1 to read Test262 source files is risky and possibly incorrect.
The Problem: Test262 contains tests with Unicode identifiers and string literals (stored as UTF-8). Reading them as ISO-8859-1 treats the bytes as Latin-1 characters. If the server framework later encodes the response as UTF-8 (which is standard), multi-byte characters will be "double-encoded" (mangled). For example, a UTF-8 byte sequence for a specific emoji will be read as separate Latin-1 characters and then encoded again.
Fix: Use encoding='utf-8'. If you are worried about mixed encodings in legacy tests, use errors='replace', but Test262 should be UTF-8 compliant.
d5eb82e to
dcdca82
Compare
Handled |
dcdca82 to
df146d5
Compare
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
|
@jgraham This should be good to go now |
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
|
As stated in the other PR, I adjusted the names of the javascript files. If all is well, I can adjust the PR description with the updated names. |
DanielRyanSmith
left a comment
There was a problem hiding this comment.
Some more optional suggestions:
1. Module Execution Order in Test262WindowModuleTestHandler
The wrapper for Test262WindowModuleTestHandler defines the following script:
<script type="module">
test262Setup();
import {} from "%(path)s";
test262Done();
</script>This will not execute in the intended order. In JavaScript ES modules, static import declarations are hoisted. This means that the imported test module (%(path)s) will be fetched and evaluated before test262Setup() is executed. Since test262Setup() initializes the testing harness context (like assert or reporting mechanisms), the test will run without the required setup.
Furthermore, if the imported Test262 module utilizes top-level await, test262Done() will not wait for the module's execution to complete because import inside the same script tag doesn't block the execution of the surrounding synchronous code in the way one might expect when mixing static imports and inline code.
Recommendation:
Separate the setup and teardown into their own script blocks, or use dynamic import() to guarantee execution order.
<script type="module">
test262Setup();
</script>
<script type="module">
import "%(path)s";
</script>
<script type="module">
test262Done();
</script>Note: Using dynamic import("%(path)s").then(test262Done) might be more robust if top-level await is involved.
Optimizations
1. File Read Efficiency in Test262StrictHandler._get_script
In Test262StrictHandler._get_script, the file is loaded into memory entirely:
def _get_script(self, request):
path = self._get_filesystem_path(request)
try:
with open(path, encoding='utf-8') as f:
yield f.read()
except OSError:
raise HTTPException(404)Test262 files can occasionally be large. Reading the entire file into memory at once with f.read() before yielding might cause unnecessary memory overhead, especially if the server processes many concurrent requests.
Recommendation:
Yield the file in chunks instead of a single string.
with open(path, encoding='utf-8') as f:
while True:
chunk = f.read(8192)
if not chunk:
break
yield chunk
Thanks for the suggestions @DanielRyanSmith! I have implemented the module execution order fix. However, I left the streaming part alone for now. We would need to change handle_request in WrapperHandler to stream the whole response. Not just the part that calls _get_script |
| Test262WindowHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowModuleHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowModuleTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictWindowHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictWindowTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictHandler.__test__ = False # type: ignore[attr-defined] |
There was a problem hiding this comment.
I don't understand what this is for.
There was a problem hiding this comment.
Because those handlers start with Test, the unit test runner thinks it is a test to run.
Without these lines completely, we get:
ERROR serve/test_serve.py::Test262WindowHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262WindowHandler' because it has a __init__ constructor...
ERROR serve/test_serve.py::Test262WindowTestHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262WindowTestHandler' because it has a __init__ constru...
ERROR serve/test_serve.py::Test262WindowModuleHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262WindowModuleHandler' because it has a __init__ const...
ERROR serve/test_serve.py::Test262WindowModuleTestHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262WindowModuleTestHandler' because it has a __init__ c...
ERROR serve/test_serve.py::Test262StrictWindowHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262StrictWindowHandler' because it has a __init__ const...
ERROR serve/test_serve.py::Test262StrictWindowTestHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262StrictWindowTestHandler' because it has a __init__ c...
ERROR serve/test_serve.py::Test262StrictHandler - pytest.PytestCollectionWarning: cannot collect test class 'Test262StrictHandler' because it has a __init__ constructor...
We ignore the attr-defined rule for these because, we will get these mypy errors otherwise:
tools/serve/test_serve.py:272: error: "type[Test262WindowHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:273: error: "type[Test262WindowTestHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:274: error: "type[Test262WindowModuleHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:275: error: "type[Test262WindowModuleTestHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:276: error: "type[Test262StrictWindowHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:277: error: "type[Test262StrictWindowTestHandler]" has no attribute "__test__" [attr-defined]
tools/serve/test_serve.py:278: error: "type[Test262StrictHandler]" has no attribute "__test__" [attr-defined]
This is similar to this instance:
wpt/tools/wptrunner/wptrunner/tests/test_wptrunner.py
Lines 12 to 13 in 3d39e2d
or
this (but all mypy errors are ignored here)
wpt/tools/wptrunner/wptrunner/tests/test_wpttest.py
Lines 1 to 13 in 3d39e2d
There was a problem hiding this comment.
Thanks! I realised what was probably going on right before looking at this review again. I think it's confusing enough to warrant a comment.
adef084 to
956ba8b
Compare
| Test262WindowHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowModuleHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262WindowModuleTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictWindowHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictWindowTestHandler.__test__ = False # type: ignore[attr-defined] | ||
| Test262StrictHandler.__test__ = False # type: ignore[attr-defined] |
There was a problem hiding this comment.
Thanks! I realised what was probably going on right before looking at this review again. I think it's confusing enough to warrant a comment.
This commit introduces the necessary server-side handlers within `wptserve`
to dynamically generate HTML wrappers for Test262 JavaScript tests.
This is needed to enable Test262 execution within WPT.
Key changes and their purpose:
- Introduction of several new `HtmlWrapperHandler` and `WrapperHandler`
subclasses (e.g., `Test262WindowHandler`, `Test262WindowTestHandler`,
`Test262StrictHandler`). These handlers are responsible for:
- Identifying Test262 test requests based on URL patterns.
- Dynamically constructing an HTML page that loads the Test262
`.js` test file within an isolated `iframe`.
- Injecting the required Test262 harness files (`assert.js`, `sta.js`)
and the WPT-specific `testharness-client.js` and `harness-adapter.js`
into the generated HTML.
- Processing Test262-specific metadata (like `includes` and `negative`
expectations) extracted by the manifest tooling from PR 1.
- Updates to `RoutesBuilder` in `serve.py` to map incoming requests
for Test262 test URLs to the appropriate new handler.
- Unit tests in `test_serve.py` to validate the correct
behavior of these new handlers, including URL rewriting, metadata
processing, and the structure of the generated HTML wrappers.
This work directly supports the integration of Test262 into WPT as detailed
in the RFC: web-platform-tests/rfcs#229
This commit is the second in a series of smaller PRs split from the larger,
original implementation in #55997.
Co-authored-by: jgraham <[email protected]>
12f7b3e to
1f27a1e
Compare
|
The failing check is this: And it's only failing on Mac os x on a particular python version (whereas other versions passed). And it seems unrelated. Will merge. |
…e tests This commit completes the core integration of Test262 into the WPT runner (`wptrunner`), enabling the execution of Test262 JavaScript conformance tests within the browser environment. This work builds upon the manifest tooling (PR 1 #56840) and server-side handling (PR 2 #56841) to provide a full end-to-end testing solution for Test262. Key components introduced and integrated: - **Client-Side Harness:** New JavaScript files (`harness-adapter.js`, `testharness-client.js`, `testharness.js`) under `resources/test262/` provide the necessary environment for Test262 tests to execute in an `iframe` and report results back to the main WPT testharness. - **Test262 Assertion Libraries (Vendored):** For the purpose of enabling these initial smoke tests, the standard Test262 assertion libraries (`assert.js` and `sta.js`) are directly placed into `third_party/test262/harness/`. This provides the immediate dependencies required by the smoke tests. An autoamted vendoring solution, including version tracking via `vendored.toml`, will be implemented in a subsequent PR focused on automated updates, as described in the RFC. - **Wptrunner Integration:** Modifications to `tools/wptrunner/wpttest.py` and `tools/wptrunner/browsers/*.py` enable `wptrunner` to recognize the `test262` test type and execute it using existing testharness executors. - **Smoke Tests and Metadata:** A suite of basic Test262 smoke tests (`infrastructure/test262/`) and their corresponding expected results (`infrastructure/metadata/infrastructure/test262/`) are added to verify the correct functioning of the entire integration. - **Linting Exemption:** `lint.ignore` is updated to exclude the vendored Test262 harness files from linting, respecting their upstream style. This integration allows browser vendors to run Test262 directly with `wptrunner`, streamlining conformance testing efforts as specified in the RFC: web-platform-tests/rfcs#229 This commit is the third in a series of smaller PRs split from the larger, original implementation in #55997.
This commit introduces the necessary server-side handlers within
wptserveto dynamically generate HTML wrappers for Test262 JavaScript tests. This is needed to enable Test262 execution within WPT.Key changes and their purpose:
HtmlWrapperHandlerandWrapperHandlersubclasses (e.g.,Test262WindowHandler,Test262WindowTestHandler,Test262StrictHandler). These handlers are responsible for:.jstest file within an isolatediframe.assert.js,sta.js) and the WPT-specifictestharness-client.jsandharness-adapter.jsinto the generated HTML.includesandnegativeexpectations) extracted by the manifest tooling from PR 1 (feat(manifest): Add initial tooling for Test262 test types [pt 1/5] #56840 .RoutesBuilderinserve.pyto map incoming requests for Test262 test URLs to the appropriate new handler.test_serve.pyto validate the correct behavior of these new handlers, including URL rewriting, metadata processing, and the structure of the generated HTML wrappers.This work directly supports the integration of Test262 into WPT as detailed in the RFC: web-platform-tests/rfcs#229
This commit is the second in a series of smaller PRs split from the larger, original implementation in #55997.