diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml index 133f2d27..8ba21550 100644 --- a/.github/workflows/BuildAndTest.yml +++ b/.github/workflows/BuildAndTest.yml @@ -280,12 +280,24 @@ jobs: run: cmake . -B ${{github.workspace}}/build-cef -DCMAKE_BUILD_TYPE=Release -DWEBFRONT_EMBED_CEF=ON -DWEBFRONT_BUILD_EXAMPLES=OFF -DENABLE_TESTING=ON -DWEBFRONT_DEVELOPER_FIXTURES=${{github.workspace}}/build-developer-environment - name: Build browser test - run: cmake --build ${{github.workspace}}/build-cef --target webtest developer_integration --parallel 2 + run: cmake --build ${{github.workspace}}/build-cef --target webtest developer_integration webfront-wf --parallel 2 + # Everything is provisioned by the configure step: the tests must not reach the public network. + - name: Cut the public network + run: | + sudo iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -A OUTPUT ! -o lo -j REJECT + sudo ip6tables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo ip6tables -A OUTPUT ! -o lo -j REJECT - name: Run Jasmine bridge test run: >- ctest --test-dir ${{github.workspace}}/build-cef -L web-integration --output-on-failure --no-tests=error --parallel 4 --output-junit "${{ github.workspace }}/build-cef/test-results.xml" + - name: Restore the network + if: always() + run: | + sudo iptables -F OUTPUT + sudo ip6tables -F OUTPUT - name: Retain test timings and diagnostics if: always() uses: actions/upload-artifact@v4 diff --git a/AGENTS.md b/AGENTS.md index 6782434e..910b6d3c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,7 +20,7 @@ The README introduces WebFront through the Game of Life walkthrough, demonstrati - `examples/`: only Hello World (`hello-world/`) and Game of Life (`life/`, with console, developer and embedded stages). - `js/core/`: readable browser bridge, fallback and bootstrap loader compiled into `include/webfront/`, plus the embedding CMake modules; `js/developer/`: developer environment (its terminal and `wf`), build and vendoring tools. Production C++ remains header-only in `include/webfront/`. - `js/developer/tools/starters/pi/`, `test/fixtures/`, `test/web/fixtures/`: retained package and regression fixtures, not public example applications. -- `test/unit/`: Catch2 unit tests; `test/web/`: Jasmine real-browser integration test; `test/fuzz/`, `test/fixtures/`; `test/cmake/`: CMake test scripts and sub-projects. The `RepositoryLayout` CTest case pins the tracked root. +- `test/unit/`: Catch2 unit tests; `test/web/`: Jasmine real-browser integration test; `test/driver/`: `webfront-wf`, the non-interactive `wf` driver for tests; `test/fuzz/`, `test/fixtures/`; `test/cmake/`: CMake test scripts and sub-projects. The `RepositoryLayout` CTest case pins the tracked root. - `cmake/`: build modules (frontends, CEF, CPM, compiler options); `.github/`: workflows, `.github/CONTRIBUTING.md`. - `.devcontainer/`: devcontainer and its Dockerfile; `docs/`: documentation, `docs/CHANGELOG.md`, `docs/Doxyfile.in`. - `docs/PROJECT_STATUS.md`: evidence-based status snapshot and known limitations. diff --git a/cmake/WebFrontBootstrap.cmake b/cmake/WebFrontBootstrap.cmake new file mode 100644 index 00000000..66eec1aa --- /dev/null +++ b/cmake/WebFrontBootstrap.cmake @@ -0,0 +1,148 @@ +# Bootstrap environment used to test WebFront: the pinned archive wf runs from, provisioned at configure time. +# +# It is distinct from include/webfront/system/DeveloperReleaseData.hpp (the environment applications start from) and is +# updated by an explicit pull request, once a published environment can build and test itself without interaction. +# 0.5.0 is the last published environment: it has no non-interactive mode yet, so the driver tests run the environment built +# from the current sources (the "environment under test") until the first environment that can bootstrap itself is pinned. +set(WEBFRONT_BOOTSTRAP_VERSION "0.5.0") +set(WEBFRONT_BOOTSTRAP_URL "https://ambroise-leclerc.github.io/WebFront/developer/0.5.0/environment.tgz") +set(WEBFRONT_BOOTSTRAP_INTEGRITY "sha512-TV6S61kUhnCJc99/Ow890Pro47mfZ0fBqki17lx0xnpCNmcfcqZPpO1SG09Su50WIEtRDopMxt3yvanFwbLEdQ==") + +# A directory holding environment.tgz (the pinned archive) replaces the download on a machine without network access. +set(WEBFRONT_BOOTSTRAP_DIR "" CACHE PATH "Directory with the pinned bootstrap environment.tgz, instead of downloading it") + +# Converts a base64 value to lowercase hexadecimal bytes. +function(webfront_base64_to_hex value output) + set(alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") + string(LENGTH "${value}" length) + math(EXPR remainder "${length} % 4") + if(NOT remainder EQUAL 0) + message(FATAL_ERROR "Invalid base64 value (length ${length})") + endif() + set(hex "") + math(EXPR last "${length} - 1") + foreach(start RANGE 0 ${last} 4) + set(group 0) + set(padding 0) + foreach(offset RANGE 0 3) + math(EXPR position "${start} + ${offset}") + string(SUBSTRING "${value}" ${position} 1 character) + if(character STREQUAL "=") + math(EXPR padding "${padding} + 1") + set(sextet 0) + else() + string(FIND "${alphabet}" "${character}" sextet) + if(sextet EQUAL -1) + message(FATAL_ERROR "Invalid base64 character '${character}'") + endif() + endif() + math(EXPR group "(${group} << 6) | ${sextet}") + endforeach() + math(EXPR bytes "3 - ${padding}") + foreach(index RANGE 0 ${bytes}) + if(index EQUAL bytes) + break() + endif() + math(EXPR shift "16 - 8 * ${index}") + math(EXPR byte "(${group} >> ${shift}) & 255" OUTPUT_FORMAT HEXADECIMAL) + string(SUBSTRING "${byte}" 2 -1 digits) + string(LENGTH "${digits}" digitCount) + if(digitCount EQUAL 1) + set(digits "0${digits}") + endif() + string(APPEND hex "${digits}") + endforeach() + endforeach() + set(${output} "${hex}" PARENT_SCOPE) +endfunction() + +# The hexadecimal SHA-512 of an SRI value ("sha512-"). +function(webfront_sri_to_sha512 integrity output) + if(NOT integrity MATCHES "^sha512-([A-Za-z0-9+/]+=*)$") + message(FATAL_ERROR "Bootstrap integrity must be a sha512- SRI value: '${integrity}'") + endif() + webfront_base64_to_hex("${CMAKE_MATCH_1}" hex) + string(LENGTH "${hex}" length) + if(NOT length EQUAL 128) + message(FATAL_ERROR "Bootstrap integrity is not a SHA-512 digest") + endif() + set(${output} "${hex}" PARENT_SCOPE) +endfunction() + +# Makes the verified path of an environment archive: / when LOCAL_DIR is given, else the +# download of URL into DESTINATION (reused when it already matches). A wrong digest or a missing file stops the configure. +function(webfront_provision_bootstrap archive) + cmake_parse_arguments(ARG "" "URL;INTEGRITY;DESTINATION;LOCAL_DIR" "" ${ARGN}) + webfront_sri_to_sha512("${ARG_INTEGRITY}" expected) + get_filename_component(name "${ARG_URL}" NAME) + if(ARG_LOCAL_DIR) + set(path "${ARG_LOCAL_DIR}/${name}") + if(NOT EXISTS "${path}") + message(FATAL_ERROR "Bootstrap environment ${path} is missing: WEBFRONT_BOOTSTRAP_DIR must hold ${name}") + endif() + else() + set(path "${ARG_DESTINATION}/${name}") + set(present FALSE) + if(EXISTS "${path}") + file(SHA512 "${path}" actual) + if(actual STREQUAL expected) + set(present TRUE) + endif() + endif() + if(NOT present) + file(MAKE_DIRECTORY "${ARG_DESTINATION}") + file(DOWNLOAD "${ARG_URL}" "${path}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) + list(GET result 0 code) + if(NOT code EQUAL 0) + file(REMOVE "${path}") + list(GET result 1 reason) + message(FATAL_ERROR "Cannot download the bootstrap environment ${ARG_URL}: ${reason}. " + "Provision it with -DWEBFRONT_BOOTSTRAP_DIR=.") + endif() + endif() + endif() + file(SHA512 "${path}" actual) + if(NOT actual STREQUAL expected) + if(NOT ARG_LOCAL_DIR) + file(REMOVE "${path}") + endif() + message(FATAL_ERROR "Bootstrap environment integrity check failed for ${path}: expected ${ARG_INTEGRITY}") + endif() + set(${archive} "${path}" PARENT_SCOPE) +endfunction() + +# The SRI value ("sha512-") of a file, for archives a test builds itself. +function(webfront_file_sri file output) + file(SHA512 "${file}" hex) + set(alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") + string(LENGTH "${hex}" length) + set(encoded "") + foreach(start RANGE 0 ${length} 6) + if(start GREATER_EQUAL length) + break() + endif() + math(EXPR remaining "(${length} - ${start}) / 2") + string(SUBSTRING "${hex}" ${start} 6 digits) + string(LENGTH "${digits}" digitCount) + string(APPEND digits "000000") + string(SUBSTRING "${digits}" 0 6 digits) + math(EXPR group "0x${digits}") + set(characters 4) + if(remaining EQUAL 1) + set(characters 2) + elseif(remaining EQUAL 2) + set(characters 3) + endif() + foreach(index RANGE 0 3) + math(EXPR shift "18 - 6 * ${index}") + math(EXPR sextet "(${group} >> ${shift}) & 63") + if(index LESS characters) + string(SUBSTRING "${alphabet}" ${sextet} 1 character) + else() + set(character "=") + endif() + string(APPEND encoded "${character}") + endforeach() + endforeach() + set(${output} "sha512-${encoded}" PARENT_SCOPE) +endfunction() diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7de45e54..9f658b3f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,13 @@ ### Added +- `webfront-wf` test driver and bootstrap provisioning (#321): runs one `wf` command without interaction on a project + and exits with its status (64 usage, 70 bootstrap failure, 71 time limit, 72 no result), with an optional JSON report. + `cmake/WebFrontBootstrap.cmake` pins the bootstrap environment (0.5.0 for now) and, with `ENABLE_TESTING=ON`, downloads + and verifies it at configure time, or takes it from `WEBFRONT_BOOTSTRAP_DIR`. `environment.json` declares `protocol` and + `api`; `webfront.developer.config` exposes the supported versions and the loader refuses an incompatible archive with an + explicit diagnostic. The Linux CEF job blocks the public network after configure. + - `wf test [--timeout ] [pattern]` (#310, environment sources; release pin unchanged): builds the manifest's `test.specs` with esbuild-wasm and runs them under the project's locked `jasmine-core`, obtained by `wf install` from the registry, in a hidden same-origin frame. Progress and a summary stream to the terminal; the structured report diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 80b0e671..7a5c12f5 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -481,7 +481,7 @@ each per spec). `status` is `passed`, `failed`, `incomplete`, `error` (the specs ### Without a terminal -An application that drives the environment from its own page (the C++ driver of #321 will be one) calls +An application that drives the environment from its own page (`webfront-wf`, below, is one) calls `runNonInteractive(argv, {bridge, config, preview, reporter, onExit})` from `runtime.mjs`: ```js @@ -496,6 +496,44 @@ by default closes the window. A command that fails, or a result that cannot be s the session is never left open. The C++ side reads the result, closes the application's window if it has not been closed and returns the code as its process status. +### The test driver (`webfront-wf`) and the bootstrap environment + +`webfront-wf` (`test/driver/WebFrontWf.cpp`, built with the browser tests) starts a `BasicDeveloperApp` on a project, runs +one `wf` command through `runNonInteractive`, prints its output and exits with its status: + +```sh +webfront-wf --project [--environment --integrity ] [--registry-dir ] \ + [--report ] [--timeout ] [--] [arguments...] +``` + +- Without `--environment`, it uses the **bootstrap environment** provisioned at configure time. `cmake/WebFrontBootstrap.cmake` + pins its URL and SHA-512 (distinct from `DeveloperReleaseData.hpp`, the environment applications start from, and changed + by an explicit pull request). With `ENABLE_TESTING=ON`, configure downloads it to `/bootstrap/` and verifies the + digest; a wrong digest or an unreachable URL stops the configure. On a machine without network access, pass + `-DWEBFRONT_BOOTSTRAP_DIR=`: the archive is verified the same way. +- `--environment` and `--integrity` run an archive built elsewhere, such as the one built from the current sources (the + environment under test of #315). `--registry-dir` serves a local npm registry from the driver's origin and imposes it. + The project is the directory `wf` reads and writes; run `wf install` once, then the other commands, on the same project. +- Exit status: the command's own (`wf test`: 0, 1, 124, 130); **64** usage; **70** bootstrap failure (archive absent, wrong + integrity, incompatible protocol or API, no non-interactive mode); **71** the driver's `--timeout` (default 600 s) elapsed, + after asking the page to close; **72** the browser closed without a result. `--report` writes the JSON result + `{exitCode, output, report}` of the command, cut to fit a bridge string as described above. + +**Compatibility contract.** `environment.json` declares `protocol` (the environment's wire protocol) and `api` (the +`webfront.developer.*` callbacks it expects; absent means 1, the value of every environment published before the +field). `webfront.developer.config` carries `supported: {protocol: [1], api: [1]}`, from `developer::protocolVersion` and +`developer::apiVersion`. The loader refuses an archive outside those lists before publishing anything, with +`Incompatible WebFront developer environment: api version 2, this application supports 1`; it never falls back. A change +to the callbacks increments `apiVersion` and requires publishing a new bootstrap environment. + +The pin is 0.5.0, the last published environment, which has no non-interactive mode: the driver reports it as a bootstrap +failure (70). Until an environment that can run `wf test` is published and pinned (the milestone of #321, a maintainer +step), the CTest cases `WfDriver*` run the environment built from the current sources (`WEBFRONT_DEVELOPER_FIXTURES`): +`wf install` and `wf test` on a fixture project (pass, fail, report file), an unknown command, the time limit, a wrong +integrity, a missing archive and archives with an incompatible protocol or API. `BootstrapProvisioning` checks the +configure-time provisioning (verified download, reuse, local directory, wrong digest, malformed value). The Linux CEF CI job +blocks the public network after the configure step. + ## Dependencies, storage and limitations - `wf install` accepts exact versions, registry tags and semver ranges, resolves ordinary diff --git a/docs/PROJECT_STATUS.md b/docs/PROJECT_STATUS.md index f9079dcf..6ddad553 100644 --- a/docs/PROJECT_STATUS.md +++ b/docs/PROJECT_STATUS.md @@ -132,7 +132,7 @@ Status snapshot: 2026-07-19. Optional mddlog integration note: 2026-10-02. Newco manifest permissions, which frame the `context` API only and are not a sandbox. Peers require explicit compatible roots/direct dependencies. The environment's terminal (#308) runs `wf`, built-in and C++ commands (`webfront::Commands`: per-browser coroutine sessions, streamed output, Ctrl+C cancellation without waiting, drained at shutdown) with - multi-row editing, CJK/emoji widths, persistent history and completion. `wf build` / `wf dev` (#309, environment sources) publish manifest entries and rebuild the preview automatically with a reused esbuild context, bounded input polling, error overlays and Ctrl+C cancellation; `wf test` (#310, environment sources) runs the manifest's specs under the project's locked `jasmine-core` in a hidden frame, with a structured report, exit codes 0/1/124/130 and a non-interactive entry that reports to C++; the release pin is unchanged. `wf restore [--offline]` (0.5.0, #306) rebuilds or checks + multi-row editing, CJK/emoji widths, persistent history and completion. `wf build` / `wf dev` (#309, environment sources) publish manifest entries and rebuild the preview automatically with a reused esbuild context, bounded input polling, error overlays and Ctrl+C cancellation; `wf test` (#310, environment sources) runs the manifest's specs under the project's locked `jasmine-core` in a hidden frame, with a structured report, exit codes 0/1/124/130 and a non-interactive entry that reports to C++; the release pin is unchanged. `webfront-wf` (#321) runs one `wf` command without interaction and returns its status; the bootstrap environment is pinned and verified at configure time (0.5.0 for now: the first environment able to run `wf test` still has to be published and pinned), and `environment.json` declares the `protocol` and `api` versions that the loader checks. `wf restore [--offline]` (0.5.0, #306) rebuilds or checks the cache from the lock, from the application's registry option, else the manifest's, else npmjs. See [DEVELOPER_ENVIRONMENT](DEVELOPER_ENVIRONMENT.md) for exact commands and limits. diff --git a/include/webfront/DeveloperApp.hpp b/include/webfront/DeveloperApp.hpp index a212c2e3..aa92e66f 100644 --- a/include/webfront/DeveloperApp.hpp +++ b/include/webfront/DeveloperApp.hpp @@ -45,6 +45,12 @@ inline void validateBootstrap(std::string_view mode, const std::filesystem::path throw std::invalid_argument("The developer registry must be an HTTPS URL or a same-origin path"); } +/// The environment contract this C++ implements. An environment's environment.json declares the "protocol" it +/// speaks and the "api" (the webfront.developer.* callbacks) it expects; the loader refuses any other version. +/// Changing a callback increments apiVersion and requires publishing a new bootstrap environment. +inline constexpr int protocolVersion = 1; +inline constexpr int apiVersion = 1; + inline constexpr std::string_view defaultRegistry{"https://registry.npmjs.org/"}; /// The configuration the environment reads. "registry" always names a usable registry, for environments @@ -52,7 +58,8 @@ inline constexpr std::string_view defaultRegistry{"https://registry.npmjs.org/"} inline std::string bootstrapConfig(const DeveloperBootstrapOptions& options) { return "{\"environment\":" + json::quote(options.environment) + ",\"integrity\":" + json::quote(options.integrity) + ",\"registry\":" + json::quote(options.registry.value_or(std::string(defaultRegistry))) - + ",\"registryExplicit\":" + (options.registry ? "true" : "false") + "}"; + + ",\"registryExplicit\":" + (options.registry ? "true" : "false") + + ",\"supported\":{\"protocol\":[" + std::to_string(protocolVersion) + "],\"api\":[" + std::to_string(apiVersion) + "]}}"; } } // namespace developer diff --git a/include/webfront/system/DeveloperBootstrapData.hpp b/include/webfront/system/DeveloperBootstrapData.hpp index 0f656918..2bbdc69e 100644 --- a/include/webfront/system/DeveloperBootstrapData.hpp +++ b/include/webfront/system/DeveloperBootstrapData.hpp @@ -9,9 +9,9 @@ namespace webfront::fs::generated { struct DeveloperBootstrapData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{6195}; - static constexpr std::array data{ - 0x766172206c3d6e65, 0x7720546578744465, 0x636f6465723b6173, 0x796e632066756e63, 0x74696f6e20682865, + static constexpr std::size_t dataSize{6534}; + static constexpr std::array data{ + 0x766172206c3d6e65, 0x7720546578744465, 0x636f6465723b6173, 0x796e632066756e63, 0x74696f6e20772865, 0x2c74297b6c657420, 0x723d537472696e67, 0x28743f3f2222292e, 0x73706c6974282f5c, 0x732b2f292e66696c, 0x74657228613d3e61, 0x2e73746172747357, 0x6974682822736861, 0x3531322d2229292e, 0x6d617028613d3e61, 0x2e73706c69742822, 0x3f22295b305d293b, 0x696628722e6c656e, 0x6774683d3d3d3029, 0x7468726f77206e65, @@ -24,7 +24,7 @@ struct DeveloperBootstrapData { 0x792e66726f6d286e, 0x2c613d3e53747269, 0x6e672e66726f6d43, 0x686172436f646528, 0x6129292e6a6f696e, 0x28222229293b6966, 0x2821722e696e636c, 0x75646573286f2929, 0x7468726f77206e65, 0x77204572726f7228, 0x60496e7465677269, 0x747920636865636b, 0x206661696c65643a, 0x2065787065637465, 0x6420247b725b305d, - 0x7d2c20676f742024, 0x7b6f7d60293b7265, 0x7475726e206f7d61, 0x73796e632066756e, 0x6374696f6e207028, + 0x7d2c20676f742024, 0x7b6f7d60293b7265, 0x7475726e206f7d61, 0x73796e632066756e, 0x6374696f6e206828, 0x652c743d32363834, 0x3335343536297b6c, 0x657420723d6e6577, 0x20426c6f62285b65, 0x5d292e7374726561, 0x6d28292e70697065, 0x5468726f75676828, 0x6e6577204465636f, 0x6d7072657373696f, 0x6e53747265616d28, 0x22677a6970222929, 0x2e67657452656164, 0x657228292c6e3d5b, 0x5d2c6f3d303b666f, 0x72286c657420613d, @@ -41,131 +41,140 @@ struct DeveloperBootstrapData { 0x293b6c6574206e3d, 0x7528652c742c7229, 0x2e7472696d28293b, 0x696628212f5e5b30, 0x2d375d2a242f2e74, 0x657374286e292974, 0x68726f77206e6577, 0x204572726f722822, 0x436f727275707420, 0x7461722068656164, 0x657222293b726574, 0x75726e206e3d3d3d, 0x22223f303a706172, 0x7365496e74286e2c, 0x38297d66756e6374, - 0x696f6e207a286529, 0x7b6c657420743d30, 0x3b666f72286c6574, 0x20723d303b723c35, 0x31323b2b2b722974, + 0x696f6e2042286529, 0x7b6c657420743d30, 0x3b666f72286c6574, 0x20723d303b723c35, 0x31323b2b2b722974, 0x2b3d723e3d313438, 0x2626723c3135363f, 0x33323a655b725d3b, 0x6966287928652c31, 0x34382c3829213d3d, 0x74297468726f7720, 0x6e6577204572726f, 0x722822436f727275, 0x7074207461722068, 0x6561646572206368, - 0x65636b73756d2229, 0x7d66756e6374696f, 0x6e20422865297b6c, 0x657420743d7b7d2c, 0x723d303b666f7228, + 0x65636b73756d2229, 0x7d66756e6374696f, 0x6e20542865297b6c, 0x657420743d7b7d2c, 0x723d303b666f7228, 0x3b723c652e6c656e, 0x6774683b297b6c65, 0x74206e3d652e696e, 0x6465784f66283332, 0x2c72292c6f3d6e3c, 0x303f4e614e3a4e75, 0x6d626572286c2e64, 0x65636f646528652e, 0x7375626172726179, 0x28722c6e2929293b, 0x69662821286f3e30, 0x297c7c722b6f3e65, 0x2e6c656e67746829, 0x7468726f77206e65, 0x77204572726f7228, 0x22436f7272757074, 0x2070617820686561, 0x64657222293b6c65, 0x7420613d6c2e6465, 0x636f646528652e73, 0x7562617272617928, 0x6e2b312c722b6f2d, 0x3129292c693d612e, 0x696e6465784f6628, 0x223d22293b745b61, 0x2e736c6963652830, 0x2c69295d3d612e73, 0x6c69636528692b31, 0x292c722b3d6f7d72, 0x657475726e20747d, - 0x66756e6374696f6e, 0x205428652c74297b, 0x6c657420723d652e, 0x7375626172726179, 0x28742c742b353132, - 0x293b7a2872293b6c, 0x6574206e3d792872, 0x2c3132342c313229, 0x2c6f3d742b353132, 0x3b6966286f2b6e3e, + 0x66756e6374696f6e, 0x204328652c74297b, 0x6c657420723d652e, 0x7375626172726179, 0x28742c742b353132, + 0x293b422872293b6c, 0x6574206e3d792872, 0x2c3132342c313229, 0x2c6f3d742b353132, 0x3b6966286f2b6e3e, 0x652e6c656e677468, 0x297468726f77206e, 0x6577204572726f72, 0x28225472756e6361, 0x7465642074617220, 0x6172636869766522, 0x293b72657475726e, 0x7b6865616465723a, 0x722c747970653a72, 0x5b3135365d3d3d3d, 0x303f2230223a5374, 0x72696e672e66726f, 0x6d43686172436f64, 0x6528725b3135365d, 0x292c646174613a65, 0x2e73756261727261, 0x79286f2c6f2b6e29, 0x2c6e6578743a6f2b, 0x4d6174682e636569, 0x6c286e2f35313229, - 0x2a3531327d7d6675, 0x6e6374696f6e2043, 0x28652c74297b7265, 0x7475726e20742b35, 0x31323e652e6c656e, + 0x2a3531327d7d6675, 0x6e6374696f6e2049, 0x28652c74297b7265, 0x7475726e20742b35, 0x31323e652e6c656e, 0x6774687c7c652e73, 0x7562617272617928, 0x742c742b35313229, 0x2e65766572792872, 0x3d3e723d3d3d3029, - 0x7d66756e6374696f, 0x6e20492865297b6c, 0x657420743d752865, 0x2c302c313030292c, 0x723d7528652c3235, + 0x7d66756e6374696f, 0x6e20552865297b6c, 0x657420743d752865, 0x2c302c313030292c, 0x723d7528652c3235, 0x372c35293d3d3d22, 0x7573746172223f75, 0x28652c3334352c31, 0x3535293a22223b72, 0x657475726e20723f, - 0x60247b727d2f247b, 0x747d603a747d7661, 0x7220773d7b783a28, 0x652c74293d3e287b, 0x2e2e2e652c706178, - 0x3a422874292e7061, 0x74687d292c4c3a28, 0x652c74293d3e287b, 0x2e2e2e652c6c6f6e, 0x673a7528742c302c, + 0x60247b727d2f247b, 0x747d603a747d7661, 0x7220703d7b783a28, 0x652c74293d3e287b, 0x2e2e2e652c706178, + 0x3a542874292e7061, 0x74687d292c4c3a28, 0x652c74293d3e287b, 0x2e2e2e652c6c6f6e, 0x673a7528742c302c, 0x742e6c656e677468, 0x297d292c673a653d, 0x3e657d3b66756e63, 0x74696f6e206d2865, 0x297b6c657420743d, - 0x5b5d2c723d7b7d3b, 0x666f72286c657420, 0x6e3d303b21432865, 0x2c6e293b297b6c65, 0x747b686561646572, - 0x3a6f2c747970653a, 0x612c646174613a69, 0x2c6e6578743a737d, 0x3d5428652c6e293b, 0x6966286e3d732c4f, - 0x626a6563742e6861, 0x734f776e28772c61, 0x29297b723d775b61, 0x5d28722c69293b63, 0x6f6e74696e75657d, + 0x5b5d2c723d7b7d3b, 0x666f72286c657420, 0x6e3d303b21492865, 0x2c6e293b297b6c65, 0x747b686561646572, + 0x3a6f2c747970653a, 0x612c646174613a69, 0x2c6e6578743a637d, 0x3d4328652c6e293b, 0x6966286e3d632c4f, + 0x626a6563742e6861, 0x734f776e28702c61, 0x29297b723d705b61, 0x5d28722c69293b63, 0x6f6e74696e75657d, 0x28613d3d3d223022, 0x7c7c613d3d3d2237, 0x22292626742e7075, 0x7368287b70617468, 0x3a722e7061783f3f, - 0x722e6c6f6e673f3f, 0x49286f292c627974, 0x65733a697d292c72, 0x3d7b7d7d72657475, 0x726e20747d766172, - 0x20633d28652c742c, 0x2e2e2e72293d3e65, 0x2e63707046756e63, 0x74696f6e28607765, 0x6266726f6e742e64, - 0x6576656c6f706572, 0x2e247b747d602928, 0x2e2e2e72293b6173, 0x796e632066756e63, 0x74696f6e20672865, - 0x2c74297b6c657420, 0x723d5b5d2c6e3d30, 0x3b666f72283b3b29, 0x7b6c6574206f3d61, 0x7761697420632865, + 0x722e6c6f6e673f3f, 0x55286f292c627974, 0x65733a697d292c72, 0x3d7b7d7d72657475, 0x726e20747d766172, + 0x20733d28652c742c, 0x2e2e2e72293d3e65, 0x2e63707046756e63, 0x74696f6e28607765, 0x6266726f6e742e64, + 0x6576656c6f706572, 0x2e247b747d602928, 0x2e2e2e72293b6173, 0x796e632066756e63, 0x74696f6e20622865, + 0x2c74297b6c657420, 0x723d5b5d2c6e3d30, 0x3b666f72283b3b29, 0x7b6c6574206f3d61, 0x7761697420732865, 0x2c2272656164222c, 0x742c6e293b696628, 0x722e70757368286f, 0x292c6e2b3d6f2e6c, 0x656e6774682c6f2e, 0x6c656e6774683c32, 0x3632313434296272, 0x65616b3b6966286e, 0x3e3235362a313032, 0x342a313032342974, 0x68726f77206e6577, 0x204572726f722822, 0x50726f6a65637420, 0x66696c6520697320, 0x746f6f206c617267, 0x6522297d72657475, 0x726e206e65772055, 0x696e743841727261, 0x7928617761697420, 0x6e657720426c6f62, - 0x2872292e61727261, 0x7942756666657228, 0x29297d6173796e63, 0x2066756e6374696f, 0x6e205528652c7b69, + 0x2872292e61727261, 0x7942756666657228, 0x29297d6173796e63, 0x2066756e6374696f, 0x6e202428652c7b69, 0x643a742c70617468, 0x3a722c6279746573, 0x3a6e7d2c6f297b66, 0x6f72286c65742061, 0x3d303b613c6e2e6c, 0x656e6774687c7c61, 0x3d3d3d303b612b3d, 0x323632313434296f, 0x3f2e7468726f7749, 0x6641626f72746564, - 0x28292c6177616974, 0x206328652c227772, 0x697465222c742c72, 0x2c612c6e2e737562, 0x617272617928612c, - 0x612b323632313434, 0x29297d6173796e63, 0x2066756e6374696f, 0x6e206628652c742c, 0x722c7b6469726563, + 0x28292c6177616974, 0x207328652c227772, 0x697465222c742c72, 0x2c612c6e2e737562, 0x617272617928612c, + 0x612b323632313434, 0x29297d6173796e63, 0x2066756e6374696f, 0x6e206428652c742c, 0x722c7b6469726563, 0x746f72793a6e3d21, 0x302c7369676e616c, 0x3a6f2c7265706c61, 0x63653a613d21307d, 0x3d7b7d297b6c6574, - 0x20693d6177616974, 0x206328652c613f22, 0x626567696e223a22, 0x626567696e4e6577, 0x222c742c6e293b74, - 0x72797b666f72286c, 0x65745b732c535d6f, 0x6620722961776169, 0x74205528652c7b69, 0x643a692c70617468, - 0x3a732c6279746573, 0x3a537d2c6f293b6f, 0x3f2e7468726f7749, 0x6641626f72746564, 0x28292c6177616974, - 0x206328652c22636f, 0x6d6d6974222c6929, 0x7d63617463682873, 0x297b7468726f7720, 0x6177616974206328, - 0x652c2261626f7274, 0x222c69292e636174, 0x63682828293d3e7b, 0x7d292c737d7d6173, 0x796e632066756e63, - 0x74696f6e20502865, 0x2c74297b6c657420, 0x723d5b5d2c6e3d30, 0x3b666f72283b3b29, 0x7b6c65747b646f6e, + 0x20693d6177616974, 0x207328652c613f22, 0x626567696e223a22, 0x626567696e4e6577, 0x222c742c6e293b74, + 0x72797b666f72286c, 0x65745b632c7a5d6f, 0x6620722961776169, 0x74202428652c7b69, 0x643a692c70617468, + 0x3a632c6279746573, 0x3a7a7d2c6f293b6f, 0x3f2e7468726f7749, 0x6641626f72746564, 0x28292c6177616974, + 0x207328652c22636f, 0x6d6d6974222c6929, 0x7d63617463682863, 0x297b7468726f7720, 0x6177616974207328, + 0x652c2261626f7274, 0x222c69292e636174, 0x63682828293d3e7b, 0x7d292c637d7d6173, 0x796e632066756e63, + 0x74696f6e206a2865, 0x2c74297b6c657420, 0x723d5b5d2c6e3d30, 0x3b666f72283b3b29, 0x7b6c65747b646f6e, 0x653a6f2c76616c75, 0x653a617d3d617761, 0x697420652e726561, 0x6428293b6966286f, 0x2972657475726e20, 0x723b6966286e2b3d, 0x612e6c656e677468, 0x2c6e3e7429746872, 0x6f77206e65772045, 0x72726f722822436f, 0x6d70726573736564, 0x20646f776e6c6f61, 0x6420657863656564, 0x7320697473206279, 0x7465206c696d6974, - 0x22293b722e707573, 0x682861297d7d6173, 0x796e632066756e63, 0x74696f6e20242865, 0x2c74297b7472797b, - 0x72657475726e2061, 0x7761697420502865, 0x2c74297d63617463, 0x682872297b746872, 0x6f77206177616974, + 0x22293b722e707573, 0x682861297d7d6173, 0x796e632066756e63, 0x74696f6e20502865, 0x2c74297b7472797b, + 0x72657475726e2061, 0x77616974206a2865, 0x2c74297d63617463, 0x682872297b746872, 0x6f77206177616974, 0x20652e63616e6365, 0x6c28292e63617463, 0x682828293d3e7b7d, 0x292c727d66696e61, 0x6c6c797b652e7265, - 0x6c656173654c6f63, 0x6b28297d7d617379, 0x6e632066756e6374, 0x696f6e206228652c, 0x743d36342a313032, + 0x6c656173654c6f63, 0x6b28297d7d617379, 0x6e632066756e6374, 0x696f6e207628652c, 0x743d36342a313032, 0x342a31303234297b, 0x69662821652e6f6b, 0x297468726f77206e, 0x6577204572726f72, 0x2860446f776e6c6f, 0x61643a2048545450, 0x20247b652e737461, 0x7475737d60293b69, 0x66284e756d626572, 0x28652e6865616465, 0x72732e6765742822, 0x636f6e74656e742d, 0x6c656e6774682229, 0x293e74297468726f, 0x77206e6577204572, 0x726f722822436f6d, 0x7072657373656420, 0x646f776e6c6f6164, 0x2065786365656473, 0x2069747320627974, 0x65206c696d697422, 0x293b72657475726e, 0x206e65772055696e, 0x7438417272617928, 0x6177616974206e65, - 0x7720426c6f622861, 0x7761697420242865, 0x2e626f64792e6765, 0x7452656164657228, 0x292c7429292e6172, - 0x7261794275666665, 0x722829297d766172, 0x206a3d2f5b5c5c5c, 0x303a2a3f223c3e7c, 0x5d2f2c413d653d3e, + 0x7720426c6f622861, 0x7761697420502865, 0x2e626f64792e6765, 0x7452656164657228, 0x292c7429292e6172, + 0x7261794275666665, 0x722829297d766172, 0x204f3d2f5b5c5c5c, 0x303a2a3f223c3e7c, 0x5d2f2c413d653d3e, 0x652e73706c697428, 0x222f22292e736f6d, 0x6528743d3e21747c, 0x7c743d3d3d222e22, 0x7c7c743d3d3d222e, - 0x2e22293b66756e63, 0x74696f6e20762865, 0x297b72657475726e, 0x20747970656f6620, 0x65213d2273747269, - 0x6e67227c7c21657c, 0x7c6a2e7465737428, 0x65293f21303a4128, 0x65297d7661722064, 0x3d653d3e21762865, - 0x292c4f3d6e657720, 0x546578744465636f, 0x6465723b66756e63, 0x74696f6e20462865, 0x2c74297b69662821, + 0x2e22293b66756e63, 0x74696f6e20672865, 0x297b72657475726e, 0x20747970656f6620, 0x65213d2273747269, + 0x6e67227c7c21657c, 0x7c4f2e7465737428, 0x65293f21303a4128, 0x65297d7661722066, 0x3d653d3e21672865, + 0x292c463d6e657720, 0x546578744465636f, 0x6465723b66756e63, 0x74696f6e204c2865, 0x2c74297b69662821, 0x742e706174682e73, 0x7461727473576974, 0x6828227061636b61, 0x67652f2229297468, 0x726f77206e657720, 0x4572726f72282249, 0x6e76616c69642065, 0x6e7669726f6e6d65, 0x6e74206172636869, 0x766520726f6f7422, - 0x293b6c657420723d, 0x742e706174682e73, 0x6c6963652838293b, 0x6966282164287229, 0x7c7c652e68617328, + 0x293b6c657420723d, 0x742e706174682e73, 0x6c6963652838293b, 0x6966282166287229, 0x7c7c652e68617328, 0x7229297468726f77, 0x206e657720457272, 0x6f722822496e7661, 0x6c6964206f722064, 0x75706c6963617465, 0x20656e7669726f6e, 0x6d656e7420706174, 0x6822293b652e7365, 0x7428722c742e6279, 0x746573297d66756e, - 0x6374696f6e204c28, 0x65297b6c65742074, 0x3d6e6577204d6170, 0x3b666f72286c6574, 0x2072206f66206d28, - 0x6529294628742c72, 0x293b72657475726e, 0x20747d66756e6374, 0x696f6e204e28652c, 0x74297b7265747572, - 0x6e20652e70726f74, 0x6f636f6c213d3d31, 0x7c7c216428652e65, 0x6e747279293f2131, 0x3a742e6861732865, - 0x2e656e747279297d, 0x6173796e63206675, 0x6e6374696f6e2078, 0x28652c74297b6177, 0x616974206828652c, - 0x74293b6c65742072, 0x3d4c286177616974, 0x2070286529293b69, 0x662821722e686173, 0x2822656e7669726f, - 0x6e6d656e742e6a73, 0x6f6e222929746872, 0x6f77206e65772045, 0x72726f722822456e, 0x7669726f6e6d656e, - 0x7420617263686976, 0x6520686173206e6f, 0x20656e7669726f6e, 0x6d656e742e6a736f, 0x6e22293b6c657420, - 0x6e3d4a534f4e2e70, 0x61727365284f2e64, 0x65636f646528722e, 0x6765742822656e76, 0x69726f6e6d656e74, - 0x2e6a736f6e222929, 0x293b696628214e28, 0x6e2c722929746872, 0x6f77206e65772045, 0x72726f722822556e, - 0x737570706f727465, 0x642057656246726f, 0x6e7420646576656c, 0x6f70657220656e76, 0x69726f6e6d656e74, - 0x22293b7265747572, 0x6e7b66696c65733a, 0x722c6d616e696665, 0x73743a6e7d7d7661, 0x7220453d222e7765, - 0x6266726f6e742f64, 0x6576656c6f706572, 0x2f656e7669726f6e, 0x6d656e742e74677a, 0x223b6173796e6320, - 0x66756e6374696f6e, 0x205228652c74297b, 0x7472797b6c657420, 0x723d617761697420, 0x6728652c45293b72, - 0x657475726e206177, 0x616974207828722c, 0x74292c727d636174, 0x63687b7265747572, 0x6e206e756c6c7d7d, - 0x6173796e63206675, 0x6e6374696f6e2044, 0x28652c74297b6c65, 0x7420723d6e657720, 0x55524c28652e656e, - 0x7669726f6e6d656e, 0x742c6c6f63617469, 0x6f6e2e6872656629, 0x3b696628722e7072, 0x6f746f636f6c213d, - 0x3d2268747470733a, 0x222626722e6f7269, 0x67696e213d3d6c6f, 0x636174696f6e2e6f, 0x726967696e297468, - 0x726f77206e657720, 0x4572726f72282254, 0x686520656e766972, 0x6f6e6d656e74206d, 0x7573742075736520, - 0x4854545053206f72, 0x2074686520617070, 0x6c69636174696f6e, 0x206f726967696e22, 0x293b6c6574206e3d, - 0x6177616974207428, 0x72293b696628216e, 0x2e6f6b297468726f, 0x77206e6577204572, 0x726f722860456e76, - 0x69726f6e6d656e74, 0x20646f776e6c6f61, 0x643a204854545020, 0x247b6e2e73746174, 0x75737d60293b7265, - 0x7475726e2062286e, 0x297d66756e637469, 0x6f6e20482865297b, 0x72657475726e2165, 0x7c7c216428652e61, - 0x726368697665293f, 0x21313a537472696e, 0x6728652e696e7465, 0x6772697479292e73, 0x7461727473576974, - 0x6828227368613531, 0x322d22297d66756e, 0x6374696f6e205728, 0x652c74297b726574, 0x75726e204f626a65, - 0x63742e66726f6d45, 0x6e7472696573284f, 0x626a6563742e656e, 0x747269657328652e, 0x7374617274657273, - 0x3f3f7b7d292e6d61, 0x7028285b722c6e5d, 0x293d3e7b69662821, 0x48286e2929746872, 0x6f77206e65772045, - 0x72726f722822496e, 0x76616c6964207069, 0x6e6e656420737461, 0x72746572206d6574, 0x616461746122293b, - 0x72657475726e5b72, 0x2c7b75726c3a6e65, 0x772055524c286e2e, 0x617263686976652c, 0x74292e687265662c, - 0x696e746567726974, 0x793a6e2e696e7465, 0x67726974797d5d7d, 0x29297d6173796e63, 0x2066756e6374696f, - 0x6e206b28652c742c, 0x723d66657463682c, 0x6e3d28293d3e7b7d, 0x297b6c6574206f3d, 0x6177616974205228, - 0x652c742e696e7465, 0x6772697479293b6f, 0x3f6e28225573696e, 0x6720766572696669, 0x6564206361636865, - 0x6420646576656c6f, 0x70657220656e7669, 0x726f6e6d656e7422, 0x293a286e2822446f, 0x776e6c6f6164696e, - 0x6720646576656c6f, 0x70657220656e7669, 0x726f6e6d656e7422, 0x292c6f3d61776169, 0x74204428742c7229, - 0x293b6c65747b6669, 0x6c65733a612c6d61, 0x6e69666573743a69, 0x7d3d617761697420, 0x78286f2c742e696e, - 0x7465677269747929, 0x2c733d5728692c6e, 0x65772055524c2874, 0x2e656e7669726f6e, 0x6d656e742c6c6f63, - 0x6174696f6e2e6872, 0x656629293b726574, 0x75726e2061776169, 0x74206628652c222e, 0x77656266726f6e74, - 0x2f646576656c6f70, 0x65722f656e766972, 0x6f6e6d656e74222c, 0x61292c6177616974, 0x206628652c452c6e, - 0x6577204d6170285b, 0x5b226f7574707574, 0x222c6f5d5d292c7b, 0x6469726563746f72, 0x793a21317d292c7b, - 0x75726c3a602f7765, 0x6266726f6e742f64, 0x6576656c6f706572, 0x2f656e7669726f6e, 0x6d656e742f247b69, - 0x2e656e7472797d60, 0x2c636f6e6669673a, 0x7b2e2e2e742c7374, 0x6172746572733a73, 0x7d7d7d6966287479, - 0x70656f6620646f63, 0x756d656e743c2275, 0x222626646f63756d, 0x656e742e67657445, 0x6c656d656e744279, - 0x4964282272657472, 0x792229297b6c6574, 0x20653d646f63756d, 0x656e742e67657445, 0x6c656d656e744279, - 0x4964282273746174, 0x757322292c743d64, 0x6f63756d656e742e, 0x676574456c656d65, 0x6e74427949642822, - 0x726574727922292c, 0x723d6173796e6328, 0x293d3e7b742e6869, 0x6464656e3d21303b, 0x7472797b61776169, - 0x742077656246726f, 0x6e742e7265616479, 0x3b6c6574206e3d4a, 0x534f4e2e70617273, 0x6528617761697420, - 0x632877656246726f, 0x6e742c22636f6e66, 0x69672229292c7b75, 0x726c3a6f2c636f6e, 0x6669673a617d3d61, - 0x77616974206b2877, 0x656246726f6e742c, 0x6e2c66657463682c, 0x733d3e7b652e7465, 0x7874436f6e74656e, - 0x743d737d293b6177, 0x6169742861776169, 0x7420696d706f7274, 0x286f29292e6d6f75, 0x6e74287b62726964, - 0x67653a7765624672, 0x6f6e742c636f6e66, 0x69673a612c746572, 0x6d696e616c3a646f, 0x63756d656e742e67, - 0x6574456c656d656e, 0x7442794964282274, 0x65726d696e616c22, 0x292c707265766965, 0x773a646f63756d65, - 0x6e742e676574456c, 0x656d656e74427949, 0x6428227072657669, 0x657722297d292c65, 0x2e74657874436f6e, - 0x74656e743d224465, 0x76656c6f70657220, 0x656e7669726f6e6d, 0x656e742072656164, 0x792e205479706520, - 0x77662068656c702e, 0x227d636174636828, 0x6e297b652e746578, 0x74436f6e74656e74, 0x3d60426f6f747374, - 0x726170206661696c, 0x65643a20247b6e2e, 0x6d6573736167657d, 0x602c742e68696464, 0x656e3d21317d7d3b, - 0x742e616464457665, 0x6e744c697374656e, 0x65722822636c6963, 0x6b222c72292c7228, 0x297d0a0000000000 + 0x6374696f6e204e28, 0x65297b6c65742074, 0x3d6e6577204d6170, 0x3b666f72286c6574, 0x2072206f66206d28, + 0x6529294c28742c72, 0x293b72657475726e, 0x20747d7661722078, 0x3d7b70726f746f63, 0x6f6c3a5b315d2c61, + 0x70693a5b315d7d3b, 0x66756e6374696f6e, 0x205228652c74297b, 0x6c657420723d7b70, 0x726f746f636f6c3a, + 0x652e70726f746f63, 0x6f6c2c6170693a65, 0x2e6170693f3f317d, 0x3b666f72286c6574, 0x5b6e2c6f5d6f6620, + 0x4f626a6563742e65, 0x6e74726965732872, 0x29297b6c65742061, 0x3d743f2e5b6e5d3f, 0x3f785b6e5d3b6966, + 0x2821612e696e636c, 0x75646573286f2929, 0x7468726f77206e65, 0x77204572726f7228, 0x60496e636f6d7061, + 0x7469626c65205765, 0x6246726f6e742064, 0x6576656c6f706572, 0x20656e7669726f6e, 0x6d656e743a20247b, + 0x6e7d207665727369, 0x6f6e20247b6f7d2c, 0x2074686973206170, 0x706c69636174696f, 0x6e20737570706f72, + 0x747320247b612e6a, 0x6f696e28222c2022, 0x297d60297d7d6675, 0x6e6374696f6e2044, 0x28652c74297b6966, + 0x28747970656f6620, 0x652e656e74727921, 0x3d22737472696e67, 0x227c7c216628652e, 0x656e747279297c7c, + 0x21742e6861732865, 0x2e656e7472792929, 0x7468726f77206e65, 0x77204572726f7228, 0x22556e737570706f, + 0x7274656420576562, 0x46726f6e74206465, 0x76656c6f70657220, 0x656e7669726f6e6d, 0x656e743a20696e76, + 0x616c696420656e74, 0x727922297d617379, 0x6e632066756e6374, 0x696f6e204528652c, 0x742c723d78297b61, + 0x7761697420772865, 0x2c74293b6c657420, 0x6e3d4e2861776169, 0x742068286529293b, 0x696628216e2e6861, + 0x732822656e766972, 0x6f6e6d656e742e6a, 0x736f6e2229297468, 0x726f77206e657720, 0x4572726f72282245, + 0x6e7669726f6e6d65, 0x6e74206172636869, 0x766520686173206e, 0x6f20656e7669726f, 0x6e6d656e742e6a73, + 0x6f6e22293b6c6574, 0x206f3d4a534f4e2e, 0x706172736528462e, 0x6465636f6465286e, 0x2e6765742822656e, + 0x7669726f6e6d656e, 0x742e6a736f6e2229, 0x29293b7265747572, 0x6e2052286f2c7229, 0x2c44286f2c6e292c, + 0x7b66696c65733a6e, 0x2c6d616e69666573, 0x743a6f7d7d766172, 0x206b3d222e776562, 0x66726f6e742f6465, + 0x76656c6f7065722f, 0x656e7669726f6e6d, 0x656e742e74677a22, 0x3b6173796e632066, 0x756e6374696f6e20, + 0x5728652c742c7229, 0x7b7472797b6c6574, 0x206e3d6177616974, 0x206228652c6b293b, 0x72657475726e2061, + 0x776169742045286e, 0x2c742c72292c6e7d, 0x63617463687b7265, 0x7475726e206e756c, 0x6c7d7d6173796e63, + 0x2066756e6374696f, 0x6e204828652c7429, 0x7b6c657420723d6e, 0x65772055524c2865, 0x2e656e7669726f6e, + 0x6d656e742c6c6f63, 0x6174696f6e2e6872, 0x6566293b69662872, 0x2e70726f746f636f, 0x6c213d3d22687474, + 0x70733a222626722e, 0x6f726967696e213d, 0x3d6c6f636174696f, 0x6e2e6f726967696e, 0x297468726f77206e, + 0x6577204572726f72, 0x282254686520656e, 0x7669726f6e6d656e, 0x74206d7573742075, 0x7365204854545053, + 0x206f722074686520, 0x6170706c69636174, 0x696f6e206f726967, 0x696e22293b6c6574, 0x206e3d6177616974, + 0x20742872293b6966, 0x28216e2e6f6b2974, 0x68726f77206e6577, 0x204572726f722860, 0x456e7669726f6e6d, + 0x656e7420646f776e, 0x6c6f61643a204854, 0x545020247b6e2e73, 0x74617475737d6029, 0x3b72657475726e20, + 0x76286e297d66756e, 0x6374696f6e204d28, 0x65297b7265747572, 0x6e21657c7c216628, 0x652e617263686976, + 0x65293f21313a5374, 0x72696e6728652e69, 0x6e74656772697479, 0x292e737461727473, 0x5769746828227368, + 0x613531322d22297d, 0x66756e6374696f6e, 0x204a28652c74297b, 0x72657475726e204f, 0x626a6563742e6672, + 0x6f6d456e74726965, 0x73284f626a656374, 0x2e656e7472696573, 0x28652e7374617274, 0x6572733f3f7b7d29, + 0x2e6d617028285b72, 0x2c6e5d293d3e7b69, 0x6628214d286e2929, 0x7468726f77206e65, 0x77204572726f7228, + 0x22496e76616c6964, 0x2070696e6e656420, 0x7374617274657220, 0x6d65746164617461, 0x22293b7265747572, + 0x6e5b722c7b75726c, 0x3a6e65772055524c, 0x286e2e6172636869, 0x76652c74292e6872, 0x65662c696e746567, + 0x726974793a6e2e69, 0x6e74656772697479, 0x7d5d7d29297d6173, 0x796e632066756e63, 0x74696f6e20532865, + 0x2c742c723d666574, 0x63682c6e3d28293d, 0x3e7b7d297b6c6574, 0x206f3d6177616974, 0x205728652c742e69, + 0x6e74656772697479, 0x2c742e737570706f, 0x72746564293b6f3f, 0x6e28225573696e67, 0x2076657269666965, + 0x6420636163686564, 0x20646576656c6f70, 0x657220656e766972, 0x6f6e6d656e742229, 0x3a286e2822446f77, + 0x6e6c6f6164696e67, 0x20646576656c6f70, 0x657220656e766972, 0x6f6e6d656e742229, 0x2c6f3d6177616974, + 0x204828742c722929, 0x3b6c65747b66696c, 0x65733a612c6d616e, 0x69666573743a697d, 0x3d61776169742045, + 0x286f2c742e696e74, 0x6567726974792c74, 0x2e737570706f7274, 0x6564292c633d4a28, 0x692c6e6577205552, + 0x4c28742e656e7669, 0x726f6e6d656e742c, 0x6c6f636174696f6e, 0x2e6872656629293b, 0x72657475726e2061, + 0x7761697420642865, 0x2c222e7765626672, 0x6f6e742f64657665, 0x6c6f7065722f656e, 0x7669726f6e6d656e, + 0x74222c61292c6177, 0x616974206428652c, 0x6b2c6e6577204d61, 0x70285b5b226f7574, 0x707574222c6f5d5d, + 0x292c7b6469726563, 0x746f72793a21317d, 0x292c7b75726c3a60, 0x2f77656266726f6e, 0x742f646576656c6f, + 0x7065722f656e7669, 0x726f6e6d656e742f, 0x247b692e656e7472, 0x797d602c636f6e66, 0x69673a7b2e2e2e74, + 0x2c73746172746572, 0x733a637d7d7d6966, 0x28747970656f6620, 0x646f63756d656e74, 0x3c2275222626646f, + 0x63756d656e742e67, 0x6574456c656d656e, 0x7442794964282272, 0x657472792229297b, 0x6c657420653d646f, + 0x63756d656e742e67, 0x6574456c656d656e, 0x7442794964282273, 0x746174757322292c, 0x743d646f63756d65, + 0x6e742e676574456c, 0x656d656e74427949, 0x6428227265747279, 0x22292c723d617379, 0x6e6328293d3e7b74, + 0x2e68696464656e3d, 0x21303b7472797b61, 0x7761697420776562, 0x46726f6e742e7265, 0x6164793b6c657420, + 0x6e3d4a534f4e2e70, 0x6172736528617761, 0x6974207328776562, 0x46726f6e742c2263, 0x6f6e666967222929, + 0x2c7b75726c3a6f2c, 0x636f6e6669673a61, 0x7d3d617761697420, 0x532877656246726f, 0x6e742c6e2c666574, + 0x63682c633d3e7b65, 0x2e74657874436f6e, 0x74656e743d637d29, 0x3b61776169742861, 0x7761697420696d70, + 0x6f7274286f29292e, 0x6d6f756e74287b62, 0x72696467653a7765, 0x6246726f6e742c63, 0x6f6e6669673a612c, + 0x7465726d696e616c, 0x3a646f63756d656e, 0x742e676574456c65, 0x6d656e7442794964, 0x28227465726d696e, + 0x616c22292c707265, 0x766965773a646f63, 0x756d656e742e6765, 0x74456c656d656e74, 0x4279496428227072, + 0x657669657722297d, 0x292c652e74657874, 0x436f6e74656e743d, 0x22446576656c6f70, 0x657220656e766972, + 0x6f6e6d656e742072, 0x656164792e205479, 0x7065207766206865, 0x6c702e227d636174, 0x6368286e297b652e, + 0x74657874436f6e74, 0x656e743d60426f6f, 0x7473747261702066, 0x61696c65643a2024, 0x7b6e2e6d65737361, + 0x67657d602c742e68, 0x696464656e3d2131, 0x7d7d3b742e616464, 0x4576656e744c6973, 0x74656e6572282263, + 0x6c69636b222c7229, 0x2c7228297d0a0000 }; }; diff --git a/js/core/bootstrap/bootstrap.bundle.mjs b/js/core/bootstrap/bootstrap.bundle.mjs index 6aa88502..5e4f2eb0 100644 --- a/js/core/bootstrap/bootstrap.bundle.mjs +++ b/js/core/bootstrap/bootstrap.bundle.mjs @@ -1 +1 @@ -var l=new TextDecoder;async function h(e,t){let r=String(t??"").split(/\s+/).filter(a=>a.startsWith("sha512-")).map(a=>a.split("?")[0]);if(r.length===0)throw new Error("The package has no SHA-512 integrity");if(!globalThis.crypto?.subtle)throw new Error("Integrity checks need a secure context (https or localhost)");let n=new Uint8Array(await crypto.subtle.digest("SHA-512",e)),o="sha512-"+btoa(Array.from(n,a=>String.fromCharCode(a)).join(""));if(!r.includes(o))throw new Error(`Integrity check failed: expected ${r[0]}, got ${o}`);return o}async function p(e,t=268435456){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream("gzip")).getReader(),n=[],o=0;for(let a=await r.read();!a.done;a=await r.read()){if(o+=a.value.length,o>t)throw await r.cancel(),new Error(`The tarball unpacks to more than ${t} bytes`);n.push(a.value)}return new Uint8Array(await new Blob(n).arrayBuffer())}function u(e,t,r){let n=e.subarray(t,t+r),o=n.indexOf(0);return l.decode(o<0?n:n.subarray(0,o))}function y(e,t,r){if(e[t]&128)return e.subarray(t+1,t+r).reduce((o,a)=>o*256+a,e[t]&127);let n=u(e,t,r).trim();if(!/^[0-7]*$/.test(n))throw new Error("Corrupt tar header");return n===""?0:parseInt(n,8)}function z(e){let t=0;for(let r=0;r<512;++r)t+=r>=148&&r<156?32:e[r];if(y(e,148,8)!==t)throw new Error("Corrupt tar header checksum")}function B(e){let t={},r=0;for(;r0)||r+o>e.length)throw new Error("Corrupt pax header");let a=l.decode(e.subarray(n+1,r+o-1)),i=a.indexOf("=");t[a.slice(0,i)]=a.slice(i+1),r+=o}return t}function T(e,t){let r=e.subarray(t,t+512);z(r);let n=y(r,124,12),o=t+512;if(o+n>e.length)throw new Error("Truncated tar archive");return{header:r,type:r[156]===0?"0":String.fromCharCode(r[156]),data:e.subarray(o,o+n),next:o+Math.ceil(n/512)*512}}function C(e,t){return t+512>e.length||e.subarray(t,t+512).every(r=>r===0)}function I(e){let t=u(e,0,100),r=u(e,257,5)==="ustar"?u(e,345,155):"";return r?`${r}/${t}`:t}var w={x:(e,t)=>({...e,pax:B(t).path}),L:(e,t)=>({...e,long:u(t,0,t.length)}),g:e=>e};function m(e){let t=[],r={};for(let n=0;!C(e,n);){let{header:o,type:a,data:i,next:s}=T(e,n);if(n=s,Object.hasOwn(w,a)){r=w[a](r,i);continue}(a==="0"||a==="7")&&t.push({path:r.pax??r.long??I(o),bytes:i}),r={}}return t}var c=(e,t,...r)=>e.cppFunction(`webfront.developer.${t}`)(...r);async function g(e,t){let r=[],n=0;for(;;){let o=await c(e,"read",t,n);if(r.push(o),n+=o.length,o.length<262144)break;if(n>256*1024*1024)throw new Error("Project file is too large")}return new Uint8Array(await new Blob(r).arrayBuffer())}async function U(e,{id:t,path:r,bytes:n},o){for(let a=0;a{}),s}}async function P(e,t){let r=[],n=0;for(;;){let{done:o,value:a}=await e.read();if(o)return r;if(n+=a.length,n>t)throw new Error("Compressed download exceeds its byte limit");r.push(a)}}async function $(e,t){try{return await P(e,t)}catch(r){throw await e.cancel().catch(()=>{}),r}finally{e.releaseLock()}}async function b(e,t=64*1024*1024){if(!e.ok)throw new Error(`Download: HTTP ${e.status}`);if(Number(e.headers.get("content-length"))>t)throw new Error("Compressed download exceeds its byte limit");return new Uint8Array(await new Blob(await $(e.body.getReader(),t)).arrayBuffer())}var j=/[\\\0:*?"<>|]/,A=e=>e.split("/").some(t=>!t||t==="."||t==="..");function v(e){return typeof e!="string"||!e||j.test(e)?!0:A(e)}var d=e=>!v(e),O=new TextDecoder;function F(e,t){if(!t.path.startsWith("package/"))throw new Error("Invalid environment archive root");let r=t.path.slice(8);if(!d(r)||e.has(r))throw new Error("Invalid or duplicate environment path");e.set(r,t.bytes)}function L(e){let t=new Map;for(let r of m(e))F(t,r);return t}function N(e,t){return e.protocol!==1||!d(e.entry)?!1:t.has(e.entry)}async function x(e,t){await h(e,t);let r=L(await p(e));if(!r.has("environment.json"))throw new Error("Environment archive has no environment.json");let n=JSON.parse(O.decode(r.get("environment.json")));if(!N(n,r))throw new Error("Unsupported WebFront developer environment");return{files:r,manifest:n}}var E=".webfront/developer/environment.tgz";async function R(e,t){try{let r=await g(e,E);return await x(r,t),r}catch{return null}}async function D(e,t){let r=new URL(e.environment,location.href);if(r.protocol!=="https:"&&r.origin!==location.origin)throw new Error("The environment must use HTTPS or the application origin");let n=await t(r);if(!n.ok)throw new Error(`Environment download: HTTP ${n.status}`);return b(n)}function H(e){return!e||!d(e.archive)?!1:String(e.integrity).startsWith("sha512-")}function W(e,t){return Object.fromEntries(Object.entries(e.starters??{}).map(([r,n])=>{if(!H(n))throw new Error("Invalid pinned starter metadata");return[r,{url:new URL(n.archive,t).href,integrity:n.integrity}]}))}async function k(e,t,r=fetch,n=()=>{}){let o=await R(e,t.integrity);o?n("Using verified cached developer environment"):(n("Downloading developer environment"),o=await D(t,r));let{files:a,manifest:i}=await x(o,t.integrity),s=W(i,new URL(t.environment,location.href));return await f(e,".webfront/developer/environment",a),await f(e,E,new Map([["output",o]]),{directory:!1}),{url:`/webfront/developer/environment/${i.entry}`,config:{...t,starters:s}}}if(typeof document<"u"&&document.getElementById("retry")){let e=document.getElementById("status"),t=document.getElementById("retry"),r=async()=>{t.hidden=!0;try{await webFront.ready;let n=JSON.parse(await c(webFront,"config")),{url:o,config:a}=await k(webFront,n,fetch,s=>{e.textContent=s});await(await import(o)).mount({bridge:webFront,config:a,terminal:document.getElementById("terminal"),preview:document.getElementById("preview")}),e.textContent="Developer environment ready. Type wf help."}catch(n){e.textContent=`Bootstrap failed: ${n.message}`,t.hidden=!1}};t.addEventListener("click",r),r()} +var l=new TextDecoder;async function w(e,t){let r=String(t??"").split(/\s+/).filter(a=>a.startsWith("sha512-")).map(a=>a.split("?")[0]);if(r.length===0)throw new Error("The package has no SHA-512 integrity");if(!globalThis.crypto?.subtle)throw new Error("Integrity checks need a secure context (https or localhost)");let n=new Uint8Array(await crypto.subtle.digest("SHA-512",e)),o="sha512-"+btoa(Array.from(n,a=>String.fromCharCode(a)).join(""));if(!r.includes(o))throw new Error(`Integrity check failed: expected ${r[0]}, got ${o}`);return o}async function h(e,t=268435456){let r=new Blob([e]).stream().pipeThrough(new DecompressionStream("gzip")).getReader(),n=[],o=0;for(let a=await r.read();!a.done;a=await r.read()){if(o+=a.value.length,o>t)throw await r.cancel(),new Error(`The tarball unpacks to more than ${t} bytes`);n.push(a.value)}return new Uint8Array(await new Blob(n).arrayBuffer())}function u(e,t,r){let n=e.subarray(t,t+r),o=n.indexOf(0);return l.decode(o<0?n:n.subarray(0,o))}function y(e,t,r){if(e[t]&128)return e.subarray(t+1,t+r).reduce((o,a)=>o*256+a,e[t]&127);let n=u(e,t,r).trim();if(!/^[0-7]*$/.test(n))throw new Error("Corrupt tar header");return n===""?0:parseInt(n,8)}function B(e){let t=0;for(let r=0;r<512;++r)t+=r>=148&&r<156?32:e[r];if(y(e,148,8)!==t)throw new Error("Corrupt tar header checksum")}function T(e){let t={},r=0;for(;r0)||r+o>e.length)throw new Error("Corrupt pax header");let a=l.decode(e.subarray(n+1,r+o-1)),i=a.indexOf("=");t[a.slice(0,i)]=a.slice(i+1),r+=o}return t}function C(e,t){let r=e.subarray(t,t+512);B(r);let n=y(r,124,12),o=t+512;if(o+n>e.length)throw new Error("Truncated tar archive");return{header:r,type:r[156]===0?"0":String.fromCharCode(r[156]),data:e.subarray(o,o+n),next:o+Math.ceil(n/512)*512}}function I(e,t){return t+512>e.length||e.subarray(t,t+512).every(r=>r===0)}function U(e){let t=u(e,0,100),r=u(e,257,5)==="ustar"?u(e,345,155):"";return r?`${r}/${t}`:t}var p={x:(e,t)=>({...e,pax:T(t).path}),L:(e,t)=>({...e,long:u(t,0,t.length)}),g:e=>e};function m(e){let t=[],r={};for(let n=0;!I(e,n);){let{header:o,type:a,data:i,next:c}=C(e,n);if(n=c,Object.hasOwn(p,a)){r=p[a](r,i);continue}(a==="0"||a==="7")&&t.push({path:r.pax??r.long??U(o),bytes:i}),r={}}return t}var s=(e,t,...r)=>e.cppFunction(`webfront.developer.${t}`)(...r);async function b(e,t){let r=[],n=0;for(;;){let o=await s(e,"read",t,n);if(r.push(o),n+=o.length,o.length<262144)break;if(n>256*1024*1024)throw new Error("Project file is too large")}return new Uint8Array(await new Blob(r).arrayBuffer())}async function $(e,{id:t,path:r,bytes:n},o){for(let a=0;a{}),c}}async function j(e,t){let r=[],n=0;for(;;){let{done:o,value:a}=await e.read();if(o)return r;if(n+=a.length,n>t)throw new Error("Compressed download exceeds its byte limit");r.push(a)}}async function P(e,t){try{return await j(e,t)}catch(r){throw await e.cancel().catch(()=>{}),r}finally{e.releaseLock()}}async function v(e,t=64*1024*1024){if(!e.ok)throw new Error(`Download: HTTP ${e.status}`);if(Number(e.headers.get("content-length"))>t)throw new Error("Compressed download exceeds its byte limit");return new Uint8Array(await new Blob(await P(e.body.getReader(),t)).arrayBuffer())}var O=/[\\\0:*?"<>|]/,A=e=>e.split("/").some(t=>!t||t==="."||t==="..");function g(e){return typeof e!="string"||!e||O.test(e)?!0:A(e)}var f=e=>!g(e),F=new TextDecoder;function L(e,t){if(!t.path.startsWith("package/"))throw new Error("Invalid environment archive root");let r=t.path.slice(8);if(!f(r)||e.has(r))throw new Error("Invalid or duplicate environment path");e.set(r,t.bytes)}function N(e){let t=new Map;for(let r of m(e))L(t,r);return t}var x={protocol:[1],api:[1]};function R(e,t){let r={protocol:e.protocol,api:e.api??1};for(let[n,o]of Object.entries(r)){let a=t?.[n]??x[n];if(!a.includes(o))throw new Error(`Incompatible WebFront developer environment: ${n} version ${o}, this application supports ${a.join(", ")}`)}}function D(e,t){if(typeof e.entry!="string"||!f(e.entry)||!t.has(e.entry))throw new Error("Unsupported WebFront developer environment: invalid entry")}async function E(e,t,r=x){await w(e,t);let n=N(await h(e));if(!n.has("environment.json"))throw new Error("Environment archive has no environment.json");let o=JSON.parse(F.decode(n.get("environment.json")));return R(o,r),D(o,n),{files:n,manifest:o}}var k=".webfront/developer/environment.tgz";async function W(e,t,r){try{let n=await b(e,k);return await E(n,t,r),n}catch{return null}}async function H(e,t){let r=new URL(e.environment,location.href);if(r.protocol!=="https:"&&r.origin!==location.origin)throw new Error("The environment must use HTTPS or the application origin");let n=await t(r);if(!n.ok)throw new Error(`Environment download: HTTP ${n.status}`);return v(n)}function M(e){return!e||!f(e.archive)?!1:String(e.integrity).startsWith("sha512-")}function J(e,t){return Object.fromEntries(Object.entries(e.starters??{}).map(([r,n])=>{if(!M(n))throw new Error("Invalid pinned starter metadata");return[r,{url:new URL(n.archive,t).href,integrity:n.integrity}]}))}async function S(e,t,r=fetch,n=()=>{}){let o=await W(e,t.integrity,t.supported);o?n("Using verified cached developer environment"):(n("Downloading developer environment"),o=await H(t,r));let{files:a,manifest:i}=await E(o,t.integrity,t.supported),c=J(i,new URL(t.environment,location.href));return await d(e,".webfront/developer/environment",a),await d(e,k,new Map([["output",o]]),{directory:!1}),{url:`/webfront/developer/environment/${i.entry}`,config:{...t,starters:c}}}if(typeof document<"u"&&document.getElementById("retry")){let e=document.getElementById("status"),t=document.getElementById("retry"),r=async()=>{t.hidden=!0;try{await webFront.ready;let n=JSON.parse(await s(webFront,"config")),{url:o,config:a}=await S(webFront,n,fetch,c=>{e.textContent=c});await(await import(o)).mount({bridge:webFront,config:a,terminal:document.getElementById("terminal"),preview:document.getElementById("preview")}),e.textContent="Developer environment ready. Type wf help."}catch(n){e.textContent=`Bootstrap failed: ${n.message}`,t.hidden=!1}};t.addEventListener("click",r),r()} diff --git a/js/developer/environment/bootstrap.mjs b/js/developer/environment/bootstrap.mjs index d27284db..3b1f8ee4 100644 --- a/js/developer/environment/bootstrap.mjs +++ b/js/developer/environment/bootstrap.mjs @@ -19,27 +19,41 @@ function archiveFiles(tarball) { return files; } -function supported(manifest, files) { - if (manifest.protocol !== 1) return false; - if (!safePath(manifest.entry)) return false; - return files.has(manifest.entry); +// What the current C++ accepts when it does not say (a test, a config written before the contract): the first release. +const defaultSupported = {protocol: [1], api: [1]}; + +// An archive is refused with the reason, never used with a fallback. An environment that predates "api" was built for the +// first webfront.developer.* API, so a missing "api" reads as 1; any other declared version must be one the C++ supports. +function checkCompatible(manifest, supported) { + const versions = {protocol: manifest.protocol, api: manifest.api ?? 1}; + for (const [name, version] of Object.entries(versions)) { + const accepted = supported?.[name] ?? defaultSupported[name]; + if (!accepted.includes(version)) + throw new Error(`Incompatible WebFront developer environment: ${name} version ${version}, this application supports ${accepted.join(', ')}`); + } +} + +function checkEntry(manifest, files) { + if (typeof manifest.entry !== 'string' || !safePath(manifest.entry) || !files.has(manifest.entry)) + throw new Error('Unsupported WebFront developer environment: invalid entry'); } -export async function environmentFiles(bytes, integrity) { +export async function environmentFiles(bytes, integrity, supported = defaultSupported) { await verifyIntegrity(bytes, integrity); const files = archiveFiles(await gunzip(bytes)); if (!files.has('environment.json')) throw new Error('Environment archive has no environment.json'); const manifest = JSON.parse(decoder.decode(files.get('environment.json'))); - if (!supported(manifest, files)) throw new Error('Unsupported WebFront developer environment'); + checkCompatible(manifest, supported); + checkEntry(manifest, files); return {files, manifest}; } const cachedPath = '.webfront/developer/environment.tgz'; -async function verifiedCache(bridge, integrity) { +async function verifiedCache(bridge, integrity, supported) { try { const candidate = await readProject(bridge, cachedPath); - await environmentFiles(candidate, integrity); + await environmentFiles(candidate, integrity, supported); return candidate; } catch { return null; } } @@ -67,13 +81,13 @@ function pinnedStarters(manifest, environmentUrl) { } export async function bootstrap(bridge, config, fetchImpl = fetch, progress = () => {}) { - let bytes = await verifiedCache(bridge, config.integrity); + let bytes = await verifiedCache(bridge, config.integrity, config.supported); if (bytes) progress('Using verified cached developer environment'); else { progress('Downloading developer environment'); bytes = await downloadEnvironment(config, fetchImpl); } - const {files, manifest} = await environmentFiles(bytes, config.integrity); + const {files, manifest} = await environmentFiles(bytes, config.integrity, config.supported); const starters = pinnedStarters(manifest, new URL(config.environment, location.href)); // All files and the trusted archive are published only after validation succeeds. await publish(bridge, '.webfront/developer/environment', files); diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 326258d5..ccaf989f 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -11,7 +11,7 @@ "js/developer/environment/typecheck-snapshot.mjs": "2b68ae117cb39a3f67e3fe2c0b88c479ed0aed31f793c95725488b0af7d97d54", "js/developer/environment/typecheck-worker.mjs": "7c072f7ce902ba8d6ee59015be93c3a5c358d95a5153758309ea825bd39a903e", "js/developer/environment/packages-entry.mjs": "e0b4acd4330b8b51eb0e695384c8df2b103a4be4f598ac83277838022f747e30", - "js/developer/environment/bootstrap.mjs": "b46c9d66ea7083f17fc9b29a8cd9c350966e2420b39fd44b910e8fdd274854df", + "js/developer/environment/bootstrap.mjs": "5fa50cc9264809a6a9eb03564a60fbe3171a3ffcc781d26352ae59e2866a7090", "js/developer/environment/bootstrap-entry.mjs": "ff8084f23f5acc721f97eb1ed0a454e7bfee1894de17d54f0100fa11f7ef8b77", "js/developer/environment/packages.mjs": "6636219f3fef20ea1d274dc9298d8af451ef257b86fe6c1ed0de9a7c797b11d8", "js/developer/environment/starter.mjs": "f38e290e03aebe146623c2ca9b590d645fb91a51acdf7a98101bb00b5b88096c", @@ -40,11 +40,11 @@ "examples/life/ui/main.tsx": "ed11a82aad1639eb6997af8b0fca4d5c5ed4c36422c22a74ac49ae73078d0a91", "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", "js/developer/tools/distribution.json": "4c8703b10e0bfca70e47e1c2b9f5afe7bbe4b4b87cd8be99e15082cfd2915373", - "js/developer/tools/build.mjs": "c0ee8d7502688f14cc45f0234cc90d3df062c9d05e4e51597ce435a63fa41662", + "js/developer/tools/build.mjs": "c9767060d2d181a6d048d9a878e622297a929597b73a1e396b69e1d186ac5d42", "js/developer/tools/site.mjs": "1827d3fd7e1e470336aab25ea8686c912c2b674a10f7be496f2f0077fbc45292", "js/developer/tools/archive.mjs": "bfe9feeb5e4d4e1b7c44c4dec4dcbeab4ae59c2bf16a1d2b32cd6910a2b84e7b", "js/developer/vendor/package-lock.json": "f6aefe8b4cb0b15f866f41eae425f6654d2c6c2d96438fd0da878c5651585616", - "js/core/bootstrap/bootstrap.bundle.mjs": "1069b307799ed2b0de53914748521731bc9796414a416d56340bbda983ef2443", + "js/core/bootstrap/bootstrap.bundle.mjs": "536831257f0fc92e31911841750e1e59247f7c64e756b0fcb878efd9860a741f", "js/developer/environment/packages.bundle.mjs": "e36d1052285a313f7db67c1f58f8332da9e97446b1e2085422ebdae379288045", "include/webfront/system/DeveloperReleaseData.hpp": "d5aaddb2ba839e4c8df46b7d37e2861163233a9018b0f2fb35a6f79831e16569" } diff --git a/js/developer/tools/build.mjs b/js/developer/tools/build.mjs index a766ed60..f816e6bb 100644 --- a/js/developer/tools/build.mjs +++ b/js/developer/tools/build.mjs @@ -57,7 +57,7 @@ for (const [name, provider] of [['pi', 'PiUI'], ['life', 'LifeUI']]) { await writeFile(resolve(output, archive), starterBytes); starters[name] = {archive, integrity: 'sha512-' + createHash('sha512').update(starterBytes).digest('base64')}; } -await writeFile(resolve(output, 'environment.json'), JSON.stringify({protocol: 1, version, entry: 'runtime.mjs', +await writeFile(resolve(output, 'environment.json'), JSON.stringify({protocol: 1, api: 1, version, entry: 'runtime.mjs', compiler: `esbuild-wasm@${dependencies['esbuild-wasm']}`, semver: dependencies.semver, starters}, null, 2) + '\n'); await writeFile(resolve(output, 'package.json'), JSON.stringify({name: '@webfront/developer-environment', version, description: 'Browser-powered WebFront developer environment', type: 'module', diff --git a/js/developer/tools/check.mjs b/js/developer/tools/check.mjs index cc2aa0e0..6b38c389 100644 --- a/js/developer/tools/check.mjs +++ b/js/developer/tools/check.mjs @@ -128,7 +128,15 @@ test('environment integrity and protocol are checked before publication', async assert.equal(environment.manifest.entry, 'runtime.mjs'); await assert.rejects(environmentFiles(archive, integrity(encode('wrong'))), /Integrity check failed/); const wrong = compress(tar(new Map([['package/environment.json', encode({protocol: 2, entry: 'runtime.mjs'})], ['package/runtime.mjs', encode('')]]))); - await assert.rejects(environmentFiles(wrong, integrity(wrong)), /Unsupported WebFront/); + await assert.rejects(environmentFiles(wrong, integrity(wrong)), /Incompatible WebFront developer environment: protocol version 2, this application supports 1/); + // The API an environment expects must be one the C++ declares; an environment from before "api" reads as API 1. + const withApi = api => compress(tar(new Map([['package/environment.json', encode({protocol: 1, api, entry: 'runtime.mjs'})], ['package/runtime.mjs', encode('')]]))); + const newer = withApi(2); + await assert.rejects(environmentFiles(newer, integrity(newer)), /api version 2, this application supports 1/); + assert.equal((await environmentFiles(newer, integrity(newer), {protocol: [1], api: [1, 2]})).manifest.api, 2); + await assert.rejects(environmentFiles(archive, integrity(archive), {protocol: [1], api: [2]}), /api version 1, this application supports 2/); + const current = withApi(1); + assert.equal((await environmentFiles(current, integrity(current))).manifest.api, 1); const missing = compress(tar(new Map([['package/runtime.mjs', encode('')]]))); await assert.rejects(environmentFiles(missing, integrity(missing)), /no environment\.json/); }); diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake new file mode 100644 index 00000000..7b107b08 --- /dev/null +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -0,0 +1,111 @@ +# Bootstrap provisioning at configure time: SRI conversion, verified download, local directory, integrity failures. +# Usage: cmake -DROOT= -DWORK= -P CheckBootstrapProvisioning.cmake +include("${ROOT}/cmake/WebFrontBootstrap.cmake") + +# No line break: a text-mode write would turn it into CRLF on Windows and change the digest. +set(content "webfront bootstrap test archive") +set(sri "sha512-tp5zEsnN4U2b4SrnPY7GY6cYRK/sFQRO9ZX/xlR7mRyMxqedrks3Oc6EVPRYECyrQE8C4FAg6wH5CVNFoNoT6Q==") +set(hex "b69e7312c9cde14d9be12ae73d8ec663a71844afec15044ef595ffc6547b991c8cc6a79dae4b3739ce8454f458102cab404f02e05020eb01f9095345a0da13e9") + +function(expect_equal actual expected message) + if(NOT actual STREQUAL expected) + message(FATAL_ERROR "${message}: expected '${expected}', got '${actual}'") + endif() +endfunction() + +# The pinned value of the repository is a well-formed SHA-512. +webfront_sri_to_sha512("${WEBFRONT_BOOTSTRAP_INTEGRITY}" pinned) +string(LENGTH "${pinned}" pinnedLength) +expect_equal("${pinnedLength}" 128 "The pinned integrity must decode to 64 bytes") + +webfront_sri_to_sha512("${sri}" decoded) +expect_equal("${decoded}" "${hex}" "SRI conversion") + +file(REMOVE_RECURSE "${WORK}") +# The SRI of a file built by a test round-trips through the conversion above. +file(MAKE_DIRECTORY "${WORK}") +file(WRITE "${WORK}/sri.bin" "${content}") +webfront_file_sri("${WORK}/sri.bin" encoded) +expect_equal("${encoded}" "${sri}" "SRI encoding") + +# Each case runs in its own cmake process: a failed integrity check is a FATAL_ERROR. +file(MAKE_DIRECTORY "${WORK}/source" "${WORK}/local") +file(WRITE "${WORK}/source/environment.tgz" "${content}") +file(WRITE "${WORK}/local/environment.tgz" "${content}") +file(WRITE "${WORK}/tampered.tgz" "tampered\n") +file(WRITE "${WORK}/run.cmake" [[ +include("${ROOT}/cmake/WebFrontBootstrap.cmake") +if(LOCAL) + webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${WORK}/cache" LOCAL_DIR "${LOCAL}") +else() + webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${WORK}/cache") +endif() +message(STATUS "provisioned ${archive}") +]]) + +function(provision name result_var output_var) + cmake_parse_arguments(ARG "" "URL;INTEGRITY;LOCAL" "" ${ARGN}) + execute_process(COMMAND "${CMAKE_COMMAND}" -DROOT=${ROOT} -DWORK=${WORK} -DURL=${ARG_URL} -DINTEGRITY=${ARG_INTEGRITY} + -DLOCAL=${ARG_LOCAL} -P "${WORK}/run.cmake" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + set(${result_var} "${result}" PARENT_SCOPE) + set(${output_var} "${out}${err}" PARENT_SCOPE) +endfunction() + +# A file URL: a Windows drive letter needs a third slash. +if(WORK MATCHES "^[A-Za-z]:") + set(scheme "file:///") +else() + set(scheme "file://") +endif() +set(url "${scheme}${WORK}/source/environment.tgz") + +provision(download result text URL "${url}" INTEGRITY "${sri}") +expect_equal("${result}" 0 "A matching download must be provisioned: ${text}") +if(NOT EXISTS "${WORK}/cache/environment.tgz") + message(FATAL_ERROR "The verified archive must be kept in the destination") +endif() + +# A cached archive is reused without the source. +file(REMOVE "${WORK}/source/environment.tgz") +provision(reuse result text URL "${url}" INTEGRITY "${sri}") +expect_equal("${result}" 0 "A verified cached archive must be reused: ${text}") + +# A wrong digest stops the configure and leaves no unverified archive behind. +file(REMOVE_RECURSE "${WORK}/cache") +file(COPY "${WORK}/tampered.tgz" DESTINATION "${WORK}/source") +file(RENAME "${WORK}/source/tampered.tgz" "${WORK}/source/environment.tgz") +provision(wrong result text URL "${url}" INTEGRITY "${sri}") +if(result EQUAL 0 OR NOT text MATCHES "integrity check failed") + message(FATAL_ERROR "A wrong integrity must fail the configure: ${result} ${text}") +endif() +if(EXISTS "${WORK}/cache/environment.tgz") + message(FATAL_ERROR "A downloaded archive that fails its integrity check must be removed") +endif() + +# A download failure names the offline alternative. +provision(missing result text URL "${scheme}${WORK}/absent/environment.tgz" INTEGRITY "${sri}") +if(result EQUAL 0 OR NOT text MATCHES "WEBFRONT_BOOTSTRAP_DIR") + message(FATAL_ERROR "A failed download must point to WEBFRONT_BOOTSTRAP_DIR: ${result} ${text}") +endif() + +# A local provisioning directory replaces the download and is verified too. +provision(local result text URL "https://offline.invalid/environment.tgz" INTEGRITY "${sri}" LOCAL "${WORK}/local") +expect_equal("${result}" 0 "A local directory must replace the download: ${text}") +file(WRITE "${WORK}/local/environment.tgz" "tampered\n") +provision(localWrong result text URL "https://offline.invalid/environment.tgz" INTEGRITY "${sri}" LOCAL "${WORK}/local") +if(result EQUAL 0 OR NOT text MATCHES "integrity check failed") + message(FATAL_ERROR "A tampered local archive must fail the configure: ${result} ${text}") +endif() +file(REMOVE "${WORK}/local/environment.tgz") +provision(localMissing result text URL "https://offline.invalid/environment.tgz" INTEGRITY "${sri}" LOCAL "${WORK}/local") +if(result EQUAL 0 OR NOT text MATCHES "is missing") + message(FATAL_ERROR "An absent local archive must fail the configure: ${result} ${text}") +endif() + +# A malformed integrity is refused before anything is downloaded. +provision(malformed result text URL "${url}" INTEGRITY "sha256-abc") +if(result EQUAL 0 OR NOT text MATCHES "sha512- SRI") + message(FATAL_ERROR "A non SHA-512 integrity must be refused: ${result} ${text}") +endif() +message(STATUS "Bootstrap provisioning checks passed") diff --git a/test/cmake/PrepareWfProject.cmake b/test/cmake/PrepareWfProject.cmake new file mode 100644 index 00000000..ff6e10dc --- /dev/null +++ b/test/cmake/PrepareWfProject.cmake @@ -0,0 +1,4 @@ +# Gives the driver tests a fresh copy of the fixture project. +# Usage: cmake -DSOURCE= -DPROJECT= -P PrepareWfProject.cmake +file(REMOVE_RECURSE "${PROJECT}") +file(COPY "${SOURCE}/" DESTINATION "${PROJECT}") diff --git a/test/cmake/RunWfDriver.cmake b/test/cmake/RunWfDriver.cmake new file mode 100644 index 00000000..2c975008 --- /dev/null +++ b/test/cmake/RunWfDriver.cmake @@ -0,0 +1,86 @@ +# Runs webfront-wf and checks its exit status and output. +# Usage: cmake -DDRIVER= -DPROJECT= -DEXPECT_STATUS= [-DENVIRONMENT= -DINTEGRITY=] +# [-DREGISTRY=] [-DTIMEOUT=] [-DEXPECT_OUTPUT=] [-DEXPECT_REPORT=] [-DFORGE=: +# -DWORK=] [-DRENAME_ENTRY=] [-DFRESH_PROJECT=: an empty project instead of PROJECT] -DCOMMAND=|... -P RunWfDriver.cmake +# FORGE replaces ENVIRONMENT with an archive whose environment.json declares the given protocol and API versions. +if(FORGE) + include("${ROOT}/cmake/WebFrontBootstrap.cmake") + string(REPLACE ":" ";" versions "${FORGE}") + list(GET versions 0 protocol) + list(GET versions 1 api) + file(REMOVE_RECURSE "${WORK}/forged") + file(MAKE_DIRECTORY "${WORK}/forged/package") + file(WRITE "${WORK}/forged/package/environment.json" "{\"protocol\": ${protocol}, \"api\": ${api}, \"entry\": \"runtime.mjs\"}\n") + file(WRITE "${WORK}/forged/package/runtime.mjs" "export function mount() {}\n") + execute_process(COMMAND "${CMAKE_COMMAND}" -E tar czf "${WORK}/forged.tgz" --format=gnutar package + WORKING_DIRECTORY "${WORK}/forged" RESULT_VARIABLE tarred) + if(NOT tarred EQUAL 0) + message(FATAL_ERROR "Cannot build the forged environment") + endif() + set(ENVIRONMENT "${WORK}/forged.tgz") + webfront_file_sri("${ENVIRONMENT}" INTEGRITY) +endif() + +if(FRESH_PROJECT) + set(PROJECT "${FRESH_PROJECT}") + file(REMOVE_RECURSE "${PROJECT}") + file(MAKE_DIRECTORY "${PROJECT}") +endif() +if(RENAME_ENTRY) + # The real environment, with its entry module renamed: the driver must follow environment.json. + include("${ROOT}/cmake/WebFrontBootstrap.cmake") + file(REMOVE_RECURSE "${WORK}/renamed") + file(MAKE_DIRECTORY "${WORK}/renamed") + execute_process(COMMAND "${CMAKE_COMMAND}" -E tar xzf "${ENVIRONMENT}" WORKING_DIRECTORY "${WORK}/renamed" RESULT_VARIABLE unpacked) + if(NOT unpacked EQUAL 0) + message(FATAL_ERROR "Cannot unpack the environment") + endif() + file(RENAME "${WORK}/renamed/package/runtime.mjs" "${WORK}/renamed/package/${RENAME_ENTRY}") + file(READ "${WORK}/renamed/package/environment.json" manifest) + string(JSON manifest SET "${manifest}" entry "\"${RENAME_ENTRY}\"") + file(WRITE "${WORK}/renamed/package/environment.json" "${manifest}") + file(REMOVE "${WORK}/renamed.tgz") + execute_process(COMMAND "${CMAKE_COMMAND}" -E tar czf "${WORK}/renamed.tgz" --format=gnutar package + WORKING_DIRECTORY "${WORK}/renamed" RESULT_VARIABLE packed) + if(NOT packed EQUAL 0) + message(FATAL_ERROR "Cannot repack the environment") + endif() + set(ENVIRONMENT "${WORK}/renamed.tgz") + webfront_file_sri("${ENVIRONMENT}" INTEGRITY) +endif() + +set(arguments --project "${PROJECT}") +if(ENVIRONMENT) + list(APPEND arguments --environment "${ENVIRONMENT}" --integrity "${INTEGRITY}") +endif() +if(REGISTRY) + list(APPEND arguments --registry-dir "${REGISTRY}") +endif() +if(TIMEOUT) + list(APPEND arguments --timeout "${TIMEOUT}") +endif() +if(EXPECT_REPORT) + set(report "${PROJECT}/report.json") + file(REMOVE "${report}") + list(APPEND arguments --report "${report}") +endif() +string(REPLACE "|" ";" command "${COMMAND}") +execute_process(COMMAND "${DRIVER}" ${arguments} -- ${command} + RESULT_VARIABLE status OUTPUT_VARIABLE output ERROR_VARIABLE errors) +set(text "${output}${errors}") +message(STATUS "exit status ${status}\n${text}") +if(NOT status EQUAL EXPECT_STATUS) + message(FATAL_ERROR "Expected exit status ${EXPECT_STATUS}, got ${status}") +endif() +if(EXPECT_OUTPUT AND NOT text MATCHES "${EXPECT_OUTPUT}") + message(FATAL_ERROR "The output does not match '${EXPECT_OUTPUT}'") +endif() +if(EXPECT_REPORT) + if(NOT EXISTS "${report}") + message(FATAL_ERROR "The driver wrote no report") + endif() + file(READ "${report}" content) + if(NOT content MATCHES "${EXPECT_REPORT}") + message(FATAL_ERROR "The report does not match '${EXPECT_REPORT}': ${content}") + endif() +endif() diff --git a/test/driver/WebFrontWf.cpp b/test/driver/WebFrontWf.cpp new file mode 100644 index 00000000..ef6cb3f7 --- /dev/null +++ b/test/driver/WebFrontWf.cpp @@ -0,0 +1,376 @@ +// webfront-wf: runs one wf command of the browser developer environment without interaction and exits with its status. +// +// webfront-wf --project [--environment --integrity ] [--registry-dir ] +// [--report ] [--timeout ] [--] [arguments...] +// +// The environment defaults to the provisioned bootstrap archive (cmake/WebFrontBootstrap.cmake); the project is the +// directory wf reads and writes. Exit status: the command's own status; 64 usage; 70 bootstrap failure (archive missing, +// wrong integrity, incompatible protocol or API); 71 time limit of the driver; 72 the browser closed without a result. +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WEBFRONT_DRIVER_FRONTEND + #error "WEBFRONT_DRIVER_FRONTEND must name the browser frontend" +#endif + +namespace { +using namespace std::chrono_literals; + +constexpr int usageStatus = 64; +constexpr int bootstrapStatus = 70; +constexpr int timeoutStatus = 71; +constexpr int noResultStatus = 72; + +struct Options { + std::filesystem::path project; + std::optional environment; + std::optional integrity; + std::optional registryDirectory; + std::optional report; + std::chrono::seconds timeout{600}; + std::vector command; +}; + +struct UsageError : std::invalid_argument { + using std::invalid_argument::invalid_argument; +}; + +Options parse(int argc, char** argv) { + Options options; + const std::vector arguments(argv + 1, argv + argc); + for (std::size_t i = 0; i < arguments.size(); ++i) { + const auto& argument = arguments[i]; + const auto value = [&]() -> const std::string& { + if (++i == arguments.size()) + throw UsageError(argument + " expects a value"); + return arguments[i]; + }; + if (argument == "--") { + options.command.assign(arguments.begin() + static_cast(i) + 1, arguments.end()); + break; + } + if (argument == "--project") + options.project = value(); + else if (argument == "--environment") + options.environment = value(); + else if (argument == "--integrity") + options.integrity = value(); + else if (argument == "--registry-dir") + options.registryDirectory = value(); + else if (argument == "--report") + options.report = value(); + else if (argument == "--timeout") { + const auto& seconds = value(); + long parsed = 0; + const auto [end, error] = std::from_chars(seconds.data(), seconds.data() + seconds.size(), parsed); + if (error != std::errc{} || end != seconds.data() + seconds.size() || parsed < 1) + throw UsageError("--timeout expects whole seconds"); + options.timeout = std::chrono::seconds(parsed); + } else if (argument.starts_with("--")) + throw UsageError("Unknown option " + argument); + else { + options.command.assign(arguments.begin() + static_cast(i), arguments.end()); + break; + } + } + if (options.project.empty()) + throw UsageError("--project is required"); + if (options.command.empty()) + throw UsageError("A wf command is required"); + if (options.environment.has_value() != options.integrity.has_value()) + throw UsageError("--environment and --integrity go together"); +#if defined(WEBFRONT_BOOTSTRAP_ARCHIVE) && defined(WEBFRONT_BOOTSTRAP_INTEGRITY) + if (!options.environment) { + options.environment = WEBFRONT_BOOTSTRAP_ARCHIVE; + options.integrity = WEBFRONT_BOOTSTRAP_INTEGRITY; + } +#endif + if (!options.environment) + throw UsageError("Pass --environment and --integrity: no bootstrap archive was provisioned at build time"); + return options; +} + +// Where DriverFS finds what it serves: a filesystem provider is built from the project directory alone, and this process +// runs a single application. +struct Sources { + std::filesystem::path archive; + std::optional registry; +}; +Sources& sources() { + static Sources instance; + return instance; +} + +/// Serves the environment archive and the optional local registry under /driver/, from outside the project. +class DriverFS { +public: + explicit DriverFS(const std::filesystem::path&) {} + + std::optional open(std::filesystem::path path) const { + const auto relative = path.relative_path().generic_string(); + if (relative == "driver/environment.tgz") + return read(sources().archive); + // The starters the environment pins sit next to its archive: plain file names only. + constexpr std::string_view driverPrefix = "driver/"; + if (relative.starts_with(driverPrefix)) { + const std::filesystem::path name = relative.substr(driverPrefix.size()); + if (name.extension() == ".tgz" && name == name.filename() && name.string().find("..") == std::string::npos) + return read(sources().archive.parent_path() / name); + } + constexpr std::string_view prefix = "driver/registry/"; + if (sources().registry && relative.starts_with(prefix)) { + try { + return read(webfront::developer::projectPath(*sources().registry, std::string_view(relative).substr(prefix.size()))); + } catch (const std::exception&) {} + } + return {}; + } + +private: + static std::optional read(const std::filesystem::path& file) { + std::ifstream stream(file, std::ios::binary); + if (stream && std::filesystem::is_regular_file(file)) + return webfront::fs::File{std::move(stream)}; + return {}; + } +}; + +// What the page reports: the command's result, or the reason the environment could not start. +class Outcome { +public: + void result(int exitCode, std::string json) { + finish([&] { + status = exitCode; + resultJson = std::move(json); + hasResult = true; + }); + } + void bootstrapFailed(std::string message) { + finish([&] { + status = bootstrapStatus; + failure = std::move(message); + }); + } + void timedOut() { + finish([&] { + status = timeoutStatus; + failure = "The time limit of the driver elapsed"; + }); + } + bool finished() const { + std::scoped_lock lock{mutex}; + return done; + } + template + void inspect(Function&& function) const { + std::scoped_lock lock{mutex}; + function(done, status, hasResult, resultJson, failure); + } + bool wait(std::chrono::seconds limit) { + std::unique_lock lock{mutex}; + return changed.wait_for(lock, limit, [this] { + return done; + }); + } + +private: + template + void finish(Function&& function) { + { + std::scoped_lock lock{mutex}; + if (done) + return; // the first outcome wins + function(); + done = true; + } + changed.notify_all(); + } + + mutable std::mutex mutex; + std::condition_variable changed; + bool done = false; + bool hasResult = false; + int status = noResultStatus; + std::string resultJson; + std::string failure; +}; + +// Waits for the environment, runs the command and reports to C++; the page closes itself when it is done. +constexpr auto driverScript = R"JS( +(async () => { + const report = (name, ...args) => webFront.cppFunction(name)(...args); + const stop = () => window.close(); + try { + await webFront.ready; + for (;;) { + const text = document.getElementById('status')?.textContent ?? ''; + if (text.startsWith('Bootstrap failed:')) throw Object.assign(new Error(text), {bootstrap: true}); + if (text.startsWith('Developer environment ready.')) break; + await new Promise(resolve => setTimeout(resolve, 50)); + } + const config = JSON.parse(await report('webfront.developer.config')); + const environment = await (await fetch('/webfront/developer/environment/environment.json')).json(); + const runtime = await import(`/webfront/developer/environment/${environment.entry}`); + if (typeof runtime.runNonInteractive !== 'function') + throw Object.assign(new Error('Bootstrap failed: this developer environment has no non-interactive mode'), {bootstrap: true}); + config.starters = Object.fromEntries(Object.entries(environment.starters ?? {}).map(([name, value]) => + [name, {url: new URL(value.archive, new URL(config.environment, location.href)).href, integrity: value.integrity}])); + const argv = JSON.parse(await report('wf.arguments')); + await runtime.runNonInteractive(argv, {bridge: webFront, config, preview: document.getElementById('preview'), + signal: new AbortController().signal, write: () => {}, onExit: () => {}, + reporter: json => report('wf.result', JSON.parse(json).exitCode, json)}); + } catch (error) { + await report('wf.bootstrapFailed', String(error?.message ?? error)).catch(() => {}); + } finally { stop(); } +})(); +)JS"; + +std::string jsonArray(const std::vector& items) { + std::string json = "["; + for (const auto& item : items) + json += (json.size() > 1 ? "," : "") + webfront::json::quote(item); + return json + "]"; +} + +void writeReport(const Options& options, const std::string& json) { + if (!options.report) + return; + std::ofstream file(*options.report, std::ios::binary | std::ios::trunc); + file << json << '\n'; + if (!file) + throw std::runtime_error("Cannot write the report " + options.report->string()); +} + +// Prints what the command wrote: the "output" member of the result. +void printOutput(const std::string& json) { + webfront::json::Reader reader{json}; + reader.object([&](const std::string& key) { + if (key == "output") + std::cout << reader.string() << std::endl; + else + reader.skipValue(); + }); +} + +int run(const Options& options) { + using App = webfront::BasicDeveloperApp; + if (!std::filesystem::is_regular_file(*options.environment)) { + std::cerr << "Bootstrap environment archive not found: " << *options.environment << '\n'; + return bootstrapStatus; + } + if (!std::filesystem::is_directory(options.project)) { + std::cerr << "Project directory not found: " << options.project << '\n'; + return usageStatus; + } + sources() = {std::filesystem::canonical(*options.environment), options.registryDirectory}; + if (sources().registry) + sources().registry = std::filesystem::canonical(*sources().registry); + + Outcome outcome; + App app{options.project, {}}; + app.cppFunction("wf.arguments", [arguments = jsonArray(options.command)] { + return arguments; + }); + app.cppFunction("wf.result", [&outcome](double exitCode, std::string json) { + outcome.result(static_cast(exitCode), std::move(json)); + }); + app.cppFunction("wf.bootstrapFailed", [&outcome](std::string message) { + outcome.bootstrapFailed(std::move(message)); + }); + app.bootstrap("developer", + {.environment = "/driver/environment.tgz", + .integrity = *options.integrity, + .registry = options.registryDirectory ? std::optional{"/driver/registry/"} : std::nullopt}); + + std::mutex uiMutex; + std::optional browser; + auto subscription = app.subscribeUIStarted([&](App::UI ui) { + ui.addScript(driverScript); + std::scoped_lock lock{uiMutex}; + browser.emplace(ui); + }); + // The time limit: ask the page to close, then end the process if the browser does not follow. + std::jthread watchdog([&](std::stop_token stop) { + std::mutex mutex; + std::condition_variable_any wake; + std::unique_lock lock{mutex}; + if (wake.wait_for(lock, + stop, + options.timeout, + [] { + return false; + }) + || stop.stop_requested()) + return; + outcome.timedOut(); + { + std::scoped_lock ui{uiMutex}; + if (browser) { + try { + browser->addScript("window.close()"); + } catch (const std::exception&) {} // the bridge is gone: the forced exit below still applies + } + } + if (!stop.stop_requested() + && !wake.wait_for(lock, + stop, + 10s, + [] { + return false; + }) + && !stop.stop_requested()) { + std::cerr << "The browser did not close after the time limit of " << options.timeout.count() << " s\n"; + std::cerr.flush(); + std::_Exit(timeoutStatus); + } + }); + app.show(); + watchdog.request_stop(); + app.shutdown(); + + int status = noResultStatus; + bool hasResult = false; + std::string json, failure; + outcome.inspect([&](bool, int code, bool result, const std::string& resultJson, const std::string& reason) { + status = code; + hasResult = result; + json = resultJson; + failure = reason; + }); + if (hasResult) { + printOutput(json); + writeReport(options, json); + } else if (status == bootstrapStatus || status == timeoutStatus) + std::cerr << failure << '\n'; + else + std::cerr << "The browser closed before the command reported a result\n"; + return status; +} +} // namespace + +int main(int argc, char** argv) { + try { + // CEF child processes must dispatch before interpreting application arguments or creating files. + webfront::detail::ensureFrontendInitialized(); + return run(parse(argc, argv)); + } catch (const UsageError& error) { + std::cerr << "webfront-wf: " << error.what() << "\nUsage: webfront-wf --project [--environment --integrity ] " + << "[--registry-dir ] [--report ] [--timeout ] [--] [arguments...]\n"; + return usageStatus; + } catch (const std::exception& error) { + std::cerr << "webfront-wf: " << error.what() << '\n'; + return bootstrapStatus; + } +} diff --git a/test/fixtures/wf-project/tests/arithmetic.spec.js b/test/fixtures/wf-project/tests/arithmetic.spec.js new file mode 100644 index 00000000..79d6d09a --- /dev/null +++ b/test/fixtures/wf-project/tests/arithmetic.spec.js @@ -0,0 +1,4 @@ +describe('arithmetic', () => { + it('adds', () => { expect(1 + 1).toBe(2); }); + it('fails on purpose', () => { expect(1 + 1).toBe(3); }); +}); diff --git a/test/fixtures/wf-project/tools/sleep.mjs b/test/fixtures/wf-project/tools/sleep.mjs new file mode 100644 index 00000000..519e2131 --- /dev/null +++ b/test/fixtures/wf-project/tools/sleep.mjs @@ -0,0 +1,2 @@ +// A command longer than any driver time limit of the tests. +export default async () => new Promise(resolve => setTimeout(resolve, 120000)); diff --git a/test/fixtures/wf-project/webfront.project.json b/test/fixtures/wf-project/webfront.project.json new file mode 100644 index 00000000..3802a327 --- /dev/null +++ b/test/fixtures/wf-project/webfront.project.json @@ -0,0 +1,8 @@ +{ + "format": 1, + "name": "wf-driver-fixture", + "version": "0.1.0", + "dependencies": {}, + "scripts": {"sleep": "tools/sleep.mjs"}, + "test": {"specs": ["tests/arithmetic.spec.js"]} +} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 97831848..0cf4c524 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -40,6 +40,9 @@ add_test(NAME ReleaseVersionRegression COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -DWORK=${CMAKE_CURRENT_BINARY_DIR}/release-version-regression -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckReleaseVersionTests.cmake) +add_test(NAME BootstrapProvisioning + COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -DWORK=${CMAKE_CURRENT_BINARY_DIR}/bootstrap-provisioning + -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckBootstrapProvisioning.cmake) # Windows bash.exe may be the WSL launcher rather than a native Bash runtime. if(UNIX) diff --git a/test/unit/DeveloperTests.cpp b/test/unit/DeveloperTests.cpp index 39d1856d..0fb73423 100644 --- a/test/unit/DeveloperTests.cpp +++ b/test/unit/DeveloperTests.cpp @@ -359,14 +359,14 @@ SCENARIO("The environment learns whether the application chose the npm registry" GIVEN("no registry option") { THEN("the default registry is passed and marked as not chosen, so the manifest's applies") { REQUIRE(developer::bootstrapConfig(trusted) - == R"({"environment":"https://example.test/env.tgz","integrity":"sha512-abc","registry":"https://registry.npmjs.org/","registryExplicit":false})"); + == R"({"environment":"https://example.test/env.tgz","integrity":"sha512-abc","registry":"https://registry.npmjs.org/","registryExplicit":false,"supported":{"protocol":[1],"api":[1]}})"); } } GIVEN("a same-origin mirror chosen by the application") { auto options = trusted; options.registry = "/mirror/"; THEN("it is passed as the application's choice") { - REQUIRE_THAT(developer::bootstrapConfig(options), Catch::Matchers::EndsWith(R"("registry":"/mirror/","registryExplicit":true})")); + REQUIRE_THAT(developer::bootstrapConfig(options), Catch::Matchers::EndsWith(R"("registry":"/mirror/","registryExplicit":true,"supported":{"protocol":[1],"api":[1]}})")); } } } diff --git a/test/web/CMakeLists.txt b/test/web/CMakeLists.txt index 58db65df..73dd3041 100644 --- a/test/web/CMakeLists.txt +++ b/test/web/CMakeLists.txt @@ -18,6 +18,21 @@ if(${WEBFRONT_FRONTEND_${WEBFRONT_WEBTEST_FRONTEND}_OPTION} endif() webfront_add_browser_tests(webtest "${WEBFRONT_WEBTEST_FRONTEND}" "${CMAKE_CURRENT_SOURCE_DIR}" frontend_lifecycle) +# The pinned bootstrap environment is downloaded and verified at configure time (or taken from WEBFRONT_BOOTSTRAP_DIR on a +# machine without network access); webfront-wf runs wf commands without interaction from it, or from an environment passed +# explicitly (the one built from the current sources). +include(WebFrontBootstrap) +if(${WEBFRONT_FRONTEND_${WEBFRONT_WEBTEST_FRONTEND}_OPTION} + AND CMAKE_SYSTEM_NAME IN_LIST WEBFRONT_FRONTEND_${WEBFRONT_WEBTEST_FRONTEND}_TEST_PLATFORMS) + webfront_provision_bootstrap(WEBFRONT_BOOTSTRAP_ARCHIVE URL "${WEBFRONT_BOOTSTRAP_URL}" + INTEGRITY "${WEBFRONT_BOOTSTRAP_INTEGRITY}" DESTINATION "${CMAKE_BINARY_DIR}/bootstrap" LOCAL_DIR "${WEBFRONT_BOOTSTRAP_DIR}") + add_executable(webfront-wf ../driver/WebFrontWf.cpp) + target_link_libraries(webfront-wf PRIVATE WebFront_test_hardening WebFront WebFront_warnings WebFront_options) + target_compile_definitions(webfront-wf PRIVATE WEBFRONT_DRIVER_FRONTEND=${WEBFRONT_WEBTEST_FRONTEND_TYPE} + WEBFRONT_BOOTSTRAP_ARCHIVE="${WEBFRONT_BOOTSTRAP_ARCHIVE}" WEBFRONT_BOOTSTRAP_INTEGRITY="${WEBFRONT_BOOTSTRAP_INTEGRITY}") + webfront_setup_frontends_for_target(webfront-wf) +endif() + # Exercise actual CEF command IDs, context-menu filtering and DevTools creation in the vendored runtime. if(WEBFRONT_EMBED_CEF AND CMAKE_SYSTEM_NAME STREQUAL "Linux") add_executable(cef_content_policy CEFContentPolicy.cpp) @@ -55,6 +70,75 @@ if(WEBFRONT_DEVELOPER_FIXTURES "${WEBFRONT_DEVELOPER_FIXTURES}" "${CMAKE_CURRENT_BINARY_DIR}/developer-generated") webfront_set_browser_test_properties(DeveloperBrowserIntegration "${CMAKE_CURRENT_SOURCE_DIR}" 180) set_tests_properties(DeveloperBrowserIntegration PROPERTIES FIXTURES_SETUP DeveloperGenerated) + # The driver on the environment built from the current sources: statuses, output and reports reach CTest. + if(TARGET webfront-wf) + file(READ "${WEBFRONT_DEVELOPER_FIXTURES}/provision.json" _provision) + string(JSON _environment_integrity GET "${_provision}" integrity) + set(_wf_project "${CMAKE_CURRENT_BINARY_DIR}/wf-driver-project") + set(_wf_run "${CMAKE_COMMAND}" -DROOT=${PROJECT_SOURCE_DIR} -DDRIVER=$ + -DPROJECT=${_wf_project} -DWORK=${CMAKE_CURRENT_BINARY_DIR}/wf-driver-work + -DENVIRONMENT=${WEBFRONT_DEVELOPER_FIXTURES}/environment.tgz -DINTEGRITY=${_environment_integrity} + -DREGISTRY=${WEBFRONT_DEVELOPER_FIXTURES}/registry) + set(_developer_xvfb_prefix "") + if(_developer_xvfb) + set(_developer_xvfb_prefix "${_developer_xvfb}" -a) + set(_wf_run ${_developer_xvfb_prefix} ${_wf_run}) + endif() + add_test(NAME WfDriverProject + COMMAND ${CMAKE_COMMAND} -DSOURCE=${PROJECT_SOURCE_DIR}/test/fixtures/wf-project -DPROJECT=${_wf_project} + -P ${PROJECT_SOURCE_DIR}/test/cmake/PrepareWfProject.cmake) + set_tests_properties(WfDriverProject PROPERTIES FIXTURES_SETUP WfDriverProject LABELS "web-integration" TIMEOUT 30) + + # webfront_add_driver_test( + # [OUTPUT ] [REPORT ] [DRIVER_TIMEOUT ] [FORGE :] + # [ENVIRONMENT INTEGRITY ] [FRESH_PROJECT ] [RENAME_ENTRY ] [REQUIRES ] [PROVIDES ]) + function(webfront_add_driver_test name status command) + cmake_parse_arguments(ARG "" "OUTPUT;REPORT;DRIVER_TIMEOUT;FORGE;ENVIRONMENT;INTEGRITY;FRESH_PROJECT;RENAME_ENTRY;REQUIRES;PROVIDES" "" ${ARGN}) + set(options -DEXPECT_STATUS=${status} "-DCOMMAND=${command}") + foreach(option OUTPUT REPORT) + if(ARG_${option}) + list(APPEND options "-DEXPECT_${option}=${ARG_${option}}") + endif() + endforeach() + foreach(option FORGE ENVIRONMENT INTEGRITY FRESH_PROJECT RENAME_ENTRY) + if(ARG_${option}) + list(APPEND options "-D${option}=${ARG_${option}}") + endif() + endforeach() + if(ARG_DRIVER_TIMEOUT) + list(APPEND options -DTIMEOUT=${ARG_DRIVER_TIMEOUT}) + endif() + add_test(NAME ${name} COMMAND ${_wf_run} ${options} -P ${PROJECT_SOURCE_DIR}/test/cmake/RunWfDriver.cmake) + webfront_set_browser_test_properties(${name} "${CMAKE_CURRENT_SOURCE_DIR}" 120) + set_tests_properties(${name} PROPERTIES FIXTURES_REQUIRED "WfDriverProject;${ARG_REQUIRES}") + if(ARG_PROVIDES) + set_tests_properties(${name} PROPERTIES FIXTURES_SETUP ${ARG_PROVIDES}) + endif() + endfunction() + + # The fixture manifest has no jasmine-core: wf test asks for it, and wf install resolves it from the local registry. + webfront_add_driver_test(WfDriverInstall 0 "install|jasmine-core" OUTPUT "Installed 1 packages" PROVIDES WfDriverInstalled) + webfront_add_driver_test(WfDriverTestPasses 0 "test|adds" OUTPUT "PASSED: 1 spec" REPORT "\"status\":\"passed\"" REQUIRES WfDriverInstalled) + # A failing command: its status, its output and the structured report reach CTest. + webfront_add_driver_test(WfDriverTestFails 1 "test|fails" OUTPUT "FAILED: 1 spec, 1 failure" REPORT "\"failed\":1" REQUIRES WfDriverInstalled) + # The starters pinned by the environment are served next to its archive. + webfront_add_driver_test(WfDriverCreateStarter 0 "create|pi" OUTPUT "Created" + FRESH_PROJECT "${CMAKE_CURRENT_BINARY_DIR}/wf-driver-starter") + # The entry module is the one environment.json declares, not a fixed name. + webfront_add_driver_test(WfDriverRenamedEntry 0 "list" RENAME_ENTRY runner.mjs) + webfront_add_driver_test(WfDriverUnknownCommand 1 "nosuchcommand" OUTPUT "nosuchcommand") + webfront_add_driver_test(WfDriverTimeout 71 "run|sleep" OUTPUT "time limit of the driver" DRIVER_TIMEOUT 4) + webfront_add_driver_test(WfDriverWrongIntegrity 70 "list" OUTPUT "Integrity check failed" + INTEGRITY "sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") + webfront_add_driver_test(WfDriverMissingArchive 70 "list" OUTPUT "archive not found" + ENVIRONMENT "${CMAKE_CURRENT_BINARY_DIR}/wf-driver-work/absent.tgz") + webfront_add_driver_test(WfDriverIncompatibleApi 70 "list" OUTPUT "api version 2, this application supports 1" FORGE "1:2") + webfront_add_driver_test(WfDriverIncompatibleProtocol 70 "list" OUTPUT "protocol version 2, this application supports 1" FORGE "2:1") + add_test(NAME WfDriverUsage COMMAND ${_developer_xvfb_prefix} $ --project "${_wf_project}") + add_test(NAME WfDriverBadTimeout COMMAND ${_developer_xvfb_prefix} $ --project "${_wf_project}" --timeout abc -- list) + set_tests_properties(WfDriverBadTimeout PROPERTIES PASS_REGULAR_EXPRESSION "--timeout expects whole seconds" LABELS "web-integration" TIMEOUT 30) + set_tests_properties(WfDriverUsage PROPERTIES PASS_REGULAR_EXPRESSION "A wf command is required" LABELS "web-integration" TIMEOUT 30) + endif() # Build the actual browser-generated header only after the setup test has produced it. add_executable(developer_embedded EXCLUDE_FROM_ALL DeveloperEmbeddedTest.cpp) target_link_libraries(developer_embedded PRIVATE WebFront_test_hardening WebFront WebFront_warnings WebFront_options)