Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test(web): real-browser dashboard tests and guard-removal mutation checks

Aldo Juniorb63b80a84ab3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f6ec6fc5..199390c0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -153,6 +153,19 @@ jobs:
if: matrix.os == 'ubuntu-latest'
with:
node-version: "24"
+ # Browser tooling is test-only. Building/distributing the Rust server
+ # and its embedded web UI still needs Cargo alone.
+ - name: Install pinned Chromium for dashboard regression tests
+ if: matrix.os == 'ubuntu-latest'
+ run: npx --yes [email protected] install --with-deps --only-shell chromium
+ - name: Real dashboard browser tests and mutation checks
+ if: matrix.os == 'ubuntu-latest'
+ env:
+ AI_MEMORY_BIN: ${{ github.workspace }}/target/debug/ai-memory
+ run: node tests/e2e/web_dashboard_mutations.mjs
+ - name: Dashboard Rust mutation checks
+ if: matrix.os == 'ubuntu-latest'
+ run: python3 scripts/check-dashboard-core-mutations.py
- name: Generated capture-policy TypeScript runtime evidence
if: matrix.os == 'ubuntu-latest'
# `--workspace` reuses the test binaries built above instead of
diff --git a/README.md b/README.md
index 2a5ef5d4..8c7cdf00 100644
--- a/README.md
+++ b/README.md
@@ -726,6 +726,7 @@ diagram, crate breakdown, schema notes, and invariants.
| File | What it is |
|---|---|
+| [`docs/testing-dashboard.md`](docs/testing-dashboard.md) | Dashboard behavior tests, real-browser CI and mutation probes that prove regression guards fail. |
| [`docs/cookbook.md`](docs/cookbook.md) | **Task-oriented cheat sheet.** "I want to do X" → how: recall prior work, keep a project rule, import an existing knowledge base, get two agents/repos working together. Start here. |
| [`docs/install.md`](docs/install.md) | **Installation cookbook.** Every agent CLI, every alternative (curl, source build, no-docker, no-auth), and the server-on-a-different-machine walkthrough. |
| [`docs/usage.md`](docs/usage.md) | Handoffs, proactive memory queries, slim routing snippet + managed Agent Skills, web UI, raw-wiki inspection, and the rules, memory and profile precedence. |
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index dfc5d231..c505d83f 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -91,8 +91,8 @@ the legitimate restricted-project control and the failed-query cases.
| 8d | Messaging: an inferred scope never changes a queue; a read names it (#854) | `scope.rs` `ScopeSource::is_inferred`; `ai-memory-mcp/src/server.rs` `refuse_inferred_message_scope`, called by `memory_message_pop` and `memory_message_cancel` (mailbox scope) and `memory_message_send` (sender scope) before admission or any writer call, so a `shared_slot`/`startup_seed`/`default`/`default_after_mismatch` scope is refused with nothing claimed, cancelled, or delivered; `inferred_scope_hint` on every inferred `memory_message_list` (inbox and outbox, empty or not); the SessionStart notice (`ai-memory-hooks/src/router.rs` `render_inbox_notice`) and `memory_briefing` `scope` name the inbox from server-side names only | `agent_messages_scope.rs` `unscoped_pop_from_the_shared_slot_is_refused_and_claims_nothing`, `unscoped_cancel_from_the_shared_slot_is_refused_and_the_outbox_survives`, `unscoped_send_from_the_shared_slot_is_refused_and_explicit_sender_is_stamped` (each with the shared slot on another project; session-bound and explicit callers as controls; each fails with the guard removed), `unscoped_list_names_the_mailbox_it_read_even_when_not_empty`; `agent_messages_briefing.rs` `no_scope_pop_is_refused_and_the_briefing_names_the_inbox_to_pop`, `no_scope_inbox_list_that_misses_the_mail_names_the_inferred_scope`; router `session_start_notice_surfaces_pending_mail_without_consuming_it` (names the inbox, carries no message text) | STRONG |
| 8e | Messaging: admission is the same for MCP and admin sends (#756) | `ai-memory-mcp/src/admin.rs` `handle_send_message` runs `Wiki::authorize_operation(.., AdmissionOp::MessageSend, ..)` at the recipient scope before `insert_message` (a refusal is 403 and stores nothing) and calls `notify_operation_observers` only after a successful commit; skipping webhooks needs `Capability::SkipAdmissionChain` (`skip_webhooks_for_admin_request`); the MCP path is `server.rs` `memory_message_send` | `admin.rs` `admin_message_send_reject_leaves_inbox_empty` (a rejecting webhook gets 403 and an empty inbox; fails with the admission call removed), controls `admin_message_send_observer_sees_commit_without_blocking_response` and `admin_message_send_full_inbox_does_not_notify_observer` | STRONG |
| 8f | Messaging: the web mailbox shows a restricted sender's name and a card's count only to a reader of that repository; it never consumes mail | `ai-memory-store/src/reader.rs` `list_inbox_with_senders` (`readable_repository_predicate("sp.id", viewer)` on the sender join, so the name is `NULL` for an unreadable sender) and `pending_inbox_counts` (`readable_repository_predicate("p.id", viewer)`); `ai-memory-web/src/routes/project.rs` `mailbox` is `list`-only, no pop/cancel route exists, and `mailbox_scope` matches the URL's exact project name (as `list_pages` does), so an alias never shows another project's mail | `routes.rs` `web_mailbox_hides_restricted_sender_names_and_cards` (a granted reader of the recipient is shown "a project you cannot read", the restricted sender's name and card never reach the grid, alice as the control; fails with either predicate removed), `web_mailbox_lists_only_this_projects_inbox_and_never_consumes_it` (sender and bystander pages show nothing of the recipient's mail, a POST is 405 and the message is still pending, the body is HTML-escaped), `web_mailbox_does_not_follow_a_project_alias` (a legacy key that resolves to `acme-api` shows none of its mail on `/w/default/api`; `acme-api` itself is the control) | STRONG |
-| 8h | Per-response usage stays scoped to project/session/owner and cannot be inflated by replay or reduced by partial reports | `ai-memory-store/src/reader.rs` `token_usage_report_page` applies the resolved project/session, `OwnerFilter`, search and signals before ordering/pagination; summary totals retain the full authorized scope; `ops.rs` `upsert_token_calls` keys native ids by session and merges monotonic counters in the writer transaction | Hooks `live_token_calls_update_open_sessions_without_an_end_event` attempts a foreign workspace/project and owner with an authorized control; web `operations_agent_aggregates_and_drilldowns_apply_ownership_before_totals`; hooks `live_token_calls_scrub_private_labels_before_truncating` refuses private/malformed ids and tests a secret crossing the model-label size bound with a public control; store `live_token_usage.rs` checks replayed/partial row and aggregate consistency and reused native ids across sessions, harnesses and projects `token_call_queries_search_and_order_before_pagination_with_scope_and_owner_guards` checks a tiny newest response beyond fifty larger ones, search, pages, foreign session and owner isolation with root controls. | STRONG |
-| 8i | Live sidebar notifications and browser mailbox context hide restricted project names/counts; message sends preserve write authorization on both coordinates, sanitization and admission; directed mail can only be claimed by its harness | `ai-memory-web/src/routes/inbox.rs` derives queue context from viewer-filtered projects and grouped pending counts, honors explicit scope and refuses partial/foreign scope; it uses `Capability::NormalWrite` and guarded source/target scope lookups; `Wiki::send_agent_message` sanitizes and admits before the writer; `ops.rs` checks `to_agent` in selection and the atomic claim | `notifications.rs` uses viewer-filtered grouped counts, returns at most five project names without message content and disables caching; state-filtered history retains both coordinate guards before pagination, and received mail defaults to pending. `operations_notifications_are_read_only_and_hide_restricted_projects` attempts disclosure with root/read controls and tests non-consumption. `operations.rs` `operations_inbox_queue_context_hides_foreign_projects_and_preserves_mail` attempts restricted-project disclosure and explicit/partial-scope access with legitimate read/root controls `operations.rs` tests anonymous/read-only refusal with write/root controls, write grants on both coordinates, sanitizer/admission refusals and explicit cross-workspace delivery; `agent_messages.rs` `addressed_messages_are_claimed_once_only_by_the_selected_harness` | STRONG |
+| 8h | Per-response usage stays scoped to project/session/owner and cannot be inflated by replay or reduced by partial reports | `ai-memory-store/src/reader.rs` `token_usage_report_page` applies the resolved project/session, `OwnerFilter`, search and signals before ordering/pagination; summary totals retain the full authorized scope; `ops.rs` `upsert_token_calls` keys native ids by session and merges monotonic counters in the writer transaction | Hooks `live_token_calls_update_open_sessions_without_an_end_event` attempts a foreign workspace/project and owner with an authorized control; web `operations_agent_aggregates_and_drilldowns_apply_ownership_before_totals`; hooks `live_token_calls_scrub_private_labels_before_truncating` refuses private/malformed ids and tests a secret crossing the model-label size bound with a public control; store `live_token_usage.rs` checks replayed/partial row and aggregate consistency and reused native ids across sessions, harnesses and projects; the Rust mutation campaign requires lowered response counters and wrong Codex cache accounting to fail `token_call_queries_search_and_order_before_pagination_with_scope_and_owner_guards` checks a tiny newest response beyond fifty larger ones, search, pages, foreign session and owner isolation with root controls; mutation probes remove the owner/search predicates and require assertion failures. CLI cursor tests cover 300 responses, byte windows, incomplete records and enqueue failure; the native hook and cursor mutation probes require failures if progress resets or advances before enqueue. Browser `capture-backlog`, `call-history` and `session-live-usage` exercise native capture through delivery, full-history queries and live session updates. | STRONG |
+| 8i | Live sidebar notifications and browser mailbox context hide restricted project names/counts; message sends preserve write authorization on both coordinates, sanitization and admission; directed mail can only be claimed by its harness | `ai-memory-web/src/routes/inbox.rs` derives queue context from viewer-filtered projects and grouped pending counts, honors explicit scope and refuses partial/foreign scope; it uses `Capability::NormalWrite` and guarded source/target scope lookups; `Wiki::send_agent_message` sanitizes and admits before the writer; `ops.rs` checks `to_agent` in selection and the atomic claim | `notifications.rs` uses viewer-filtered grouped counts, returns at most five project names without message content and disables caching; state-filtered history retains both coordinate guards before pagination, and received mail defaults to pending. `operations_notifications_are_read_only_and_hide_restricted_projects` attempts disclosure with root/read controls and tests non-consumption; the mutation gate removes its viewer filter and requires failure. Browser `notifications` checks anonymous refusal, live appearance/collection, correct project links and clearing stale data on a 403. `operations.rs` `operations_inbox_queue_context_hides_foreign_projects_and_preserves_mail` attempts restricted-project disclosure and explicit/partial-scope access with legitimate read/root controls; the core mutation gate removes the project visibility filter and requires failure. Browser `mailbox-context` exercises same-name projects in different workspaces, navigation, responsive links and non-consuming reads. `operations.rs` tests anonymous/read-only refusal with write/root controls, write grants on both coordinates, sanitizer/admission refusals and explicit cross-workspace delivery; `agent_messages.rs` `addressed_messages_are_claimed_once_only_by_the_selected_harness`; real HTTP/Chromium `web_dashboard_browser.mjs` `delivery` verifies legacy GET-only auth, cleared one-request credentials, escaped text, wrong-harness refusal and claim-once; `check-dashboard-core-mutations.py` removes harness checks and requires the claim test to fail | STRONG |
| 9 | Scope resolution fail-closed | `ai-memory-store/src/scope.rs` no-create `lookup_existing_*`; identity-aware lookup accepts exact/canonical/v2-basename keys only when they deduplicate to one UUID; `ops.rs` `resolve_project_name_for_write` performs write authorization, optional name-only promotion, and audit in one writer transaction; create only via `create_explicit_scope`; `ops.rs` `get_or_create_project_as` — the capture and managed-run creator path — consults the same coordinate lookup before inserting, so a name a promoted project still answers to (its `legacy_name` or `canonical_name`) reuses that row, an ambiguous name is refused, and no twin is minted under a key the read path already resolves (the lookup is skipped only while the schema predates V76, via `project_coordinates::supports_coordinates`). The admin destructive project routes (`admin.rs` `resolve_target_for_admin`, used by `purge-project` / `rename-project` / `move-project`) accept a bare `project_id` as an alternative to the name: it is parsed to a UUID (400 on a malformed one), looked up **within the workspace the request named** via `ReaderPool::project_name_by_id` (404 when it names no row there, so a real id from another workspace is refused rather than resolved), and the two spellings are mutually exclusive (both or neither is a 400). `list-projects` carries the id in each row, and inherits the same row-level visibility filter as the name, so a restricted project leaks neither. `ProjectNameAmbiguous` refuses cross-forge/multi-candidate keys before mutation; its message names each holder and the key it matched by, but a restricted holder only as "a restricted project", because the lookup runs before any caller is authorized and the project list hides restricted names from callers without a grant; an audit failure after the name UPDATE rolls the transaction back. V76's derived-key indexes bound hot lookup to exact/canonical/legacy equality probes with at most four rows. Promoting public APIs return `ResolvedWriteScope` metadata (no untraced promotion API); MCP, admin, and managed-workstream write entry points make Wiki refresh/checkpoint the committed scope manifest after promotion and surface `manifest_warning` on success or any later operation failure; pure managed-run input validation precedes promotion. A managed run whose `project` is the name its checkout's git remote derives (`PrepareManagedRunRequest.repository_identity`, accepted only through `accept_wire_identity` and only when `path_style_name` equals the requested name) resolves through `resolve_project_by_identity_for_capture` — the identity holder, else the cwd-prefix project with `$HOME` excluded, claimed or renamed only for a writer — and then `authorize_scope_for(Write)` on the writer connection, so an identity can neither redirect a differently named run nor open, claim, or create a project the caller may not write; Project manifests persist the typed full identity/source and derived keys so clean reindex restores the same UUID and lookup behavior. Also `ai-memory-hooks/src/router.rs` `workspace_override_is_rescope` — the hook router's session-sticky gate resolves a marker's `workspace` override via this same no-create `lookup_existing_workspace` (never a hand-rolled lookup) and fails closed (treats it as a rescope, disqualifying sticky) on a different or unresolvable workspace; only an override that resolves to the session's OWN workspace is not a rescope (#976) | `scope.rs` `read_resolution_table_driven`, `multi_scope_resolution_deduplicates_and_validates`, `identity_resolution.rs` `a_capture_naming_a_promoted_projects_legacy_key_reuses_it` (a capture naming the promoted project's legacy key lands in it, creates nothing and leaves the name resolvable), `a_capture_of_an_existing_exact_name_still_lands_there`, `a_capture_of_a_new_name_still_creates_its_project` (controls: the fallback runs only after the exact-name miss and still records the creator), hooks `two_api_checkouts_with_different_remotes_get_two_projects` (an identity-less capture under a key two projects claim refuses and creates nothing; a fresh folder-named capture still creates its project as the control), `a_slashed_label_reaches_only_a_project_the_caller_may_use` (a `workspace/project` label passed as the project is authorized as the pair it names and creates nothing when refused; granted control), `a_slashed_write_resolves_its_own_pair_and_never_creates`, `an_existing_slashed_project_wins_over_the_split`, no-auto-create + `unscoped_write_with_unresolvable_coordinate_errors`; `dual_key_scope.rs` `page_write_failure_after_promotion_preserves_manifest_warning`, `handoff_failure_after_promotion_preserves_manifest_warning`; `workstream.rs` `managed_run_rejects_mutually_exclusive_selection_before_promotion`, `managed_run_downstream_failure_after_promotion_preserves_manifest_warning`; `identity_resolution.rs` `canonical_and_legacy_reads_resolve_one_legacy_row_without_renaming`, `authorized_write_promotes_in_place_and_preserves_dependents_and_legacy_lookup`, `read_only_user_cannot_promote_a_legacy_name`, `canonical_target_conflict_rolls_back_the_promotion`, `audit_failure_rolls_back_promotion_and_keeps_the_writer_alive`, `exact_name_that_is_another_forges_canonical_key_fails_closed`, `an_ambiguous_name_names_its_holders_but_not_a_restricted_one` (restricted holder unnamed; open holder named as the control), `concurrent_legacy_and_canonical_resolve_or_create_converge_on_one_uuid`; admin `admin_purge.rs` `purge_project_refuses_a_real_id_from_another_workspace` (a row that really exists in another workspace answers 404 from `default` and is left intact), admin_rename/admin_move `rename_project_refuses_a_real_id_from_another_workspace` / `move_project_refuses_a_real_id_from_another_workspace` (the same for rename and move, the foreign project keeps its name and workspace, with the same id accepted from its own workspace as the control), `purge_project_still_refuses_an_ambiguous_name_by_default` (a name held by two rows -- one via its `legacy_name` -- stays a 400 and purges nothing), `purge_project_by_id_reaches_the_twin_and_leaves_the_name_holder_intact` (legitimate control: the id reaches the row the name could not, and the name-holder survives with its name), and store `list_projects_with_stats_hides_a_restricted_projects_id_from_an_ungranted_viewer` (the id is absent exactly where the name is, for an ungranted viewer, and present for the operator -- bite-checked with the visibility filter removed); `project_coordinates.rs` `shared_candidate_query_deduplicates_before_bound_and_uses_only_indexes`; wiki `promoted_identity_round_trips_through_manifest_and_clean_reindex`, `old_project_manifest_without_identity_still_reindexes`, `reindex_rejects_project_coordinate_fields_that_do_not_match_identity`; admin `write_page_surfaces_manifest_failure_after_promotion`, `bootstrap_surfaces_manifest_failure_after_promotion`, `move_project_merge_surfaces_destination_promotion_manifest_warning`, `move_session_create_surfaces_destination_promotion_manifest_warning`; `multi_session.rs` `two_operators_promote_two_clone_keys_to_one_uuid_without_moving_active_pointers`; MCP `dual_key_scope.rs`; hooks `workstream.rs` `managed_run_by_remote_identity_claims_the_folder_named_project`, `managed_run_by_remote_identity_routes_past_an_identityless_twin` (name-only control is ambiguous), `managed_run_identity_never_redirects_another_project_name`, `managed_run_by_remote_identity_refuses_a_viewer_without_write` (outsider refused with no project created; granted member admitted as the control), `managed_run_identity_never_claims_a_restricted_legacy_project` (an outsider whose cwd sits in a restricted identity-less project is refused, the identity stays unrecorded and no twin appears; fails with either the writer's claim check or the route's write check removed; a granted member claims it as the control), `managed_run_identity_routing_stays_inside_the_requested_workspace`, `concurrent_identity_runs_on_a_legacy_project_converge_on_it` (invariant #16), `managed_run_promotion_refreshes_the_scope_manifest`, `managed_run_discloses_manifest_failure_after_committed_promotion` static read/write/authz/cross-workspace/cross-forge cases; `router.rs` `workspace_override_is_rescope_only_on_a_genuine_workspace_change` (same/different/unresolvable workspace cases), `sticky_routing_keeps_the_session_project_across_a_sibling_checkout` (regression: same workspace forwarded on every event + `project_src=repo-root` from a nested checkout stays sticky), `sticky_routing_still_rescopes_when_marker_names_a_different_workspace_mid_session` (opposite direction: a genuinely different workspace still rescopes even under `sticky`) | STRONG |
| 10 | Destructive-op live-process refusal + confirm flags (invariant #9); `purge-project`'s `dry_run` always wins over `confirm` so a preview request can never become destructive; an explicitly empty or whitespace-only CLI scope flag cannot silently select the checkout | `ai-memory-cli/src/commands/process_guard.rs` `sibling_processes` + confirm flags in `reset`/`restore`/`reindex`/`uninstall --purge-data`/`purge_project`; `admin.rs` `handle_purge_project` checks `req.dry_run` unconditionally, before `req.confirm`, mirroring `reclaim-ledger-versions`; `ai-memory-cli/src/commands/mod.rs` `resolve_scope_noting_marker_project`, `resolve_scope_with_marker`, and `resolve_workspace` call `commands::refuse_empty_explicit` at the shared choke point before resolution or HTTP | `admin_purge.rs` confirm→400; `removal.rs` — injected live-sibling makes each destructive command bail before touching the data dir; `uninstall.rs` `purge_guard_refuses_a_live_sibling_before_stopping_the_service` — `uninstall --purge-data` checks for siblings (the `setup` service's own pid excepted) before it stops that service, and `purge_guard_rechecks_after_stopping_the_service` refuses when the stopped service is still alive; `admin_purge.rs` `purge_project_confirm_true_and_dry_run_true_still_only_previews` — `{"confirm": true, "dry_run": true}` deletes nothing (the regression this row now also covers); `ops.rs` `purge_project_dry_run_changes_nothing` — every project-scoped row count, the `purged_scopes` tombstone, and the `audit_log` row are identical before/after a `PurgeMode::Preview` run; `ops.rs` `purge_project_counts_collateral_damage_in_another_project` and `admin_purge.rs` `purge_project_dry_run_and_confirmed_purge_both_report_collateral_damage_in_another_project` — a purge of project P collaterally deletes an observation, and orphans a handoff's session reference, in a *different* project Q (via `sessions` cascading out of P), and both the preview and the confirmed report count it; CLI `commands::tests::resolve_scope_and_workspace_refuse_empty_and_whitespace_flags` and `tests/suite/marker_scope.rs` `restore_page_refuses_empty_scope_flags_without_sending_a_mutation` refuse empty and whitespace-only `--workspace`/`--project` with no POST; omitted, partially explicit and fully explicit scopes reach only the expected target as controls. Without the guard, the shipped binary sends the restore to the marker scope and the test fails | STRONG |
| 10b | Session purge is scope+owner-bound (no cross-session/project over-delete); `purge-session`'s `dry_run` always wins over `confirm`, same as `purge-project` | `ai-memory-store/src/ops.rs` `purge_session` — selection scoped to `(workspace_id, project_id)` and keyed on this session's own `summary_page_id` **or** `path='sessions/<sid>.md'` + `json_extract(frontmatter_json,'$.session_id')=<sid>` (frontmatter owner, not the recursive latest-chain); `in_scope==0 → NotFound` fail-closed; the session's prompt `profile_candidates` (`source_ref = 'session:<sid>'`, a globally unique id) are deleted in whichever project the harvest filed them, matching the `observations` cascade they were harvested from; whole op in one transaction, and the tombstone it leaves is checked by `begin_session_row` and by the new-session arm of `admit_hook_session_event`; `move_project_workspace` re-stamps the `purged_sessions` tombstone with the rest of the project so it still matches after a move; `admin.rs` `handle_purge_session` checks `req.dry_run` unconditionally, before `req.confirm` | `ops.rs` `purge_session_leaves_a_sibling_session_in_the_same_project_intact`, `…refuses_a_session_from_another_project_and_deletes_nothing`, `…refuses_a_session_from_another_workspace`, `…does_not_delete_an_identically_pathed_page_in_another_project`, `…removes_older_summary_versions_without_deleting_prior_manual_page` (#862); `admin_purge.rs` `purge_session_confirm_true_and_dry_run_true_still_only_previews` — `{"confirm": true, "dry_run": true}` deletes nothing; `ops.rs` `purge_session_dry_run_changes_nothing` — every table a session purge touches, the `purged_sessions` tombstone, and the `audit_log` row are identical before/after a `PurgeMode::Preview` run; `ops.rs` `purge_session_counts_collateral_damage_in_another_project` and `admin_purge.rs` `purge_session_dry_run_and_confirmed_purge_both_report_collateral_damage_in_another_project` — purging session S collaterally deletes an observation, and orphans a handoff's session reference, in a *different* project (via `S`'s own id cascading), and both the preview and the confirmed report count it; `admin_purge.rs` `purge_session_dry_run_refuses_a_session_outside_its_named_scope` — the same session previewed under a different real project (same workspace) or a different real workspace whose project shares the name both 404 with no counts in the body, with the session's own scope as the 200 control; the `purged_sessions` tombstone holds against live hook ingest as well as `begin_session`: `ops.rs` `a_purged_session_is_not_recreated_by_hook_admission` (`admit_hook_session_event` refuses a purged session and writes nothing, with a sibling session and the same id in another project admitted as controls) and `router.rs` `async_processing_drops_events_of_a_purged_session` (the late delivery is a terminal `dropped_invalid`, not a failure the client retries) and `batch_drops_a_purged_session_then_commits_next_item` (the batch endpoint acknowledges it as `dropped_invalid` and commits the next item instead of stopping fail-fast); the user's own sentences the profile harvested from the session's prompts go with it: `ops.rs` `purge_session_deletes_the_profile_candidates_harvested_from_it` (including the candidate harvested from a prompt the session recorded in another project, whose observation the purge deletes through the cascade; a sibling session's candidates in both projects and a page candidate survive); `ops.rs` `a_purged_session_stays_purged_after_its_project_moves` (after `move-project`, `begin_session` for the purged id in the destination is refused with `SessionPurged`; a fresh session there is admitted as the control) | STRONG |
@@ -257,6 +257,11 @@ filter dimensions and foreign/session intersections; existing qualified-owner
search regressions remain active. `token_context_rolls_back_with_response_counters_and_aggregates`
injects a child-row failure and verifies both rows and aggregates roll back.
+Guard-removal validation detected all six deliberate faults above through their
+intended assertions (foreign citation scope, source owner, contradiction viewer,
+admin-setting mask, exact model and UTC lower bound). The permanent cases are in
+`scripts/check-dashboard-core-mutations.py`; compilation failures do not count.
+
## Keeping this current (the standing protocol)
1. **Touch a guard, add/extend its adversarial test.** Any change to code in the
diff --git a/docs/testing-dashboard.md b/docs/testing-dashboard.md
new file mode 100644
index 00000000..2027f489
--- /dev/null
+++ b/docs/testing-dashboard.md
@@ -0,0 +1,136 @@
+# Dashboard regression tests
+
+The dashboard is built and distributed with Cargo alone. Browser testing uses
+Node 22+ and Chromium separately. It adds no JavaScript dependency to the Rust
+server, its assets, the Docker image or the native packages.
+
+## Run the checks
+
+Run the repository's normal gates from `AGENTS.md`, including the full Rust
+suite. The browser suite needs a built executable and an installed Chromium:
+
+```bash
+cargo build --locked --bin ai-memory
+# Pinned test browser; installation follows Playwright's browser installer.
+npx --yes [email protected] install --with-deps --only-shell chromium
+node tests/e2e/web_dashboard_browser.mjs
+node tests/e2e/web_dashboard_mutations.mjs
+python3 scripts/check-dashboard-core-mutations.py
+# Focused mailbox isolation probe (the CI gate runs every case).
+python3 scripts/check-dashboard-core-mutations.py --case expose-restricted-mailbox-projects
+```
+
+Use `AI_MEMORY_BIN` for another built executable and `AI_MEMORY_BROWSER` for an
+existing Chromium executable. On Linux, the runner also finds Chromium in the
+Playwright cache. An absent executable, a missing browser, a failed setup or a
+JavaScript exception fails the command. The Linux CI job installs the pinned
+browser and runs both mutation gates, without `continue-on-error` or retries.
+The [browser installation reference](https://playwright.dev/docs/browsers)
+describes the test browser's system dependencies and headless shell.
+
+The browser runner starts its own Rust server, uses synthetic projects and a
+fake root token, and drives Chromium through its native debugging protocol. It
+replaces no DOM and contacts no running production server. Messages are sent
+over HTTP and claimed through the native CLI. Every run keeps logs and a JSON
+report in the printed artifact directory, and failed browser cases also keep a
+screenshot.
+
+Run the Rust mutation command alone, with no other build running and no editor
+writing the selected source files. It temporarily changes clean tracked source
+files, stores the exact originals and restores them in `finally`. A concurrent
+edit is refused instead of overwritten. Each probe needs a passing baseline and
+a specific failed test assertion, so compiler errors and timeouts do not count.
+Logs and originals stay under `target/dashboard-core-mutations-*`.
+
+## Behaviors protected
+
+Six deliberate faults were confirmed to fail their intended assertions: source
+scope, source ownership, contradiction visibility, admin-setting disclosure,
+exact model filtering and the UTC lower bound. Compiler errors do not count.
+Reproduce them with the matching cases in
+`scripts/check-dashboard-core-mutations.py`.
+
+The contextual investigation additions are covered by the browser cases
+`contextual-investigation`, `feature-states` and `knowledge-evidence`, which run
+against the real Rust server. They check combined server filters beyond fifty
+responses, reload, empty results, native association labels, effective zero-LLM
+states, source navigation, on-page recall and mobile overflow. Rust regressions
+in `contextual.rs`, `live_token_usage.rs`, `session_usage.rs` and the hooks
+router also cover foreign source IDs, private contradictions, source ownership,
+root controls, redacted admin settings, transaction rollback, native cursor
+continuity, malformed gaps and sanitization before truncation. Historical
+unknown data is a required outcome and is never replaced by guessed coordinates.
+
+| Behavior | Automated regression guard |
+| --- | --- |
+| Only the selected tab is visible/accessibility-exposed; keyboard, history, reload and old section links work | `web_dashboard_browser.mjs`: `tabs`; Rust `operations_project_tabs_have_one_default_panel_and_matching_controls` |
+| Recipient filtering includes workspace and project, clears stale selection, disables empty projects and recovers | Browser `recipients`; Rust `operations_inbox_filters_initial_agents_by_both_project_coordinates` |
+| Inbox queue counts name each workspace/project, links and selectors open the matching mailbox, empty states do not claim new mail, reading leaves messages queued, collection reduces counts | Browser `mailbox-context`; Rust `operations_inbox_queue_context_hides_foreign_projects_and_preserves_mail` also refuses foreign/partial scopes and hides restricted project names with legitimate read/root controls |
+| Sidebar notifications appear for actual queued mail, refresh without reload, link to the right workspace/project, disappear after collection and clear on authorization loss | Browser `notifications`; Rust `operations_notifications_are_read_only_and_hide_restricted_projects` covers access-filtered totals, bounded links, zero state, no caching and non-consumption |
+| Pending notification links and the default received mailbox find older messages behind collected history; explicit all/claimed filters retain history | Rust `operations_pending_mail_is_filtered_before_history_pagination`; server state predicate runs before LIMIT/OFFSET |
+| Resumed substantive work reopens scoped API/detail reads, leaves completed listings, refuses a foreign project and closes after another SessionEnd | Browser `resumed-session`; store `session_activity` tests preserve the persisted watermark and owner/project controls |
+| Legacy browser reads cannot send; invalid tokens are refused and cleared; authorized sends reach the chosen harness once | Browser `delivery`, against real HTTP auth and native CLI claims; Rust `operations_message_write_obeys_root_user_and_project_grants`, `operations_message_requires_write_access_to_both_project_coordinates`, store `addressed_messages_are_claimed_once_only_by_the_selected_harness` |
+| Sanitization, admission rejection, foreign origin and unknown recipients | Rust `operations_browser_messages_use_the_configured_sanitizer_and_admission`, `operations_browser_send_refuses_cross_origin_unknown_recipient_and_empty_body`; browser `delivery` checks escaped message text |
+| Usage reaches the server before session-end, repeated reports do not add calls, refresh preserves active tab/filter/focus | Browser `live-usage`; hooks `live_token_calls_update_open_sessions_without_an_end_event` |
+| More than 256 responses and a transcript larger than 4 MiB recover across successive hook processes, without advancing on enqueue failure or duplicating responses | Browser `capture-backlog` uses native hooks, spool drain, the real server and dashboard; CLI `native_hook_recovers_a_response_backlog_and_does_not_advance_on_spool_failure`, `live_token_cursor_replays_until_commit_then_recovers_every_response`, `live_token_cursor_crosses_byte_windows_and_retries_partial_usage` |
+| Search and recent ordering include small responses beyond the largest fifty; pagination and reload keep query state | Browser `call-history`; store `token_call_queries_search_and_order_before_pagination_with_scope_and_owner_guards`; web `operations_response_search_and_pagination_cover_the_full_project_and_session` |
+| Session usage updates without reload and preserves filter focus | Browser `session-live-usage` |
+| The native hook actually reads Claude/Codex transcripts for each supported event | CLI `native_hook_reports_live_usage_for_every_supported_event_and_harness` uses the built executable and inspects the delivered spool payload |
+| Streaming/replayed counters cannot decrease the displayed response or disagree with session totals | Store `token_calls_keep_partial_reports_monotonic_in_rows_and_aggregates` |
+| Reused response ids stay separate across sessions, agents and projects | Store `token_calls_group_by_session_and_agent_without_merging_foreign_responses`; web ownership/aggregate tests |
+| Codex cached input is excluded from fresh input | CLI `live_token_codex_reads_modern_usage_without_counting_cached_input_twice`; migration `v90_normalizes_codex_cache_once_and_preserves_claude` |
+| Private/malformed response ids are refused; private model labels are scrubbed before the 64-character bound | Hooks `live_token_calls_scrub_private_labels_before_truncating` checks a private value crossing the limit, with a public-label control |
+| Light/dark selection persists; system mode follows OS changes; palettes differ | Browser `themes` |
+| Navigation remains visible with usable targets and no page overflow at 320, 390 and 768 px | Browser `responsive` |
+| Bundled guide HTML/Markdown/JSON, search, release selection, mount prefixes, traversal refusal | `tests/suite/documentation.rs`; browser `documentation` uses the real authenticated server |
+| Changing a release loads its notes without a button, keeps links/history/reload consistent and works with manual submission without JavaScript | Browser `documentation` |
+
+## Prove the guards detect faults
+
+The browser campaign first runs every case against the original application. It
+then changes one served HTML response at a time through Chromium's network
+interception, while the tested controller still runs in Chromium. A mutant
+counts only if the response was changed and the intended behavioral case failed.
+
+| Deliberate fault | Required failing case |
+| --- | --- |
+| Reset the response cursor on every hook | Cursor backlog regression |
+| Advance the cursor before enqueue succeeds | Native-hook backlog/enqueue-failure regression |
+| Ignore response search before selecting the page | Full-history response query regression |
+| Remove response-owner filtering | Full-history query ownership regression with root control |
+| Disable periodic refresh on the session page | `session-live-usage` |
+| Drop server query fields from response controls | `call-history` |
+| Display every tab panel | `tabs` |
+| Ignore recipient workspace | `recipients` |
+| Ignore recipient project | `recipients` |
+| Retain the write credential | `delivery` |
+| Enable duplicate sending while a request is pending | `delivery` |
+| Enable sending to an empty project after a request completes | `delivery` |
+| Disable automatic usage refresh | `live-usage` |
+| Stop saving the selected theme | `themes` |
+| Capture browser navigation shortcuts in the tab controller | `tabs` |
+| Disable automatic release submission | `documentation` |
+| Restore a stale release selection on browser history navigation | `documentation` |
+| Show a fabricated new-message alert with no queued mail | `mailbox-context` |
+| Ignore the workspace when selecting a mailbox | `mailbox-context` |
+| Expose restricted projects in the mailbox overview | Mailbox context isolation regression |
+| Stop loading sidebar notifications | `notifications` |
+| Ignore a notification's workspace | `notifications` |
+| Expose restricted notification totals or project names | Notification isolation regression |
+| Apply history pagination before its state filter | Pending-mail pagination regression |
+| Treat resumed substantive session work as ended | Store `resumed_summary_is_open_and_preserves_the_persisted_end` |
+| Capture usage only on session-end | Native-hook event/harness integration test |
+| Count Codex cache as fresh input | Codex transcript parser regression |
+| Overwrite a response with lower replayed counters | Response/session consistency regression |
+| Remove harness checks from the claim lookup and atomic update | Directed harness claim regression |
+
+Browser results are summarized in `target/web-dashboard-mutations.json`. The
+source anchors used to inject a fault need updating when the implementation is
+reorganized, and a fault that was not injected fails the campaign. Assertions
+stay on the behavior above, not on a particular function body.
+
+These are bounded probes, not proof against every possible defect. Rust tests
+also run the existing authorization, isolation, concurrency and recovery suites.
+The browser gate covers Chromium on Linux only. It does not establish Firefox or
+Safari rendering or pixel-perfect appearance. A behavior-preserving refactor
+should pass the regression tests.
diff --git a/scripts/check-dashboard-core-mutations.py b/scripts/check-dashboard-core-mutations.py
new file mode 100644
index 00000000..3ed6820d
--- /dev/null
+++ b/scripts/check-dashboard-core-mutations.py
@@ -0,0 +1,177 @@
+#!/usr/bin/env python3
+"""Prove focused Rust tests reject semantic faults; restore sources in finally.
+
+Run alone, with no concurrent builds. This touches only clean tracked source
+files, backs up their exact bytes, and never writes production data. A compiler
+error, a failed baseline or a timeout does not count as a killed mutation.
+"""
+import argparse
+import json
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+
+ROOT = Path(__file__).resolve().parents[1]
+TARGET = ROOT / "target"
+TARGET.mkdir(exist_ok=True)
+OUT = Path(tempfile.mkdtemp(prefix="dashboard-core-mutations-", dir=TARGET))
+LOCK = TARGET / "dashboard-core-mutations.lock"
+REPORT = {"mutants": [], "complete": False}
+
+CASES = [
+ {'name': 'expose-foreign-page-citations', 'file': 'crates/ai-memory-store/src/provenance.rs', 'start': 'pub async fn page_provenance(', 'end': '\n}', 'before': 'AND s.workspace_id=?2 AND s.project_id=?3', 'after': 'AND ?2 IS NOT NULL AND ?3 IS NOT NULL', 'command': ['cargo', 'test', '-p', 'ai-memory-web', '--lib', 'contextual_page_sources_preserve_shared_pages_and_refuse_foreign_or_private_evidence']},
+ {'name': 'ignore-response-time-lower-bound', 'file': 'crates/ai-memory-store/src/reader.rs', 'start': 'pub async fn token_usage_report_page(', 'end': '/// Total reported token usage', 'before': 'COALESCE(c.response_at,c.observed_at)>=?13', 'after': 'COALESCE(c.response_at,c.observed_at)>=COALESCE(c.response_at,c.observed_at)', 'command': ['cargo', 'test', '-p', 'ai-memory-store', '--lib', 'token_investigation_filters_before_paging_and_keeps_native_context']},
+ {'name': 'expose-private-page-contradictions', 'file': 'crates/ai-memory-store/src/provenance.rs', 'start': 'pub async fn page_provenance(', 'end': '\n}', 'before': 'readable_repository_predicate("pg.project_id", viewer)', 'after': 'readable_repository_predicate("pg.project_id", viewer.and(None))', 'command': ['cargo', 'test', '-p', 'ai-memory-web', '--lib', 'contextual_page_sources_preserve_shared_pages_and_refuse_foreign_or_private_evidence']},
+ {'name': 'expose-other-owners-page-sources', 'file': 'crates/ai-memory-store/src/provenance.rs', 'start': 'pub async fn page_provenance(', 'end': '\n}', 'before': 'OwnerFilter::User(a) => (1, a)', 'after': 'OwnerFilter::User(a) => (0, a)', 'command': ['cargo', 'test', '-p', 'ai-memory-web', '--lib', 'contextual_page_sources_preserve_shared_pages_and_refuse_foreign_or_private_evidence']},
+ {'name': 'expose-admin-feature-settings', 'file': 'crates/ai-memory-web/src/features.rs', 'start': 'pub(crate) async fn states(', 'end': '\n}', 'before': 'if private && !admin', 'after': 'if private && false && !admin', 'command': ['cargo', 'test', '-p', 'ai-memory-web', '--lib', 'contextual_states_report_effective_configuration_and_mask_admin_settings']},
+ {'name': 'ignore-exact-model-filter', 'file': 'crates/ai-memory-store/src/reader.rs', 'start': 'pub async fn token_usage_report_page(', 'end': '/// Total reported token usage', 'before': "COALESCE(c.model,'Not reported')=?10", 'after': "COALESCE(c.model,'Not reported')=COALESCE(c.model,'Not reported')", 'command': ['cargo', 'test', '-p', 'ai-memory-store', '--lib', 'token_investigation_filters_before_paging_and_keeps_native_context']},
+ {
+ "name": "rewind-live-response-cursor", "file": "crates/ai-memory-cli/src/commands/session_usage.rs",
+ "start": "pub fn extract_live_calls(", "end": "/// Cumulative token usage",
+ "before": "if cursor.offset > len", "after": "if true || cursor.offset > len",
+ "command": ["cargo", "test", "-p", "ai-memory-cli", "--lib", "live_token_cursor_replays_until_commit_then_recovers_every_response"],
+ },
+ {
+ "name": "advance-usage-before-enqueue", "file": "crates/ai-memory-cli/src/commands/hook.rs",
+ "start": " if !antigravity_turn_only {", "end": " if let Some(prompts) = antigravity_prompts {",
+ "before": "if hook_spool::enqueue_with_config(&spool, &entry, Some(&spool_policy)).is_err()",
+ "after": "if { if let Some(batch) = live_batch.take() { batch.commit(); } hook_spool::enqueue_with_config(&spool, &entry, Some(&spool_policy)) }.is_err()",
+ "command": ["cargo", "test", "-p", "ai-memory-cli", "--test", "suite", "native_hook_recovers_a_response_backlog_and_does_not_advance_on_spool_failure"],
+ },
+ {
+ "name": "ignore-response-search", "file": "crates/ai-memory-store/src/reader.rs",
+ "start": "pub async fn token_usage_report_page(", "end": "/// Total reported token usage",
+ "before": "(?6 = '' OR instr", "after": "(?6 = ?6 OR instr",
+ "command": ["cargo", "test", "-p", "ai-memory-store", "--lib", "token_call_queries_search_and_order_before_pagination_with_scope_and_owner_guards"],
+ },
+ {
+ "name": "expose-other-owners-response-search", "file": "crates/ai-memory-store/src/reader.rs",
+ "start": "pub async fn token_usage_report_page(", "end": "/// Total reported token usage",
+ "before": "OwnerFilter::User(a) => (1, a)", "after": "OwnerFilter::User(a) => (0, a)",
+ "command": ["cargo", "test", "-p", "ai-memory-store", "--lib", "token_call_queries_search_and_order_before_pagination_with_scope_and_owner_guards"],
+ },
+
+ {
+ "name": "expose-private-notification-projects", "file": "crates/ai-memory-web/src/routes/notifications.rs",
+ "start": "pub(crate) async fn handler(", "end": "let notifications =",
+ "before": "pending_inbox_counts(viewer.map(|v| v.0.user()))", "after": "pending_inbox_counts(viewer.filter(|_| false).map(|v| v.0.user()))",
+ "command": ["cargo", "test", "-p", "ai-memory-web", "--lib", "operations_notifications_are_read_only_and_hide_restricted_projects"],
+ },
+ {
+ "name": "ignore-message-state-before-pagination", "file": "crates/ai-memory-store/src/dashboard.rs",
+ "start": "pub async fn message_history_filtered(", "end": "/// Read this session",
+ "before": "(?5 IS NULL OR state=?5)", "after": "(?5 IS NULL OR ?5 IS NOT NULL)",
+ "command": ["cargo", "test", "-p", "ai-memory-web", "--lib", "operations_pending_mail_is_filtered_before_history_pagination"],
+ },
+ {
+ "name": "hide-resumed-session-activity", "file": "crates/ai-memory-store/src/reader.rs",
+ "start": "fn sessions_for_scope_sql(", "end": "fn handoff_listing_sql(",
+ "before": "AND resumed.created_at > s.ended_at", "after": "AND resumed.created_at > s.ended_at AND 0",
+ "command": ["cargo", "test", "-p", "ai-memory-store", "--lib", "resumed_summary_is_open_and_preserves_the_persisted_end"],
+ },
+ {
+ "name": "expose-restricted-mailbox-projects", "file": "crates/ai-memory-web/src/routes/inbox.rs",
+ "start": "pub(crate) async fn handler(", "end": "#[derive(Deserialize)]",
+ "before": "list_projects_with_stats(viewer)", "after": "list_projects_with_stats(viewer.and(None))",
+ "command": ["cargo", "test", "-p", "ai-memory-web", "--lib", "operations_inbox_queue_context_hides_foreign_projects_and_preserves_mail"],
+ },
+ {
+ "name": "capture-only-at-session-end", "file": "crates/ai-memory-cli/src/commands/hook.rs",
+ "start": 'if matches!(\n args.event.as_str(),',
+ "end": ' // Token-usage visibility',
+ "before": '"post-tool-use" | "stop" | "pre-compact" | "session-end"', "after": '"session-end"',
+ "command": ["cargo", "test", "-p", "ai-memory-cli", "--test", "suite", "native_hook_reports_live_usage_for_every_supported_event_and_harness"],
+ },
+ {
+ "name": "count-codex-cache-as-fresh-input", "file": "crates/ai-memory-cli/src/commands/session_usage.rs",
+ "start": "pub fn extract_live_calls(", "end": "/// Cumulative token usage",
+ "before": "input.saturating_sub(cached)", "after": "input",
+ "command": ["cargo", "test", "-p", "ai-memory-cli", "--lib", "live_token_codex_reads_modern_usage_without_counting_cached_input_twice"],
+ },
+ {
+ "name": "let-replayed-counters-decrease", "file": "crates/ai-memory-store/src/ops.rs",
+ "start": "pub fn upsert_token_calls(", "end": "\npub fn ",
+ "before": "output_tokens = MAX(output_tokens, excluded.output_tokens)", "after": "output_tokens = excluded.output_tokens",
+ "command": ["cargo", "test", "-p", "ai-memory-store", "--lib", "token_calls_keep_partial_reports_monotonic_in_rows_and_aggregates"],
+ },
+ {
+ "name": "allow-the-wrong-harness-to-claim", "file": "crates/ai-memory-store/src/ops.rs",
+ "start": "pub(crate) fn pop_message_in_transaction(", "end": "/// Cancel",
+ "replacements": [("(to_agent IS NULL OR to_agent = ?3)", "(?3 IS NOT NULL)", 2), ("(to_agent IS NULL OR to_agent = ?4)", "(?4 IS NOT NULL)", 1)],
+ "command": ["cargo", "test", "-p", "ai-memory-store", "--lib", "addressed_messages_are_claimed_once_only_by_the_selected_harness"],
+ },
+]
+
+parser = argparse.ArgumentParser(description=__doc__)
+parser.add_argument("--case", choices=[case["name"] for case in CASES])
+selected = parser.parse_args().case
+if selected:
+ CASES = [case for case in CASES if case["name"] == selected]
+
+
+def run(case, label):
+ log = OUT / (case["name"] + "-" + label + ".log")
+ with log.open("w") as output:
+ result = subprocess.run(case["command"], cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, timeout=300)
+ return result.returncode, log.read_text(errors="replace")
+
+
+def replace_bytes(path, contents):
+ staged = path.with_name(path.name + ".mutation-tmp")
+ try:
+ staged.write_bytes(contents)
+ os.chmod(staged, path.stat().st_mode & 0o777)
+ os.replace(staged, path)
+ finally:
+ staged.unlink(missing_ok=True)
+
+
+with LOCK.open("x"):
+ try:
+ for case in CASES:
+ path = ROOT / case["file"]
+ subprocess.run(["git", "diff", "--exit-code", "HEAD", "--", case["file"]], cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
+ original = path.read_bytes()
+ (OUT / (case["name"] + ".original")).write_bytes(original)
+ text = original.decode()
+ start = text.index(case["start"])
+ end = text.index(case["end"], start)
+ section = text[start:end]
+ for before, after, count in case.get("replacements", [(case.get("before"), case.get("after"), 1)]):
+ assert section.count(before) == count, case["name"] + ": source anchor drifted"
+ section = section.replace(before, after)
+ changed = (text[:start] + section + text[end:]).encode()
+ code, _ = run(case, "baseline")
+ assert code == 0, case["name"] + ": baseline failed"
+ try:
+ replace_bytes(path, changed)
+ code, output = run(case, "mutant")
+ assert code != 0 and "test result: FAILED." in output, case["name"] + ": mutation survived or failed outside a test: " + output[-1500:]
+ assert case["command"][-1] + " ... FAILED" in output, case["name"] + ": unrelated test failed"
+ REPORT["mutants"].append({"name": case["name"], "killed": True, "test": case["command"][-1]})
+ print("KILLED " + case["name"], flush=True)
+ finally:
+ assert path.read_bytes() == changed, "Source changed concurrently; original backup: " + str(OUT)
+ replace_bytes(path, original)
+ # Every changed file must be back to its exact committed content.
+ subprocess.run(["git", "diff", "--exit-code", "HEAD", "--", *sorted({c["file"] for c in CASES})], cwd=ROOT, check=True)
+ except Exception as error:
+ REPORT["error"] = str(error)
+ raise
+ finally:
+ try:
+ # Source restoration alone leaves the last deliberately broken
+ # executable in target/. Rebuild before another test consumes it.
+ subprocess.run(["git", "diff", "--exit-code", "HEAD", "--", *sorted({c["file"] for c in CASES})], cwd=ROOT, check=True, stdout=subprocess.DEVNULL)
+ with (OUT / "restore-build.log").open("w") as log:
+ subprocess.run(["cargo", "build", "--locked", "--bin", "ai-memory"], cwd=ROOT, stdout=log, stderr=subprocess.STDOUT, timeout=300, check=True)
+ REPORT["executable_restored"] = True
+ REPORT["complete"] = len(REPORT["mutants"]) == len(CASES) and "error" not in REPORT
+ except Exception as error:
+ REPORT["restore_error"] = str(error)
+ raise
+ finally:
+ (OUT / "report.json").write_text(json.dumps(REPORT, indent=2) + "\n")
+ LOCK.unlink(missing_ok=True)
+ print("Core mutation report: " + str(OUT / "report.json"), flush=True)
diff --git a/tests/e2e/web_dashboard_browser.mjs b/tests/e2e/web_dashboard_browser.mjs
new file mode 100644
index 00000000..d8244d2d
--- /dev/null
+++ b/tests/e2e/web_dashboard_browser.mjs
@@ -0,0 +1,552 @@
+#!/usr/bin/env node
+// Real Chromium + the built Rust server. No npm dependencies or DOM substitutes.
+import assert from 'node:assert/strict';
+import {spawn, spawnSync} from 'node:child_process';
+import fs from 'node:fs';
+import net from 'node:net';
+import os from 'node:os';
+import path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
+const binary = path.resolve(process.env.AI_MEMORY_BIN || path.join(root, 'target/debug/ai-memory'));
+const artifacts = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'ai-memory-web-e2e-'));
+fs.chmodSync(artifacts, 0o700);
+const token = 'FAKEfake0123456789WebDashboardRoot';
+const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
+function contrast(a, b) {
+ const luminance = color => color.match(/[\d.]+/g).slice(0, 3).map(Number).map(value => {
+ const channel = value / 255;return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
+ }).reduce((sum, value, index) => sum + value * [0.2126, 0.7152, 0.0722][index], 0);
+ const values = [luminance(a), luminance(b)].sort((x, y) => y - x);
+ return (values[0] + 0.05) / (values[1] + 0.05);
+}
+const mutation = process.argv.find(arg => arg.startsWith('--mutation='))?.split('=')[1];
+const mutations = {
+ 'all-panels-visible': {test: 'tabs', from: 'panel.hidden=!selected', to: 'panel.hidden=false'},
+ 'ignore-recipient-workspace': {test: 'recipients', from: 'option.dataset.workspace===scope.dataset.workspace&&', to: ''},
+ 'ignore-recipient-project': {test: 'recipients', from: 'option.dataset.project===scope.dataset.project', to: 'true'},
+ 'retain-write-token': {test: 'delivery', from: 'if(token)token.value=""', to: 'if(token)token.value=token.value'},
+ 'disable-live-refresh': {test: 'live-usage', from: 'timer=setTimeout(refresh,10000);', to: 'timer=0;'},
+ 'disable-session-live-refresh': {test: 'session-live-usage', from: 'timer=setTimeout(refresh,10000);', to: 'timer=0;'},
+ 'drop-usage-query': {test: 'call-history', from: 'new FormData(form).forEach(function(value,key){url.searchParams.set(key,value);});', to: 'void form;'},
+ 'forget-theme': {test: 'themes', from: 'localStorage.setItem(key,selected)', to: 'void selected'},
+ 'steal-browser-shortcut': {test: 'tabs', from: 'if(event.altKey||event.ctrlKey||event.metaKey)return;', to: ''},
+ 'enable-send-while-pending': {test: 'delivery', from: 'button.disabled=sending||!toAgent', to: 'button.disabled=!toAgent'},
+ 'enable-send-for-empty-project-after-request': {test: 'delivery', from: 'sending=false;updateSendButton();result.focus()', to: 'sending=false;button.disabled=false;result.focus()'},
+ 'disable-release-auto-submit': {test: 'documentation', from: 'releaseSelect.form.requestSubmit();', to: 'void releaseSelect;'},
+ 'restore-stale-release-on-history': {test: 'documentation', from: 'releaseSelect.form.reset();', to: 'void releaseSelect;'},
+ 'show-false-inbox-alert': {test: 'mailbox-context', from: 'Inbox <span id="inbox-pending-count"', to: 'Inbox <small>NEW MESSAGE</small> <span id="inbox-pending-count"'},
+ 'ignore-mailbox-workspace': {test: 'mailbox-context', from: 'url.searchParams.set("workspace",o.dataset.workspace);', to: 'url.searchParams.set("workspace","team");'},
+ 'disable-inbox-notifications': {test: 'notifications', from: ' refreshInboxNotifications();\n})();', to: ' void refreshInboxNotifications;\n})();'},
+ 'ignore-notification-workspace': {test: 'notifications', from: 'url.searchParams.set("workspace",project.workspace);', to: 'url.searchParams.set("workspace","team");'},
+};
+assert(!mutation || mutations[mutation], 'Unknown mutation');
+const report = {mutation: mutation || null, mutationApplied: 0, cases: []};
+const children = [];
+let cdp;
+
+function chromePath() {
+ if (process.env.AI_MEMORY_BROWSER) return process.env.AI_MEMORY_BROWSER;
+ const cache = process.env.PLAYWRIGHT_BROWSERS_PATH || path.join(os.homedir(), '.cache/ms-playwright');
+ if (fs.existsSync(cache)) {
+ const versions = fs.readdirSync(cache).filter(name => /^chromium_headless_shell-\d+$/.test(name))
+ .sort((a, b) => Number(b.split('-').at(-1)) - Number(a.split('-').at(-1)));
+ for (const version of versions) {
+ const executable = path.join(cache, version, 'chrome-headless-shell-linux64/chrome-headless-shell');
+ if (fs.existsSync(executable)) return executable;
+ }
+ }
+ throw Error('Chromium required: set AI_MEMORY_BROWSER or install the pinned browser from docs/testing-dashboard.md');
+}
+
+function launch(executable, args, env, log) {
+ const fd = fs.openSync(path.join(artifacts, log), 'w', 0o600);
+ try {
+ const child = spawn(executable, args, {cwd: artifacts, env, stdio: ['ignore', fd, fd]});
+ child.completion = new Promise(resolve => {
+ child.once('error', error => resolve({error: error.message}));
+ child.once('exit', code => resolve({code}));
+ });
+ children.push(child);
+ return child;
+ } finally { fs.closeSync(fd); }
+}
+
+async function until(predicate, label, timeout = 12000) {
+ const deadline = Date.now() + timeout;
+ do {
+ if (await predicate()) return;
+ await delay(50);
+ } while (Date.now() < deadline);
+ assert.fail(label);
+}
+
+// Values interpolated into code sent to Runtime.evaluate: escape the characters
+// JSON leaves raw that can end or re-parse a script, not only quotes.
+const literal = value => JSON.stringify(value).replace(/[<>\/\u2028\u2029]/g, c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0'));
+
+class Cdp {
+ constructor(socket) {
+ this.socket = socket; this.next = 0; this.pending = new Map(); this.listeners = new Map(); this.errors = [];
+ socket.onmessage = event => {
+ const message = JSON.parse(event.data);
+ if (message.id) {
+ const pending = this.pending.get(message.id);
+ if (!pending) return;
+ this.pending.delete(message.id); clearTimeout(pending.timer);
+ if (message.error) pending.reject(Error(message.error.message)); else pending.resolve(message.result);
+ } else {
+ if (message.method === 'Runtime.exceptionThrown') this.errors.push(message.params.exceptionDetails.text);
+ const listener = this.listeners.get(message.method);
+ if (typeof listener === 'function') Promise.resolve(listener(message)).catch(error => this.errors.push(error.message));
+ }
+ };
+ socket.onclose = () => {
+ for (const pending of this.pending.values()) {clearTimeout(pending.timer);pending.reject(Error('Chromium disconnected'));}
+ this.pending.clear();
+ };
+ }
+ send(method, params = {}, sessionId = this.sessionId) {
+ return new Promise((resolve, reject) => {
+ const id = ++this.next;
+ const timer = setTimeout(() => {this.pending.delete(id);reject(Error('CDP timeout: ' + method));}, 10000);
+ this.pending.set(id, {resolve, reject, timer});
+ this.socket.send(JSON.stringify({id, method, params, ...(sessionId ? {sessionId} : {})}));
+ });
+ }
+ async evaluate(expression) {
+ const result = await this.send('Runtime.evaluate', {expression, returnByValue: true, awaitPromise: true});
+ if (result.exceptionDetails) throw Error(result.exceptionDetails.text);
+ return result.result.value;
+ }
+ async goto(url, selector, expected = url) {
+ await this.send('Page.navigate', {url});
+ await until(() => this.evaluate(`location.href===${literal(expected)}&&document.readyState==='complete'&&!!document.querySelector(${literal(selector)})`), 'Page did not load: ' + selector);
+ }
+ async reload() {
+ await this.evaluate('window.reloadMarker=true');await this.send('Page.reload');
+ await until(() => this.evaluate('!window.reloadMarker&&document.readyState==="complete"'), 'Page did not reload');
+ }
+ async key(key) {
+ await this.send('Input.dispatchKeyEvent', {type: 'keyDown', key});
+ await this.send('Input.dispatchKeyEvent', {type: 'keyUp', key});
+ }
+}
+
+async function main() {
+ assert(fs.existsSync(binary), 'Build ai-memory first or set AI_MEMORY_BIN');
+ const browserBinary = chromePath();
+ const portSocket = net.createServer();await new Promise(resolve => portSocket.listen(0, '127.0.0.1', resolve));
+ const port = portSocket.address().port;await new Promise(resolve => portSocket.close(resolve));
+ const base = `http://127.0.0.1:${port}`;
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('AI_MEMORY_')));
+ env.AI_MEMORY_AUTH_TOKEN = token;
+ const server = launch(binary, ['--data-dir', path.join(artifacts, 'server'), 'serve', '--transport', 'http', '--bind', `127.0.0.1:${port}`, '--enable-web', '--no-watcher', '--workspace', 'team', '--project', 'app'], env, 'server.log');
+ const request = async (route, payload) => {
+ const response = await fetch(base + route, {method: payload === undefined ? 'GET' : 'POST', headers: {Authorization: 'Bearer ' + token, 'Content-Type': 'application/json', 'X-Ai-Memory-UI': '1'}, ...(payload === undefined ? {} : {body: JSON.stringify(payload)}), signal: AbortSignal.timeout(15000)});
+ assert(response.ok, `Fixture request ${route.split('?')[0]} returned ${response.status}`);
+ return response;
+ };
+ await until(async () => {
+ assert(server.exitCode === null, 'Isolated server exited');
+ try {return (await fetch(base + '/web/', {headers: {Authorization: 'Bearer ' + token}})).ok;} catch {return false;}
+ }, 'Isolated server failed to start');
+ const sessions = new Map();
+ for (const [workspace, project, agent] of [['team','app','codex'], ['team','app','claude-code'], ['team','other','claude-code'], ['other','app','gemini-cli']]) {
+ const id = crypto.randomUUID();sessions.set(workspace + '/' + project + '/' + agent, id);
+ await request('/hook?' + new URLSearchParams({workspace, project, agent, event: 'session-start'}), {session_id: id, cwd: path.join(artifacts, workspace, project)});
+ }
+ for (const project of ['app', 'empty']) await request('/admin/write-page', {workspace: 'team', project, path: 'concepts/fixture.md', title: 'Synthetic knowledge', body: '# Synthetic knowledge\n\nPublic fixture only.'});
+ const id = sessions.get('team/app/codex');
+ const calls = Array.from({length: 5}, (_, i) => ({call_id: 'response-' + i, input_tokens: i === 4 ? 150000 : 1000, output_tokens: i === 3 ? 25000 : 100, cache_read_tokens: 200, cache_write_tokens: 10, model: 'codex-fixture'}));
+ const usage = async value => request('/hook?' + new URLSearchParams({workspace: 'team', project: 'app', agent: 'codex', event: 'post-tool-use'}), {session_id: id, tool_name: 'Bash', tool_input: {command: 'echo fixture'}, tool_response: 'fixture', _ai_memory_usage_calls: value});
+ await usage(calls);await usage(calls);
+ await until(async () => {
+ const response = await request('/web/w/team/app');return (await response.text()).includes('Captured calls</span><strong>5</strong>');
+ }, 'Hook reports never reached the real server');
+ const profile = path.join(artifacts, 'chromium');
+ launch(browserBinary, ['--headless', '--no-sandbox', '--disable-dev-shm-usage', '--remote-debugging-port=0', '--user-data-dir=' + profile, 'about:blank'], env, 'browser.log');
+ const active = path.join(profile, 'DevToolsActivePort');await until(() => fs.existsSync(active), 'Chromium did not start');
+ const debugPort = fs.readFileSync(active, 'utf8').split('\n')[0];
+ const version = await (await fetch(`http://127.0.0.1:${debugPort}/json/version`)).json();
+ const socket = new WebSocket(version.webSocketDebuggerUrl);await new Promise((resolve, reject) => {socket.onopen = resolve;socket.onerror = reject;});
+ cdp = new Cdp(socket);
+ const {targetId} = await cdp.send('Target.createTarget', {url: 'about:blank'});
+ cdp.sessionId = (await cdp.send('Target.attachToTarget', {targetId, flatten: true})).sessionId;
+ await cdp.send('Page.enable');await cdp.send('Runtime.enable');await cdp.send('Network.enable');
+ await cdp.send('Network.setCacheDisabled', {cacheDisabled: true});
+ await cdp.send('Network.setCookie', {name: 'ai_memory_auth', value: token, url: base, httpOnly: true, sameSite: 'Strict'});
+ await cdp.send('Emulation.setDeviceMetricsOverride', {width: 1440, height: 1100, deviceScaleFactor: 1, mobile: false});
+ {
+ const change = mutation && mutations[mutation];
+ cdp.listeners.set('Fetch.requestPaused', async message => {
+ const p = message.params;
+ if (cdp.notificationStatus && p.responseStatusCode && new URL(p.request.url).pathname === '/web/inbox/notifications') {
+ await cdp.send('Fetch.fulfillRequest', {requestId:p.requestId,responseCode:cdp.notificationStatus,responseHeaders:[{name:'Content-Type',value:'application/json'}],body:Buffer.from('{}').toString('base64')});return;
+ }
+ if (cdp.delayMessages && !p.responseStatusCode && new URL(p.request.url).pathname === '/web/messages') {
+ cdp.pausedMessage = p.requestId;return;
+ }
+ if (change && p.responseStatusCode === 200 && p.responseHeaders?.some(h => h.name.toLowerCase() === 'content-type' && h.value.includes('text/html'))) {
+ const body = await cdp.send('Fetch.getResponseBody', {requestId: p.requestId});
+ let html = body.base64Encoded ? Buffer.from(body.body, 'base64').toString() : body.body;
+ if (html.includes(change.from)) {html = html.split(change.from).join(change.to);report.mutationApplied++;}
+ await cdp.send('Fetch.fulfillRequest', {requestId: p.requestId, responseCode: 200, responseHeaders: p.responseHeaders.filter(h => !['content-length','content-encoding'].includes(h.name.toLowerCase())), body: Buffer.from(html).toString('base64')});
+ } else await cdp.send('Fetch.continueRequest', {requestId: p.requestId});
+ });
+ await cdp.send('Fetch.enable', {patterns: [...(mutation ? [{urlPattern: '*', requestStage: 'Response'}] : [{urlPattern:base+'/web/inbox/notifications',requestStage:'Response'}]), {urlPattern: base + '/web/messages', requestStage: 'Request'}]});
+ }
+ const project = base + '/web/w/team/app';
+ const tab = async name => {
+ await cdp.evaluate(`document.querySelector('[data-project-tab="${name}"]').click()`);
+ await selected(name);
+ };
+ const selected = async name => {
+ assert.deepEqual(await cdp.evaluate(`Array.from(document.querySelectorAll('[role=tabpanel]')).filter(p=>getComputedStyle(p).display!=='none').map(p=>p.id)`), ['project-panel-' + name]);
+ assert.equal(await cdp.evaluate(`document.querySelector('[role=tab][aria-selected=true]').dataset.projectTab`), name);
+ };
+ const changeScope = (field, workspace, project) => cdp.evaluate(`(()=>{const s=document.getElementById(${literal(field)});s.selectedIndex=Array.from(s.options).findIndex(o=>o.dataset.workspace===${literal(workspace)}&&o.dataset.project===${literal(project)});if(s.selectedIndex<0)throw Error('Scope missing');s.dispatchEvent(new Event('change',{bubbles:true}));})()`);
+ const recipients = () => cdp.evaluate(`Array.from(document.getElementById('message-to').options).filter(o=>o.dataset.agent).map(o=>[o.dataset.workspace,o.dataset.project,o.dataset.agent])`);
+ const chooseAgent = agent => cdp.evaluate(`(()=>{const s=document.getElementById('message-to');s.value=Array.from(s.options).find(o=>o.dataset.agent===${literal(agent)}).value;})()`);
+ const cases = {
+ async notifications() {
+ await cdp.goto(base+'/web/docs','.docs-search');
+ await until(()=>cdp.evaluate('document.getElementById("inbox-notification-status").textContent==="No messages waiting for agents."'),'Initial notification check failed');
+ assert(await cdp.evaluate('getComputedStyle(document.getElementById("inbox-pending-count")).display==="none"'));
+ const anonymous=await fetch(base+'/web/inbox/notifications',{headers:{Accept:'application/json'},redirect:'manual'});assert.equal(anonymous.status,401);
+ const sent=await (await request('/web/messages',{from_workspace:'team',from_project:'other',to_workspace:'other',to_project:'app',to_agent:'gemini-cli',subject:'Notification fixture',body:'Synthetic pending message.'})).json();
+ await until(()=>cdp.evaluate('!document.getElementById("inbox-pending-count").hidden&&document.getElementById("inbox-pending-count").textContent==="1"'),'New message never reached the sidebar without reload',18000);
+ assert.equal(await cdp.evaluate('location.pathname'),'/web/docs');
+ const href=await cdp.evaluate('document.querySelector("[data-notification-project]").href');
+ assert.equal(new URL(href).searchParams.get('workspace'),'other');assert.equal(new URL(href).searchParams.get('project'),'app');assert.equal(new URL(href).searchParams.get('state'),'pending');
+ assert(await cdp.evaluate('document.getElementById("inbox-notifications").textContent.includes("other / app")'));
+ cdp.notificationStatus=403;await cdp.evaluate('document.dispatchEvent(new Event("visibilitychange"))');
+ await until(()=>cdp.evaluate('document.getElementById("inbox-pending-count").hidden&&document.getElementById("inbox-notification-projects").children.length===0'),'Authorization loss must clear stale counts and projects');
+ cdp.notificationStatus=0;await cdp.evaluate('document.dispatchEvent(new Event("visibilitychange"))');
+ await until(()=>cdp.evaluate('!document.getElementById("inbox-pending-count").hidden'),'Notifications did not recover');
+ await cdp.goto(href,'.mail-row');assert.equal(await cdp.evaluate('document.querySelector(".page-heading strong").textContent'),'other / app');
+ assert(await cdp.evaluate('document.querySelector(".mail-row").textContent.includes("Notification fixture")'));
+ const popped=spawnSync(binary,['message','pop','--workspace','other','--project','app','--agent','gemini-cli','--id',sent.message_id,'--json'],{env:{...env,AI_MEMORY_SERVER_URL:base,AI_MEMORY_DATA_DIR:path.join(artifacts,'client')},encoding:'utf8',timeout:15000});
+ assert.equal(popped.status,0);assert.equal(JSON.parse(popped.stdout).message.id,sent.message_id);
+ await until(()=>cdp.evaluate('document.getElementById("inbox-pending-count").hidden&&document.getElementById("inbox-notifications").hidden'),'Collected mail must clear the notification without reload',18000);
+ await cdp.evaluate('document.getElementById("mail-state").value="claimed";document.getElementById("mail-state").dispatchEvent(new Event("change",{bubbles:true}))');
+ await until(()=>cdp.evaluate('new URL(location.href).searchParams.get("state")==="claimed"&&!!document.querySelector(".mail-row[data-state=claimed]")'),'State selector did not load collected history');
+ assert.equal(new URL(await cdp.evaluate('document.querySelector(".segmented-tabs a[aria-current]").href')).searchParams.get('state'),'claimed');
+ await cdp.goto(base+'/web/docs','.docs-search');await cdp.reload();
+ await until(()=>cdp.evaluate('document.getElementById("inbox-notification-status").textContent==="No messages waiting for agents."'),'Notifications did not survive navigation and reload');
+ },
+ async 'resumed-session'() {
+ const resumedId=crypto.randomUUID(),endpoint='/api/v1/workspaces/team/projects/app/sessions';
+ const capture=event=>request('/hook?'+new URLSearchParams({workspace:'team',project:'app',agent:'codex',event}),{session_id:resumedId,cwd:path.join(artifacts,'team/app'),tool_name:'Bash',tool_input:{command:'echo synthetic-resume'},tool_response:'synthetic'});
+ const recorded=async includeOpen=>(await (await request(endpoint+'?include_open='+includeOpen)).json()).sessions.find(s=>s.session_id===resumedId);
+ await capture('session-start');await capture('post-tool-use');await capture('session-end');
+ await until(async()=>!!(await recorded(false))?.ended_at,'Session end was not recorded');
+ await capture('post-tool-use');
+ await until(async()=>{const row=await recorded(true);return !!row&&!row.ended_at;},'New scoped work must reopen the read view');
+ assert.equal(await recorded(false),undefined,'Completed listing must exclude resumed work before pagination');
+ await cdp.goto(project+'/s/'+resumedId,'#scrubber');assert(await cdp.evaluate('document.querySelector("main").textContent.includes("still open")'));
+ const foreign=await fetch(base+'/web/w/team/other/s/'+resumedId,{headers:{Authorization:'Bearer '+token}});assert.equal(foreign.status,404);
+ await capture('session-end');await until(async()=>!!(await recorded(false))?.ended_at,'A later SessionEnd must close resumed work');
+ await cdp.reload();assert.equal(await cdp.evaluate('document.querySelector("main").textContent.includes("still open")'),false);
+ },
+ async tabs() {
+ await cdp.goto(project, '#project-panel-overview');await selected('overview');
+ for (const name of ['agents','tokens','sessions','knowledge']) {await tab(name);assert.equal(new URL(await cdp.evaluate('location.href')).searchParams.get('tab'), name);}
+ await cdp.evaluate('history.back()');await until(() => cdp.evaluate(`document.querySelector('[data-project-tab=sessions]').getAttribute('aria-selected')==='true'`), 'Back did not restore Sessions');await selected('sessions');
+ await cdp.evaluate('history.forward()');await until(() => cdp.evaluate(`document.querySelector('[data-project-tab=knowledge]').getAttribute('aria-selected')==='true'`), 'Forward did not restore Knowledge');
+ for (const [key, expected] of [['ArrowRight','overview'], ['ArrowLeft','knowledge'], ['Home','overview'], ['End','knowledge']]) {await cdp.key(key);await selected(expected);}
+ await cdp.reload();await selected('knowledge');
+ await cdp.evaluate(`document.querySelector('[data-project-tab=knowledge]').focus();document.addEventListener('keydown',event=>{window.shortcutCanceled=event.defaultPrevented;},{once:true});`);
+ await cdp.send('Input.dispatchKeyEvent', {type: 'keyDown', key: 'ArrowLeft', modifiers: 1});
+ await cdp.send('Input.dispatchKeyEvent', {type: 'keyUp', key: 'ArrowLeft', modifiers: 1});
+ assert.equal(await cdp.evaluate('window.shortcutCanceled'), false, 'Tabs stole a browser shortcut');
+ await cdp.goto(project + '#token-usage', '#token-usage', project + '?tab=tokens');await selected('tokens');
+ await cdp.send('Accessibility.enable');const tree = await cdp.send('Accessibility.getFullAXTree');
+ assert.equal(tree.nodes.filter(n => !n.ignored && n.role?.value === 'tabpanel').length, 1);
+ },
+ async recipients() {
+ await cdp.goto(base + '/web/inbox?workspace=team&project=app&agent=codex', '#message-to');
+ assert.equal((await recipients()).length, 2);
+ await changeScope('message-from', 'team', 'other');
+ assert.deepEqual(await recipients(), [['team','other','claude-code']]);
+ assert.equal(await cdp.evaluate('document.getElementById("message-to").value'), '');
+ await changeScope('message-to-project', 'other', 'app');
+ assert.deepEqual(await recipients(), [['other','app','gemini-cli']]);
+ await changeScope('message-from', 'team', 'empty');
+ assert.deepEqual(await recipients(), []);
+ assert(await cdp.evaluate(`document.getElementById('message-to').disabled&&document.querySelector('#message-composer button[type=submit]').disabled`));
+ await changeScope('message-to-project', 'team', 'app');assert.equal((await recipients()).length, 2);
+ assert(await cdp.evaluate(`!document.getElementById('message-to').disabled&&!document.querySelector('#message-composer button[type=submit]').disabled`));
+ },
+ async delivery() {
+ await cdp.goto(base + '/web/inbox?workspace=team&project=other', '#message-composer');
+ await changeScope('message-to-project', 'other', 'app');await chooseAgent('gemini-cli');
+ const storage = await cdp.evaluate('JSON.stringify({local:Object.entries(localStorage),session:Object.entries(sessionStorage)})');
+ assert.equal(await cdp.evaluate(`fetch(new URL('messages',document.baseURI),{method:'POST',headers:{'Content-Type':'application/json','X-Ai-Memory-UI':'1'},body:'{}'}).then(r=>r.status)`), 401);
+ await cdp.evaluate(`document.getElementById('message-access-token').value='FAKEfake0123456789InvalidWrite';document.getElementById('message-body').value='Synthetic request';document.querySelector('#message-composer button[type=submit]').click()`);
+ await until(() => cdp.evaluate(`document.getElementById('message-result').classList.contains('send-error')`), 'Invalid credentials were not rejected');
+ assert.equal(await cdp.evaluate('document.getElementById("message-access-token").value'), '');
+ assert.equal(await cdp.evaluate('JSON.stringify({local:Object.entries(localStorage),session:Object.entries(sessionStorage)})'), storage);
+ assert.equal(await cdp.evaluate('document.getElementById("message-body").value'), 'Synthetic request');
+ cdp.delayMessages = true;
+ await cdp.evaluate(`document.getElementById('message-access-token').value=${literal(token)};document.getElementById('message-subject').value='Review <script>window.fixtureXss=true</script>';document.querySelector('#message-composer button[type=submit]').click()`);
+ await until(() => !!cdp.pausedMessage, 'Message request was not issued');
+ assert(await cdp.evaluate(`document.querySelector('#message-composer button[type=submit]').disabled`), 'Sending must remain disabled during a request');
+ await changeScope('message-to-project', 'team', 'app');
+ assert(await cdp.evaluate(`document.querySelector('#message-composer button[type=submit]').disabled`), 'Changing project must not allow duplicate sends');
+ await changeScope('message-to-project', 'team', 'empty');
+ cdp.delayMessages = false;
+ await cdp.send('Fetch.continueRequest', {requestId: cdp.pausedMessage});
+ await until(() => cdp.evaluate(`document.getElementById('message-result').classList.contains('send-success')`), 'Authorized message was not queued');
+ assert.equal(await cdp.evaluate('document.getElementById("message-access-token").value'), '');
+ assert.equal(await cdp.evaluate('JSON.stringify({local:Object.entries(localStorage),session:Object.entries(sessionStorage)})'), storage);
+ assert.equal(await cdp.evaluate('document.getElementById("message-body").value'), '');
+ assert(await cdp.evaluate(`document.querySelector('#message-composer button[type=submit]').disabled`), 'An empty destination must remain disabled after completion');
+ const messageId = (await cdp.evaluate('document.getElementById("message-result").textContent')).match(/[0-9a-f]{8}-[0-9a-f-]{27,}/i)?.[0];assert(messageId);
+ const sent = await cdp.evaluate('document.querySelector("#message-result a").href');
+ await cdp.goto(sent, '.mail-row');assert(await cdp.evaluate(`document.querySelector('.mail-row').textContent.includes('Review <script>window.fixtureXss=true</script>')&&!window.fixtureXss`));
+ const pop = agent => {
+ const result = spawnSync(binary, ['message','pop','--workspace','other','--project','app','--agent',agent,'--id',messageId,'--json'], {env: {...env, AI_MEMORY_SERVER_URL: base, AI_MEMORY_DATA_DIR: path.join(artifacts, 'client')}, encoding: 'utf8', timeout: 15000});
+ assert.equal(result.status, 0, 'Native message pop failed');return JSON.parse(result.stdout).message;
+ };
+ assert.equal(pop('codex'), null);assert.equal(pop('gemini-cli').id, messageId);assert.equal(pop('gemini-cli'), null);
+ },
+ async 'live-usage'() {
+ await cdp.goto(project + '?tab=tokens', '#token-usage');await selected('tokens');
+ assert.equal(await cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)'), 5);
+ assert(await cdp.evaluate(`Array.from(document.querySelectorAll('[data-call-row]')).some(r=>r.textContent.includes('Above 3× average'))`));
+ await cdp.evaluate(`document.getElementById('call-filter').value='codex-fixture';document.getElementById('call-filter').dispatchEvent(new Event('input',{bubbles:true}));document.getElementById('call-filter').focus()`);
+ await until(()=>cdp.evaluate(`new URL(location.href).searchParams.get('calls_q')==='codex-fixture'&&!document.getElementById('call-query').hasAttribute('aria-busy')`),'Search must settle before testing the periodic refresh');
+ const next = {...calls[0], call_id: 'response-live', input_tokens: 321};await usage([next]);await usage([next]);
+ await until(() => cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)===6'), 'Live reports did not refresh exactly once', 18000);
+ await selected('tokens');assert(await cdp.evaluate(`document.activeElement.id==='call-filter'&&document.getElementById('call-filter').value==='codex-fixture'`));
+ await tab('agents');assert.equal(await cdp.evaluate(`Number(document.querySelector('[data-agent=codex] .agent-card-usage div:last-child strong').textContent)`), 6);
+ await cdp.goto(project + '/s/' + id, '#token-usage');
+ assert.equal(await cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)'), 6);
+ },
+ async 'capture-backlog'() {
+ const cwd=path.join(artifacts,'backlog-repository'),client=path.join(artifacts,'backlog-client'),transcript=path.join(artifacts,'backlog.jsonl'),sid=crypto.randomUUID();
+ fs.mkdirSync(cwd);fs.writeFileSync(path.join(cwd,'.ai-memory.toml'),'workspace = "backlog"\nproject = "capture"\n');
+ fs.writeFileSync(transcript,Array.from({length:300},(_,n)=>JSON.stringify({type:'assistant',message:{id:'backlog-'+n,model:'backlog-model',usage:{input_tokens:100,output_tokens:20}}})+'\n').join(''));
+ const options={cwd,env:{...env,AI_MEMORY_HOME:client},encoding:'utf8',timeout:15000};
+ for(const expected of [256,300,300]) {
+ const hook=spawnSync(binary,['--data-dir',client,'hook','--event','post-tool-use','--agent','claude-code','--server-url',base,'--auth-token',token],{...options,input:JSON.stringify({session_id:sid,cwd,transcript_path:transcript,tool_name:'Bash',tool_input:{command:'echo fixture'},tool_response:'fixture'})});
+ assert.equal(hook.status,0,'Native catch-up hook failed: '+hook.stderr);
+ const drain=spawnSync(binary,['--data-dir',client,'hook-drain'],options);assert.equal(drain.status,0,'Native catch-up drain failed: '+drain.stderr);
+ await until(async()=> (await (await request('/web/w/backlog/capture')).text()).includes('Captured calls</span><strong>'+expected+'</strong>'),'Native backlog did not reach '+expected+' distinct stored responses');
+ }
+ await cdp.goto(base+'/web/w/backlog/capture?tab=tokens','#token-usage');
+ assert.equal(await cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)'),300);
+ assert(await cdp.evaluate('document.querySelector(".usage-pagination").textContent.includes("300 matching responses")'));
+ },
+ async 'session-live-usage'() {
+ await cdp.goto(project+'/s/'+id,'#token-usage');
+ const before=await cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)');
+ await cdp.evaluate(`document.getElementById('call-filter').value='codex-fixture';document.getElementById('call-filter').dispatchEvent(new Event('input',{bubbles:true}));document.getElementById('call-filter').focus()`);
+ await until(()=>cdp.evaluate(`new URL(location.href).searchParams.get('calls_q')==='codex-fixture'&&!document.getElementById('call-query').hasAttribute('aria-busy')`),'Session search must settle before the new response');
+ await usage([{...calls[0],call_id:'session-live-response',input_tokens:123}]);
+ await until(()=>cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)==='+ (before+1)), 'Session usage did not refresh without reload',18000);
+ assert(await cdp.evaluate(`document.activeElement.id==='call-filter'&&document.getElementById('call-filter').value==='codex-fixture'`));
+ assert(await cdp.evaluate(`Array.from(document.querySelectorAll('[data-call-row]')).some(r=>r.textContent.includes('session-live-response'))`));
+ },
+ async 'call-history'() {
+ const workspace='history',name='app',sid=crypto.randomUUID(),href=base+'/web/w/history/app';
+ const hook='/hook?'+new URLSearchParams({workspace,project:name,agent:'codex',event:'post-tool-use'});
+ const publish=async rows=>request(hook,{session_id:sid,tool_name:'Bash',tool_input:{command:'echo synthetic'},tool_response:'synthetic',_ai_memory_usage_calls:rows.map(row=>({cache_read_tokens:0,cache_write_tokens:0,...row}))});
+ await request('/hook?'+new URLSearchParams({workspace,project:name,agent:'codex',event:'session-start'}),{session_id:sid});
+ await publish(Array.from({length:56},(_,n)=>({call_id:'bulk-'+n,input_tokens:1000+n,output_tokens:10,model:'bulk-model'})));
+ await until(async()=> (await (await request('/web/w/history/app')).text()).includes('Captured calls</span><strong>56</strong>'),'History fixture did not settle');
+ await publish([{call_id:'tiny-newest',input_tokens:1,output_tokens:1,model:'unique-tiny-model'}]);
+ await until(async()=> (await (await request('/web/w/history/app')).text()).includes('Captured calls</span><strong>57</strong>'),'Small response did not settle');
+ await cdp.goto(href+'?tab=tokens','#token-usage');await selected('tokens');
+ assert.equal(await cdp.evaluate('document.querySelectorAll("[data-call-row]").length'),50);
+ assert(!await cdp.evaluate('document.querySelector(".usage-results").textContent.includes("tiny-newest")'));
+ await cdp.evaluate(`document.getElementById('call-sort').value='recent';document.getElementById('call-sort').dispatchEvent(new Event('change',{bubbles:true}))`);
+ await until(()=>cdp.evaluate('document.querySelector("[data-call-row]")?.textContent.includes("tiny-newest")'),'Recent ordering omitted the small newest response');
+ await cdp.evaluate(`document.getElementById('call-filter').value='unique-tiny-model';document.getElementById('call-filter').dispatchEvent(new Event('input',{bubbles:true}))`);
+ await until(()=>cdp.evaluate('document.querySelectorAll("[data-call-row]").length===1&&document.querySelector("[data-call-row]")?.textContent.includes("tiny-newest")'),'Search did not cover calls outside the largest fifty');
+ assert.equal(await cdp.evaluate('Number(document.querySelector(".usage-metrics strong").textContent)'),57);
+ await cdp.evaluate(`document.getElementById('call-filter').value='';document.querySelector('#call-query').requestSubmit()`);
+ await until(()=>cdp.evaluate('document.querySelectorAll("[data-call-row]").length===50&&!!document.querySelector("[data-call-page]")'),'Clearing search did not restore the page');
+ await cdp.evaluate('document.querySelector("[data-call-page]").click()');
+ await until(()=>cdp.evaluate('document.querySelectorAll("[data-call-row]").length===7&&new URL(location.href).searchParams.get("calls_offset")==="50"'),'Response pagination lost results');
+ await cdp.reload();assert.equal(await cdp.evaluate('document.querySelectorAll("[data-call-row]").length'),7);
+ assert.equal(await cdp.evaluate('document.getElementById("call-sort").value'),'recent');
+ await cdp.goto(href+'/s/'+sid+'?calls_q=unique-tiny-model','#token-usage');
+ assert.equal(await cdp.evaluate('document.querySelectorAll("[data-call-row]").length'),1);
+ assert(await cdp.evaluate('document.querySelector("[data-call-row]").textContent.includes("tiny-newest")'));
+ },
+ async 'contextual-investigation'() {
+ const sid=crypto.randomUUID(),href=base+'/web/w/investigation/app';
+ const hook='/hook?'+new URLSearchParams({workspace:'investigation',project:'app',agent:'codex',event:'post-tool-use'});
+ await request('/hook?'+new URLSearchParams({workspace:'investigation',project:'app',agent:'codex',event:'session-start'}),{session_id:sid});
+ const rows=Array.from({length:57},(_,n)=>({call_id:'context-'+n,model:n===56?'rare-model':'bulk-model',input_tokens:20,output_tokens:2,cache_read_tokens:0,cache_write_tokens:0,context:{turn_id:'native-turn',response_id:'native-'+n,recorded_at:'2026-10-01T12:00:00Z',tools:[{id:'exec-1',name:'exec_command',relation:'turn',is_error:true}]}}));
+ await request(hook,{session_id:sid,tool_name:'Bash',tool_input:{command:'echo synthetic'},tool_response:'synthetic',_ai_memory_usage_calls:rows});
+ await until(async()=> (await (await request('/web/w/investigation/app')).text()).includes('Captured calls</span><strong>57</strong>'),'Context fixture never reached storage');
+ await cdp.goto(href+'?tab=tokens','#token-usage');
+ await cdp.evaluate(`document.querySelector('[name=calls_model]').value='rare-model';document.querySelector('[name=calls_agent]').value='codex';document.querySelector('[name=calls_session]').value=${literal(sid)};document.querySelector('[name=calls_from]').value='2026-10-01T12:00:00';document.querySelector('[name=calls_until]').value='2026-10-01T12:00:01';document.querySelector('[name=calls_tool]').value='exec_command';document.getElementById('call-query').requestSubmit()`);
+ await until(()=>cdp.evaluate('document.querySelectorAll("[data-call-row]").length===1&&!document.querySelector("#call-query").hasAttribute("aria-busy")'),'Server investigation filters did not isolate the response outside the first fifty');
+ assert(await cdp.evaluate('document.querySelector("[data-call-row]").textContent.includes("native-56")&&document.querySelector("[data-call-row]").textContent.includes("association")'));
+ await cdp.reload();assert.equal(await cdp.evaluate('document.querySelectorAll("[data-call-row]").length'),1);
+ await cdp.evaluate(`document.querySelector('[name=calls_model]').value='missing-model';document.querySelector('[name=calls_model]').dispatchEvent(new Event('change',{bubbles:true}))`);
+ await until(()=>cdp.evaluate('document.querySelectorAll("[data-call-row]").length===0&&!document.querySelector("#call-query").hasAttribute("aria-busy")'),'A mismatched exact model must remove all rows');
+ for(const width of [320,390]) {await cdp.send('Emulation.setDeviceMetricsOverride',{width,height:960,deviceScaleFactor:1,mobile:true});assert(await cdp.evaluate('document.documentElement.scrollWidth<=innerWidth'),'Investigation controls overflow the viewport');}
+ await cdp.send('Emulation.setDeviceMetricsOverride',{width:1440,height:1100,deviceScaleFactor:1,mobile:false});
+ },
+ async 'feature-states'() {
+ await cdp.goto(base+'/web/docs/features','.installation-status');
+ assert(await cdp.evaluate(`document.querySelector('[data-feature="learning"]').textContent.includes("Unavailable without LLM")`));
+ assert(await cdp.evaluate(`document.querySelector('[data-feature="external-clients"]').textContent.includes("Client setup unknown")`));
+ assert(await cdp.evaluate(`document.querySelector('[data-feature="consolidation"]').textContent.includes("Next step:")`));
+ assert.equal((await fetch(base+'/api/v1/docs/features/status',{redirect:'manual'})).status,401);
+ const status=await (await request('/api/v1/docs/features/status')).json();assert.equal(status.features.find(f=>f.id==='embeddings').state,'Not configured');
+ },
+ async 'knowledge-evidence'() {
+ const sid=sessions.get('team/app/codex');
+ const rpc=async(body,session)=> {
+ const response=await fetch(base+'/mcp',{method:'POST',headers:{Authorization:'Bearer '+token,'Content-Type':'application/json',Accept:'application/json, text/event-stream',...(session?{'Mcp-Session-Id':session}:{})},body:JSON.stringify(body),signal:AbortSignal.timeout(15000)});
+ assert(response.ok,'MCP fixture returned '+response.status);
+ const text=await response.text();const payload=text.trim().startsWith('{')?JSON.parse(text):JSON.parse(text.split('\n').find(line=>line.startsWith('data: ')).slice(6));return {payload,session:response.headers.get('Mcp-Session-Id')};
+ };
+ const initialized=await rpc({jsonrpc:'2.0',id:1,method:'initialize',params:{protocolVersion:'2025-03-26',capabilities:{},clientInfo:{name:'synthetic-dashboard-test',version:'1'}}});
+ const written=await rpc({jsonrpc:'2.0',id:2,method:'tools/call',params:{name:'memory_write_page',arguments:{workspace:'team',project:'app',path:'concepts/evidence.md',body:'# Evidence fixture\n\nVerificationneedle source.',session_id:sid}}},initialized.session);
+ assert(!written.payload.error&&!written.payload.result?.isError,'MCP evidence fixture failed: '+JSON.stringify(written.payload));
+ await cdp.goto(base+'/web/search?workspace=team&project=app&q=Verificationneedle','[data-hit-path]');
+ const href=await cdp.evaluate(`document.querySelector('[data-hit-path="concepts/evidence.md"] a').href`);assert.equal(new URL(href).searchParams.get('recall_q'),'Verificationneedle');
+ await cdp.goto(href,'.knowledge-evidence');assert(await cdp.evaluate('document.querySelector(".knowledge-evidence").textContent.includes("Session '+sid+'")'));
+ await cdp.evaluate('document.querySelector(".knowledge-evidence a.secondary-button").click()');await until(()=>cdp.evaluate('!!document.querySelector("[data-page-recall-trace]")'),'Page did not recompute its actual recall trace');
+ assert(await cdp.evaluate('document.querySelector(".knowledge-evidence").textContent.includes("Recomputed now")'));
+ for(const width of [320,390]) {await cdp.send('Emulation.setDeviceMetricsOverride',{width,height:960,deviceScaleFactor:1,mobile:true});assert(await cdp.evaluate('document.documentElement.scrollWidth<=innerWidth'),'Knowledge evidence overflows the viewport');}
+ await cdp.send('Emulation.setDeviceMetricsOverride',{width:1440,height:1100,deviceScaleFactor:1,mobile:false});
+ },
+ async themes() {
+ await cdp.goto(project, '#project-panel-overview');
+ await cdp.send('Emulation.setEmulatedMedia', {features: [{name: 'prefers-color-scheme', value: 'light'}]});
+ await cdp.evaluate(`document.querySelector('[data-theme-choice=dark]').click()`);await cdp.reload();
+ assert.equal(await cdp.evaluate('document.documentElement.classList.contains("dark")'), true);
+ await cdp.evaluate(`document.querySelector('[data-theme-choice=light]').click()`);
+ assert.equal(await cdp.evaluate('document.documentElement.classList.contains("dark")'), false);
+ await cdp.evaluate(`document.querySelector('[data-theme-choice=system]').click()`);
+ await cdp.send('Emulation.setEmulatedMedia', {features: [{name: 'prefers-color-scheme', value: 'dark'}]});
+ await until(() => cdp.evaluate('document.documentElement.classList.contains("dark")'), 'System theme did not follow OS');
+ await cdp.evaluate(`document.querySelector('[data-theme-choice=light]').click()`);
+ const colors = await cdp.evaluate(`({background:getComputedStyle(document.body).backgroundColor,foreground:getComputedStyle(document.body).color})`);
+ assert(contrast(colors.background, colors.foreground) >= 4.5, 'Light body text is not readable');
+ await cdp.evaluate(`document.querySelector('[data-theme-choice=dark]').click()`);
+ assert.notEqual(await cdp.evaluate('getComputedStyle(document.body).backgroundColor'), colors.background);
+ assert.notEqual(await cdp.evaluate('getComputedStyle(document.body).color'), colors.foreground);
+ const dark = await cdp.evaluate(`({background:getComputedStyle(document.body).backgroundColor,foreground:getComputedStyle(document.body).color})`);
+ assert(contrast(dark.background, dark.foreground) >= 4.5, 'Dark body text is not readable');
+ },
+ async documentation() {
+ await cdp.goto(base + '/web/docs', '.docs-search');
+ const anonymous = await fetch(base + '/api/v1/docs', {redirect: 'manual'});assert.equal(anonymous.status, 401);
+ await cdp.evaluate(`document.getElementById('documentation-query').value='Token accounting';document.querySelector('.docs-search').requestSubmit()`);
+ await until(() => cdp.evaluate(`new URL(location.href).searchParams.get('q')==='Token accounting'&&document.querySelector('.docs-card')?.textContent.includes('Features')`), 'Documentation search failed');
+ const catalog = await (await request('/api/v1/docs')).json();assert(catalog.documents.length >= 28);
+ for (const doc of catalog.documents) {
+ const json = await (await request('/api/v1/docs/' + doc.id)).json();
+ assert.equal(json.markdown, await (await request('/web/docs/' + doc.id + '.md')).text());
+ }
+ const release = await (await request('/api/v1/docs/changelog?release=3.2.2')).json();
+ assert(release.markdown.startsWith('## [3.2.2]'));assert(!release.markdown.includes('## [3.2.1]'));
+ await cdp.goto(base + '/web/docs/changelog', '#release-version');
+ assert.equal(await cdp.evaluate('document.querySelector(".docs-release button")'), null, 'JavaScript users should not need a submit button');
+ const selectedRelease = async version => {
+ await until(() => cdp.evaluate(`new URL(location.href).searchParams.get('release')===${literal(version)}&&document.readyState==='complete'&&document.getElementById('release-version')?.value===${literal(version)}&&document.querySelector('.docs-article h2')?.textContent.startsWith(${literal('[' + version + ']')})`), 'Release selection did not load ' + version);
+ assert.equal(await cdp.evaluate('document.getElementById("release-version").value'), version);
+ assert(await cdp.evaluate(`new URL(document.querySelector('.page-heading a').href).searchParams.get('release')===${literal(version)}&&Array.from(document.querySelectorAll('.docs-outline a')).every(a=>new URL(a.href).searchParams.get('release')===${literal(version)})`), 'Release links must match the displayed content');
+ };
+ for (const version of ['3.2.2', '3.2.0', 'Unreleased']) {
+ await cdp.evaluate(`(()=>{const select=document.getElementById('release-version');select.value=${literal(version)};select.dispatchEvent(new Event('change',{bubbles:true}));})()`);
+ await selectedRelease(version);
+ }
+ await cdp.reload();await selectedRelease('Unreleased');
+ await cdp.evaluate('history.back()');await selectedRelease('3.2.0');
+ await cdp.evaluate('history.forward()');await selectedRelease('Unreleased');
+ await cdp.send('Emulation.setScriptExecutionDisabled', {value: true});
+ try {
+ await cdp.goto(base + '/web/docs/changelog?release=3.2.2', '.docs-release button');
+ assert(await cdp.evaluate('getComputedStyle(document.querySelector(".docs-release button")).display!=="none"'), 'No-JavaScript release submission must remain available');
+ await cdp.evaluate(`document.getElementById('release-version').value='3.2.0';document.querySelector('.docs-release button').click()`);
+ await selectedRelease('3.2.0');
+ } finally {await cdp.send('Emulation.setScriptExecutionDisabled', {value: false});}
+ const missing = await fetch(base + '/web/docs/.env.md', {headers: {Authorization: 'Bearer ' + token}});assert.equal(missing.status, 404);
+ },
+ async 'mailbox-context'() {
+ await cdp.goto(base + '/web/inbox?workspace=team&project=empty', '#mail-project');
+ assert.equal(await cdp.evaluate('document.querySelector("[data-nav=inbox]").textContent.includes("NEW MESSAGE")'), false, 'Navigation must not show a fabricated new-message alert');
+ assert.equal(await cdp.evaluate('document.querySelectorAll(".mailbox-link").length'), 0);
+ assert(await cdp.evaluate('document.querySelector(".mail-overview").textContent.includes("No messages waiting")'));
+ const ids = [];
+ for (const [workspace, agent] of [['team','codex'], ['other','gemini-cli'], ['other','gemini-cli']]) {
+ const sent = await request('/web/messages', {from_workspace:'team',from_project:'other',to_workspace:workspace,to_project:'app',to_agent:agent,subject:'Mailbox context fixture',body:'Synthetic context check.'});
+ ids.push((await sent.json()).message_id);
+ }
+ await cdp.reload();
+ const cards = await cdp.evaluate(`Array.from(document.querySelectorAll('.mailbox-link')).map(a=>({workspace:a.dataset.mailboxWorkspace,project:a.dataset.mailboxProject,href:a.href,text:a.textContent}))`);
+ assert.equal(cards.length, 2);
+ for (const [workspace, count] of [['team',1], ['other',2]]) {
+ const card = cards.find(c => c.workspace === workspace && c.project === 'app');assert(card);
+ assert(card.text.includes(count + ' queued'));assert.equal(new URL(card.href).searchParams.get('workspace'), workspace);assert.equal(new URL(card.href).searchParams.get('project'), 'app');
+ }
+ assert(await cdp.evaluate('document.querySelector(".mail-overview").textContent.includes("3 queued")'));
+ assert.equal(await cdp.evaluate('document.querySelector(".page-heading strong").textContent'), 'team / empty');
+ await changeScope('mail-project', 'other', 'app');
+ await until(() => cdp.evaluate(`new URL(location.href).searchParams.get('workspace')==='other'&&document.querySelector('.page-heading strong')?.textContent==='other / app'&&document.querySelectorAll('.mail-row[data-state=pending]').length===2`), 'Mailbox selector must include workspace and project');
+ assert(await cdp.evaluate(`Array.from(document.querySelectorAll('.mail-preview small')).every(e=>e.textContent.includes('Gemini CLI'))`));
+ await cdp.evaluate('document.getElementById("compose-shortcut").click()');
+ assert.equal(new URL(await cdp.evaluate('location.href')).searchParams.get('workspace'), 'other');
+ await cdp.evaluate(`document.querySelector('[data-mailbox-workspace="team"][data-mailbox-project="app"]').click()`);
+ await until(() => cdp.evaluate(`document.querySelector('.page-heading strong')?.textContent==='team / app'&&document.querySelectorAll('.mail-row[data-state=pending]').length===1`), 'Queue link must open the named project');
+ for (const width of [320,390,768]) {
+ await cdp.send('Emulation.setDeviceMetricsOverride', {width,height:960,deviceScaleFactor:1,mobile:width<640});
+ assert(await cdp.evaluate(`document.documentElement.scrollWidth<=innerWidth&&Array.from(document.querySelectorAll('.mailbox-link')).every(a=>{const r=a.getBoundingClientRect();return r.left>=0&&r.right<=innerWidth&&r.height>=44;})`), 'Mailbox links overflow or are too small');
+ }
+ await cdp.goto(base + '/web/inbox', '#mail-project');
+ assert.equal(await cdp.evaluate('document.getElementById("mail-project").selectedOptions[0].dataset.project'), 'app', 'Default should prefer a project with queued mail');
+ const claimed = spawnSync(binary, ['message','pop','--workspace','other','--project','app','--agent','gemini-cli','--id',ids[1],'--json'], {env:{...env,AI_MEMORY_SERVER_URL:base,AI_MEMORY_DATA_DIR:path.join(artifacts,'client')},encoding:'utf8',timeout:15000});
+ assert.equal(claimed.status, 0);assert.equal(JSON.parse(claimed.stdout).message.id, ids[1], 'Reading must leave the queued message available to its agent');
+ await cdp.reload();
+ assert(await cdp.evaluate(`document.querySelector('.mail-overview').textContent.includes('2 queued')&&document.querySelector('[data-mailbox-workspace="other"]').textContent.includes('1 queued')`), 'Collected messages must leave the queued counts');
+ },
+ async responsive() {
+ await cdp.goto(project, '#project-panel-overview');
+ for (const width of [320,390,768]) {
+ await cdp.send('Emulation.setDeviceMetricsOverride', {width, height: 960, deviceScaleFactor: 1, mobile: width < 640});
+ for (const name of ['overview','agents','tokens','sessions','knowledge']) {
+ await tab(name);
+ assert(await cdp.evaluate(`document.documentElement.scrollWidth<=innerWidth&&Array.from(document.querySelectorAll('.project-tabs a,.project-tools a')).every(a=>{const r=a.getBoundingClientRect();return r.left>=0&&r.right<=innerWidth&&r.height>=44;})`), `Navigation overflow or small target at ${width}px`);
+ }
+ }
+ },
+ };
+ for (const [name, run] of Object.entries(cases)) {
+ if (mutation && mutations[mutation].test !== name) continue;
+ try {await run();report.cases.push({name, passed: true});console.log('PASS ' + name);}
+ catch (error) {
+ report.cases.push({name, passed: false, error: error.message});console.error('FAIL ' + name + ': ' + error.message);
+ const shot = await cdp.send('Page.captureScreenshot', {format: 'png'}).catch(() => null);
+ if (shot) fs.writeFileSync(path.join(artifacts, name + '.png'), Buffer.from(shot.data, 'base64'));
+ }
+ }
+ assert.deepEqual(cdp.errors, [], 'Browser JavaScript errors');
+ assert(!mutation || report.mutationApplied > 0, 'Mutation was not applied');
+ assert(report.cases.every(c => c.passed), 'Browser regression checks failed');
+}
+
+try {await main();}
+catch (error) {report.error = error.message;process.exitCode = 1;console.error(error.message);}
+finally {
+ if (cdp) cdp.socket.close();
+ for (const child of children.reverse()) {
+ if (child.exitCode === null) child.kill('SIGTERM');
+ let timer;
+ const result = await Promise.race([child.completion, new Promise(resolve => {timer=setTimeout(() => resolve(null),5000);})]);
+ clearTimeout(timer);
+ if (!result && child.exitCode === null) {child.kill('SIGKILL');await child.completion;}
+ }
+ fs.writeFileSync(path.join(artifacts, 'report.json'), JSON.stringify(report, null, 2));
+ console.log('Artifacts: ' + artifacts);
+}
diff --git a/tests/e2e/web_dashboard_mutations.mjs b/tests/e2e/web_dashboard_mutations.mjs
new file mode 100644
index 00000000..0ec87011
--- /dev/null
+++ b/tests/e2e/web_dashboard_mutations.mjs
@@ -0,0 +1,65 @@
+#!/usr/bin/env node
+// A passing baseline is required before a deliberate behavioral fault can count.
+import assert from 'node:assert/strict';
+import {spawn} from 'node:child_process';
+import fs from 'node:fs';
+import path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const here = path.dirname(fileURLToPath(import.meta.url));
+const manifest = {baseline: null, mutants: []};
+const faults = [
+ ['all-panels-visible', 'tabs'],
+ ['ignore-recipient-workspace', 'recipients'],
+ ['ignore-recipient-project', 'recipients'],
+ ['retain-write-token', 'delivery'],
+ ['disable-live-refresh', 'live-usage'],
+ ['disable-session-live-refresh', 'session-live-usage'],
+ ['drop-usage-query', 'call-history'],
+ ['forget-theme', 'themes'],
+ ['steal-browser-shortcut', 'tabs'],
+ ['enable-send-while-pending', 'delivery'],
+ ['enable-send-for-empty-project-after-request', 'delivery'],
+ ['disable-release-auto-submit', 'documentation'],
+ ['restore-stale-release-on-history', 'documentation'],
+ ['show-false-inbox-alert', 'mailbox-context'],
+ ['ignore-mailbox-workspace', 'mailbox-context'],
+ ['disable-inbox-notifications', 'notifications'],
+ ['ignore-notification-workspace', 'notifications'],
+];
+
+async function run(mutation) {
+ const child = spawn(process.execPath, [path.join(here, 'web_dashboard_browser.mjs'), ...(mutation ? ['--mutation=' + mutation] : [])], {env: process.env});
+ let output = '', errors = '';
+ child.stdout.on('data', data => {output += data;});
+ child.stderr.on('data', data => {errors += data;});
+ const timer = setTimeout(() => child.kill('SIGKILL'), 90000);
+ const code = await new Promise((resolve, reject) => {child.on('error', reject);child.on('exit', resolve);});
+ clearTimeout(timer);
+ const directory = output.match(/^Artifacts: (.+)$/m)?.[1];
+ assert(directory, 'Browser runner did not produce a report: ' + errors.slice(-500));
+ return {code, directory, result: JSON.parse(fs.readFileSync(path.join(directory, 'report.json'), 'utf8'))};
+}
+
+try {
+ const baseline = await run();
+ assert.equal(baseline.code, 0, 'Baseline must pass; inspect ' + baseline.directory);
+ assert(baseline.result.cases.length >= 16 && baseline.result.cases.every(c => c.passed));
+ manifest.baseline = baseline.directory;
+ console.log('PASS unmodified server and browser baseline');
+ for (const [fault, name] of faults) {
+ const mutant = await run(fault);
+ assert.equal(mutant.code, 1, fault + ' survived or the runner crashed');
+ assert(mutant.result.mutationApplied > 0, fault + ' never reached the served application');
+ assert.equal(mutant.result.error, 'Browser regression checks failed', 'An unrelated failure must not count as a killed mutant');
+ assert(mutant.result.cases.some(c => c.name === name && c.passed === false), fault + ' escaped its behavioral test');
+ manifest.mutants.push({fault, caughtBy: name, killed: true, artifacts: mutant.directory});
+ console.log('KILLED ' + fault + ' by ' + name);
+ }
+} catch (error) {manifest.error = error.message;console.error(error.message);process.exitCode = 1;}
+finally {
+ const output = path.resolve(here, '../../target/web-dashboard-mutations.json');
+ fs.mkdirSync(path.dirname(output), {recursive: true});
+ fs.writeFileSync(output, JSON.stringify(manifest, null, 2));
+ console.log('Mutation report: ' + output);
+}