Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
- 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
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
148 changes: 148 additions & 0 deletions cmake/WebFrontBootstrap.cmake
Original file line number Diff line number Diff line change
@@ -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-<base64>").
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 <archive> the verified path of an environment archive: <LOCAL_DIR>/<name> 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=<directory holding ${name}>.")
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-<base64>") 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()
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <s>] [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
Expand Down
40 changes: 39 additions & 1 deletion docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <dir> [--environment <environment.tgz> --integrity <sha512-...>] [--registry-dir <dir>] \
[--report <file>] [--timeout <seconds>] [--] <wf command> [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 `<build>/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=<directory holding environment.tgz>`: 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
Expand Down
2 changes: 1 addition & 1 deletion docs/PROJECT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 8 additions & 1 deletion include/webfront/DeveloperApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ 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
/// that predate "registryExplicit"; the latter tells whether the application chose it.
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

Expand Down
Loading
Loading