Skip to content
ERPForAll DocsDevelopment

    Component tests with Elang

    Use @erpforall/elang-test from a workspace test to exercise the real component runtime. Keep every test’s work inside withTestScope; it tears down mounted roots and restores registry and patch mutations even when the callback rejects. The package is test infrastructure and must not be imported by a production addon entry point.

    import { withTestScope } from "@erpforall/elang-test";
    const model = { label() { return "original"; } };
    await withTestScope(async scope => {
    scope.patch(model, sup => ({
    label() { return `${sup.label.call(this)} patched`; },
    }));
    // Assert the component's behavior while this patch is installed.
    });
    // model.label() is restored here.

    scope.patch and scope.patchStatic explicitly give the scope ownership of a patch; teardown removes it. To own a synchronous addon registration or PatchSet operation, wrap it in scope.manage(() => { /* register here */ }). The callback must be synchronous; Promise-returning callbacks are rejected by the type boundary and unexpected runtime thenables remain observed during cleanup. An outstanding patch installed directly through the runtime without scope ownership is reported as a leaked patch: the scope fails the test boundary, then attempts restoration. Calling its returned unpatch function before teardown avoids the leak. This catches accidental patches while allowing intentional scoped overrides.

    scope.mount(ComponentClass, options) returns the real component instance and an attached root. Supply the same props and compiled templates that the runtime expects. Scope teardown unmounts the component and removes the root; a failed mount also cleans its target. Use semantic DOM assertions across the entire mounted app, including portals and overlays where the component creates them. A small fixture establishes only the behavior it exercises.

    Before mounting, call scope.mockService(CanonicalServiceClass, mockInstance) to replace that service’s instance while keeping its canonical class identity. Register other required services on scope.services. Startup uses the real container: dependency errors, cycles and startup failures still reject. Every scope gets a fresh environment, service container and registry hub. Registry mutations made during the scope are restored with their original sequence, ordering and value identity. Rollback restores registrations, not arbitrary in-place mutations to an entry’s payload object.

    Only one scope may own runtime mutation tracking in a test realm at a time. Overlapping or nested scopes fail explicitly, including while another scope is disposing. Do not use concurrent tests for shared patch/registry state. Disposal keeps ownership until known service-startup and component lifecycle work settles; when testing a deliberately deferred operation, begin disposal, release that operation, and then await disposal. Arbitrary detached asynchronous callbacks are not canceled by the harness: the test author must await or stop them before the scope ends. createTestScope() is available when lifecycle control is required; always await scope.dispose() in finally and preserve both the test error and cleanup errors. withTestScope handles that combination. Do not call scope.dispose() from a component teardown callback; the harness rejects that reentry instead of making cleanup await itself. While a returned asynchronous teardown callback is pending, additional disposal calls are refused even from outside that callback. Keep and await the first disposal promise. Ordinary repeated disposal calls during pending service startup share that first promise when no teardown callback is pending.

    MockRpc<Contract> accepts caller-owned operation types with request and response members. Import response/request DTOs from their generated owner; TypeScript checks handler arguments and results. Register each operation with on, call it with call, and inspect calls. An operation without a handler rejects rather than silently returning an empty value. Handler errors propagate.

    The harness does not invent production view request types or a universal model/method map. UIX supplies generation tooling and its test-only schema; production view slices own their DTOs. The harness suite checks the generic boundary against generated declarations, including the human client’s generated company DTO. Mock success establishes neither HTTP transport nor authorization acceptance. Keep live server and browser tests for those boundaries.

    Place workspace harness suites under web/packages/*/tests/*.test.ts or addon suites under addons/<name>/static/tests/*.test.ts; the shared Vitest configuration discovers them. Use the pinned web toolchain and the normal TypeScript checks. Builds and tests run on an approved build host through the documented sync path, never on the editing laptop.

    A leaked-patch error identifies remaining members. Restore manual patches or move intentional registration into scope ownership. A cleanup error remains a failure even when another cleanup succeeded; inspect all errors in an aggregate before retrying. Do not turn these errors into ignored teardown warnings.

    web/scripts/browser-human-ui.mjs exercises the compiled client in an isolated Chrome profile against loopback HTTP protocol fixtures. It checks login rendering, list and form interactions, search, Settings, Addons, confirmation, loading and permission-dialog recovery at desktop and narrow widths. The fixture supplies its own records and denied responses: it does not establish real authentication, authorization grants, database persistence, multi-node behavior or deployment acceptance.

    The full CI browser stage runs this fixture as web-browser-human-ui. It builds erp-ui-compiler-cli’s erp-ui-compile executable from the same revision, through the build gate with cargo build --locked, and honors CARGO_TARGET_DIR. It then sets ERP_UI_COMPILER to that executable and runs node web/scripts/build-human-ui.mjs --addons web,acceptance_notes. The explicit addon list is required because the fixture exercises the acceptance-notes title widget; the asset builder’s default selects only web.

    Run the full check from a clean, committed task worktree. Have the operator set ERP_CI_HOST to an approved build host:

    Terminal window
    CI_HOST="${ERP_CI_HOST:?Select an approved build host}" scripts/ci-remote.sh --no-wait <slice>

    The wrapper syncs the revision, starts CI under nohup, and prints the remote location. Follow that existing run with --wait; do not launch a duplicate run while it is active. Standalone scripts/ci.sh --lane web retains its cargo-free TypeScript/Vitest checks and does not run this compiler-dependent fixture.

    Use the pinned web toolchain on the build host. Chrome must already be installed; CHROME_BIN can select its executable. On macOS the default is /Applications/Google Chrome.app/Contents/MacOS/Google Chrome. A missing or non-executable browser fails the check with its path. Report that prerequisite to the operator rather than installing software or skipping the browser step.

    CI runs the complete default/light fixture with its diagnostic and reduced-scope options disabled. Each run gets a fresh directory under logs/browser-human-ui-<revision>-<timestamp>.*, with evidence/result.json and screenshots. Keep the surrounding CI log as well. A successful result records the source revision, asset hashes, browser version, host and capture time. A missing, failed, mismatched-revision or diagnostic-only result cannot satisfy the gate.

    For a focused rerun after building the compiler from the same revision on the approved build host, choose a new output directory rather than reusing an old receipt. The wrapper sync can remove generated assets, so rebuild them inside the wrapped command:

    Terminal window
    scripts/mini-build.sh <slice> 'set -eu
    eval "$(scripts/web-toolchain.sh env)"
    target_dir="${CARGO_TARGET_DIR:-target}"
    case "$target_dir" in
    /*) compiler="$target_dir/debug/erp-ui-compile" ;;
    *) compiler="$PWD/$target_dir/debug/erp-ui-compile" ;;
    esac
    ERP_UI_COMPILER="$compiler" node web/scripts/build-human-ui.mjs --addons web,acceptance_notes
    mkdir -p logs
    capture=$(mktemp -d "$PWD/logs/browser-human-ui-focused.XXXXXX")
    env -u CLIENT_BROWSER_CDP CLIENT_BROWSER_OUTPUT="$capture/evidence" CLIENT_BROWSER_THEME=light CLIENT_BROWSER_OFFICE_BLUE=0 CLIENT_BROWSER_LIST_ONLY=0 CLIENT_BROWSER_DIALOG_PROBE=0 CLIENT_BROWSER_VIEWPORT_ONLY=0 node web/scripts/browser-human-ui.mjs'

    Preserve the complete failure log before diagnosing a stale assertion or client defect. A missing browser, failed asset build or fixture setup error is not proof of a product regression. The functional browser checks do not enable the deferred product performance inventory.

    Keep extension fixtures under an addon’s test directory (or the test package’s tests/fixtures/ directory); do not import them from production addon entry points. The UI6 completion fixture in web/packages/elang-test/tests/fixtures/extension-test-addon.ts is a small copyable example. It adds one validated registry entry and patches one component method. Define the typed category in the scope, register addons through the normal loader, and keep registration inside scope.manage so the harness owns the patch handles:

    import { registerAddons } from "@erpforall/elang";
    import { withTestScope } from "@erpforall/elang-test";
    import { extensionTestAddon } from "./fixtures/extension-test-addon.js";
    class Heading { label(): string { return "Base"; } }
    await withTestScope(async scope => {
    scope.manage(() => {
    scope.registries.define("extensionTemplate", (value): value is string => typeof value === "string");
    });
    scope.manage(() => registerAddons([
    extensionTestAddon({ id: "first", label: "First", target: Heading.prototype }),
    extensionTestAddon({ id: "second", label: "Second", target: Heading.prototype }),
    ], { registry: scope.registries }));
    expect(new Heading().label()).toBe("Base / First / Second");
    });

    After the scope closes, check that the component returns its original value and that the scope’s registry hub no longer contains the test category. The fixture proves this small composition and cleanup path; it does not replace addon installation or browser end-to-end tests.

    The opt-in Contacts List test logs into the existing reference, switches the real Contacts action to List mode, and asserts that the rendered table contains at least one row. It reads the view only and writes a redacted JSON receipt (row count and route, no record values) with mode 0600:

    Terminal window
    set -a && . "$HOME/.config/erpforall/odoo-ui-ref.env" && set +a && eval "$(scripts/web-toolchain.sh env)" && node web/scripts/odoo-reference-view-test.mjs --origin http://127.0.0.1:18369 --output /tmp/ui6-odoo-list

    The operator-managed file must be outside the checkout, mode 0600, and export ODOO_UI_REF_PASSWORD; never pass the value on the command line or save it in the repository. HTTP is allowed only on loopback; use HTTPS for network hosts. The output directory must not already exist; choose a fresh path for each run. The Odoo demo must already be running. A missing credential, unsafe origin, authentication error, HTTP failure or empty list fails the test with a clear error. The receipt is an observation of this one list flow; it does not establish backend authorization parity, form behavior or full view parity. Keep the receipt with the slice evidence.

    Playwright fixtures belong to the shell tests.

    The focused runner (run-focused.sh) exercises the shared Rust/browser URL corpus and mounted-app search integration. The native runner (run-native.sh http) runs the actual CLI server HTTP boundary; run-native.sh browser additionally builds the compiler/client at the synced revision and drives web/scripts/browser-shell-url.mjs. Run these only through the build gate on an approved host, with a clean scripts/sync.sh revision and its protected .env. Before invoking either runner, include $HOME/.cargo/bin in PATH and evaluate eval "$(scripts/web-toolchain.sh env)" in that same remote shell. The SSH login shell’s default Node is not the pinned web toolchain and can fail driver syntax before any test runs. Use an approved remote build host under its build gate. Historical receipts retain their original host and source; new runs need their own exact-source receipts. Initialize the pinned toolchain in the same gated invocation as the runner, before its syntax check or builds. The internal deployment and development setup documents own host selection.

    The browser mode reuses the installed-fixture private handoff in support/wizard_browser.rs, starts the real native server/database, and checks source/asset revision plus manifest hashes. It requires the operator-owned Playwright installation at ~/.local/share/erpforall-qa and an installed Chrome (CHROME_BIN, default /usr/bin/google-chrome for this Linux runner). Credentials remain in a mode-600 temporary fixture contract and must never be copied to evidence. Only credential-free result JSON, screenshots and command output belong in the branch.

    The native HTTP assertions run with the ordinary human_runtime suite. Browser mode is explicit installed acceptance for the shell; the broader browser-stage and retention work remains open. Protocol fixtures alone do not prove native acceptance.