Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

test: remove ineffective coverage and strengthen regression guards (#872)

Sam Julien72a0b1f55941
diff --git a/agent-adk/tests/test_model_spec.py b/agent-adk/tests/test_model_spec.py
index 0a54e5cc..c0012240 100644
--- a/agent-adk/tests/test_model_spec.py
+++ b/agent-adk/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-adk")' in source
diff --git a/agent-ag2/tests/test_model_spec.py b/agent-ag2/tests/test_model_spec.py
index 00aa3a0d..b8d280c9 100644
--- a/agent-ag2/tests/test_model_spec.py
+++ b/agent-ag2/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-ag2")' in source
diff --git a/agent-agno/tests/test_model_spec.py b/agent-agno/tests/test_model_spec.py
index df4ce361..1ef9da4d 100644
--- a/agent-agno/tests/test_model_spec.py
+++ b/agent-agno/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-5.5")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-agno")' in source
diff --git a/agent-antigravity/tests/test_model_spec.py b/agent-antigravity/tests/test_model_spec.py
index 0313507d..e4efc2ea 100644
--- a/agent-antigravity/tests/test_model_spec.py
+++ b/agent-antigravity/tests/test_model_spec.py
@@ -40,23 +40,3 @@ def test_the_model_is_still_the_deployments_to_choose(monkeypatch):
assert bot_settings(BOT_ID, pinned_provider=PINNED) == BotSettings(
provider="google", model="gemini-3.8-flash"
)
-
-
-def test_this_bots_source_reads_the_spec_with_the_pin():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert 'bot_settings("agent-antigravity", pinned_provider="google")' in source
-
-
-def test_the_key_and_base_url_come_from_the_provider_row():
- """Not hardcoded here.
-
- `shared/model-providers.json` names Google's key and base-url variables, and a Bot that
- spelled them out itself would drift from the file the moment either changed. The base-url
- variable is what points this Bot at a Gemini-compatible endpoint — a gateway, or aimock —
- instead of Google.
- """
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert '"key_variable"' in source
- assert '"base_url_variable"' in source
- assert "GOOGLE_API_KEY" not in source
- assert "GOOGLE_GENERATIVE_AI_BASE_URL" not in source
diff --git a/agent-computer/tests/aria-snapshot.test.ts b/agent-computer/tests/aria-snapshot.test.ts
index 79d93d50..5a06e3e3 100644
--- a/agent-computer/tests/aria-snapshot.test.ts
+++ b/agent-computer/tests/aria-snapshot.test.ts
@@ -46,12 +46,6 @@ const CAPTURED = `- generic [ref=e2]:
- button "Submit order" [ref=e44]`;
describe("parseAriaSnapshot, against captured output", () => {
- test("the fixture is genuinely valid YAML", () => {
- // The guard against the mistake that made this rewrite necessary: an invented fixture will most
- // likely fail here first.
- expect(() => Bun.YAML.parse(CAPTURED)).not.toThrow();
- });
-
test("keeps the controls and drops the scaffolding", () => {
const { elements } = parseAriaSnapshot(CAPTURED);
// `generic`, `paragraph`, `group` and `text` all carry refs but are not things a Bot can act on,
@@ -132,10 +126,6 @@ describe("parseAriaSnapshot, against captured output", () => {
- checkbox "Extra Cheese" [ref=e9]
- text: Extra Cheese`;
- test("the mixed fixture is genuinely valid YAML", () => {
- expect(() => Bun.YAML.parse(MIXED)).not.toThrow();
- });
-
test("a half-ticked box is not reported as ticked", () => {
const byName = new Map(
parseAriaSnapshot(MIXED).elements.map((e) => [e.name, e]),
diff --git a/agent-computer/tests/viewer.test.ts b/agent-computer/tests/viewer.test.ts
index 9e26f134..adf2697f 100644
--- a/agent-computer/tests/viewer.test.ts
+++ b/agent-computer/tests/viewer.test.ts
@@ -161,19 +161,6 @@ describe("a close that lands while the browser is still starting", () => {
expect(claim.setFollow(() => {})).toBe(false);
});
- test("the claim is released even when the launch threw", async () => {
- // `open`'s catch closes the socket after sending an error frame. If nothing released the claim
- // there, the slot would stay occupied forever and `forgetIdle` could never sweep the
- // session, which is the unbounded growth it exists to stop.
- const slot = createViewerSlot();
- const socket = { id: "a" };
- slot.claim(socket, () => {});
-
- await slot.release(socket);
-
- expect(slot.occupied()).toBe(false);
- });
-
test("releasing the same socket twice is harmless", async () => {
// The catch path closes the socket, so `close` runs release a second time for the same socket.
const slot = createViewerSlot();
@@ -448,18 +435,6 @@ describe("the session sweep asking whether anybody is watching", () => {
expect(slot.occupied()).toBe(true);
});
- test("a Bot stays watched until teardown has finished", async () => {
- const slot = createViewerSlot();
- const socket = { id: "a" };
- const claim = slot.claim(socket, () => {});
- await claim.install(fakeCast());
-
- const releasing = slot.release(socket);
- await releasing;
-
- expect(slot.occupied()).toBe(false);
- });
-
test("a Bot is still watched while its cast is stopping", async () => {
// Occupancy has to count the teardown itself, not just whether somebody holds the slot. The
// sweep drops sessions with nobody watching and no live browser, and a session dropped while its
diff --git a/agent-crewai/tests/test_model_spec.py b/agent-crewai/tests/test_model_spec.py
index 74c43fe9..af49e69a 100644
--- a/agent-crewai/tests/test_model_spec.py
+++ b/agent-crewai/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-5.5")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-crewai")' in source
diff --git a/agent-crewai/tests/test_token_restoration.py b/agent-crewai/tests/test_token_restoration.py
deleted file mode 100644
index 6500bce3..00000000
--- a/agent-crewai/tests/test_token_restoration.py
+++ /dev/null
@@ -1,175 +0,0 @@
-"""Exercise the role test's real pytest teardown in an isolated process."""
-
-import argparse
-import ipaddress
-import json
-import os
-import socket
-import subprocess
-import sys
-import threading
-import time
-from pathlib import Path
-
-import httpx
-import pytest
-import uvicorn
-
-
-ROLE_TEST = "test_crewai_endpoint_preserves_leading_bot_role_for_provider"
-
-
-def isolated_environment(directory):
- directory.mkdir(parents=True, exist_ok=True)
- inherited = (
- "HOME", "USERPROFILE", "HOMEDRIVE", "HOMEPATH", "CODEX_HOME",
- "PATH", "LANG", "SYSTEMROOT", "WINDIR",
- )
- environment = {name: os.environ[name] for name in inherited if name in os.environ}
- environment.update(
- OTEL_SDK_DISABLED="true",
- CREWAI_TELEMETRY_DISABLED="true",
- CREWAI_STORAGE_DIR=str(directory / "crewai"),
- LITELLM_LOCAL_MODEL_COST_MAP="True",
- PYTEST_DISABLE_PLUGIN_AUTOLOAD="1",
- PYTHONPYCACHEPREFIX=str(directory / "pycache"),
- TMPDIR=str(directory),
- )
- return environment
-
-
-def prohibit_external_connections(event, arguments):
- if event == "socket.getaddrinfo":
- host = arguments[0]
- elif event in ("socket.connect", "socket.sendto"):
- address = arguments[1]
- if not isinstance(address, tuple):
- raise RuntimeError("Only loopback TCP/IP is allowed in this probe")
- host = address[0]
- else:
- return
- if host != "localhost" and not ipaddress.ip_address(host).is_loopback:
- raise RuntimeError("External network access is prohibited in this probe")
-
-
-class RoleTestLifecycle:
- def __init__(self, failure):
- self.failure = failure
- self.role_assertion_passed = False
- self.phases = {}
-
- def pytest_collection_modifyitems(self, items):
- assert len(items) == 1 and items[0].name == ROLE_TEST
- original = items[0].obj
-
- def exercise_role_test(monkeypatch):
- original(monkeypatch)
- self.role_assertion_passed = True
- if self.failure == "assertion":
- assert False, "injected assertion after role test"
- if self.failure == "exception":
- raise RuntimeError("injected exception after role test")
-
- items[0].obj = exercise_role_test
-
- def pytest_runtest_logreport(self, report):
- self.phases[report.when] = report.outcome
-
-
-def auth_statuses(app, header):
- """Use real loopback HTTP after pytest has returned in this same process."""
- with socket.socket() as listener:
- listener.bind(("127.0.0.1", 0))
- port = listener.getsockname()[1]
- server = uvicorn.Server(uvicorn.Config(app, log_level="error", lifespan="off"))
- thread = threading.Thread(target=server.run, kwargs={"sockets": [listener]})
- thread.start()
- try:
- deadline = time.monotonic() + 10
- while not server.started and thread.is_alive() and time.monotonic() < deadline:
- time.sleep(0.01)
- assert server.started, "loopback app server did not start"
- with httpx.Client(base_url=f"http://127.0.0.1:{port}", timeout=5, trust_env=False) as client:
- return {
- "health": client.get("/health").status_code,
- "previous": client.post("/", headers={header: "synthetic-original-token"}, json={}).status_code,
- "test": client.post("/", headers={header: "test-token"}, json={}).status_code,
- "missing": client.post("/", json={}).status_code,
- }
- finally:
- server.should_exit = True
- thread.join(timeout=10)
- assert not thread.is_alive(), "loopback app server did not stop"
-
-
-def run_probe(source_root, output, initial_token, failure):
- sys.addaudithook(prohibit_external_connections)
- expected = "synthetic-original-token" if initial_token == "present" else None
- if expected is None:
- os.environ.pop("MANAGED_AGENT_TOKEN", None)
- else:
- os.environ["MANAGED_AGENT_TOKEN"] = expected
- lifecycle = RoleTestLifecycle(failure)
- target = source_root / "agent-crewai/tests/test_main.py"
- code = pytest.main(
- [f"{target}::{ROLE_TEST}", "-q", "-p", "no:cacheprovider"],
- plugins=[lifecycle],
- )
- main = sys.modules["src.main"]
- result = {
- "sourceRoot": str(source_root),
- "initialToken": initial_token,
- "failure": failure,
- "pytestExit": int(code),
- "phases": lifecycle.phases,
- "roleAssertionPassed": lifecycle.role_assertion_passed,
- "restored": os.environ.get("MANAGED_AGENT_TOKEN") == expected,
- "leakedTestToken": os.environ.get("MANAGED_AGENT_TOKEN") == "test-token",
- "http": auth_statuses(main.app, main.TOKEN_HEADER),
- }
- output.write_text(json.dumps(result, indent=2) + "\n")
- assert code == (0 if failure == "none" else 1), result
- assert lifecycle.role_assertion_passed, result
- assert lifecycle.phases == {
- "setup": "passed",
- "call": "passed" if failure == "none" else "failed",
- "teardown": "passed",
- }, result
- assert result["restored"], "MANAGED_AGENT_TOKEN was not restored after pytest teardown"
- assert result["http"] == {
- "health": 200,
- "previous": 422 if initial_token == "present" else 401,
- "test": 401,
- "missing": 401,
- }, result
-
-
[email protected]("initial_token", ["present", "absent"])
[email protected]("failure", ["none", "assertion", "exception"])
-def test_role_test_restores_token_after_pytest_teardown(tmp_path, initial_token, failure):
- output = tmp_path / "result.json"
- result = subprocess.run(
- [
- sys.executable, str(Path(__file__).resolve()),
- "--source-root", str(Path(__file__).resolve().parents[2]),
- "--output", str(output),
- "--initial-token", initial_token,
- "--failure", failure,
- ],
- cwd=tmp_path,
- env=isolated_environment(tmp_path),
- text=True,
- capture_output=True,
- timeout=90,
- )
- assert result.returncode == 0, result.stdout + result.stderr
-
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("--source-root", type=Path, required=True)
- parser.add_argument("--output", type=Path, required=True)
- parser.add_argument("--initial-token", choices=["present", "absent"], required=True)
- parser.add_argument("--failure", choices=["none", "assertion", "exception"], default="none")
- arguments = parser.parse_args()
- run_probe(arguments.source_root.resolve(), arguments.output, arguments.initial_token, arguments.failure)
diff --git a/agent-langgraph-agui/tests/test_model_spec.py b/agent-langgraph-agui/tests/test_model_spec.py
index a6e9d3c1..4c858c9a 100644
--- a/agent-langgraph-agui/tests/test_model_spec.py
+++ b/agent-langgraph-agui/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-langgraph-agui")' in source
diff --git a/agent-langroid/tests/test_model_spec.py b/agent-langroid/tests/test_model_spec.py
index 6a2d6ce1..50a6bb5b 100644
--- a/agent-langroid/tests/test_model_spec.py
+++ b/agent-langroid/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-langroid")' in source
diff --git a/agent-llamaindex/tests/test_model_spec.py b/agent-llamaindex/tests/test_model_spec.py
index b3ecc171..70364f23 100644
--- a/agent-llamaindex/tests/test_model_spec.py
+++ b/agent-llamaindex/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-5.5")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-llamaindex")' in source
diff --git a/agent-microsoft/tests/test_model_spec.py b/agent-microsoft/tests/test_model_spec.py
index 2e775bc4..d593b0a8 100644
--- a/agent-microsoft/tests/test_model_spec.py
+++ b/agent-microsoft/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-microsoft")' in source
diff --git a/agent-pydantic-ai/tests/test_model_spec.py b/agent-pydantic-ai/tests/test_model_spec.py
index 5e6f161b..7657d44f 100644
--- a/agent-pydantic-ai/tests/test_model_spec.py
+++ b/agent-pydantic-ai/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-pydantic-ai")' in source
diff --git a/agent-strands/tests/test_model_spec.py b/agent-strands/tests/test_model_spec.py
index 6961425f..71853ec8 100644
--- a/agent-strands/tests/test_model_spec.py
+++ b/agent-strands/tests/test_model_spec.py
@@ -30,8 +30,3 @@ def test_blank_environment_falls_through_to_the_file(monkeypatch):
monkeypatch.setenv("BOT_PROVIDER", "")
monkeypatch.setenv("BOT_MODEL", " ")
assert bot_settings(BOT_ID) == BotSettings(provider="openai", model="gpt-4o-mini")
-
-
-def test_this_bots_source_reads_the_spec():
- source = (Path(__file__).resolve().parents[1] / "src" / "main.py").read_text(encoding="utf-8")
- assert f'bot_settings("agent-strands")' in source
diff --git a/app/src/lib/lookup.ts b/app/src/lib/lookup.ts
index a5dfae68..138e0e13 100644
--- a/app/src/lib/lookup.ts
+++ b/app/src/lib/lookup.ts
@@ -12,8 +12,7 @@
* nowhere else, and the next table went back to an object literal.
*
* So the prototype-safe read is a named function rather than a habit: `keyedLookup(TABLE, key)`
- * reads the same whichever page writes it, greps as one symbol, and has exactly one definition —
- * `server/tests/sole-definition.test.ts` asserts that it does.
+ * reads the same whichever page writes it and keeps the prototype-safe read in one place.
*
* A `Map` answers only with what was PUT IN IT. That is the whole mechanism; this function adds
* nothing to it but a name. Taking a `ReadonlyMap` is the point — passing an object literal is a
diff --git a/app/tests/admin-plugins-vocabulary-wiring.test.ts b/app/tests/admin-plugins-vocabulary-wiring.test.ts
deleted file mode 100644
index f242a52a..00000000
--- a/app/tests/admin-plugins-vocabulary-wiring.test.ts
+++ /dev/null
@@ -1,144 +0,0 @@
-// app/tests/admin-plugins-vocabulary-wiring.test.ts
-/**
- * Guard: the admin plugins pages CALL the provider vocabulary; they do not
- * re-hardcode a vendor name.
- *
- * WHY: arcade-admin-plugins.test.tsx pins every string the vocabulary
- * functions return, but nothing pinned that `index.tsx` and `$key.tsx` actually
- * call them. A guard on return values without one on call sites reads as
- * coverage while protecting nothing: a later edit can paste "Composio" straight
- * back into the JSX, every vocabulary test stays green, and an Arcade
- * deployment shows a Composio-named screen (spec D11: screens show the ACTIVE
- * provider only; this PR changes no Composio behaviour). It is the same
- * argument the server-side vendor-name guard makes about catching one spelling
- * of a mistake and not the other.
- *
- * Reads the route sources as TEXT (like arcade-no-browser-calls.test.ts) and
- * imports nothing from them. Comments are stripped first, so docblocks may
- * still explain the vendor. Then:
- * 1. NO route file under the plugins directory contains a capitalised
- * "Composio" NOR the all-caps "COMPOSIO" (string literal, JSX text or test
- * id). `composio.tsx` USED to be exempt, on the argument that the route is
- * Composio-gated by construction. The screen it held has moved to
- * `components/plugins/broker-directory.tsx`, so the file holds no vendor
- * literal and the exemption has no reason left — and an exemption kept
- * after its reason has gone is an escape hatch waiting to be used a second
- * time.
- * The rule scans EVERY route file (`ALL_ROUTES`, enumerated from the
- * directory), not a hand-kept list: an un-scanned sibling is the same
- * escape hatch by omission, and `arcade.tsx` — the likeliest place for
- * a pasted "Composio" — would have been one.
- * 2. NO route file contains a hard-coded `/admin/plugins/composio` or
- * `/admin/plugins/arcade` navigation target. THIS IS THE LOWERCASE
- * SPELLING RULE (1) CANNOT SEE, and it is the one that stranded the
- * enablement notes: `index.tsx` linked every deployment, Arcade ones
- * included, at the Composio directory, which redirected them straight
- * back — so two measured warnings rendered on no deployment that exists.
- * The path belongs in `providerVocabulary().directoryPath`, whose literal
- * union is checked against the generated route tree. Each file's own
- * `createFileRoute("/_authed/admin/plugins/…")` id is not a navigation
- * target and is excluded by the `_authed` prefix.
- * 3. each vocabulary function appears in the file that should call it.
- *
- * If this goes red, route the string through provider-vocabulary.ts; do not
- * loosen the guard. The scanned-count and file-length assertions stop it
- * passing vacuously.
- */
-import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
-import {
- logicalLines,
- sourceFiles,
- stripComments,
-} from "../../server/tests/support/source-scan";
-
-const DIR = join(import.meta.dir, "../src/routes/_authed/admin/plugins");
-
-function load(name: string): string {
- return stripComments(readFileSync(join(DIR, name), "utf8"));
-}
-
-/**
- * Every route file under the directory, so a new one is scanned the day it lands — and a new one
- * in a SUBdirectory too, which a `readdirSync` of the top level would have walked straight past.
- * Names are relative to `DIR`, so a top-level route still reads as `arcade.tsx`.
- */
-const ALL_ROUTES = sourceFiles(DIR, [".tsx"]).map((p) =>
- p.slice(DIR.length + 1),
-);
-
-const VOCAB_CALLERS: Record<string, string[]> = {
- "index.tsx": [
- "moreAppsRow",
- "moreAppsSectionDescription",
- "providerVocabulary",
- ],
- "$key.tsx": [
- "brokeredConnectionDescription",
- "brokeredReach",
- "brokeredDisconnectNote",
- "brokeredProvenance",
- ],
- "composio.tsx": ["directoryRouteDecision"],
- "arcade.tsx": ["directoryRouteDecision"],
-};
-
-// Self-extending, like rule 2: a hand-kept list is an un-scanned sibling waiting to happen, and
-// the Arcade route is the likeliest place for a "Composio" literal to be pasted into.
-const NO_VENDOR_LITERAL = ALL_ROUTES;
-
-test("the plugins routes carry no Composio literal", () => {
- // Every route file in the directory is scanned (no exemptions; arcade.tsx and the $key_.*
- // children included). The floor and the two named files keep the scan from passing on an
- // empty or truncated list.
- expect(NO_VENDOR_LITERAL.length).toBeGreaterThanOrEqual(6);
- expect(NO_VENDOR_LITERAL).toContain("arcade.tsx");
- expect(NO_VENDOR_LITERAL).toContain("composio.tsx");
- const offenders: string[] = [];
- for (const name of NO_VENDOR_LITERAL) {
- const text = load(name);
- expect(text.length).toBeGreaterThan(500);
- for (const { line: at, text: line } of logicalLines(text)) {
- // Capitalised AND all-caps. `COMPOSIO_API_KEY` is a user-visible string 1.8 moved
- // into the vocabulary (`envVar`), rendered as "Set COMPOSIO_API_KEY on this
- // deployment." — it must read ARCADE_API_KEY on an Arcade deployment, and an
- // env-var name is exactly the string an editor inlines as a constant. NOT
- // case-insensitive: `composioConfigured` and the `/_authed/admin/plugins/composio`
- // route id are legitimate and must stay legal.
- if (/Composio|COMPOSIO/.test(line))
- offenders.push(`${name}:${at}: ${line.trim()}`);
- }
- }
- expect(offenders).toEqual([]);
-});
-
-test("no plugins route hard-codes a directory path", () => {
- expect(ALL_ROUTES.length).toBeGreaterThanOrEqual(6);
- expect(ALL_ROUTES).toContain("arcade.tsx");
- expect(ALL_ROUTES).toContain("composio.tsx");
- const offenders: string[] = [];
- for (const name of ALL_ROUTES) {
- const text = load(name);
- expect(text.length).toBeGreaterThan(500);
- for (const { line: at, text: line } of logicalLines(text)) {
- // The route's own file id carries `_authed` and is not somewhere anybody navigates.
- if (/(?<!_authed)\/admin\/plugins\/(composio|arcade)/.test(line))
- offenders.push(`${name}:${at}: ${line.trim()}`);
- }
- }
- expect(offenders).toEqual([]);
-});
-
-test("each plugins page calls the vocabulary functions it should", () => {
- expect(Object.keys(VOCAB_CALLERS).length).toBe(4);
- const missing: string[] = [];
- for (const [name, fns] of Object.entries(VOCAB_CALLERS)) {
- const text = load(name);
- for (const fn of fns) {
- if (!new RegExp(`\\b${fn}\\(`).test(text))
- missing.push(`${name} -> ${fn}`);
- }
- }
- expect(missing).toEqual([]);
-});
diff --git a/app/tests/arcade-no-browser-calls.test.ts b/app/tests/arcade-no-browser-calls.test.ts
deleted file mode 100644
index c1f2df57..00000000
--- a/app/tests/arcade-no-browser-calls.test.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-// app/tests/arcade-no-browser-calls.test.ts
-/**
- * Guard: no browser code under `app/src` ever dials Arcade.
- *
- * WHY: the vendor key never leaves the server and the browser never talks to
- * Arcade (spec D25). The grant-status route exists precisely so a browser asks
- * OpenBot rather than the vendor. A direct dial from `app/` would either need
- * the deployment's key in the bundle or would leak which identities have flows
- * outstanding.
- *
- * Flags any line that imports `@arcadeai/arcadejs` (static, dynamic `import(`,
- * or `require(`), names an `arcade.dev` host, or names an Arcade API path.
- *
- * NOT AN OFFENCE: an `arcade://` url string. That is a brokered row's url, as
- * the server hands it to the browser, and is not a network target. It is
- * excluded explicitly below (and does not match the host pattern anyway); do
- * not widen the host pattern to bare "arcade" or this guard starts crying wolf
- * and gets weakened.
- *
- * EXPECTED GREEN. Unlike brokered-provenance.test.ts (committed RED as a
- * checklist), no browser Arcade code exists, so this passes from the start.
- * If it goes red, remove the offending browser code; do not loosen the guard.
- * The scan-count assertion stops it passing vacuously against an empty walk.
- */
-import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
-import {
- logicalLines,
- sourceFiles,
-} from "../../server/tests/support/source-scan";
-
-const SRC_DIR = join(import.meta.dir, "../src");
-
-const PATTERNS: RegExp[] = [
- /@arcadeai\/arcadejs/,
- /\barcade\.dev\b/,
- /\/v1\/tools\/execute/,
- /\/v1\/tools\/authorize/,
- /oauth\/confirm_user/,
-];
-
-// `arcade://` is a row url, not a dial. Blanked before matching.
-const ROW_URL = /arcade:\/\/\S*/g;
-
-test("no browser code under app/src dials Arcade", () => {
- // Enumeration and line-splitting come from the shared scanner, so the walk is recursive (a
- // future `src/<dir>/` is scanned the day it lands) and a dial prettier wrapped across two
- // physical lines is one line to the patterns. Comments are deliberately NOT stripped: a
- // docblock naming `arcade.dev` is still this guard's business.
- const files = sourceFiles(SRC_DIR, [".ts", ".tsx"]);
- expect(files.length).toBeGreaterThan(50);
- const offenders: string[] = [];
- for (const file of files) {
- for (const { line, text } of logicalLines(readFileSync(file, "utf8"))) {
- const scanned = text.replace(ROW_URL, "");
- if (PATTERNS.some((re) => re.test(scanned))) {
- offenders.push(`${file.slice(SRC_DIR.length + 1)}:${line}`);
- }
- }
- }
- expect(offenders).toEqual([]);
-});
diff --git a/app/tests/channel-new-error-state.fixture.tsx b/app/tests/channel-new-error-state.fixture.tsx
index 870d9d31..2183fd65 100644
--- a/app/tests/channel-new-error-state.fixture.tsx
+++ b/app/tests/channel-new-error-state.fixture.tsx
@@ -1,28 +1,27 @@
-import { mock } from "bun:test";
+import type { NewBotSheet } from "@/components/agents/new-bot-sheet";
-mock.module("@/components/layout/sidebar-toggle", () => ({
- SidebarToggle: () => <button type="button">Toggle sidebar</button>,
-}));
+export function SidebarToggleStub() {
+ return <button type="button">Toggle sidebar</button>;
+}
// Exercise the recipient picker's creation handoff without running the separate creation flow.
-mock.module("@/components/agents/new-bot-sheet", () => ({
- NewBotSheet: ({
- open,
- onClose,
- onCreated,
- }: {
- open: boolean;
- onClose: () => void;
- onCreated: (id: string) => void;
- }) =>
- open ? (
- <div role="dialog" aria-label="New Bot">
- <button type="button" onClick={onClose}>
- Cancel creation
- </button>
- <button type="button" onClick={() => onCreated("created-bot")}>
- Finish creation
- </button>
- </div>
- ) : null,
-}));
+export function NewBotCreationStub({
+ open,
+ onClose,
+ onCreated,
+}: Parameters<typeof NewBotSheet>[0]) {
+ return (
+ <>
+ {open ? (
+ <div role="dialog" aria-label="New Bot">
+ <button type="button" onClick={onClose}>
+ Cancel creation
+ </button>
+ <button type="button" onClick={() => onCreated("created-bot")}>
+ Finish creation
+ </button>
+ </div>
+ ) : null}
+ </>
+ );
+}
diff --git a/app/tests/channel-new-error-state.test.tsx b/app/tests/channel-new-error-state.test.tsx
index 37df841b..d9112d6b 100644
--- a/app/tests/channel-new-error-state.test.tsx
+++ b/app/tests/channel-new-error-state.test.tsx
@@ -1,6 +1,12 @@
-import "./channel-new-error-state.fixture";
-
-import { afterAll, afterEach, beforeAll, expect, test } from "bun:test";
+import {
+ afterAll,
+ afterEach,
+ beforeAll,
+ beforeEach,
+ expect,
+ spyOn,
+ test,
+} from "bun:test";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
@@ -13,13 +19,48 @@ import {
} from "@tanstack/react-router";
import { cleanup, fireEvent, render, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
+import * as NewBotSheetModule from "@/components/agents/new-bot-sheet";
+import * as SidebarToggleModule from "@/components/layout/sidebar-toggle";
import { type AgentProfile, agentKeys } from "@/lib/agents/queries";
import { Route as ChannelNewRoute } from "@/routes/_authed/_app/channel/new";
+import {
+ NewBotCreationStub,
+ SidebarToggleStub,
+} from "./channel-new-error-state.fixture";
import { settleReactWork } from "./settle-react-work";
beforeAll(() => GlobalRegistrator.register());
-afterEach(() => cleanup());
+// The shared preload supplies the Vite-only marks module before importing the real sheet.
+// Namespace spies can be restored; mock.module would leak these handoff stubs into later suites.
+const realNewBotSheet = NewBotSheetModule.NewBotSheet;
+const realSidebarToggle = SidebarToggleModule.SidebarToggle;
+let restoreComponents = () => {};
+
+beforeEach(() => {
+ const newBotSheetSpy = spyOn(
+ NewBotSheetModule,
+ "NewBotSheet",
+ ).mockImplementation(NewBotCreationStub);
+ const sidebarToggleSpy = spyOn(
+ SidebarToggleModule,
+ "SidebarToggle",
+ ).mockImplementation(SidebarToggleStub);
+ restoreComponents = () => {
+ newBotSheetSpy.mockRestore();
+ sidebarToggleSpy.mockRestore();
+ };
+});
+
+afterEach(() => {
+ try {
+ cleanup();
+ } finally {
+ restoreComponents();
+ expect(NewBotSheetModule.NewBotSheet).toBe(realNewBotSheet);
+ expect(SidebarToggleModule.SidebarToggle).toBe(realSidebarToggle);
+ }
+});
afterAll(async () => {
await settleReactWork();
diff --git a/app/tests/composer-queue-attachments.test.tsx b/app/tests/composer-queue-attachments.test.tsx
index 93343834..291a9e6c 100644
--- a/app/tests/composer-queue-attachments.test.tsx
+++ b/app/tests/composer-queue-attachments.test.tsx
@@ -7,19 +7,19 @@ import {
spyOn,
test,
} from "bun:test";
+import * as ReactCoreV2 from "@copilotkit/react-core/v2";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
import {
cleanup,
fireEvent,
- render,
type RenderResult,
+ render,
waitFor,
} from "@testing-library/react";
-import * as ReactCoreV2 from "@copilotkit/react-core/v2";
import { useCallback } from "react";
import { Composer } from "@/components/channels/composer/composer";
-import { ConversationView } from "@/components/channels/conversation-view";
import type { ComposerDraft } from "@/components/channels/composer/draft";
+import { ConversationView } from "@/components/channels/conversation-view";
import {
attachmentUrl,
MAX_ATTACHMENTS_PER_MESSAGE,
@@ -77,15 +77,6 @@ afterAll(async () => {
let removeAttachmentCalls: string[];
let consumeAttachmentsCallCount: number;
-/**
- * Every distinct function identity the spy has handed a rendering composer, so the test below can
- * say that it handed out exactly one of each. See the note on stability under the spy itself.
- */
-const handedOut = {
- removeAttachment: new Set<unknown>(),
- consumeAttachments: new Set<unknown>(),
-};
-
/**
* A THIN SPY AROUND THE REAL HOOK, NOT A REPLACEMENT FOR IT. Every other field — `attachments`,
* `processFiles`, the drag handlers — passes straight through to the real `useAttachments`, so
@@ -127,9 +118,6 @@ beforeAll(() => {
return hook.consumeAttachments();
}, [hook.consumeAttachments]);
- handedOut.removeAttachment.add(removeAttachment);
- handedOut.consumeAttachments.add(consumeAttachments);
-
return { ...hook, removeAttachment, consumeAttachments };
},
);
@@ -161,8 +149,6 @@ let uploads: string[];
beforeEach(() => {
removeAttachmentCalls = [];
consumeAttachmentsCallCount = 0;
- handedOut.removeAttachment.clear();
- handedOut.consumeAttachments.clear();
deletes = [];
uploads = [];
global.fetch = (async (path: string, init: RequestInit) => {
@@ -471,26 +457,6 @@ test("a full queue drains whole, with nothing bumped and nothing to release", as
expect(uploads).toHaveLength(MAX_ATTACHMENTS_PER_MESSAGE);
});
-test("the spy hands the composer one stable pair of callbacks, not a fresh pair per render", async () => {
- // THE HARNESS MEASURING ITSELF, and worth the test. The SDK builds `removeAttachment` and
- // `consumeAttachments` as `useCallback(…, [])` — stable for the life of the hook, deliberately —
- // and `submitDraft` lists `removeAttachment` in its dependency array. A spy that mints a new
- // wrapper on every render silently rebuilds that memo on every render too, so the thing under
- // test would be reacting to the instrument rather than to the code.
- const view = render(
- <Composer channelId="channel-1" compact onSubmit={() => {}} />,
- );
-
- // Several renders: the placeholder going on the strip, the upload resolving, the strip
- // re-rendering without it.
- await dropAndWait(view, [notes()]);
- fireEvent.click(view.getByLabelText("Remove notes.txt"));
- await waitFor(() => expect(chips(view)).toEqual([]));
-
- expect(handedOut.removeAttachment.size).toBe(1);
- expect(handedOut.consumeAttachments.size).toBe(1);
-});
-
/**
* Registered after the `afterAll` that restores, so it runs after it: the real function is back on
* the module and no file bun walks into this process after this one is holding a spy. This is the
diff --git a/app/tests/form-submit-controls.test.ts b/app/tests/form-submit-controls.test.ts
deleted file mode 100644
index bf99ce3f..00000000
--- a/app/tests/form-submit-controls.test.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import { expect, test } from "bun:test";
-import { Glob } from "bun";
-import ts from "typescript";
-
-/**
- * Every `<form onSubmit>` has something that submits it.
- *
- * Base UI's `Button` renders `type="button"` unless told otherwise, so a `<Button>` that looks like
- * a form's submit does nothing when pressed, and the form's own tests still pass because they fire
- * `submit` on the form directly. That shipped four dead forms at once (Remember, Add and sync
- * source, Confirm phone, Turn on background research) and the recorder before them. A plain
- * `<button>` defaults to submit, so it counts; a `<Button>` counts only with `type="submit"`.
- *
- * A submit control outside the form counts when it names the form: `form={id}` matching the form's
- * own `id={id}`. A dialog does this to keep its submit in `DialogFooter` while `DialogBody` stays a
- * direct child of `DialogContent`.
- *
- * A form submitted some other way (the composer's Enter key and send action) names itself here with
- * a reason, rather than every form losing the check.
- */
-const SUBMITTED_ELSEWHERE = new Set([
- // Enter submits through the editor, and the send action is its own typed control.
- "src/components/channels/composer/composer.tsx",
- // The Browser page's address bar, which Enter submits as a browser's does: its one field submits the form on its
- // own (HTML's implicit submission), and a Go button would be the one thing no browser's address bar has.
- "src/components/browser/browser-screen.tsx",
-]);
-
-function attribute(node: ts.JsxOpeningLikeElement, name: string) {
- return node.attributes.properties.find(
- (property): property is ts.JsxAttribute =>
- ts.isJsxAttribute(property) && property.name.getText() === name,
- );
-}
-
-function submits(node: ts.JsxOpeningLikeElement): boolean {
- const tag = node.tagName.getText();
- const type = attribute(node, "type")?.initializer;
- const typeText =
- type && ts.isStringLiteral(type)
- ? type.text
- : type && ts.isJsxExpression(type) && type.expression
- ? type.expression.getText().replace(/["'`]/g, "")
- : undefined;
- if (tag === "button") return typeText === undefined || typeText === "submit";
- if (tag === "input") return typeText === "submit";
- return typeText === "submit";
-}
-
-test("every form with an onSubmit has a control that submits it", async () => {
- const dead: string[] = [];
- for await (const file of new Glob("src/**/*.tsx").scan(
- `${import.meta.dir}/..`,
- )) {
- if (SUBMITTED_ELSEWHERE.has(file)) continue;
- const text = await Bun.file(`${import.meta.dir}/../${file}`).text();
- const source = ts.createSourceFile(
- file,
- text,
- ts.ScriptTarget.Latest,
- true,
- ts.ScriptKind.TSX,
- );
- /** The `form` attribute of every submit control in the file, as written. */
- const named = new Set<string>();
- const collect = (node: ts.Node) => {
- if (
- (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
- submits(node)
- ) {
- const form = attribute(node, "form")?.initializer;
- if (form) named.add(form.getText());
- }
- ts.forEachChild(node, collect);
- };
- collect(source);
- const visit = (node: ts.Node) => {
- if (
- ts.isJsxElement(node) &&
- node.openingElement.tagName.getText() === "form" &&
- attribute(node.openingElement, "onSubmit")
- ) {
- const id = attribute(node.openingElement, "id")?.initializer;
- let found = id !== undefined && named.has(id.getText());
- const inside = (child: ts.Node) => {
- if (found) return;
- if (
- (ts.isJsxOpeningElement(child) ||
- ts.isJsxSelfClosingElement(child)) &&
- submits(child)
- )
- found = true;
- ts.forEachChild(child, inside);
- };
- ts.forEachChild(node, inside);
- if (!found) {
- const { line } = source.getLineAndCharacterOfPosition(
- node.getStart(),
- );
- dead.push(`${file}:${line + 1}`);
- }
- }
- ts.forEachChild(node, visit);
- };
- visit(source);
- }
- expect(dead).toEqual([]);
-});
diff --git a/app/tests/plugin-mutation-refresh.test.ts b/app/tests/plugin-mutation-refresh.test.ts
index f11bbdd0..f306413c 100644
--- a/app/tests/plugin-mutation-refresh.test.ts
+++ b/app/tests/plugin-mutation-refresh.test.ts
@@ -1,6 +1,4 @@
import { afterEach, expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
import {
type MutationFunctionContext,
MutationObserver,
@@ -8,7 +6,6 @@ import {
QueryClient,
} from "@tanstack/react-query";
import { authorizeActionMutationOptions } from "../src/lib/plugins/grants";
-import * as pluginMutations from "../src/lib/plugins/mutations";
import {
accountModePreview,
addCuratedServerMutationOptions,
@@ -138,14 +135,6 @@ const REFUSALS: {
route: string;
status: number;
message: string;
- /**
- * THE FACTORY ITSELF, NOT A CLOSURE THAT CALLS ONE AND NOT ITS NAME AS A STRING.
- *
- * Because the completeness test below matches these against `mutations.ts`'s exported VALUES by
- * identity. A name written out here would be a third copy of the same list — the export, the
- * import at the top of this file, and a string — and a factory renamed at the source would leave
- * a case pointing at a name nothing exports, which is the failure mode this whole file is about.
- */
factory: (queryClient: QueryClient) => unknown;
variables: unknown;
}[] = [
@@ -339,93 +328,6 @@ test("asking an app what it wants refetches nothing, because it writes nothing",
).rejects.toThrow("Composio would not say what Gmail asks for.");
});
-/**
- * The exported functions that are NOT a mutation factory at all, each with why.
- *
- * Named rather than filtered out by a rule about their shape, because "it does not look like a
- * mutation factory" is precisely the judgement that let a real one go uncovered: this file had no
- * case for `connectAccountMutationOptions` for two rounds and nothing anywhere said so.
- */
-const NOT_A_MUTATION_FACTORY: Record<string, string> = {
- invalidatePlugins:
- "The refetch itself — the thing every case above asserts was asked for, not a press.",
- grantPlugin:
- "The bare write, for a caller granting a batch and refreshing once at the end. It carries no refetch on purpose, and the mutation that wraps it is covered above.",
- accountModePreview:
- "The bare read: `confirm: false` on the same PUT the real switch sends, asked not to commit. Nothing changed, so there is nothing to refetch — and the switch that does commit is covered above.",
-};
-
-/**
- * The mutation factories the property above does not apply to, each with why it does not.
- *
- * AN EXEMPTION IS A CLAIM AND IT IS WRITTEN DOWN AS ONE. Both of these are structural rather than a
- * decision somebody made in a callback — neither factory has a `QueryClient` to invalidate with —
- * so an exemption here can be checked against the code rather than taken on trust, and a factory
- * that grows a client later stops qualifying and has to move into `REFUSALS`.
- */
-const NOT_A_REFUSABLE_WRITE: Record<string, string> = {
- brokeredConnectionFieldsMutationOptions:
- "Asks an app what it wants typed in. `POST /connect` with no body writes nothing on either outcome, and the factory takes no QueryClient. Its own test is above.",
- connectAccountMutationOptions:
- "Starts a consent connection and hands back the vendor's URL for the browser to leave for. Nothing on this screen survives that navigation to be refetched, and this factory takes no QueryClient either — it takes which screen to come back to.",
-};
-
-test("every mutation factory `mutations.ts` exports is answered for by this file", () => {
- /*
- * THE COMPLETENESS CHECK, AND THE REASON THIS FILE NEEDED ONE. Both sibling drift tests count
- * their roster against the declaration it mirrors; this one counted nothing, so a fifteenth
- * factory added to `mutations.ts` with `onSuccess` where `onSettled` belongs was a case nobody
- * wrote and nobody missed. Adding the count is what turned up `connectAccountMutationOptions`,
- * which had been exported and unanswered-for the whole time.
- *
- * READ OFF THE MODULE'S RUNTIME EXPORTS, not off a list of names in this file. A namespace import
- * is the one thing here that cannot fall behind the source: a factory added, renamed or deleted
- * changes this list on the next run. Every exported function has to land in exactly one of three
- * places — a refusal case, a declared exemption, or a declared non-factory — and membership of
- * the first is matched BY VALUE, so a rename cannot leave a case pointing at a ghost.
- *
- * `typeof value === "function"` is the whole of the filter DELIBERATELY, rather than a name
- * ending in `MutationOptions`. The types this module exports are erased and never reach here, so
- * the filter costs nothing; a factory named something else entirely still shows up, which a
- * suffix rule would have let through — and a suffix rule is a convention, which is the kind of
- * thing the next file breaks without noticing.
- */
- const exported = Object.entries(pluginMutations)
- .filter(([, value]) => typeof value === "function")
- .map(([name]) => name)
- .sort();
-
- const covered = new Set<unknown>(REFUSALS.map((refusal) => refusal.factory));
- const answeredFor = Object.entries(pluginMutations)
- .filter(
- ([name, value]) =>
- typeof value === "function" &&
- (covered.has(value) ||
- name in NOT_A_REFUSABLE_WRITE ||
- name in NOT_A_MUTATION_FACTORY),
- )
- .map(([name]) => name)
- .sort();
-
- expect(answeredFor).toEqual(exported);
-
- /*
- * AND NEITHER EXEMPTION LIST OUTLIVES WHAT IT EXEMPTS. An entry naming a function this module no
- * longer exports, or one a refusal case now covers, is a claim about nothing — and a stale
- * exemption is how a roster goes on looking complete while the thing it excused was quietly
- * replaced by something that does need a case.
- */
- const unclaimed = exported.filter(
- (name) => !covered.has((pluginMutations as Record<string, unknown>)[name]),
- );
- expect(
- [
- ...Object.keys(NOT_A_REFUSABLE_WRITE),
- ...Object.keys(NOT_A_MUTATION_FACTORY),
- ].sort(),
- ).toEqual(unclaimed);
-});
-
/**
* WHAT THESE WRITES PUT IN A URL, AND WHOSE TEXT IT IS.
*
@@ -436,11 +338,6 @@ test("every mutation factory `mutations.ts` exports is answered for by this file
* before any handler is reached — and a `?` turns the rest of the id into a query string, silently
* truncating the id the route then looks up.
*
- * REPORTED THREE TIMES AND CLASSED AS COSMETIC THREE TIMES, which is what the pair of tests below
- * is really about. The first is the behaviour, one case per write that puts a caller's text in a
- * URL; the second is the lever, because a roster of cases only ever covers the writes that existed
- * when somebody wrote it — and the defect here was one new line forgetting the call its ten
- * neighbours all make.
*/
/**
@@ -609,56 +506,6 @@ for (const request of ENCODED_REQUESTS) {
});
}
-test("every id these writes interpolate into a URL goes through encodeURIComponent", () => {
- /*
- * THE LEVER, AND WHY THE ROSTER ABOVE IS NOT ENOUGH ON ITS OWN. A case list covers the writes
- * that existed when it was written, and the defect it is about is a new one forgetting what its
- * neighbours do. There is no way to enumerate from the outside every path a module MIGHT build —
- * the roster is that attempt, and it can only ever be a list — but every interpolation the file
- * contains can be enumerated, and that is the set this asks the question of.
- *
- * THE MODULE BUILDS ITS URLS NOWHERE ELSE: no base, no join helper, no concatenation. So every
- * backticked string beginning `/api/` is the whole surface rather than a sample of it, and this
- * assumption is itself pinned by the count below.
- */
- const source = readFileSync(
- join(import.meta.dir, "../src/lib/plugins/mutations.ts"),
- "utf8",
- );
- const paths = [...source.matchAll(/`(\/api\/[^`]*)`/g)].map(
- (match) => match[1] ?? "",
- );
- /*
- * AND THE ROSTER ABOVE IS THE SAME SET, COUNTED. A path with nothing interpolated into it is a
- * plain quoted string in this module and is not matched here at all, so every path this finds
- * carries somebody's text and has a case above naming the URL it must produce. A new interpolated
- * path added with no case beside it fails here, which is what keeps the roster from quietly
- * becoming a sample.
- */
- expect(paths.length).toBe(ENCODED_REQUESTS.length);
-
- /*
- * THE TWO NAMES THAT MAY GO IN RAW, AND WHY NEITHER IS A CALLER'S TEXT. `variables.kind` is
- * `PluginKind` and `returnTo` is `"settings" | "admin"` — two closed unions this module declares
- * itself, each narrowed again by the server before it decides anything. Anything else in this
- * position is somebody's typed id, and there are exactly two ways for one of those to be safe:
- * the call this test is named for, or a new entry here that somebody had to argue for.
- */
- const closedUnions = ["variables.kind", "returnTo"];
-
- const raw = paths.flatMap((path) =>
- [...path.matchAll(/\$\{([^}]*)\}/g)]
- .map((match) => (match[1] ?? "").trim())
- .filter(
- (interpolation) =>
- !interpolation.startsWith("encodeURIComponent(") &&
- !closedUnions.includes(interpolation),
- ),
- );
-
- expect(raw).toEqual([]);
-});
-
/**
* Where the vendor's callback puts somebody down is the caller's to say, and only the default was
* ever pinned.
diff --git a/app/tests/search-text.test.ts b/app/tests/search-text.test.ts
index 4a074078..3d721e6c 100644
--- a/app/tests/search-text.test.ts
+++ b/app/tests/search-text.test.ts
@@ -10,20 +10,14 @@
*
* Two halves are pinned here. `searchText` renders whatever arrived back to the text it was, and
* `parseSearchText` takes away the one case it could not have rendered back exactly — a number too
- * long to survive a double. The guard at the bottom keeps the `typeof` form from coming back.
+ * long to survive a double.
*/
import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
import {
parseSearchText,
searchText,
searchTextEntry,
} from "@/lib/search-text";
-import {
- logicalLines,
- sourceFiles,
-} from "../../server/tests/support/source-scan";
test("text is recovered from whatever the router parsed the value into", () => {
expect(searchText("abc")).toBe("abc");
@@ -68,29 +62,3 @@ test("a handle survives the URL whatever it is made of", () => {
test("a parameter that is not there stays not there", () => {
expect(searchText(parseSearchText("?other=1").flow_id)).toBeUndefined();
});
-
-/**
- * AND THE SHAPE THAT CAUSED IT DOES NOT COME BACK. A `typeof search.x === "string"` test in a
- * route's `validateSearch` is the defect itself: it reads "keep it when it is text" and means "drop
- * it whenever the sender's value happened to be valid JSON". Routes read text through `searchText`.
- */
-const ROUTES_DIR = join(import.meta.dir, "../src/routes");
-const DROPPED_STRING = /typeof\s+search\??\.\w+\s*===\s*["']string["']/;
-
-test("no route reads a search parameter by guarding on its parsed type", () => {
- // The walk and the line-splitting are the shared scanner's (server/tests/support): recursive,
- // and LOGICAL lines — prettier wraps `typeof search.flowId ===` away from its `"string"`, and
- // read one physical line at a time this guard would have reported green on the very shape it
- // exists to catch.
- const files = sourceFiles(ROUTES_DIR, [".ts", ".tsx"]);
- expect(files.length).toBeGreaterThan(10);
- const offenders: string[] = [];
- for (const file of files) {
- for (const { line, text } of logicalLines(readFileSync(file, "utf8"))) {
- if (DROPPED_STRING.test(text)) {
- offenders.push(`${file.slice(ROUTES_DIR.length + 1)}:${line}`);
- }
- }
- }
- expect(offenders).toEqual([]);
-});
diff --git a/app/tests/theme-preference.test.ts b/app/tests/theme-preference.test.ts
index 6a2681a9..bd1abf67 100644
--- a/app/tests/theme-preference.test.ts
+++ b/app/tests/theme-preference.test.ts
@@ -30,31 +30,6 @@ describe("theme preference", () => {
});
});
-describe("pre-paint theme boot", () => {
- const html = readFileSync(new URL("../index.html", import.meta.url), "utf8");
-
- test("the boot script reads the same storage key the app writes", () => {
- expect(html).toContain(THEME_STORAGE_KEY);
- });
-
- test("the boot script runs before the first paint", () => {
- const boot = html.match(/<script(?![^>]*\bsrc=)[^>]*>/);
-
- expect(boot).not.toBeNull();
- expect(boot?.[0]).not.toContain("module");
- expect(boot?.[0]).not.toContain("defer");
- });
-
- test("the boot script applies the dark class itself", () => {
- expect(html).toContain("documentElement");
- expect(html).toMatch(/classList[\s\S]*dark/);
- });
-
- test("the document declares a color scheme before the stylesheet arrives", () => {
- expect(html).toContain("colorScheme");
- });
-});
-
describe("color scheme", () => {
const styles = readFileSync(
new URL("../src/theme.css", import.meta.url),
diff --git a/app/tests/transcript-attachments.test.tsx b/app/tests/transcript-attachments.test.tsx
index 40910e24..74742107 100644
--- a/app/tests/transcript-attachments.test.tsx
+++ b/app/tests/transcript-attachments.test.tsx
@@ -2,6 +2,7 @@ import { afterAll, afterEach, beforeAll, expect, test } from "bun:test";
import type { Message, UserMessage } from "@ag-ui/core";
import type { Attachment } from "@copilotkit/react-core/v2";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
+import { frameFiring } from "@openbot/shared/routine-firing";
import {
act,
cleanup,
@@ -17,7 +18,6 @@ import {
} from "@/components/channels/chat-transcript";
import type { QueuedMessage } from "@/components/channels/composer";
import { attachmentUrl } from "@/lib/channels/attachments";
-import { frameFiring } from "@openbot/shared/routine-firing";
import { settleReactWork } from "./settle-react-work";
/**
@@ -805,11 +805,7 @@ test("a row that actually changed does not compare equal", () => {
).toBe(false);
});
-/*
- * And that it is the comparison the row is actually memoised WITH — a correct function nobody
- * passed to `memo` buys nothing, and that is precisely the state this row was in. `compare` is the
- * field `React.memo` keeps its comparator in.
- */
+// A correct comparator only protects attachment identity if the rendered row uses it.
test("the row of tiles is memoised with that comparison", () => {
expect(
(TranscriptAttachments as unknown as { compare?: unknown }).compare,
diff --git a/bunfig.toml b/bunfig.toml
index b712972f..b474b29e 100644
--- a/bunfig.toml
+++ b/bunfig.toml
@@ -6,5 +6,5 @@
#
# This applies to `bun test` run from the repository root. Bun reads bunfig.toml from the current
# working directory only, so server/bunfig.toml repeats the declaration for `bun test` run from
-# inside server/, and server/tests/bunfig-preload.test.ts keeps the two in agreement.
+# inside server/. Keep the two preload lists in agreement.
preload = ["./server/scripts/test-preload.ts", "./app/tests/preload.ts"]
diff --git a/desktop/src-tauri/src/engine.rs b/desktop/src-tauri/src/engine.rs
index 2754f497..88431a9e 100644
--- a/desktop/src-tauri/src/engine.rs
+++ b/desktop/src-tauri/src/engine.rs
@@ -690,23 +690,6 @@ fn main() {
assert_eq!(socket_override(Engine::Docker), None);
}
- #[test]
- fn a_missing_engine_is_reported_as_missing_rather_than_as_not_responding() {
- // Not a call to `detect`: this asserts the shape a caller has to distinguish. "Installed but
- // not answering" tells somebody to start it; "none found" tells them to install one, and
- // the wrong one of those sends them looking for a menu bar icon that is not there.
- let missing = EngineStatus {
- engine: None,
- address: None,
- responding: false,
- engine_socket: None,
- detail: "No container engine found. Install Podman Desktop or Docker Desktop first."
- .into(),
- };
- assert!(missing.engine.is_none());
- assert!(!missing.responding);
- }
-
#[test]
fn a_podman_machine_is_named_on_every_command_it_is_addressed_with() {
let address = Address::new(Engine::Podman, Some("openbot".into()));
diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs
index 1ae5c086..2d654af9 100644
--- a/desktop/src-tauri/src/main.rs
+++ b/desktop/src-tauri/src/main.rs
@@ -4819,23 +4819,6 @@ mod tests {
);
}
- #[test]
- fn ask_transport_regressions_do_not_load_from_the_vault() {
- let source = include_str!("main.rs");
- let test = source
- .split("\n fn ask_the_bot_uses_native_mastra_for_a_picked_mastra_harness()")
- .nth(1)
- .expect("ID12 regression")
- .split("struct TestRequest")
- .next()
- .expect("ID12 regression body");
-
- assert!(
- !test.contains("ask_the_bot("),
- "ID12 must test dispatch with resolved settings instead of loading vault-backed settings"
- );
- }
-
#[test]
fn runtime_connection_recovery_retains_installation_and_rejects_stale_run_notifications() {
let root = temp_root("runtime-connection-recovery");
@@ -5044,27 +5027,6 @@ mod tests {
std::fs::remove_dir_all(root).unwrap();
}
- #[test]
- fn credential_restore_commands_are_not_registered() {
- let source = include_str!("main.rs");
- let handlers = source
- .split("tauri::generate_handler![")
- .nth(1)
- .expect("handler list exists")
- .split("])")
- .next()
- .expect("handler list closes");
- for command in [
- ["reco", "ver", "_credential"].concat(),
- ["cancel", "_credential", "_reco", "very"].concat(),
- ] {
- assert!(
- !handlers.contains(&command),
- "{command} is still registered"
- );
- }
- }
-
#[test]
fn already_configured_trims_pasted_root_and_preserves_interior_spaces() {
let root = temp_root("openbot-pasted-root My Files");
diff --git a/desktop/src-tauri/src/plan.rs b/desktop/src-tauri/src/plan.rs
index ef96a8d0..a9f806f8 100644
--- a/desktop/src-tauri/src/plan.rs
+++ b/desktop/src-tauri/src/plan.rs
@@ -1055,19 +1055,6 @@ fn main() {
);
}
- /// The refresh token is the point of carrying a store, so the program must print all of it.
- #[test]
- fn the_login_program_prints_the_whole_store() {
- assert!(
- CHATGPT_LOGIN.contains("json.dumps(raw"),
- "the login must print the store, not one field of it"
- );
- assert!(
- !CHATGPT_LOGIN.contains("OPENBOT_CHATGPT_TOKEN"),
- "an access token alone expires within the hour and cannot be renewed"
- );
- }
-
/// The URL the vendor's login prints as its fallback.
#[test]
fn the_openai_url_is_found() {
diff --git a/desktop/src-tauri/src/stack.rs b/desktop/src-tauri/src/stack.rs
index 205d0129..feef07cc 100644
--- a/desktop/src-tauri/src/stack.rs
+++ b/desktop/src-tauri/src/stack.rs
@@ -7110,17 +7110,6 @@ fn main() {
assert!(picked.contains(&"agent-harness"));
}
- /// Stop has to name the profile, or the one Bot the person picked keeps running.
- #[test]
- fn stopping_names_the_harness_profile() {
- let source = include_str!("stack.rs");
- assert!(
- source
- .contains(r#".args(["-f", "docker-compose.yml", "--profile", "harness", "down"])"#),
- "compose down without the profile leaves agent-harness running"
- );
- }
-
#[test]
fn the_published_ports_are_read_off_a_real_listing() {
// Verbatim from `compose ps --format '{{.Ports}}'` against a running deployment.
diff --git a/desktop/src-tauri/src/test_support.rs b/desktop/src-tauri/src/test_support.rs
index f30bb9e8..ed53bb81 100644
--- a/desktop/src-tauri/src/test_support.rs
+++ b/desktop/src-tauri/src/test_support.rs
@@ -10,11 +10,6 @@ pub(crate) fn temp_root(label: &str) -> PathBuf {
path
}
-#[test]
-fn temp_roots_with_the_same_label_do_not_collide() {
- assert_ne!(temp_root("same-label"), temp_root("same-label"));
-}
-
/// Runtime PATH belongs to the scenario under test; the compiler and linker tools belong to
/// Cargo's build environment. Neither an inherited runtime RUSTC nor another test can replace it.
pub(crate) fn compile_fixture(source: &std::path::Path, binary: &std::path::Path) {
@@ -34,26 +29,6 @@ pub(crate) fn compile_fixture(source: &std::path::Path, binary: &std::path::Path
);
}
-#[test]
-fn compile_fixture_preserves_windows_executable_filename() {
- let root = temp_root("fixture-executable-filename");
- std::fs::create_dir_all(&root).unwrap();
- // Exercise Windows provider naming even when this regression runs on Unix.
- let source = root.join("docker-compose.exe.rs");
- let binary = root.join("docker-compose.exe");
- std::fs::write(
- &source,
- "fn main() { println!(\"fixture executable ran\"); }",
- )
- .unwrap();
-
- compile_fixture(&source, &binary);
- let output = std::process::Command::new(&binary).output().unwrap();
- std::fs::remove_dir_all(&root).expect("remove owned compiler fixture");
- assert!(output.status.success());
- assert_eq!(output.stdout, b"fixture executable ran\n");
-}
-
/// Tests that replace the process environment run in their own exact-test child. The normal
/// parent suite stays parallel; unrelated HTTP, compiler, and ownership tests keep their PATH.
/// Return true in the parent after the child passes, so the caller can return immediately.
diff --git a/scripts/mutation-register.ts b/scripts/mutation-register.ts
index 15283e31..5c866f75 100644
--- a/scripts/mutation-register.ts
+++ b/scripts/mutation-register.ts
@@ -38,8 +38,7 @@
//
// KEYED BY QUOTED EXPRESSION, NEVER BY `path:line`. A line-keyed list goes red when someone rewraps
// a comment three functions above the guarded code, and people learn to re-baseline it without
-// reading (`assertion-shape.test.ts`'s ALLOW list collided in three consecutive waves for exactly
-// this reason; `sole-definition.test.ts`, keyed by path and quoted expression, never has). An entry
+// reading. An entry
// names the expression itself. When the expression appears more than once in its file, `anchor`
// names a second quoted expression that occurs EXACTLY ONCE, and the mutated expression is its first
// occurrence after the anchor, within {@link ANCHOR_WINDOW} characters — so deleting the guarded
diff --git a/server/bunfig.toml b/server/bunfig.toml
index 94e82786..c306cbc3 100644
--- a/server/bunfig.toml
+++ b/server/bunfig.toml
@@ -8,5 +8,5 @@
# the race described in scripts/test-preload.ts.
#
# Both files name the same scripts, so their contents cannot drift. What could drift is this list, and
-# tests/bunfig-preload.test.ts fails if the two stop agreeing.
+# server/tests/bunfig-preload.test.ts fails if the two stop agreeing.
preload = ["./scripts/test-preload.ts", "../app/tests/preload.ts"]
diff --git a/server/src/plugins/broker.ts b/server/src/plugins/broker.ts
index d3382bc5..01f97059 100644
--- a/server/src/plugins/broker.ts
+++ b/server/src/plugins/broker.ts
@@ -657,8 +657,7 @@ export type ConnectedAppBroker = {
* IT PAIRS WITH {@link ConnectedAppBroker.authorizations}: a broker declaring `null` there
* answers `null` here, and a broker declaring a flow answers a non-null id on every successful
* mint. A broker that grew a flow and forgot the id would leave D24 with no source while every
- * type still checked, so `broker-authorization-pairing.test.ts` asserts the pair over every
- * broker literal in the tree.
+ * type still checked. A broker's authorization tests must verify this pairing.
*/
authorize(request: {
account: AccountRef;
diff --git a/server/src/plugins/plugin-store/context.ts b/server/src/plugins/plugin-store/context.ts
index 6f42bf0e..cec7bf72 100644
--- a/server/src/plugins/plugin-store/context.ts
+++ b/server/src/plugins/plugin-store/context.ts
@@ -1891,8 +1891,7 @@ export function createStoreContext(options: PluginStoreOptions) {
* and that order is kept rather than moved behind the revoke for the helper's convenience.
*
* Answers the payload fragment rather than the boolean so that no writer computes the field
- * itself: a writer spreads this, and the guard in `sole-definition.test.ts` holds that to one
- * home.
+ * itself: a writer spreads this to keep the claim's definition in one place.
*/
async function vendorRevocationClaim(
app: string,
diff --git a/server/src/plugins/route-groups/connections.ts b/server/src/plugins/route-groups/connections.ts
index ceff39ef..72fd2f32 100644
--- a/server/src/plugins/route-groups/connections.ts
+++ b/server/src/plugins/route-groups/connections.ts
@@ -1621,7 +1621,7 @@ export function mountConnectionRoutes({
* construction, the adapter's own refusals are ours, and {@link VendorTimeoutError} is ours.
*
* NOT AN AUDIT ROW. Nothing here writes to `pending_authorizations`, and the attempt's
- * missing trail rows are already debt in `pending-authorization-audit-ledger.test.ts`, under
+ * missing trail rows are tracked in https://github.com/CopilotKit/OpenBot/issues/876, under
* the claim and the expiry overwrite (B5e). Filing an event for this one branch while the
* claim it follows files none would put half a lifecycle on the trail.
*/
diff --git a/server/tests/agent-escalation.test.ts b/server/tests/agent-escalation.test.ts
index 8b87a412..2844575a 100644
--- a/server/tests/agent-escalation.test.ts
+++ b/server/tests/agent-escalation.test.ts
@@ -1,7 +1,6 @@
import { describe, expect, test } from "bun:test";
import {
askTheirOwnPerson,
- ESCALATE_TOOL,
escalationTool,
PUT_TO,
} from "../src/agents/escalation";
@@ -35,11 +34,6 @@ function recorder() {
}
describe("asking a person", () => {
- test("is offered to every run, granted anybody or not", () => {
- const tool = escalationTool({ from: FROM, route: askTheirOwnPerson });
- expect(tool.name).toBe(ESCALATE_TOOL);
- });
-
test("names who was reached, so the Bot can say what it did", async () => {
const tool = escalationTool({ from: FROM, route: askTheirOwnPerson });
@@ -65,19 +59,6 @@ describe("asking a person", () => {
expect(written[0]?.initiator).toEqual({ kind: "routine", id: "routine_7" });
});
- test("a run that says nothing leaves the row filed as a person's", async () => {
- const { written, store } = recorder();
- const tool = escalationTool({
- from: FROM,
- route: askTheirOwnPerson,
- auditStore: store,
- });
-
- await tool.execute({ question: "which account?" });
-
- expect(written[0]?.initiator).toBe(undefined);
- });
-
test("the question is on the record", async () => {
const { written, store } = recorder();
const tool = escalationTool({
diff --git a/server/tests/agent-handoff.test.ts b/server/tests/agent-handoff.test.ts
index 5d469b31..a3b9b62e 100644
--- a/server/tests/agent-handoff.test.ts
+++ b/server/tests/agent-handoff.test.ts
@@ -398,17 +398,6 @@ describe("handing work to another Bot", () => {
});
});
- test("a run that says nothing leaves the row filed as a person's", async () => {
- const plain = desk();
- await plain.desk.send({
- from: FROM,
- target: "researcher",
- envelope: { task: "t" },
- });
-
- expect(plain.events[0]?.initiator).toBe(undefined);
- });
-
test("both outcomes leave a row naming the run and the reason", async () => {
const allowed = desk();
await allowed.desk.send({
diff --git a/server/tests/agent-profile-policy.test.ts b/server/tests/agent-profile-policy.test.ts
index 437f5b7d..7c4568f4 100644
--- a/server/tests/agent-profile-policy.test.ts
+++ b/server/tests/agent-profile-policy.test.ts
@@ -83,8 +83,4 @@ describe("agent profile permissions", () => {
expect(canRunAgent(actor, agent)).toBe(false);
}
});
-
- test("exports canRunAgent as the canAccessAgent alias", () => {
- expect(canRunAgent).toBe(canAccessAgent);
- });
});
diff --git a/server/tests/arcade-attempt-schema.test.ts b/server/tests/arcade-attempt-schema.test.ts
deleted file mode 100644
index 5c8c0587..00000000
--- a/server/tests/arcade-attempt-schema.test.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-// server/tests/arcade-attempt-schema.test.ts
-import { afterAll, beforeAll, describe, expect, test } from "bun:test";
-import { randomUUID } from "node:crypto";
-import { sql } from "drizzle-orm";
-import { createDatabase } from "../src/db/client";
-import { mcpServers } from "../src/db/schema/plugins";
-import { TEST_POOL, testDatabaseUrl } from "./support/database";
-import { removePeople, seedPeople } from "./support/people";
-
-const database = createDatabase(testDatabaseUrl(), TEST_POOL);
-const suite = randomUUID().slice(0, 8);
-const serverId = `arcade-attempt-${suite}`;
-
-/*
- * The three actors the cases below claim under, seeded as real people because `actor_id` now carries
- * the key to `users` it always claimed in the docblock (and `user_id` is held equal to it). Named up here so
- * `afterAll` can delete them, and so the cascade takes the attempts with them.
- */
-const actors = [`live-${suite}`, `expired-${suite}`, `done-${suite}`];
-
-/** The one statement a start-attempt route issues: take the key if free, expired, or completed. */
-const claim = (actorId: string, authId: string) =>
- database.execute(sql`
- INSERT INTO pending_authorizations
- (actor_id, server_id, action, holder, user_id, vendor_user_id, auth_id)
- VALUES (${actorId}, ${serverId}, 'connect', 'person', ${actorId}, ${`v-${actorId}`}, ${authId})
- ON CONFLICT (actor_id) DO UPDATE SET
- server_id = EXCLUDED.server_id,
- action = EXCLUDED.action,
- holder = EXCLUDED.holder,
- user_id = EXCLUDED.user_id,
- vendor_user_id = EXCLUDED.vendor_user_id,
- auth_id = EXCLUDED.auth_id,
- created_at = now(),
- completed_at = NULL,
- outcome = NULL
- WHERE pending_authorizations.created_at < now() - interval '15 minutes'
- OR pending_authorizations.completed_at IS NOT NULL
- RETURNING *
- `);
-
-beforeAll(async () => {
- await seedPeople(database, actors);
- await database.insert(mcpServers).values({
- id: serverId,
- title: "Attempt schema",
- vendor: "test",
- url: "https://example.invalid/mcp",
- });
-});
-
-afterAll(async () => {
- await database.execute(sql`delete from mcp_servers where id = ${serverId}`);
- await removePeople(database, actors);
- await database.$client.close();
-});
-
-describe("pending_authorizations", () => {
- test("a second attempt for one actor is refused while the first is live", async () => {
- const actor = actors[0]!;
- expect((await claim(actor, "auth-1")).length).toBe(1);
- expect((await claim(actor, "auth-2")).length).toBe(0);
- const rows = await database.execute(
- sql`select auth_id from pending_authorizations where actor_id = ${actor}`,
- );
- expect(rows[0]?.auth_id).toBe("auth-1");
- });
-
- test("an expired attempt is replaceable in one statement", async () => {
- const actor = actors[1]!;
- expect((await claim(actor, "auth-old")).length).toBe(1);
- await database.execute(
- sql`update pending_authorizations set created_at = now() - interval '16 minutes' where actor_id = ${actor}`,
- );
- const replaced = await claim(actor, "auth-new");
- expect(replaced.length).toBe(1);
- expect(replaced[0]?.auth_id).toBe("auth-new");
- });
-
- test("a completed attempt is replaceable", async () => {
- const actor = actors[2]!;
- expect((await claim(actor, "auth-old")).length).toBe(1);
- await database.execute(
- sql`update pending_authorizations set completed_at = now(), outcome = 'completed' where actor_id = ${actor}`,
- );
- const replaced = await claim(actor, "auth-new");
- expect(replaced.length).toBe(1);
- expect(replaced[0]?.auth_id).toBe("auth-new");
- expect(replaced[0]?.completed_at).toBeNull();
- expect(replaced[0]?.outcome).toBeNull();
- });
-});
diff --git a/server/tests/arcade-live.test.ts b/server/tests/arcade-live.test.ts
index 1c16e040..9f905336 100644
--- a/server/tests/arcade-live.test.ts
+++ b/server/tests/arcade-live.test.ts
@@ -205,14 +205,6 @@ describe.skipIf(!live)("Arcade, for real", () => {
}
}, VENDOR_TIMEOUT_MS);
- test("the throwaway user id is printed before anything is created", () => {
- say(`ARCADE LIVE user id for this run: ${USER}`);
- say(
- `ARCADE LIVE toolkit measured: ${TOOLKIT}; verifier listens on :${PORT}`,
- );
- expect(Number.isInteger(PORT)).toBe(true);
- });
-
/**
* GATE 1 — WHAT `provider_id` ACTUALLY MEANS ON A GOOGLE-FAMILY TOOLKIT.
*
diff --git a/server/tests/arcade-pagination-engine.test.ts b/server/tests/arcade-pagination-engine.test.ts
index b803ac43..d13f8c3d 100644
--- a/server/tests/arcade-pagination-engine.test.ts
+++ b/server/tests/arcade-pagination-engine.test.ts
@@ -276,16 +276,6 @@ describe("the connection listing is read to its end, not to the SDK's", () => {
// NOT ONE DELETE WAS SPENT on a listing that could not be trusted to be the whole of it.
expect(deletes(e).length).toBe(0);
});
-
- test("isConnected and accountName read the whole listing", async () => {
- engine({ connections: 250, connectionTotal: false });
- const { broker } = createArcadeClient("never-dialled");
-
- expect(await broker.isConnected({ account, toolkit: "Gmail" })).toBe(true);
- expect(await broker.accountName({ account, toolkit: "Gmail" })).toBe(
- "person 0",
- );
- });
});
/**
diff --git a/server/tests/arcade-transport-registry.test.ts b/server/tests/arcade-transport-registry.test.ts
index fc19cb7d..ed5b7c8d 100644
--- a/server/tests/arcade-transport-registry.test.ts
+++ b/server/tests/arcade-transport-registry.test.ts
@@ -13,12 +13,12 @@ import { transportFor } from "../src/plugins/transport";
* unchecked `server/tests` would assert nothing. Run `bun run typecheck`.
*/
// @ts-expect-error a catalogue entry must not name the arcade broker's transport
-const arcadeIsNotCurated: CuratedTransportKind = "arcade";
+const _arcadeIsNotCurated: CuratedTransportKind = "arcade";
// @ts-expect-error nor the composio broker's
-const composioIsNotCurated: CuratedTransportKind = "composio";
-const arcadeIsAKind: TransportKind = "arcade";
+const _composioIsNotCurated: CuratedTransportKind = "composio";
+const _arcadeIsAKind: TransportKind = "arcade";
// BrokerProvider is the compiler's claim about TransportKind, not a comment's.
-const brokerIsAKind: TransportKind = "arcade" satisfies BrokerProvider;
+const _brokerIsAKind: TransportKind = "arcade" satisfies BrokerProvider;
describe("arcade transport registration", () => {
test("transportFor('arcade') is the arcade module and needs no credential", () => {
@@ -26,14 +26,4 @@ describe("arcade transport registration", () => {
expect(t).toBe(arcade as unknown as typeof t);
expect(t.listNeedsCredential).toBe(false);
});
-
- test("the kind constants are the literals", () => {
- const kinds: string[] = [
- arcadeIsNotCurated,
- composioIsNotCurated,
- arcadeIsAKind,
- brokerIsAKind,
- ];
- expect(kinds).toEqual(["arcade", "composio", "arcade", "arcade"]);
- });
});
diff --git a/server/tests/arcade-vendor-read-contract.test.ts b/server/tests/arcade-vendor-read-contract.test.ts
index 5535ddd4..87b65299 100644
--- a/server/tests/arcade-vendor-read-contract.test.ts
+++ b/server/tests/arcade-vendor-read-contract.test.ts
@@ -42,8 +42,6 @@
* say so. Editing a `want` to match what production does is the one move this file forbids.
*/
import { afterEach, describe, expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
import Arcade from "@arcadeai/arcadejs";
import { listTools, useArcadeClient } from "../src/plugins/arcade";
import { createArcadeClient } from "../src/plugins/arcade-adapter";
@@ -622,48 +620,6 @@ const KNOWN_FAIL_OPEN: Record<string, { now: string; finding: string }> = {};
// The checks.
// ---------------------------------------------------------------------------------------------
-const REPO = join(import.meta.dir, "..", "..");
-
-describe("every vendor-field reader is still where the table says", () => {
- const readers = [
- ...new Map(
- ROWS.map((r) => [`${r.reader.file}#${r.reader.name}`, r.reader]),
- ).values(),
- ];
- for (const reader of readers) {
- test(`${reader.name} is bound in ${reader.file}`, () => {
- const source = readFileSync(join(REPO, reader.file), "utf8");
- const binding = new RegExp(
- `(?:^|\\n)\\s*(?:export\\s+)?(?:async\\s+)?(?:function|const)\\s+${reader.name}\\b`,
- );
- expect(binding.test(source)).toBe(true);
- });
- }
-});
-
-describe("the debt list is honest", () => {
- test("every KNOWN_FAIL_OPEN entry names a row in the table", () => {
- const keys = new Set(ROWS.map(keyOf));
- expect(Object.keys(KNOWN_FAIL_OPEN).filter((k) => !keys.has(k))).toEqual(
- [],
- );
- });
-
- test("no debt entry records the right answer as its wrong one", () => {
- const wants = new Map(ROWS.map((r) => [keyOf(r), r.want]));
- expect(
- Object.entries(KNOWN_FAIL_OPEN)
- .filter(([key, debt]) => wants.get(key) === debt.now)
- .map(([key]) => key),
- ).toEqual([]);
- });
-
- test("row keys are unique", () => {
- const keys = ROWS.map(keyOf);
- expect(keys.length).toBe(new Set(keys).size);
- });
-});
-
describe("a vendor field this deployment cannot read fails closed", () => {
for (const row of ROWS) {
const key = keyOf(row);
diff --git a/server/tests/arcade-verifier-notice.test.ts b/server/tests/arcade-verifier-notice.test.ts
index 8e6c6eed..12a33707 100644
--- a/server/tests/arcade-verifier-notice.test.ts
+++ b/server/tests/arcade-verifier-notice.test.ts
@@ -1,14 +1,9 @@
import { describe, expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
import {
ARCADE_VERIFY_PATH,
arcadeVerifierNotice,
} from "../src/plugins/provider-wiring";
-const source = (path: string) =>
- readFileSync(join(import.meta.dir, "..", "src", path), "utf8");
-
/**
* Arcade's verifier setting cannot be read back, so an Arcade deployment warns at startup with the
* exact address its project's custom verifier must be set to.
@@ -36,24 +31,4 @@ describe("arcadeVerifierNotice", () => {
expect(notice).toContain("OPENBOT_PUBLIC_URL");
expect(notice).not.toContain("undefined");
});
-
- /*
- * The path in the notice is a copy of where the route is actually mounted, so it is held to it:
- * plugin routes under `/api/plugins` in app.ts, the verify route as `/arcade/verify` on them.
- */
- test("the path it names is the one the verify route is served at", () => {
- expect(ARCADE_VERIFY_PATH).toBe("/api/plugins/arcade/verify");
- expect(source("app.ts")).toMatch(
- /app\.route\(\s*"\/api\/plugins",\s*createPluginRoutes\(/,
- );
- expect(source("plugins/route-groups/connections.ts")).toContain(
- 'routes.get("/arcade/verify"',
- );
- });
-
- test("startup prints it whenever Arcade is the wired provider", () => {
- expect(source("index.ts")).toMatch(
- /if \(wiredProvider === "arcade"\) \{\s*console\.warn\(arcadeVerifierNotice\(config\.publicUrl\)\);/,
- );
- });
});
diff --git a/server/tests/assertion-shape.test.ts b/server/tests/assertion-shape.test.ts
index b8e56bdf..66b74bfa 100644
--- a/server/tests/assertion-shape.test.ts
+++ b/server/tests/assertion-shape.test.ts
@@ -78,6 +78,8 @@ export type Offence = {
line: number;
shape: Shape;
text: string;
+ expression: string;
+ context: string[];
};
function blankLiterals(text: string): string {
@@ -211,10 +213,48 @@ const UNDEFINED_PASSES = /^(?:toBeUndefined|toBeFalsy|toBeNil|toBeNullish)$/;
type Range = { start: number; end: number };
+/** Ignore formatting outside literals; literal contents remain part of the identity. */
+function expressionIdentity(source: string): string {
+ return source.replace(
+ /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|\s+/g,
+ (_match, literal: string | undefined) => literal ?? "",
+ );
+}
+
export function offencesIn(file: string, source: string): Offence[] {
const stripped = stripComments(source);
const code = blankLiterals(stripped);
const found: Offence[] = [];
+ // Include the enclosing test/describe names so identical assertions in sibling tests
+ // remain distinct. Neither the name nor the expression depends on its source line.
+ const contexts: { start: number; end: number; name: string }[] = [];
+ for (const match of code.matchAll(
+ /(?<![.\w$])(?:describe|test|it)(?:\s*\.\s*\w+)*\s*\(/g,
+ )) {
+ let open = match.index + match[0].length - 1;
+ let end = closerOf(code, open);
+ if (end < 0) continue;
+ let next = end + 1;
+ while (/\s/.test(code[next] ?? "") && next < code.length) next++;
+ if (code[next] === "(") {
+ open = next;
+ end = closerOf(code, open);
+ if (end < 0) continue;
+ }
+ const first = topLevelArgs(code.slice(open + 1, end))[0];
+ const leading =
+ code.slice(open + 1, end).length -
+ code.slice(open + 1, end).trimStart().length;
+ // The blanked first argument can be a quoted literal or a computed test name.
+ const nameStart = open + 1 + leading;
+ contexts.push({
+ start: match.index,
+ end,
+ name: expressionIdentity(
+ stripped.slice(nameStart, nameStart + first.length),
+ ),
+ });
+ }
// The logical line an offence sits in, for the message: a wrapped expression reads as one.
const joined = logicalLines(stripped);
const quote = (line: number) => {
@@ -225,9 +265,20 @@ export function offencesIn(file: string, source: string): Offence[] {
}
return best.trim().replace(/\s+/g, " ").slice(0, 110);
};
- const at = (index: number, shape: Shape) => {
+ const at = (index: number, shape: Shape, expressionStart = index) => {
const line = lineOf(code, index);
- found.push({ file, line, shape, text: quote(line) });
+ found.push({
+ file,
+ line,
+ shape,
+ text: quote(line),
+ expression: expressionIdentity(
+ stripped.slice(expressionStart, statementEnd(code, expressionStart)),
+ ),
+ context: contexts
+ .filter((c) => c.start <= index && c.end >= index)
+ .map((c) => c.name),
+ });
};
const expects: { index: number; open: number; close: number }[] = [];
@@ -248,7 +299,7 @@ export function offencesIn(file: string, source: string): Offence[] {
const prefix = head.slice(0, own);
if (/\b(?:await|return|yield)\b/.test(prefix)) continue;
if (/=>\s*$/.test(prefix)) continue;
- at(start + (head.length - head.trimStart().length), "a");
+ at(start + (head.length - head.trimStart().length), "a", start + own);
}
// (b) `?.` in the subject, under a matcher `undefined` satisfies
@@ -279,8 +330,14 @@ export function offencesIn(file: string, source: string): Offence[] {
const open = (m.index as number) + m[0].length - 1;
const close = closerOf(code, open);
if (close < 0) continue;
- if (/:\s*undefined\s*[,}]/.test(code.slice(open + 1, close)))
- at(m.index as number, "c");
+ if (/:\s*undefined\s*[,}]/.test(code.slice(open + 1, close))) {
+ const subject = expects.findLast(
+ (e) =>
+ e.close < m.index &&
+ /^[\s.\w]*$/.test(code.slice(e.close + 1, m.index)),
+ );
+ at(m.index, "c", subject?.index ?? m.index);
+ }
}
// guarded regions: the statement an `if` controls
@@ -418,19 +475,20 @@ export function scanTree(root: string, from = root): Offence[] {
*
* One ground covers every entry below and no other ground is accepted: the offence predates this
* guard, so it is fix-cycle work rather than a licence. `finding` names the review that found it,
- * or marks it as one this scan turned up that the review rounds did not. `why` quotes the
- * expression, so an entry can be read without opening the file.
+ * or marks it as one this scan turned up that the review rounds did not. `expression` quotes the full
+ * expression, and `context` names its enclosing tests. Formatting and line shifts do not change
+ * that identity; an assertion in a different test is never grandfathered by it.
*/
type Allowed = {
file: string;
- line: number;
+ expression: string;
+ context: string[];
shape: Shape;
finding: string;
- why: string;
};
-const key = (o: { file: string; line: number; shape: Shape }) =>
- `${o.file}:${o.line}:${o.shape}`;
+const key = (o: Pick<Offence, "file" | "shape" | "context" | "expression">) =>
+ JSON.stringify([o.file, o.shape, o.context, o.expression]);
/**
* THE STANDING OFFENDERS, as of the commit that added this file.
@@ -450,505 +508,686 @@ const key = (o: { file: string; line: number; shape: Shape }) =>
const ALLOW: Allowed[] = [
{
file: "app/tests/auth-client.test.ts",
- line: 83,
shape: "a",
+ context: ['"signInWith"', '"throws what the client said when it refuses"'],
+ expression:
+ 'expect(signInWith("okta",refuse)).rejects.toThrow("That provider is not configured.",)',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'expect(signInWith("okta", refuse)).rejects.toThrow( "That provider is not configured.", );',
},
{
file: "app/tests/auth-client.test.ts",
- line: 97,
shape: "a",
+ context: [
+ '"signInWith"',
+ '"names the provider when the client says nothing"',
+ ],
+ expression:
+ 'expect(signInWith("microsoft",refuse)).rejects.toThrow("Microsoft")',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'test("names the provider when the client says nothing", async () => { const refuse = async () => ({ error: {} ',
},
{
file: "app/tests/auth-client.test.ts",
- line: 101,
shape: "a",
+ context: [
+ '"signInWith"',
+ '"resolves quietly when the redirect is under way"',
+ ],
+ expression:
+ 'expect(signInWith("google",async()=>({error:null})),).resolves.toBeUndefined()',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'test("resolves quietly when the redirect is under way", async () => { expect( signInWith("google", async () =>',
},
{
file: "app/tests/auth-client.test.ts",
- line: 162,
shape: "a",
+ context: [
+ '"signInWithEmailDomain"',
+ '"throws what the client said when it refuses"',
+ ],
+ expression:
+ 'expect(signInWithEmailDomain("[email protected]",refuse),).rejects.toThrow("That domain is registered to another tenant.")',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'expect( signInWithEmailDomain("[email protected]", refuse), ).rejects.toThrow("That domain is registered to ',
},
{
file: "app/tests/auth-client.test.ts",
- line: 170,
shape: "a",
+ context: [
+ '"signInWithEmailDomain"',
+ '"says no provider is registered when the client says nothing"',
+ ],
+ expression:
+ 'expect(signInWithEmailDomain("[email protected]",refuse),).rejects.toThrow("No identity provider is registered for that address.")',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'test("says no provider is registered when the client says nothing", async () => { const refuse = async () => (',
},
{
file: "app/tests/auth-client.test.ts",
- line: 176,
shape: "a",
+ context: [
+ '"signInWithEmailDomain"',
+ '"resolves quietly when the redirect is under way"',
+ ],
+ expression:
+ 'expect(signInWithEmailDomain("[email protected]",async()=>({error:null,})),).resolves.toBeUndefined()',
finding: "round 2 — auth-client.test.ts, six sites",
- why: 'test("resolves quietly when the redirect is under way", async () => { expect( signInWithEmailDomain("someone@c',
},
{
file: "server/tests/audit-initiator.integration.test.ts",
- line: 291,
shape: "a",
+ context: [
+ '"what started a run"',
+ '"the trail stays append-only, so a row cannot be re-attributed later"',
+ ],
+ expression: "expect(reattribute()).rejects.toThrow()",
finding: "NEW (round 2 did not find this)",
- why: "expect(reattribute()).rejects.toThrow();",
},
{
file: "server/tests/component-store.integration.test.ts",
- line: 149,
shape: "a",
+ context: [
+ '"withholding"',
+ '"withholding a component that does not exist is an error, not a silent row"',
+ ],
+ expression:
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: This is the literal source expression being identified.
+ 'expect(store.revoke(`nothing_${suite}`,botA,"[email protected]"),).rejects.toThrow(ComponentNotFoundError)',
finding: "NEW (round 2 did not find this)",
- why: 'test("withholding a component that does not exist is an error, not a silent row", async () => { expect( store.',
},
{
file: "server/tests/component-store.integration.test.ts",
- line: 372,
shape: "a",
+ context: [
+ '"what a component may read"',
+ '"revoking from a component that does not exist is an error, not a silent no-op"',
+ ],
+ expression:
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: This is the literal source expression being identified.
+ "expect(store.revokeFunction(`nothing_${suite}`,fn)).rejects.toThrow(ComponentNotFoundError,)",
finding: "NEW (round 2 did not find this)",
- why: 'test("revoking from a component that does not exist is an error, not a silent no-op", async () => { expect(sto',
},
{
file: "server/tests/component-store.integration.test.ts",
- line: 404,
shape: "a",
+ context: [
+ '"what a component may read"',
+ '"a function this build does not ship cannot be run"',
+ ],
+ expression:
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: This is the literal source expression being identified.
+ "expect(store.callFunction(`nothing_${suite}`,{})).rejects.toThrow()",
finding: "NEW (round 2 did not find this)",
- why: 'test("a function this build does not ship cannot be run", async () => { expect(store.callFunction(`nothing_${s',
},
{
file: "server/tests/computer-client.test.ts",
- line: 263,
shape: "a",
+ context: [
+ '"acting on an element that is not there"',
+ '"is its own condition, not an unavailable computer"',
+ ],
+ expression:
+ 'expect(timingOut().click({ref:"e5",snapshotId:1}),).rejects.toBeInstanceOf(ElementNotFoundError)',
finding: "NEW (round 2 did not find this)",
- why: 'test("is its own condition, not an unavailable computer", async () => { expect( timingOut().click({ ref: "e5",',
},
{
file: "server/tests/computer-client.test.ts",
- line: 305,
shape: "a",
+ context: [
+ '"a 409 from the computer"',
+ '"is a person holding the wheel when the computer says so"',
+ ],
+ expression:
+ 'expect(refusing({error:"A person has taken control of this computer.",humanHasControl:true,}).click({ref:"e1",snapshotId:1}),).rejects.toBeInstanceOf(HumanHasControlError)',
finding: "NEW (round 2 did not find this)",
- why: 'test("is a person holding the wheel when the computer says so", async () => { expect( refusing({ error: "A per',
},
{
file: "server/tests/computer-client.test.ts",
- line: 316,
shape: "a",
+ context: [
+ '"a 409 from the computer"',
+ '"is a stale snapshot when it does not"',
+ ],
+ expression:
+ 'expect(refusing({error:"Snapshot 3 is not the current one."}).click({ref:"e1",snapshotId:1,}),).rejects.toBeInstanceOf(StaleSnapshotError)',
finding: "NEW (round 2 did not find this)",
- why: 'test("is a stale snapshot when it does not", async () => { expect( refusing({ error: "Snapshot 3 is not the cu',
},
{
file: "server/tests/computer-client.test.ts",
- line: 334,
shape: "a",
+ context: [
+ '"a 409 from the computer"',
+ '"is a stale snapshot for every shape that is not the flag"',
+ ],
+ expression:
+ 'expect(refusing(body).click({ref:"e1",snapshotId:1}),).rejects.toBeInstanceOf(StaleSnapshotError)',
finding: "NEW (round 2 did not find this)",
- why: 'expect( refusing(body).click({ ref: "e1", snapshotId: 1 }), ).rejects.toBeInstanceOf(StaleSnapshotError);',
},
{
file: "server/tests/computer-client.test.ts",
- line: 342,
shape: "a",
+ context: [
+ '"a 409 from the computer"',
+ '"a 409 with no body at all is still a refusal, not a crash"',
+ ],
+ expression:
+ 'expect(bodyless.click({ref:"e1",snapshotId:1})).rejects.toBeInstanceOf(StaleSnapshotError,)',
finding: "NEW (round 2 did not find this)",
- why: 'test("a 409 with no body at all is still a refusal, not a crash", async () => { const bodyless = clientWith(()',
},
{
file: "server/tests/computer-supervisor.test.ts",
- line: 65,
shape: "a",
+ context: [
+ '"locating a Bot\'s computer"',
+ '"a computer with no address at all is an error, not a fallback"',
+ ],
+ expression:
+ 'expect(client.locate("sales")).rejects.toThrow(SupervisorError)',
finding: "NEW (round 2 did not find this)",
- why: 'expect(client.locate("sales")).rejects.toThrow(SupervisorError);',
},
{
file: "server/tests/computer-supervisor.test.ts",
- line: 75,
shape: "a",
+ context: [
+ '"locating a Bot\'s computer"',
+ '"a refusal from the supervisor is reported in its own words"',
+ ],
+ expression:
+ 'expect(client.locate("bad id")).rejects.toThrow("A bot id may contain only letters.",)',
finding: "NEW (round 2 did not find this)",
- why: 'expect(client.locate("bad id")).rejects.toThrow( "A bot id may contain only letters.", );',
},
{
file: "server/tests/computer-supervisor.test.ts",
- line: 89,
shape: "a",
+ context: [
+ '"locating a Bot\'s computer"',
+ '"an unreachable supervisor says so, rather than looking like a broken computer"',
+ ],
+ expression:
+ 'expect(client.locate("sales")).rejects.toThrow(/couldnotbereached/)',
finding: "NEW (round 2 did not find this)",
- why: 'expect(client.locate("sales")).rejects.toThrow(/could not be reached/);',
},
{
file: "server/tests/people-last-sign-in.integration.test.ts",
- line: 127,
shape: "a",
+ context: [
+ '"when somebody was last here"',
+ '"a stamp that cannot be written does not refuse the sign-in"',
+ ],
+ expression:
+ 'expect(stampSignIn(broken,"anybody",SIGNED_IN_AT),).resolves.toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect( stampSignIn(broken, "anybody", SIGNED_IN_AT), ).resolves.toBeUndefined();',
},
{
file: "server/tests/plugin-user-credential.integration.test.ts",
- line: 369,
shape: "a",
+ context: [
+ '"a person who has not connected"',
+ '"is refused, and told to connect rather than told it broke"',
+ ],
+ expression:
+ "expect(store.callTool({ref,args:{},botId,actorId:askerId}),).rejects.toThrow(PluginRefusedError)",
finding: "round 2 — plugin-user-credential.integration.test.ts:361",
- why: 'describe("a person who has not connected", () => { test("is refused, and told to connect rather than told it b',
},
{
file: "app/tests/bot-setup.test.tsx",
- line: 178,
shape: "b",
+ context: [
+ '"a built-in coworker can be renamed on a deployment whose own Bot lives on localhost"',
+ ],
+ expression: "expect(updates[0]?.endpoint).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(updates[0]?.endpoint).toBeUndefined();",
},
{
file: "app/tests/voice-archive.test.ts",
- line: 98,
shape: "b",
+ context: [
+ '"a busy summary response retains the server\'s durable transcript instead of marking it unsaved"',
+ ],
+ expression: "expect(records[0]?.saveState).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(records[0]?.saveState).toBeUndefined();",
},
{
file: "app/tests/voice-archive.test.ts",
- line: 149,
shape: "b",
+ context: [
+ '"save failure remains retryable with the same session id and original transcript"',
+ ],
+ expression:
+ 'expect((awaitloadVoiceArchive("channel-1"))[0]?.saveState).toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect((await loadVoiceArchive("channel-1"))[0]?.saveState).toBeUndefined();',
},
{
file: "server/tests/agent-endpoint.test.ts",
- line: 498,
- shape: "b",
- finding: "NEW (round 2 did not find this)",
- why: "expect(forwarded.forwardedProps?.openbotRun).toBeUndefined();",
- },
- {
- file: "server/tests/agent-escalation.test.ts",
- line: 78,
- shape: "b",
- finding: "NEW (round 2 did not find this)",
- why: "expect(written[0]?.initiator).toBe(undefined);",
- },
- {
- file: "server/tests/agent-handoff.test.ts",
- // Moved from 366 by the work-list change, which added tests above it; the offence is the same one and
- // is re-keyed rather than re-found.
- line: 409,
shape: "b",
+ context: [
+ '"dialling a stored agent endpoint"',
+ '"a hop to another host does not take the signed run with it"',
+ ],
+ expression: "expect(forwarded.forwardedProps?.openbotRun).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(plain.events[0]?.initiator).toBe(undefined);",
},
{
file: "server/tests/approvals-interactive.integration.test.ts",
- line: 229,
shape: "b",
+ context: [
+ '"a click from a person\'s own chat waits, runs once on allow once, and is never repeated"',
+ ],
+ expression: "expect(continued[0]?.error).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(continued[0]?.error).toBeUndefined();",
},
{
file: "server/tests/approvals-policy.test.ts",
- line: 779,
shape: "b",
+ context: [
+ '"delegation is gated"',
+ '"an approved hand-off is re-checked, sent once, and its answer continues the conversation"',
+ ],
+ expression: "expect(continued[0]?.error).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(continued[0]?.error).toBeUndefined();",
},
{
file: "server/tests/arcade-adapter-errors.test.ts",
- line: 63,
shape: "b",
+ context: [
+ '"normalizeArcadeError"',
+ '"a connection failure keeps status undefined"',
+ ],
+ expression:
+ 'expect(normalizeArcadeError(newAPIConnectionError({message:"down"}))?.status,).toBeUndefined()',
finding: "round 2 — arcade-adapter-errors.test.ts:62-66",
- why: 'test("a connection failure keeps status undefined", () => { expect( normalizeArcadeError(new APIConnectionErro',
},
{
file: "server/tests/arcade-sibling-collateral.test.ts",
- line: 417,
shape: "b",
+ context: [
+ '"offboarding a person"',
+ '"records a sibling app as revoked, naming the app whose revoke ended it"',
+ ],
+ expression: "expect(row(t.gmail)?.payload.endedWith).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(row(t.gmail)?.payload.endedWith).toBeUndefined();",
},
{
file: "server/tests/arcade-sibling-collateral.test.ts",
- line: 421,
shape: "b",
+ context: [
+ '"offboarding a person"',
+ '"records a sibling app as revoked, naming the app whose revoke ended it"',
+ ],
+ expression: "expect(row(t.slack)?.payload.endedWith).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(row(t.slack)?.payload.endedWith).toBeUndefined();",
},
{
file: "server/tests/audit-export.test.ts",
- line: 181,
shape: "b",
+ context: [
+ '"readAuditExportRows"',
+ '"walks every matching page and drops the list\'s own paging"',
+ ],
+ expression: "expect(seen[0]?.cursor).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(seen[0]?.cursor).toBeUndefined();",
},
{
file: "server/tests/computer-gateway.test.ts",
- line: 381,
shape: "b",
+ context: [
+ '"the computer gateway"',
+ '"the local development actor is kept out of the audit foreign key"',
+ ],
+ expression: "expect(rows[0]?.actorUserId).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(rows[0]?.actorUserId).toBeUndefined();",
},
{
file: "server/tests/computer-gateway.test.ts",
- line: 443,
shape: "b",
+ context: [
+ '"the computer gateway"',
+ '"a permitted command runs and is recorded by command, never by output"',
+ ],
+ expression: "expect(rows[0]?.payload.element).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(rows[0]?.payload.element).toBeUndefined();",
},
{
file: "server/tests/computer-gateway.test.ts",
- line: 646,
shape: "b",
+ context: [
+ '"the computer gateway"',
+ '"an action that never named an element records no element"',
+ ],
+ expression: "expect(rows.at(-1)?.payload.element).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(rows.at(-1)?.payload.element).toBeUndefined();",
},
{
file: "server/tests/computer-provider.test.ts",
- line: 356,
shape: "b",
+ context: [
+ '"shared computer provider"',
+ '"answers undefined when the computer cannot say, rather than throwing"',
+ ],
+ expression: 'expect(awaitprovider.sessionOf?.("sales")).toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect(await provider.sessionOf?.("sales")).toBeUndefined();',
},
{
file: "server/tests/computer-provider.test.ts",
- line: 365,
shape: "b",
+ context: [
+ '"shared computer provider"',
+ '"answers undefined when the computer answers without one"',
+ ],
+ expression: 'expect(awaitprovider.sessionOf?.("sales")).toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect(await provider.sessionOf?.("sales")).toBeUndefined();',
},
{
file: "server/tests/computer-sandbox.test.ts",
- line: 79,
shape: "b",
+ context: [
+ '"telling one run of a Bot\'s computer from the next"',
+ '"a suspended computer has no run to name"',
+ ],
+ expression:
+ 'expect(awaitproviderWith(suspended).sessionOf?.("knowledge"),).toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect( await providerWith(suspended).sessionOf?.("knowledge"), ).toBeUndefined();',
},
{
file: "server/tests/headless-components.integration.test.ts",
- line: 350,
shape: "b",
+ context: [
+ '"an unattended routine turn answering with a governed chart"',
+ '"a grant revoked after the turn started is refused at call time"',
+ ],
+ expression: "expect(bar?.hidden).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(bar?.hidden).toBeUndefined();",
},
{
file: "server/tests/headless-components.test.ts",
- line: 202,
shape: "b",
+ context: [
+ '"headless component tools"',
+ '"a held chart is offered with its published description and records a confirmation"',
+ ],
+ expression: "expect(bar?.hidden).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(bar?.hidden).toBeUndefined();",
},
{
file: "server/tests/identity-retire.integration.test.ts",
- line: 124,
shape: "b",
+ context: [
+ '"retiring a removed person\'s links revokes their tokens and keeps the rows"',
+ ],
+ expression: "expect(audit.rows[0]?.actorUserId).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(audit.rows[0]?.actorUserId).toBeUndefined();",
},
{
file: "server/tests/identity-retire.integration.test.ts",
- line: 247,
shape: "b",
+ context: [
+ '"a directory remover is recorded in the payload only, never as the acting user"',
+ ],
+ expression: "expect(audit.rows[0]?.actorUserId).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(audit.rows[0]?.actorUserId).toBeUndefined();",
},
{
file: "server/tests/mcp-listing.test.ts",
- line: 168,
shape: "b",
+ context: [
+ '"what an MCP listing tells the classifier"',
+ '"a vendor\'s read-only claim records nothing at all"',
+ ],
+ expression: "expect(fetch?.effect).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(fetch?.effect).toBeUndefined();",
},
{
file: "server/tests/mcp-listing.test.ts",
- line: 179,
shape: "b",
+ context: [
+ '"what an MCP listing tells the classifier"',
+ '"a tool with no annotations is unchanged in every respect"',
+ ],
+ expression: "expect(search?.effect).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(search?.effect).toBeUndefined();",
},
{
file: "server/tests/mcp-listing.test.ts",
- line: 180,
shape: "b",
+ context: [
+ '"what an MCP listing tells the classifier"',
+ '"a tool with no annotations is unchanged in every respect"',
+ ],
+ expression: "expect(search?.destructive).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(search?.destructive).toBeUndefined();",
},
{
file: "server/tests/picked-harness-auth.test.ts",
- line: 290,
shape: "b",
+ context: [
+ '"a plan\'s installed picked harness authenticates without advertising a bundled Bot"',
+ ],
+ expression: "expect(result.config.managedAgent?.endpoint).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: 'test("a plan\'s installed picked harness authenticates without advertising a bundled Bot", async () => { const ',
},
{
file: "server/tests/picked-harness-auth.test.ts",
- line: 355,
shape: "b",
+ context: [
+ '"the default package\'s case-only picked URL authenticates through the real HTTP client"',
+ ],
+ expression: "expect(result.config.managedAgent?.endpoint).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(result.config.managedAgent?.endpoint).toBeUndefined();",
},
{
file: "server/tests/plugin-catalogue.test.ts",
- line: 210,
shape: "b",
+ context: ['"Notion"', '"is in the catalogue with the MCP transport"'],
+ expression: "expect(entry?.transport).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(entry?.transport).toBeUndefined();",
},
{
file: "server/tests/shared-computer-run.integration.test.ts",
- line: 264,
shape: "b",
+ context: [
+ '"a Bot on the one shared computer, against the table"',
+ '"a computer that cannot say which run it is on leaves the row unordered, not refused"',
+ ],
+ expression:
+ 'expect((awaitsnapshots.load("bot-1"))?.session).toBeUndefined()',
finding: "NEW (round 2 did not find this)",
- why: 'expect((await snapshots.load("bot-1"))?.session).toBeUndefined();',
},
{
file: "server/tests/tenant-package.test.ts",
- line: 372,
shape: "b",
+ context: [
+ '"tenant YAML validation"',
+ '"parses an explicit avatar seed and leaves an omitted seed undefined"',
+ ],
+ expression: "expect(tenantPackage.agents[1]?.avatarSeed).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(tenantPackage.agents[1]?.avatarSeed).toBeUndefined();",
},
{
file: "server/tests/tool-selection.integration.test.ts",
- line: 868,
shape: "b",
+ context: [
+ '"a remote Mastra Bot"',
+ '"keeps only authoritative OpenBot governance through the runtime clone and native Mastra request"',
+ ],
+ expression: "expect(run?.forwardedProps?.openbotRun).toBeUndefined()",
finding: "NEW (round 2 did not find this)",
- why: "expect(run?.forwardedProps?.openbotRun).toBeUndefined();",
},
{
file: "app/tests/user-preferences.test.tsx",
- line: 75,
shape: "c",
+ context: [
+ '"loads preferences from the account and renders the saved emphasis"',
+ ],
+ expression:
+ 'expect(requests).toEqual([{path:"/api/settings/preferences",method:"GET",body:undefined},])',
finding: "NEW (round 2 did not find this)",
- why: 'test("loads preferences from the account and renders the saved emphasis", async () => { const { view } = setup',
},
{
file: "server/tests/agent-handoff.test.ts",
- // Moved from 620 by the work-list change, which added tests above it; the offence is the same one and
- // is re-keyed rather than re-found.
- line: 663,
shape: "c",
+ context: [
+ '"the same ask a second time"',
+ '"is refused plainly rather than reported as handed over"',
+ ],
+ expression:
+ 'expect(twice.events.map((event)=>({eventType:event.eventType,reason:(event.payloadas{reason?:string}).reason,})),).toEqual([{eventType:"agent.handoff_offered",reason:undefined},{eventType:"agent.handoff_refused",reason:"duplicate"},])',
finding: "NEW (round 2 did not find this)",
- why: ').toEqual([ { eventType: "agent.handoff_offered", reason: undefined }, { eventType: "agent.handoff_refused", r',
},
{
file: "server/tests/agent-test-connection-headers.test.ts",
- line: 12,
shape: "c",
+ context: ['"parseConnectionHeaders"', '"absent headers stay absent"'],
+ expression:
+ "expect(parseConnectionHeaders(undefined)).toEqual({ok:true,value:undefined,})",
finding: "NEW (round 2 did not find this)",
- why: 'describe("parseConnectionHeaders", () => { test("absent headers stay absent", () => { expect(parseConnectionHe',
},
{
file: "server/tests/arcade-adapter-errors.test.ts",
- line: 55,
shape: "c",
+ context: [
+ '"normalizeArcadeError"',
+ '"an error with no body leaves name and message undefined"',
+ ],
+ expression:
+ "expect(normalizeArcadeError(newAPIError(500,undefined,undefined,newHeaders()),),).toEqual({status:500,name:undefined,message:undefined,})",
finding: "round 2 — arcade-adapter-errors.test.ts:50-60",
- why: ").toEqual({",
},
{
file: "server/tests/composio-adapter.test.ts",
- // Moved from 5412 by OB-05, which added fifteen lines of tests above it, then back three by the
- // Plugins screen, which shortened a test above it; the offence is the same one and is re-keyed
- // rather than re-found.
- line: 5424,
shape: "c",
+ context: [
+ '"an action that publishes no description, schema or version is still listed"',
+ ],
+ expression:
+ 'expect(awaitactions.listActions("gmail",{limit:WHOLE_LISTING}),).toEqual([{slug:"GMAIL_FETCH_EMAILS",description:undefined,inputParameters:undefined,tags:undefined,version:undefined,},])',
finding: "NEW (round 2 did not find this)",
- why: 'expect( await actions.listActions("gmail", { limit: WHOLE_LISTING }), ).toEqual([ { slug: "GMAIL_FETCH_EMAILS"',
},
{
file: "server/tests/composio-adapter.test.ts",
- // Moved from 5458 by OB-05, which added fifteen lines of tests above it, then back three by the
- // Plugins screen, which shortened a test above it; the offence is the same one and is re-keyed
- // rather than re-found.
- line: 5470,
shape: "c",
+ context: [
+ '"an action whose description, schema or version is null is still listed"',
+ ],
+ expression:
+ 'expect(awaitactions.listActions("gmail",{limit:WHOLE_LISTING}),).toEqual([{slug:"GMAIL_FETCH_EMAILS",description:undefined,inputParameters:undefined,tags:undefined,version:undefined,},])',
finding: "NEW (round 2 did not find this)",
- why: 'expect( await actions.listActions("gmail", { limit: WHOLE_LISTING }), ).toEqual([ { slug: "GMAIL_FETCH_EMAILS"',
},
{
file: "server/tests/computer-gateway.test.ts",
- line: 808,
shape: "c",
+ context: [
+ '"the computer gateway"',
+ "\"computers maps provider status 'running' and 'stopped' directly and preserves egress distinctions\"",
+ ],
+ expression:
+ 'expect(result).toEqual({isolation:"per-bot",computers:[{botId:"bot-proxied",running:true,startedAt:"2026-08-20T12:00:00.000Z",egress:"198.51.100.42",},{botId:"bot-direct",running:false,startedAt:"2026-08-20T11:00:00.000Z",egress:null,},{botId:"bot-unknown-egress",running:false,startedAt:"2026-08-20T10:00:00.000Z",egress:undefined,},],})',
finding: "NEW (round 2 did not find this)",
- why: 'expect(result).toEqual({ isolation: "per-bot", computers: [ { botId: "bot-proxied",',
},
{
file: "server/tests/demonstrations.test.ts",
- line: 294,
shape: "c",
+ context: [
+ '"scheduling creates a routine for the recording\'s own Bot through the routine store"',
+ ],
+ expression:
+ 'expect(created).toEqual([{ownerUserId:"owner",agentId:"bot",instruction:demonstrationRoutineInstruction({title:"Find invoice",slug:"find-invoice",}),cron:"0 9 * * 1-5",timezone:undefined,channelId:undefined,},])',
finding: "NEW (round 2 did not find this)",
- why: 'expect(created).toEqual([ { ownerUserId: "owner", agentId: "bot", instruction: demonstrationRoutineInstruction',
},
{
file: "server/tests/routine-runner.test.ts",
- // Moved from 169 by the work-list change, which added tests above it; the offence is the same one and
- // is re-keyed rather than re-found.
- line: 185,
shape: "c",
+ context: [
+ '"createRoutineRunner"',
+ '"runs the owner\'s thread and records the reply exactly once"',
+ ],
+ expression:
+ 'expect(recorded.finished).toEqual([{runId:RUN_ID,status:"succeeded",error:undefined},])',
finding: "NEW (round 2 did not find this)",
- why: 'expect(recorded.finished).toEqual([ { runId: RUN_ID, status: "succeeded", error: undefined }, ]);',
},
{
file: "server/tests/routine-runner.test.ts",
- // Moved from 272 by the work-list change, which added tests above it; the offence is the same one and
- // is re-keyed rather than re-found.
- line: 289,
shape: "c",
+ context: [
+ '"createRoutineRunner"',
+ '"keeps a succeeded run recorded when the channel cannot be written to"',
+ ],
+ expression:
+ 'expect(recorded.finished).toEqual([{runId:RUN_ID,status:"succeeded",error:undefined},])',
finding: "NEW (round 2 did not find this)",
- why: 'expect(recorded.finished).toEqual([ { runId: RUN_ID, status: "succeeded", error: undefined }, ]);',
},
{
file: "app/tests/connected-accounts-authorized-notice.test.tsx",
- line: 104,
shape: "d",
+ context: [
+ '"what ?authorized=%s answers is a sentence or nothing, never a function or an object"',
+ ],
+ expression:
+ 'test.each(["no-attempt","toString","constructor","__proto__","something-somebody-made-up",])("what ?authorized=%s answers is a sentence or nothing, never a function or an object",(value)=>{constnotice=authorizationNoticeFor(value);if(notice!==null)expect(typeofnotice).toBe("string");},)',
finding: "round 2 — connected-accounts-authorized-notice.test.tsx:103-115",
- why: 'test.each([ "no-attempt", "toString", "constructor", "__proto__",',
},
{
file: "app/tests/connected-account-grants.test.tsx",
- line: 126,
shape: "e",
+ context: [],
+ expression: "constsiblingReads:string[]=[]",
finding: "NEW (round 2 did not find this)",
- why: "const siblingReads: string[] = [];",
},
- /*
- * `server/tests/arcade-attempt-store.integration.test.ts:81` — `const actors: string[] = []`,
- * written and never read — is GONE rather than renumbered. The list it collects is now read by
- * the `removePeople` in that file's `afterAll`: `pending_authorizations.actor_id` keys to `users`
- * and cascades, so the ids the suite invents are people it has to create and then take away, and
- * the collection that was decorative is now what the cleanup runs on.
- */
{
file: "server/tests/arcade-disconnect-cascade.test.ts",
- // Moved from 36 by round 2's A5 fix, which added three tests above it; the offence is the
- // same one and is re-keyed rather than re-found.
- line: 39,
shape: "e",
+ context: [],
+ expression: "constrevoked:string[]=[]",
finding: "round 2 — arcade-disconnect-cascade.test.ts:36,60",
- why: "const revoked: string[] = [];",
},
{
file: "server/tests/arcade-grants-route.test.ts",
- line: 139,
shape: "e",
+ context: [],
+ expression: "consttoolkits:string[]=[]",
finding: "NEW (round 2 did not find this)",
- why: "const toolkits: string[] = [];",
},
{
file: "server/tests/arcade-grants-route.test.ts",
- line: 140,
shape: "e",
+ context: [],
+ expression: "constviewers:string[]=[]",
finding: "NEW (round 2 did not find this)",
- why: "const viewers: string[] = [];",
},
{
file: "server/tests/enterprise-controls.integration.test.ts",
- line: 61,
shape: "e",
+ context: [],
+ expression: "conststopped:string[]=[]",
finding: "NEW (round 2 did not find this)",
- why: "const stopped: string[] = []; is pushed to at :68, cleared at :723 and read nowhere; the `.stopped` at :709 and :725 is the response's own field",
},
{
file: "server/tests/arcade-vendor-error-engine.test.ts",
- line: 186,
shape: "f",
+ context: [
+ '"a refusal from Arcade is an Error this deployment wrote"',
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: This is the literal source expression being identified.
+ "`${door} throws an Error carrying no vendor words`",
+ ],
+ expression: "JSON.stringify(thrown,Object.keys(thrownasobject)),",
finding: "round 2 — arcade-vendor-error-engine.test.ts:174",
- why: 'expect( JSON.stringify(thrown, Object.keys(thrown as object)), ).not.toContain("SECRET-BEARER");',
},
];
+/** Consume each allowance once: a second copy in the same test is still a new offence. */
+function unmatched<
+ T extends Pick<Offence, "file" | "shape" | "context" | "expression">,
+>(
+ candidates: T[],
+ baseline: Pick<Offence, "file" | "shape" | "context" | "expression">[],
+): T[] {
+ const remaining = new Map<string, number>();
+ for (const entry of baseline)
+ remaining.set(key(entry), (remaining.get(key(entry)) ?? 0) + 1);
+ return candidates.filter((entry) => {
+ const identity = key(entry);
+ const count = remaining.get(identity) ?? 0;
+ if (count === 0) return true;
+ remaining.set(identity, count - 1);
+ return false;
+ });
+}
+
/** One offence per line, the way a reader wants to see it. */
const report = (
offences: { shape: Shape; file: string; line: number; text: string }[],
@@ -958,9 +1197,8 @@ const report = (
for (const root of ROOTS) {
test(`${root} grows no assertion shape the fix cycle does not already own`, () => {
- const allowed = new Set(ALLOW.map(key));
const scanned = scanTree(join(REPO, root), REPO);
- expect(report(scanned.filter((o) => !allowed.has(key(o))))).toEqual([]);
+ expect(report(unmatched(scanned, ALLOW))).toEqual([]);
// And the walk reached the tree at all: a scan of nothing reports nothing.
expect(sourceFiles(join(REPO, root), EXTENSIONS).length).toBeGreaterThan(
20,
@@ -969,14 +1207,69 @@ for (const root of ROOTS) {
}
test("the allow-list holds no offence the fix cycle has already cleared", () => {
- const found = new Set(
- ROOTS.flatMap((root) => scanTree(join(REPO, root), REPO)).map(key),
- );
- const stale = ALLOW.filter((entry) => !found.has(key(entry)));
+ const found = ROOTS.flatMap((root) => scanTree(join(REPO, root), REPO));
+ const stale = unmatched(ALLOW, found);
// A fixed offence must leave the list with its fix, or the list stops meaning anything.
expect(stale.map((entry) => `${key(entry)} ${entry.finding}`)).toEqual([]);
});
+test("allowances survive comments, line shifts and expression wrapping", () => {
+ const before = offencesIn(
+ "fixture.ts",
+ 'test("existing", () => { expect(row?.value).toBeUndefined(); });',
+ );
+ const wrapped = offencesIn(
+ "fixture.ts",
+ `// New introduction.
+
+
+test("existing", () => {
+ expect(
+ row?.value
+ ).toBeUndefined();
+});`,
+ );
+ expect(before).toHaveLength(1);
+ expect(wrapped[0].line).not.toBe(before[0].line);
+ expect(unmatched(wrapped, before)).toEqual([]);
+ expect(unmatched(before, wrapped)).toEqual([]);
+});
+
+test("an allowance cannot cover the same expression in another test or a second copy", () => {
+ const original =
+ 'test("existing", () => { expect(row?.value).toBeUndefined(); });';
+ const allowed = offencesIn("fixture.ts", original);
+ const addedTest = offencesIn(
+ "fixture.ts",
+ original +
+ '\ntest("new case", () => { expect(row?.value).toBeUndefined(); });',
+ );
+ const duplicate = offencesIn(
+ "fixture.ts",
+ 'test("existing", () => { expect(row?.value).toBeUndefined(); expect(row?.value).toBeUndefined(); });',
+ );
+ expect(unmatched(addedTest, allowed).map((o) => o.context)).toEqual([
+ ['"new case"'],
+ ]);
+ expect(unmatched(duplicate, allowed)).toHaveLength(1);
+ expect(unmatched(allowed, [])).toEqual(allowed);
+});
+
+test("the full expression identity keeps literal contents and changes beyond diagnostic truncation", () => {
+ const prefix = "x".repeat(150);
+ const original = offencesIn(
+ "fixture.ts",
+ `test("existing", () => { expect(row?.["${prefix} a"]).toBeUndefined(); });`,
+ );
+ const changed = offencesIn(
+ "fixture.ts",
+ `test("existing", () => { expect(row?.["${prefix} a"]).toBeUndefined(); });`,
+ );
+ expect(original).toHaveLength(1);
+ expect(original[0].text).toBe(changed[0].text);
+ expect(unmatched(changed, original)).toHaveLength(1);
+});
+
/* POSITIVE CONTROLS.
*
* Each plants one shape in a file on disk, at a nesting and an extension the real trees have, and
diff --git a/server/tests/attachment-routes.test.ts b/server/tests/attachment-routes.test.ts
index d14d356c..363a2d34 100644
--- a/server/tests/attachment-routes.test.ts
+++ b/server/tests/attachment-routes.test.ts
@@ -1,14 +1,14 @@
import { afterAll, afterEach, describe, expect, spyOn, test } from "bun:test";
import { randomUUID } from "node:crypto";
-import { and, eq, isNull, sql } from "drizzle-orm";
-import type { MiddlewareHandler } from "hono";
-import { Hono } from "hono";
import {
attachmentUrl,
MAX_ATTACHMENTS_PER_MESSAGE,
MAX_FILE_BYTES,
MAX_IMAGE_BYTES,
} from "@openbot/shared/attachments";
+import { and, eq, isNull, sql } from "drizzle-orm";
+import type { MiddlewareHandler } from "hono";
+import { Hono } from "hono";
import { createApp, UPLOAD_BODY_LIMIT_BYTES } from "../src/app";
import type { AppVariables } from "../src/auth/guards";
import { resolveAttachmentParts } from "../src/channels/attachment-parts";
@@ -17,8 +17,8 @@ import {
createAttachmentRoutes,
createChannelAttachmentRoutes,
loadAttachmentForTurn,
- markAttachmentsSent,
MAX_STAGED_ATTACHMENTS_PER_UPLOADER,
+ markAttachmentsSent,
} from "../src/channels/attachments";
import { loadConfig } from "../src/config";
import type { Database } from "../src/db/client";
@@ -400,11 +400,8 @@ const BLOCKED_SESSION_DEADLINE_MS = BLOCKED_SESSION_TIMEOUT_MS / 3;
async function waitForBlockedSession(
applicationName: string,
settled: () => boolean,
- // Overridden by the test that pins the message below, and by nothing else: waiting the real
- // deadline out to watch it fire would put seven seconds on the suite to observe a string.
- deadlineMs: number = BLOCKED_SESSION_DEADLINE_MS,
): Promise<boolean> {
- const deadline = Date.now() + deadlineMs;
+ const deadline = Date.now() + BLOCKED_SESSION_DEADLINE_MS;
while (Date.now() < deadline) {
const blocked = await database.execute(sql`
SELECT pid
@@ -3415,27 +3412,6 @@ describe("markAttachmentsSent", () => {
),
).resolves.toBeUndefined();
});
-
- /*
- * THE HELPER'S OWN DIAGNOSTIC, WHICH USED TO BE UNREACHABLE.
- *
- * `waitForBlockedSession` gave itself 5s and Bun gives a test 5s by default, with no override
- * anywhere, so the runner always won: the message naming the session that never blocked could not
- * be printed, and both races failed as a bare "timed out after 5000ms" instead. The constants are
- * compared here because that relationship is the fault, and the message is provoked with a short
- * deadline because waiting the real one out would cost the suite seven seconds to observe a
- * string.
- */
- test("the wait for a blocked session says which session it gave up on", async () => {
- expect(BLOCKED_SESSION_DEADLINE_MS).toBeLessThan(
- BLOCKED_SESSION_TIMEOUT_MS,
- );
-
- const applicationName = `never_blocks_${randomUUID()}`;
- await expect(
- waitForBlockedSession(applicationName, () => false, 50),
- ).rejects.toThrow(applicationName);
- });
});
/**
diff --git a/server/tests/audit.test.ts b/server/tests/audit.test.ts
index ee9d8046..3e5c71e2 100644
--- a/server/tests/audit.test.ts
+++ b/server/tests/audit.test.ts
@@ -1,7 +1,4 @@
import { describe, expect, test } from "bun:test";
-import { readdirSync, readFileSync } from "node:fs";
-import { readdir, readFile } from "node:fs/promises";
-import { join } from "node:path";
import { createApp } from "../src/app";
import {
auditEventTypes,
@@ -34,44 +31,6 @@ const memberAuth = {
},
};
-/**
- * Every event type this deployment declares, it can actually write.
- *
- * The taxonomy is the trail's vocabulary, and a name in it is a promise that this deployment can
- * produce that row. Four of them could not: `connector.sync_succeeded`, `connector.sync_failed`,
- * `knowledge.searched` and `agent.invoked` outlived the document-index and connector-sync code that
- * wrote them, and stayed in the list for months because the test above named them explicitly and
- * nothing else asked. An operator filtering for one got an empty page that reads as "nothing
- * happened" rather than "nothing can".
- *
- * Read off the source rather than maintained by hand, because a hand-kept list is the thing that
- * just failed. Literal strings only: every writer today passes the type as a literal, and one that
- * computed it would fail here and should — a row type a reader cannot grep for is worse than this
- * test being strict.
- */
-describe("the audit event taxonomy", () => {
- test("declares nothing this deployment cannot write", () => {
- const root = join(import.meta.dir, "..", "src");
- const sources: string[] = [];
- const walk = (directory: string) => {
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
- const path = join(directory, entry.name);
- if (entry.isDirectory()) walk(path);
- else if (entry.name.endsWith(".ts") && entry.name !== "audit.ts") {
- sources.push(readFileSync(path, "utf8"));
- }
- }
- };
- walk(root);
- const everywhereElse = sources.join("\n");
-
- const unwritable = auditEventTypes.filter(
- (type) => !everywhereElse.includes(JSON.stringify(type)),
- );
- expect(unwritable).toEqual([]);
- });
-});
-
describe("audit payload redaction", () => {
test("defines the audit event taxonomy", () => {
expect(auditEventTypes).toEqual(
@@ -158,40 +117,6 @@ describe("audit payload redaction", () => {
});
});
-describe("audit event immutability", () => {
- /*
- * What the guard DOES is proved against a real database in
- * audit-retention.integration.test.ts. This asserts only that it is still installed by some
- * migration, and it reads the whole chain to do it.
- *
- * Reading 0000 alone stopped being true a while ago: 0007 replaced the function and 0012 replaced
- * it again and added the truncate trigger, so the old assertions described a definition no
- * database runs and would have gone on passing if the current one were edited out from under
- * them. A mirror test pinned to one file is a test of that file, not of the deployment.
- *
- * Reported by @beardthelion, alongside the TRUNCATE hole itself.
- */
- test("some migration still installs the append-only guard", async () => {
- const directory = new URL("../drizzle/", import.meta.url);
- const files = (await readdir(directory))
- .filter((name) => name.endsWith(".sql"))
- .sort();
- const chain = (
- await Promise.all(
- files.map((name) => readFile(new URL(name, directory), "utf8")),
- )
- ).join("\n");
-
- expect(chain).toContain("FUNCTION prevent_audit_event_mutation");
- expect(chain).toContain("BEFORE UPDATE OR DELETE ON audit_events");
- expect(chain).toContain("BEFORE TRUNCATE ON audit_events");
- expect(chain).toContain("Audit events are append-only");
- // A later migration removing either trigger would otherwise satisfy every line above.
- expect(chain).not.toContain("DROP TRIGGER audit_events_append_only");
- expect(chain).not.toContain("DROP TRIGGER audit_events_no_truncate");
- });
-});
-
describe("admin audit API", () => {
test("returns a filtered audit page to an administrator", async () => {
const queries: unknown[] = [];
diff --git a/server/tests/broker-authorization-pairing.test.ts b/server/tests/broker-authorization-pairing.test.ts
deleted file mode 100644
index 697a7fb2..00000000
--- a/server/tests/broker-authorization-pairing.test.ts
+++ /dev/null
@@ -1,254 +0,0 @@
-import { describe, expect, test } from "bun:test";
-import { readdirSync, readFileSync } from "node:fs";
-import { join } from "node:path";
-
-/**
- * THE PAIRING INVARIANT, asserted over every `ConnectedAppBroker` literal in the tree.
- *
- * A broker with `authorizations === null` answers `authorizationId: null`; a broker with a
- * non-null `authorizations` answers a non-null `authorizationId` on a successful mint. It is the
- * one way spec D24's binding (the attempt's `ar_…` equals the callback's `auth_id`) rots without a
- * type error: an adapter grows a flow surface and forgets the mint id.
- *
- * A literal is found by its `authorize` member — the one member every broker must have — and is
- * confirmed a broker by a `grantIsLocal` or `authorizations` sibling at the same indent. This reads
- * source text because the stubs are module-local and `server/tests` is outside `tsc`, so nothing
- * else can see them all.
- *
- * EVERY HEURISTIC HERE FAILS LOUD, NEVER QUIET. A guard that decides for itself which code to look
- * at is only as good as that decision, and a decision that silently drops the one adapter the
- * invariant exists for reads exactly like a pass. So: the shape this scan cannot read throws
- * instead of being skipped ({@link answersOf}), a broker-shaped literal with no `authorize` throws,
- * and {@link coverage} asserts by name that the production adapters are among the literals this
- * file actually checks rather than merely among the ones it found.
- */
-const ROOT = join(import.meta.dir, "..");
-const SELF = "broker-authorization-pairing.test.ts";
-/**
- * THE WHOLE OF `src` AND `tests`, RECURSIVELY. A hand-listed directory is the same silent miss as a
- * hand-tuned heuristic: a broker literal written one directory over would simply not be asserted,
- * and that reads as a pass.
- */
-const sources = (dir: string): string[] =>
- readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
- e.isDirectory()
- ? sources(join(dir, e.name))
- : e.name.endsWith(".ts") && e.name !== SELF
- ? [join(dir, e.name)]
- : [],
- );
-const files = [...sources(join(ROOT, "tests")), ...sources(join(ROOT, "src"))];
-
-type Literal = {
- where: string;
- authorizations: "null" | "flow";
- /** The object literals this `authorize` can ANSWER WITH; see {@link answersOf}. */
- answers: string[];
-};
-
-const indentOf = (l: string) => /^\s*/.exec(l)![0].length;
-
-/**
- * A member line of an object literal: `name:`, `name(`, `async name(`, or the shorthand `name,`.
- * The shorthand matters for the member AFTER `authorize`, which is where its body ends.
- */
-const MEMBER = /^\s*(async\s+)?\w+\??\s*([(:]|,\s*$|$)/;
-
-/** The lines of the object literal whose members sit at `indent`, and which of them are members. */
-function blockAt(lines: string[], at: number, indent: number) {
- let from = at;
- while (
- from > 0 &&
- (lines[from - 1]!.trim() === "" || indentOf(lines[from - 1]!) >= indent)
- )
- from--;
- let to = at;
- while (
- to < lines.length - 1 &&
- (lines[to + 1]!.trim() === "" || indentOf(lines[to + 1]!) >= indent)
- )
- to++;
- const block = lines.slice(from, to + 1);
- const members = block
- .map((l, i) => ({ l, i }))
- .filter(({ l }) => indentOf(l) === indent && MEMBER.test(l));
- const named = (name: string) =>
- members.findIndex(({ l }) =>
- new RegExp(`^\\s*(async\\s+)?${name}\\s*([(:]|,\\s*$|$)`).test(l),
- );
- return { from, block, members, named };
-}
-
-/**
- * Comments are prose: `authorizationId` in a sentence is not an answer. The `//` strip refuses a
- * `//` that follows a colon so that a `"https://…"` inside a returned literal survives — eating it
- * would unbalance the braces this reads next.
- */
-const stripComments = (s: string) =>
- s.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/[^\n]*/g, "$1");
-
-/**
- * The object literals an `authorize` body can ANSWER WITH: `return {…}` and the concise `=> ({…})`.
- * Scoping to these is what keeps the seam's own `authorizationId: string | null` annotation, a
- * local `const authorizationId`, or a sentence in a comment from reading as an answer — and what
- * lets a shorthand `return { redirectUrl, authorizationId }` be read as the answer it is.
- *
- * `=> {` is a function body, not an answer; its `return`s are found by the `return` pass.
- */
-function answersOf(body: string): string[] {
- const src = stripComments(body);
- const out: string[] = [];
- for (const m of src.matchAll(/\breturn\b|=>\s*\(/g)) {
- let i = m.index + m[0].length;
- while (i < src.length && /[\s(]/.test(src[i]!)) i++;
- if (src[i] !== "{") continue;
- let depth = 0;
- for (let j = i; j < src.length; j++) {
- if (src[j] === "{") depth++;
- else if (src[j] === "}" && --depth === 0) {
- out.push(src.slice(i, j + 1));
- break;
- }
- }
- }
- return out;
-}
-
-function literalsIn(file: string): Literal[] {
- const lines = readFileSync(file, "utf8").split("\n");
- const out: Literal[] = [];
- lines.forEach((line, at) => {
- const m = /^(\s*)(async\s+)?authorize\s*[(:]/.exec(line);
- if (!m) return;
- const indent = m[1]!.length;
- const { from, block, members, named } = blockAt(lines, at, indent);
- const g = named("grantIsLocal");
- const a = named("authorizations");
- // An `authorize` with neither sibling is somebody else's member — a vendor client's own
- // `authorize`, say — and not the seam this invariant is about.
- if (g < 0 && a < 0) return;
- // The seam's own interface declares these members too (`grantIsLocal: boolean;`). A declaration
- // is not a broker: the pairing lives in the literals that implement it, and a `;`-terminated
- // member is how a declaration gives itself away.
- if (
- [g, a].some((i) => i >= 0 && /;\s*$/.test(block[members[i]!.i]!.trim()))
- )
- return;
- const z = named("authorize");
- // The one literal that omits `authorizations` is composio-grants-for's deliberate
- // does-not-compile witness, which is then spread with `authorizations: null` — so an omission
- // is read as the null it is completed with there. That reading is the strict one: it demands
- // `authorizationId: null`, so a literal that omits the member AND mints an id fails loudly.
- const aLine = a < 0 ? "authorizations: null" : block[members[a]!.i]!;
- const end = z + 1 < members.length ? members[z + 1]!.i : block.length;
- const body = block.slice(members[z]!.i, end).join("\n");
- const answers = answersOf(body);
- // A SHAPE THIS CANNOT READ THROWS. `redirectUrl` in the body with no answer carrying it means
- // the mint is assembled somewhere this scan does not look, and silently skipping it is how a
- // guard comes to assert nothing.
- if (
- /\bredirectUrl\b/.test(stripComments(body)) &&
- !answers.some((ans) => /\bredirectUrl\b/.test(ans))
- ) {
- throw new Error(
- `${file.slice(ROOT.length + 1)}:${from + members[z]!.i + 1}: this authorize names redirectUrl but answers with a shape this guard cannot read; teach answersOf() the shape rather than leaving the literal unchecked.`,
- );
- }
- out.push({
- where: `${file.slice(ROOT.length + 1)}:${from + members[z]!.i + 1}`,
- authorizations: /authorizations:\s*null\b/.test(aLine) ? "null" : "flow",
- answers,
- });
- });
- return out;
-}
-
-/**
- * Every declared `grantIsLocal` on a broker-shaped literal must have landed in {@link literalsIn}'s
- * net. This is the net's own guard: the scan anchors on `authorize`, so a broker literal that grew
- * one without the other would otherwise go unexamined and read as a pass.
- */
-function unreachedIn(file: string): string[] {
- const lines = readFileSync(file, "utf8").split("\n");
- const out: string[] = [];
- lines.forEach((line, at) => {
- const m = /^(\s*)grantIsLocal\s*:\s*(true|false)\s*[,}]/.exec(line);
- if (!m) return;
- const { from, named } = blockAt(lines, at, m[1]!.length);
- // `{ key, grantIsLocal: true }` in a deployment config is not a broker.
- if (named("authorizations") < 0) return;
- if (named("authorize") >= 0) return;
- /*
- * A `stubBroker({ … })` WITHOUT an `authorize` IS NOT UNEXAMINED, it is unable to mint.
- *
- * This net exists because `literalsIn` anchors on `authorize`, so a hand-written literal that
- * declared the pair without one would slip past unchecked and read as a pass. The factory
- * inverts that risk: a member it is not given does not quietly answer a plausible shape, it
- * RECORDS THE CALL AND THROWS. So an omitted `authorize` here cannot mint an id, there is no
- * pairing to check, and flagging it would demand the caller write out a member whose whole
- * purpose is to be absent.
- *
- * The exemption is narrow on purpose: a `stubBroker` call that DOES provide `authorize` still
- * carries that member on its own line, so `literalsIn` finds and examines it exactly as it
- * does any other literal. Only the cannot-mint case is skipped.
- */
- if (/\bstubBroker\s*\(/.test(lines[from - 1] ?? "")) return;
- out.push(`${file.slice(ROOT.length + 1)}:${at + 1}`);
- });
- return out;
-}
-
-/** `none` is no `authorizationId` at all, which answers neither surface. */
-function idOf(answer: string): "none" | "null" | "value" {
- const m = /\bauthorizationId\b\s*(?::\s*([^,}\n]+))?/.exec(answer);
- if (!m) return "none";
- if (m[1] === undefined) return "value"; // the shorthand `{ …, authorizationId }`
- return /^null\s*$/.test(m[1]) ? "null" : "value";
-}
-
-const literals = files.flatMap(literalsIn);
-/** The literals actually asserted over: the ones whose `authorize` answers a url to visit. */
-const minting = literals
- .map((l) => ({
- ...l,
- answers: l.answers.filter((a) => /\bredirectUrl\b/.test(a)),
- }))
- .filter((l) => l.answers.length > 0);
-const coverage = minting.map((l) => l.where);
-
-describe("authorizations and authorizationId are declared as a pair", () => {
- test("the scan reaches every broker-shaped literal", () => {
- expect(files.flatMap(unreachedIn)).toEqual([]);
- });
-
- test("the production adapters are among the literals CHECKED", () => {
- // Not merely among the ones found: the Arcade adapter is the one production broker with a
- // non-null `authorizations`, so if it is not here the flow half of this invariant is asserted
- // for nothing but stubs.
- expect(
- coverage.some((p) => p.startsWith("src/plugins/arcade-adapter.ts")),
- ).toBe(true);
- expect(
- coverage.some((p) =>
- p.startsWith("src/plugins/composio-client/consent.ts"),
- ),
- ).toBe(true);
- // A floor that notices this scan collapsing, not a count to keep up to date; it sits just under
- // what the tree holds today (28) rather than at a third of it.
- expect(minting.length).toBeGreaterThanOrEqual(25);
- // BOTH BRANCHES MUST BE INHABITED. An empty one is a branch asserted for nothing, which is the
- // state this guard was in when its only non-null-`authorizations` literal was being skipped.
- expect(minting.some((l) => l.authorizations === "null")).toBe(true);
- expect(minting.some((l) => l.authorizations === "flow")).toBe(true);
- });
-
- for (const literal of minting) {
- test(literal.where, () => {
- const want = literal.authorizations === "null" ? "null" : "value";
- for (const answer of literal.answers) {
- const said = answer.replace(/\s+/g, " ");
- expect(`${idOf(answer)} in ${said}`).toBe(`${want} in ${said}`);
- }
- });
- }
-});
diff --git a/server/tests/broker-stub-ratchet.test.ts b/server/tests/broker-stub-ratchet.test.ts
deleted file mode 100644
index 3814450f..00000000
--- a/server/tests/broker-stub-ratchet.test.ts
+++ /dev/null
@@ -1,262 +0,0 @@
-// server/tests/broker-stub-ratchet.test.ts
-/**
- * Ratchet: no NEW test double gets past the broker or credential type by a cast, and no NEW
- * `revokeAccount` stub silently succeeds.
- *
- * WHY THIS EXISTS. `typecheck:tests` (CL-4) type-checks `server/tests` and fails on any new error,
- * but a cast is not an error. `{ … } as unknown as ConnectedAppBroker` and `{} as
- * ConnectedAppBroker` compile while omitting `revoke` and `revokeAccount`; `{ broker } as never`
- * compiles while omitting everything. Each one makes the type's guarantee vanish exactly as the
- * broken `import type` that round-2 C8 fixed did — the same defect by a different mechanism, and
- * one the compiler gate is structurally blind to. A `revokeAccount: async () => {}` stub is the
- * runtime half of the same drift: it type-checks, and answers "done" for a revoke that never
- * happened, on the seam this PR's Claim 2 is about.
- *
- * THE LISTS BELOW ARE A RECORD OF DEBT, in the discipline of `typecheck-baseline.txt`: every entry
- * is a real stub the compiler cannot see, not a stub that is fine. Removing one by fixing it is
- * always correct — and REQUIRED, because the comparison is equality both ways, so a fixed site
- * left on the list goes red and names itself for deletion. Adding one is not: a new cast means a
- * double written today escapes the type, and the honest alternative exists
- * (`support/stub-broker.ts`, whose unprovided members throw and record). The migration of the
- * recorded sites onto that factory is deferred to the fix cycle (convergence audit, K3); this
- * file only reads them.
- *
- * KEYED BY PATH + QUOTED EXPRESSION, NEVER `path:line`. A line-keyed list goes red when somebody
- * adds an import above a stub, and a guard that fails for a reason unrelated to what it guards is
- * one people learn to re-baseline without reading (`assertion-shape.test.ts` collided this way in
- * three consecutive waves; `sole-definition.test.ts`, keyed like this, never has). Two identical
- * expressions in one file appear as that entry twice — duplicates are significant.
- *
- * WHAT THE PATTERNS SEE, AND WHAT THEY DO NOT. Comments are blanked by the shared scanner, so a
- * docblock quoting a cast is prose. Matching runs over the whole stripped file with `\s+`, so a
- * cast wrapped across lines is still one cast. NOT seen: a cast to a local alias of the broker type
- * whose name does not end in `Broker` (`type B = ConnectedAppBroker; x as unknown as B`), a stub
- * erased by `as never` whose line names no broker (`deps as never` where `deps` holds one), and a
- * no-op `revokeAccount` written through a named function (`revokeAccount: noop`). Widening to those
- * would flag every `as never` in the suite; the escape hatch is review, and the factory.
- */
-import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
-import { sourceFiles, stripComments } from "./support/source-scan";
-
-const REPO = join(import.meta.dir, "../..");
-
-/**
- * This file is not scanned: its lists QUOTE every recorded site, and its matcher contract spells
- * the offences it must catch, so scanning it would report its own records as new stubs.
- */
-const SELF = import.meta.path;
-const ROOT = "server/tests";
-
-/** The seam types a double must not be cast to. A name ending in `Broker` covers every alias. */
-const SEAM_TYPE =
- "(?:[A-Z][\\w$]*)?(?:Broker|CredentialStore|CredentialSecretReader|CredentialStatusReader|CredentialAdminService)";
-
-/**
- * A type assertion TO a seam type: `as X`, `as unknown as X`, `as any as X`, `as never as X`, and
- * the wrapped forms `as Partial<X>` / `as unknown as Pick<X, …>`. `{} as X` is `as X`.
- */
-export const CAST_TO_SEAM = new RegExp(
- `\\bas\\s+(?:(?:unknown|any|never)\\s+as\\s+)?(?:[\\w$]+\\s*<\\s*)?${SEAM_TYPE}(?![\\w$])`,
- "g",
-);
-
-/**
- * A broker ERASED rather than cast: an expression that names a broker — the `broker` key or
- * binding, or any identifier ending in `Broker` — asserted to `never`, `any` or `unknown`, within
- * the same statement. The span stops at a `;` or a line break, so an unrelated `as never` further
- * down the file is not attributed to it.
- */
-export const ERASED_BROKER =
- /\b(?:broker|[a-z][\w$]*Broker)\b[^;\n]*?\bas\s+(?:never|any|unknown)\b(?!\s+as\b)/g;
-
-/** A `revokeAccount` that succeeds and does nothing: the silent no-op. */
-export const NOOP_REVOKE_ACCOUNT =
- /\brevokeAccount\s*(?::\s*(?:async\s*)?(?:\([^)]*\)|[\w$]+)\s*(?::\s*[^=]+?)?=>\s*(?:\{\s*\}|undefined\b|void\s+0\b|Promise\.resolve\(\s*\))|(?:async\s+)?\([^)]*\)\s*(?::\s*[^{]+?)?\{\s*\})/g;
-
-/**
- * Every match of `re` across the test tree, as `path :: expression`.
- *
- * The expression is the whole physical line(s) the match spans, whitespace collapsed, so it reads
- * as the stub a reviewer would see and survives reindentation.
- */
-export function sitesOf(re: RegExp, root = ROOT): string[] {
- const out: string[] = [];
- for (const file of sourceFiles(join(REPO, root), [".ts", ".tsx"])) {
- if (file === SELF) continue;
- const text = stripComments(readFileSync(file, "utf8"));
- for (const match of text.matchAll(re)) {
- out.push(
- `${file.slice(REPO.length + 1)} :: ${expressionAt(text, match)}`,
- );
- }
- }
- return out.sort();
-}
-
-function expressionAt(text: string, match: RegExpMatchArray): string {
- const at = match.index ?? 0;
- const from = text.lastIndexOf("\n", at) + 1;
- const end = text.indexOf("\n", at + match[0].length);
- return text
- .slice(from, end === -1 ? text.length : end)
- .replace(/\s+/g, " ")
- .trim();
-}
-
-/**
- * Casts past the broker type on record. Round-2 C8a's report counted six; the scan finds EIGHT —
- * `store-account-ref.integration` and `store-vendor-vocabulary` were not in that count. Each one
- * compiles whatever it omits, so none is checked against the seam; all are deferred to the fix
- * cycle (K3).
- */
-const KNOWN_CASTS: string[] = [
- "server/tests/directory-vendor-sentences.test.ts :: } as unknown as ComposioBroker;",
- "server/tests/routes-arcade-urls.test.ts :: } as unknown as ComposioBroker;",
- "server/tests/routes-vendor-vocabulary.test.ts :: } as unknown as ComposioBroker;",
- "server/tests/store-account-ref.integration.test.ts :: } as unknown as ConnectedAppBroker;",
- "server/tests/store-provider-required.test.ts :: const broker = {} as ConnectedAppBroker;",
- "server/tests/store-toolkit-dispatch.test.ts :: const broker = {} as ConnectedAppBroker;",
- "server/tests/store-vendor-vocabulary.test.ts :: } as unknown as ConnectedAppBroker;",
- "server/tests/vendor-deadline-sync-throw.test.ts :: } as unknown as ComposioBroker;",
-];
-
-/** Brokers erased to `never` on record. Same defect, wider: nothing of the seam is checked. */
-const KNOWN_ERASED: string[] = [
- 'server/tests/arcade-journey.integration.test.ts :: args[29] = { broker, provider: "arcade" } as never;',
- "server/tests/plugin-routes.test.ts :: listApps ? ({ broker: { listApps } } as never) : undefined,",
- 'server/tests/provider-selection.test.ts :: const arcadeBroker = { tag: "arcade-broker" } as never;',
- 'server/tests/provider-selection.test.ts :: const composioBroker = { tag: "composio-broker" } as never;',
-];
-
-/**
- * Silent no-op `revokeAccount` stubs on record. Round-2 C8c counted 21; the scan finds 22. Deferred
- * to the fix cycle (K1/K3).
- */
-const KNOWN_NOOP_REVOKES: string[] = [
- "server/tests/account-mode.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-attempt-store.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-authorize-cancel.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-authorize-route.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-completion-transaction.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-disconnect-cascade.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-disconnect-route.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-grants-route.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-grants-route.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-sibling-collateral.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-siblings.test.ts :: revokeAccount: async () => {},",
- "server/tests/arcade-verify.test.ts :: revokeAccount: async () => {},",
- "server/tests/composio-grants-for.test.ts :: revokeAccount: async () => {},",
- "server/tests/gate-foreign-provenance-call.test.ts :: revokeAccount: async () => {},",
- "server/tests/gate-grant-is-local.test.ts :: revokeAccount: async () => {},",
- "server/tests/remove-server-foreign-provenance.test.ts :: revokeAccount: async () => {},",
- "server/tests/shared-brokered-routes.test.ts :: revokeAccount: async () => {},",
- "server/tests/shared-brokered-store.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/shared-gated-mode.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/shared-wiring.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/store-account-ref.integration.test.ts :: revokeAccount: async () => {},",
- "server/tests/store-vendor-vocabulary.test.ts :: revokeAccount: async () => {},",
-];
-
-test("no new cast past the broker or credential type", () => {
- // Equality both ways: a NEW site is a double written today that escapes the type; a site that
- // is GONE was fixed, and its entry must be deleted above so the record burns down.
- expect(sitesOf(CAST_TO_SEAM)).toEqual([...KNOWN_CASTS].sort());
-});
-
-test("no new broker erased to never, any or unknown", () => {
- const erased = sitesOf(ERASED_BROKER).filter(
- (site) => !new RegExp(CAST_TO_SEAM.source).test(site),
- );
- expect(erased).toEqual([...KNOWN_ERASED].sort());
-});
-
-test("no new silent no-op revokeAccount stub", () => {
- expect(sitesOf(NOOP_REVOKE_ACCOUNT)).toEqual([...KNOWN_NOOP_REVOKES].sort());
-});
-
-/*
- * THE MATCHER CONTRACT. The real-tree comparisons above prove the lists are current; these prove
- * the patterns are read the way the lists assume — that a cast is matched when it is one and a
- * typed binding or a `satisfies` is not. Without them the ratchet could be green because a pattern
- * matches nothing at all.
- */
-const B = "ConnectedAppBroker";
-const C = "CredentialStore";
-const RA = "revokeAccount";
-const BK = "broker";
-
-function matches(re: RegExp, text: string): boolean {
- return new RegExp(re.source).test(text);
-}
-
-test("a cast to a seam type is matched; a typed binding, a satisfies or a near-name is not", () => {
- const casts = [
- `} as unknown as ${B};`,
- `const broker = {} as ${B};`,
- `} as ${B};`,
- `x as any as ${B}`,
- `x as never as Composio${"Broker"}`,
- `x as Partial<${B}>`,
- `x as unknown as Pick<${B}, "revoke">`,
- `} as\n unknown as\n ${B};`,
- `credentials: {} as ${C},`,
- `x as unknown as HostAccess${"Broker"}`,
- ];
- for (const text of casts)
- expect([text, matches(CAST_TO_SEAM, text)]).toEqual([text, true]);
- const notCasts = [
- `const broker: ${B} = {`,
- `} satisfies ${B};`,
- `import type { ${B} } from "../src/plugins/broker";`,
- `x as ${"Broker"}edProbe`,
- `x as ${"Broker"}App`,
- `alias as const`,
- `has ${B}`,
- ];
- for (const text of notCasts)
- expect([text, matches(CAST_TO_SEAM, text)]).toEqual([text, false]);
-});
-
-test("an erased broker is matched; an erased unrelated value is not", () => {
- const erased = [
- `args[29] = { ${BK}, provider: "arcade" } as never;`,
- `listApps ? ({ ${BK}: { listApps } } as never) : undefined,`,
- `const composio${"Broker"} = { tag: "x" } as never;`,
- `const deps = { ${BK}: stub } as any;`,
- ];
- for (const text of erased)
- expect([text, matches(ERASED_BROKER, text)]).toEqual([text, true]);
- const notErased = [
- `(brokerReturnUrl as any)(" "),`,
- `new (${"Broker"}UnconfiguredError as any)()`,
- `credentials: {} as never,`,
- `${BK},\n credentials: {} as never,`,
- `const ${BK} = make(); const y = z as never;`,
- ];
- for (const text of notErased)
- expect([text, matches(ERASED_BROKER, text)]).toEqual([text, false]);
-});
-
-test("a silent revokeAccount is matched; one that records or throws is not", () => {
- const silent = [
- ` ${RA}: async () => {},`,
- ` ${RA}: async (_id) => {},`,
- ` ${RA}: async (id: string) => {\n },`,
- ` ${RA}: async () => undefined,`,
- ` ${RA}: () => Promise.resolve(),`,
- ` async ${RA}() {},`,
- ` ${RA}(_id: string) {}`,
- ];
- for (const text of silent)
- expect([text, matches(NOOP_REVOKE_ACCOUNT, text)]).toEqual([text, true]);
- const honest = [
- ` ${RA}: async (id) => {\n asks.push(id);\n },`,
- ` ${RA}: unasked("revoke one account"),`,
- ` ${RA}: async () => {\n throw new Error("no");\n },`,
- ` await ${BK}.${RA}("ca_1");`,
- ];
- for (const text of honest)
- expect([text, matches(NOOP_REVOKE_ACCOUNT, text)]).toEqual([text, false]);
-});
diff --git a/server/tests/channel-activity.integration.test.ts b/server/tests/channel-activity.integration.test.ts
index 5a880d3b..30e52369 100644
--- a/server/tests/channel-activity.integration.test.ts
+++ b/server/tests/channel-activity.integration.test.ts
@@ -198,17 +198,6 @@ describe("reading a person's channels", () => {
expect(found[0]?.agentIds.sort()).toEqual([first, second].sort());
});
- test("a caller cannot ask for every channel in one page", async () => {
- // The limit arrives over HTTP, so the ceiling is what makes paging a property of the endpoint.
- const owner = await createUser();
- const agentId = await createAgent(owner);
- await createChannel(owner, [agentId]);
-
- const page = await store.list(owner, { limit: 100_000 });
-
- expect(page.channels.length).toBeLessThanOrEqual(200);
- });
-
test("a nonsense cursor reads as the first page", async () => {
const owner = await createUser();
const agentId = await createAgent(owner);
diff --git a/server/tests/component-store.integration.test.ts b/server/tests/component-store.integration.test.ts
index 89b71ab5..8f165219 100644
--- a/server/tests/component-store.integration.test.ts
+++ b/server/tests/component-store.integration.test.ts
@@ -1,7 +1,13 @@
-import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+import {
+ afterAll,
+ beforeAll,
+ beforeEach,
+ describe,
+ expect,
+ test,
+} from "bun:test";
import { randomUUID } from "node:crypto";
-import { eq, inArray } from "drizzle-orm";
-import { DATA_FUNCTIONS } from "../src/components/functions";
+import { eq, inArray, sql } from "drizzle-orm";
import {
ComponentNotFoundError,
type ComponentStore,
@@ -10,6 +16,7 @@ import {
import { createDatabase } from "../src/db/client";
import {
agents,
+ auditEvents,
componentExclusions,
componentFunctions,
components,
@@ -59,6 +66,173 @@ beforeAll(async () => {
await makeComponent(otherName, false);
});
+describe("component data functions against PostgreSQL", () => {
+ // One connection keeps this temporary table visible to every query. Copy the migrated table
+ // shape so the production SQL runs unchanged, without depending on other suites' audit rows.
+ const reportsDatabase = createDatabase(testDatabaseUrl(), { max: 1 });
+ const reports = createComponentStore(reportsDatabase);
+ const day = 86_400_000;
+
+ beforeAll(async () => {
+ await reportsDatabase.execute(
+ sql`create temporary table audit_events (like public.audit_events including all)`,
+ );
+ });
+
+ beforeEach(async () => {
+ await reportsDatabase.execute(sql`truncate table pg_temp.audit_events`);
+ });
+
+ afterAll(async () => {
+ await reportsDatabase.$client.close();
+ });
+
+ function event(overrides: Partial<typeof auditEvents.$inferInsert>) {
+ return {
+ eventType: "component.rendered",
+ targetType: "component",
+ payload: { bot: "active-bot" },
+ createdAt: new Date(Date.now() - day),
+ ...overrides,
+ };
+ }
+
+ test("bot activity aggregates recent actions and excludes older and unattributed rows", async () => {
+ await reportsDatabase
+ .insert(auditEvents)
+ .values([
+ event({}),
+ event({}),
+ event({ payload: { bot: "other-bot" } }),
+ event({ createdAt: new Date(Date.now() - 8 * day) }),
+ event({ payload: {} }),
+ ]);
+
+ expect(await reports.callFunction("botActivity", {})).toEqual({
+ days: 7,
+ rows: [
+ { bot: "active-bot", actions: 2 },
+ { bot: "other-bot", actions: 1 },
+ ],
+ });
+ });
+
+ test("bot activity caps the window at 90 days and returns only the 12 busiest bots", async () => {
+ const ranked = Array.from({ length: 13 }, (_, index) => ({
+ bot: `ranked-bot-${index}`,
+ actions: 13 - index,
+ }));
+ await reportsDatabase.insert(auditEvents).values([
+ ...ranked.flatMap(({ bot, actions }) =>
+ Array.from({ length: actions }, () =>
+ event({
+ payload: { bot },
+ createdAt: new Date(Date.now() - 30 * day),
+ }),
+ ),
+ ),
+ // If the time bound is ignored, this changes the highest-ranked bot's count.
+ event({
+ payload: { bot: "ranked-bot-0" },
+ createdAt: new Date(Date.now() - 91 * day),
+ }),
+ ]);
+
+ expect(
+ await reports.callFunction("botActivity", { days: 100_000 }),
+ ).toEqual({
+ days: 90,
+ rows: ranked.slice(0, 12),
+ });
+ });
+
+ test("recent refusals filters event types, orders newest first and reads both reason formats", async () => {
+ const now = Date.now();
+ const fixtures = [
+ {
+ eventType: "computer.action_refused",
+ payload: { bot: "computer-bot", reason: "Permission denied" },
+ },
+ {
+ eventType: "component.refused",
+ payload: {
+ bot: "component-bot",
+ decision: { rule: "Component withheld" },
+ },
+ },
+ {
+ eventType: "component.function_refused",
+ payload: {
+ bot: "function-bot",
+ reason: "Explicit reason",
+ decision: { rule: "Fallback reason" },
+ },
+ },
+ { eventType: "bot.declined", payload: {} },
+ ];
+ await reportsDatabase
+ .insert(auditEvents)
+ .values([
+ ...fixtures.map((fixture, index) =>
+ event({ ...fixture, createdAt: new Date(now - (index + 1) * 1000) }),
+ ),
+ event({ eventType: "component.rendered", createdAt: new Date(now) }),
+ ]);
+
+ expect(await reports.callFunction("recentRefusals", {})).toEqual({
+ rows: [
+ expect.objectContaining({
+ bot: "computer-bot",
+ what: "computer.action_refused",
+ reason: "Permission denied",
+ }),
+ expect.objectContaining({
+ bot: "component-bot",
+ what: "component.refused",
+ reason: "Component withheld",
+ }),
+ expect.objectContaining({
+ bot: "function-bot",
+ what: "component.function_refused",
+ reason: "Explicit reason",
+ }),
+ expect.objectContaining({
+ bot: null,
+ what: "bot.declined",
+ reason: null,
+ }),
+ ],
+ });
+ });
+
+ test("recent refusals defaults to 10 and clamps the requested limit to 1 through 50", async () => {
+ const now = Date.now();
+ const fixtures = Array.from({ length: 51 }, (_, index) =>
+ event({
+ eventType: "bot.declined",
+ payload: { bot: `refusal-bot-${index}`, reason: `Reason ${index}` },
+ createdAt: new Date(now - index * 1000),
+ }),
+ );
+ await reportsDatabase.insert(auditEvents).values(fixtures);
+ for (const { args, count } of [
+ { args: {}, count: 10 },
+ { args: { limit: 100_000 }, count: 50 },
+ { args: { limit: 0 }, count: 1 },
+ ]) {
+ expect(await reports.callFunction("recentRefusals", args)).toEqual({
+ rows: fixtures.slice(0, count).map((_, index) =>
+ expect.objectContaining({
+ bot: `refusal-bot-${index}`,
+ what: "bot.declined",
+ reason: `Reason ${index}`,
+ }),
+ ),
+ });
+ }
+ });
+});
+
afterAll(async () => {
// Register before writes so a failed assertion or partially completed setup still has teardown.
const names = [...fixtureComponentNames];
@@ -388,18 +562,6 @@ describe("what a component may read", () => {
expect(left).toHaveLength(0);
});
- test("every shipped function reads real rows and bounds its own arguments", async () => {
- for (const entry of DATA_FUNCTIONS) {
- // Run with nothing, which is what a component sends before the model has supplied anything, and
- // with a hostile number: a value from the browser is a claim, and an unbounded one is a table
- // scan somebody asked for over the wire.
- expect(await entry.run(database, {})).toBeDefined();
- expect(
- await entry.run(database, { days: 100_000, limit: 100_000 }),
- ).toBeDefined();
- }
- });
-
test("a function this build does not ship cannot be run", async () => {
expect(store.callFunction(`nothing_${suite}`, {})).rejects.toThrow();
});
diff --git a/server/tests/composio-adapter.test.ts b/server/tests/composio-adapter.test.ts
index 2b89607b..5841daf3 100644
--- a/server/tests/composio-adapter.test.ts
+++ b/server/tests/composio-adapter.test.ts
@@ -3268,10 +3268,6 @@ describe("a catalogue that might be a fragment", () => {
* the failure named there, its entry reddens and has to be deleted rather than quietly outliving
* the state it describes.
*
- * THE METHOD LIST IS THE SEAM'S OWN. It is read off the objects {@link buildComposioClient}
- * returns rather than copied into this file, and typed as `keyof ComposioBroker | keyof
- * ComposioActions`, so a method added to either seam with no entry here fails the completeness
- * test below instead of being covered by nobody.
*/
describe("what a vendor failure becomes on its way out of the seam", () => {
/**
@@ -3434,9 +3430,6 @@ describe("what a vendor failure becomes on its way out of the seam", () => {
* therefore asks nobody anything. A row in the table below would have to invent a vendor call for
* it to break on, which would assert something about the fake and nothing about the method.
*
- * NAMING IT IS WHAT KEEPS THE COMPLETENESS TEST HONEST IN BOTH DIRECTIONS: the next method added
- * to this seam is covered by the table or appears on this list on purpose, and the test below
- * then checks that what is on this list genuinely dials nothing.
*/
const DIALS_NOTHING = new Set<SeamMethod>(["authProviderOf"]);
@@ -3624,30 +3617,6 @@ describe("what a vendor failure becomes on its way out of the seam", () => {
},
];
- test("every method the seam offers has an entry in the table", () => {
- // Read off the built objects rather than listed here a second time: a method added to either
- // projection arrives in this set, and the table that does not cover it fails here rather than
- // being the one door nobody thought to probe.
- const seam = buildComposioClient(fakeVendor({}));
- // Methods only: `grantIsLocal` is a declared property of the broker, not a door to probe.
- const methodsOf = (part: object) =>
- Object.entries(part)
- .filter(([, member]) => typeof member === "function")
- .map(([name]) => name);
- expect(
- [...methodsOf(seam.broker), ...methodsOf(seam.actions)]
- .filter((name) => !DIALS_NOTHING.has(name as SeamMethod))
- .sort(),
- ).toEqual(SEAM_CASES.map((seamCase) => seamCase.method).sort());
- // Whatever is not a method must be acknowledged by name, so a new non-function member of the
- // broker is a decision somebody makes rather than a thing the filter above silently drops.
- expect(
- Object.entries(seam.broker)
- .filter(([, member]) => typeof member !== "function")
- .map(([name]) => name),
- ).toEqual(["grantIsLocal", "authorizations"]);
- });
-
/**
* The other direction of {@link DIALS_NOTHING}: what is excused from the table must genuinely
* have nothing to fail at. The vendor here has no methods at all, so any call out of this seam
diff --git a/server/tests/composio-broker-seam.test.ts b/server/tests/composio-broker-seam.test.ts
index a5382ab4..3554ace7 100644
--- a/server/tests/composio-broker-seam.test.ts
+++ b/server/tests/composio-broker-seam.test.ts
@@ -181,49 +181,6 @@ describe("grantIsLocal", () => {
null,
);
});
-
- /**
- * THE STUB IS INSTALLED BEFORE THE CLIENT IS CONSTRUCTED, AND THAT ORDER IS THE WHOLE TEST.
- *
- * `@composio/client` binds its transport once, in its constructor — `this.fetch = options.fetch
- * ?? Shims.getDefaultFetch()` (`client.mjs:122`), and `getDefaultFetch` returns whatever
- * `globalThis.fetch` is at that moment. This file used to construct the client on the line above
- * the assignment, so the SDK held the real `fetch` and the stub below governed nothing: every run
- * of this case reached `https://backend.composio.dev/api/v3.1/auth_configs` over the network, and
- * the test passed anyway because the vendor's refusal of an unknown key also fails to mention
- * `action`. Constructing after the assignment is what makes the stub the transport.
- *
- * `server/scripts/test-network-guard.ts` is the floor under this, and the two are not
- * alternatives: the guard turns a call that escapes into a failure, and this ordering is what
- * keeps the case asserting what it is about rather than tripping the guard.
- */
- test("a broker handed an action it cannot use ignores it rather than throwing", async () => {
- const original = globalThis.fetch;
- // No network: an empty config listing, so `authorize` stops at its own refusal for having no
- // config to connect against. What is asserted is that `action` was not what stopped it.
- globalThis.fetch = (async () =>
- new Response(JSON.stringify({ items: [] }), {
- status: 200,
- headers: { "content-type": "application/json" },
- })) as unknown as typeof fetch;
- try {
- const { broker } = createComposioClient("never-dialled");
- const attempt = await broker
- .authorize({
- account: { holder: "person", userId: "u", vendorUserId: "u" },
- toolkit: "linear",
- returnUrl: "https://openbot.test/connections/x",
- action: "LINEAR_CREATE_ISSUE",
- })
- .then(
- () => "resolved",
- (error: unknown) => (error instanceof Error ? error.message : ""),
- );
- expect(attempt).not.toMatch(/action/i);
- } finally {
- globalThis.fetch = original;
- }
- });
});
/**
diff --git a/server/tests/composio-connect-adopts-held-account.test.ts b/server/tests/composio-connect-adopts-held-account.test.ts
index ba408a62..ca29c1a3 100644
--- a/server/tests/composio-connect-adopts-held-account.test.ts
+++ b/server/tests/composio-connect-adopts-held-account.test.ts
@@ -306,8 +306,7 @@ describe("Connect, where Composio already holds this person's account and OpenBo
// The row confirm writes for a consent app the vendor says yes for: this person's own. The
// store records `connected_by` only for a deployment account, whose connector is not its holder.
// The two ids are equal because production writes them equal for a person (`personAccount`);
- // this expects the row the store wrote, so the collapse is recorded in
- // `fixture-identity-distinct.test.ts` rather than separated.
+ // this expects that production equality rather than independent fixture identities.
const rows = await rowsFor(toolkit);
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({
diff --git a/server/tests/composio-connection-kinds.test.ts b/server/tests/composio-connection-kinds.test.ts
index 844e156b..99cfedda 100644
--- a/server/tests/composio-connection-kinds.test.ts
+++ b/server/tests/composio-connection-kinds.test.ts
@@ -497,23 +497,7 @@ for (const padded of PADDED_SCHEMES) {
* for, so a member nobody named is not a failure anywhere; it is silence. A suite of one test per
* FINDING inherits that shape exactly, because a finding is one cell.
*
- * SO THE ROWS ARE READ OFF THE PRODUCTION ROSTERS rather than listed here a second time, which is
- * the discipline `composio-adapter.test.ts` already applies to the vendor seam ("reads the method
- * list off the built objects rather than restating it, so a new seam method cannot be covered by
- * nobody"). A member added to either vocabulary arrives in {@link SCHEME_KINDS} or
- * {@link BROKERED_PROBE_OUTCOMES}, and the completeness tests below fail for every consumer that
- * has no cell for it. The compiler says the same thing one layer up and says it first: each
- * consumer carries a `Decides<…>` roster beside its branch, and a fourth member fails `tsc` at
- * every one of them by name. This table is what the compiler cannot check — what each consumer
- * actually DOES with the member, asserted against the running code.
- *
- * NOTHING IS DECLARED RATHER THAN ASSERTED ANY MORE, AND THE MECHANISM THAT SAYS SO STAYS.
- * `confirmBrokeredConnection × consent` and `the connect route × unreadable` were each claimed by an
- * open finding: asserting what they did would have pinned the defect, and omitting the cell would
- * have left the hole invisible — which is the whole failure this table is a lever against. Both
- * findings are closed and both cells are assertions now, so {@link DECLARED_CELLS} is empty; it is
- * kept because the next contested cell has to be declared somewhere, and an empty list holds the
- * table to the claim that there is no such cell today.
+ * Each cell below exercises the consumer against a member of the production vocabulary.
*/
/**
@@ -931,17 +915,8 @@ async function refusalOf(work: Promise<unknown>): Promise<string> {
throw new Error("nothing was refused, so there is no sentence to read");
}
-/**
- * ONE CELL: what a consumer does with one member, and how that is established.
- *
- * TWO SHAPES AND NOT AN OPTIONAL ASSERTION, because "this cell has no assertion" and "this cell's
- * assertion is claimed by an open finding" are the two states that have to be told apart. An
- * optional field makes an omission look exactly like a declaration, which is the failure this whole
- * table is a lever against — at one level up.
- */
-type Cell =
- | { decides: string; assert: () => Promise<void> }
- | { decides: string; claimedBy: string };
+/** A consumer behavior and its executable assertion. */
+type Cell = { decides: string; assert: () => Promise<void> };
/** One consumer's answer for every member of one vocabulary. */
type Consumer<Member extends string> = {
@@ -1885,39 +1860,9 @@ const PROBE_CONSUMERS: Consumer<BrokeredProbe["outcome"]>[] = [
},
];
-/**
- * EVERY CELL DECLARED RATHER THAN ASSERTED, WITH THE FINDING THAT CLAIMS IT.
- *
- * EMPTY, WHICH IS A CLAIM AND NOT AN ABSENCE. It held two — `confirmBrokeredConnection × consent`,
- * which re-stamped `verified_at` on every mount, and `the connect route × unreadable`, which minted
- * a vendor link for a scheme nothing could read — and both are now assertions above. A cell that
- * goes back to being a declaration has to be named here, and a declaration that outlives the finding
- * it names reddens: a fix cycle that closes a hole and does not flip its cell fails at
- * {@link declaredCellsOf}, which is the half a `test.todo` or a commented-out case cannot do,
- * because both of those stay quiet whether or not the thing they describe is still true.
- */
-const DECLARED_CELLS: string[] = [];
-
-function declaredCellsOf(consumers: Consumer<string>[]): string[] {
- return consumers.flatMap((consumer) =>
- Object.entries(consumer.cells)
- .filter(([, cell]) => "claimedBy" in cell)
- .map(([member]) => `${consumer.name} × ${member}`),
- );
-}
-
describe.each(SCHEME_KINDS)("a %s scheme", (kind) => {
for (const consumer of SCHEME_CONSUMERS) {
const cell = consumer.cells[kind];
- if ("claimedBy" in cell) {
- test(`${consumer.name} — DECLARED, not asserted: ${cell.decides}`, () => {
- // The declaration IS the assertion here: this cell names an open finding, and the sentence
- // above records what the code does today so the next reader can tell the two apart.
- expect(cell.claimedBy).not.toBe("");
- expect(DECLARED_CELLS).toContain(`${consumer.name} × ${kind}`);
- });
- continue;
- }
test(`${consumer.name} ${cell.decides}`, cell.assert);
}
});
@@ -1925,52 +1870,11 @@ describe.each(SCHEME_KINDS)("a %s scheme", (kind) => {
describe.each(BROKERED_PROBE_OUTCOMES)("a probe that %s", (outcome) => {
for (const consumer of PROBE_CONSUMERS) {
const cell = consumer.cells[outcome];
- if ("claimedBy" in cell) {
- test(`${consumer.name} — DECLARED, not asserted: ${cell.decides}`, () => {
- expect(cell.claimedBy).not.toBe("");
- expect(DECLARED_CELLS).toContain(`${consumer.name} × ${outcome}`);
- });
- continue;
- }
test(`${consumer.name} ${cell.decides}`, cell.assert);
}
});
-/**
- * THE COMPLETENESS HALF, WHICH IS WHAT MAKES THE TABLE A LEVER RATHER THAN A LIST.
- *
- * The rows are read off the production rosters, so a member added to either vocabulary arrives here
- * and every consumer with no cell for it fails BY NAME. That is the same discipline
- * `composio-adapter.test.ts` applies to the vendor seam, and it is the runtime half of the
- * compile-time witnesses: `tsc` names the consumers whose `Decides<…>` roster is short, and this
- * names the consumers whose behaviour nobody wrote down.
- */
-describe("the vocabularies are covered by name and not by accident", () => {
- test("every consumer of a scheme kind has a cell for every member", () => {
- for (const consumer of SCHEME_CONSUMERS) {
- expect(Object.keys(consumer.cells).sort()).toEqual(
- [...SCHEME_KINDS].sort(),
- );
- }
- });
-
- test("every consumer of a probe outcome has a cell for every member", () => {
- for (const consumer of PROBE_CONSUMERS) {
- expect(Object.keys(consumer.cells).sort()).toEqual(
- [...BROKERED_PROBE_OUTCOMES].sort(),
- );
- }
- });
-
- test("the cells that are declared rather than asserted are exactly the ones an open finding claims", () => {
- expect(
- [
- ...declaredCellsOf(SCHEME_CONSUMERS),
- ...declaredCellsOf(PROBE_CONSUMERS),
- ].sort(),
- ).toEqual([...DECLARED_CELLS].sort());
- });
-
+describe("scheme classifier coverage", () => {
/**
* AND EVERY MEMBER IS ONE THE CLASSIFIER CAN ACTUALLY PRODUCE, which is the hole a table of
* consumers cannot see on its own. A member no recorded value ever classifies to is a member every
diff --git a/server/tests/composio-connections.test.ts b/server/tests/composio-connections.test.ts
index ed8267ef..9c52798a 100644
--- a/server/tests/composio-connections.test.ts
+++ b/server/tests/composio-connections.test.ts
@@ -415,14 +415,6 @@ const ownedToolkits = [
refreshedToolkit,
unschemedToolkit,
];
-/**
- * An app this file does NOT own, standing in for another run's fixture — or another file's.
- *
- * It carries this run's suffix so it cannot collide with a real row, and it is deliberately absent
- * from {@link ownedToolkits} so {@link clean} cannot reach it. Its whole purpose is to be the row
- * that a sweep keyed on `user_id` alone would take by mistake.
- */
-const foreignToolkit = `foreign-${suite}`;
/**
* The app the probe chooser reads, which holds actions and nothing else.
*
@@ -891,21 +883,6 @@ async function clean() {
await database.delete(users).where(inArray(users.id, [askerId, leaverId]));
}
-/**
- * The stand-in for somebody else's fixture, taken back by hand.
- *
- * Deliberately NOT part of {@link clean}, because a test below asserts that `clean` leaves this row
- * standing: folding it in would make that assertion agree with itself. Run beside `clean` from
- * `beforeEach` and `afterAll` instead, so the row cannot outlive the run even if the test that
- * inserts it dies partway — the same shared database that makes the row worth protecting makes a
- * leaked one everybody's problem.
- */
-async function cleanForeign() {
- await database
- .delete(brokeredConnections)
- .where(eq(brokeredConnections.app, foreignToolkit));
-}
-
/** Which of this run's app rows the deployment still holds, so "the app survived" is an assertion. */
async function appsHeld(): Promise<string[]> {
const rows = await database
@@ -1068,21 +1045,15 @@ async function addRenamedApp() {
* unreachable by the cleanup here, and reddens this file for everybody until the database is edited
* by hand. Narrowing to named apps is what makes the assertion about this run.
*
- * `within` DEFAULTS TO THIS RUN'S OWN APPS and is passed explicitly only to ask about
- * {@link foreignToolkit} — the one row this file holds that it deliberately does not own, and
- * therefore the one it has to be able to ask about separately.
*/
-async function connectedToolkitsFor(
- userId: string,
- within: string[] = ownedToolkits,
-): Promise<string[]> {
+async function connectedToolkitsFor(userId: string): Promise<string[]> {
const rows = await database
.select({ toolkit: brokeredConnections.app })
.from(brokeredConnections)
.where(
and(
eq(brokeredConnections.userId, userId),
- inArray(brokeredConnections.app, within),
+ inArray(brokeredConnections.app, ownedToolkits),
),
)
.orderBy(asc(brokeredConnections.app));
@@ -1097,7 +1068,6 @@ function recordedOfType(eventType: string) {
// one nothing to trip over.
beforeEach(async () => {
await clean();
- await cleanForeign();
events.length = 0;
reached.length = 0;
asks.length = 0;
@@ -1121,7 +1091,6 @@ afterEach(() => useComposioClient(null));
afterAll(async () => {
await clean();
- await cleanForeign();
});
/**
@@ -1478,56 +1447,6 @@ test("retiring nobody retires nothing and leaves the anonymous row alone", async
expect(asksMade()).toEqual([]);
});
-/**
- * The fixture above is taken back by the same sweep every other row here is, and by nothing wider.
- *
- * CRITERION. Two halves, and the second is the one that has teeth. After the sweep this run holds
- * no `composio_connections` row at all — the one at the anonymous actor included, which none of the
- * person ids that sweep names would reach — AND an anonymous row belonging to somebody else is
- * still standing.
- *
- * REASON. Brokered connections are removed here by toolkit, so the anonymous row is already
- * covered and needs no second, broader delete to reach it. Asserted rather than read off the code,
- * because the tempting spelling for "take the anonymous row too" is `user_id = ''`, which is every
- * app at once: the sweep that lands on another file's fixture.
- *
- * WHY THE SECOND HALF IS NOT OPTIONAL. "This run's rows are gone" is satisfied just as well by the
- * wider delete as by the narrow one — a `user_id = ''` sweep takes this run's anonymous row too,
- * and every assertion about absence goes on passing while the defect it forbids is present. Only a
- * row the correct sweep must LEAVE BEHIND can tell the two deletes apart, so {@link foreignToolkit}
- * stands in for one: a row this file inserted, deliberately outside {@link ownedToolkits}, at the
- * pair another run legitimately holds. It is cleaned up by {@link cleanForeign} rather than by the
- * sweep under test, for the reason given there.
- */
-test("the sweep takes this run's anonymous row without reaching by actor", async () => {
- await seedApp({ connect: false });
- await database.insert(brokeredConnections).values({
- provider: "composio",
- app: toolkit,
- holder: "person",
- userId: "",
- vendorUserId: "",
- });
- // Somebody else's anonymous row, at an app this file's sweep does not name.
- await database.insert(brokeredConnections).values({
- provider: "composio",
- app: foreignToolkit,
- holder: "person",
- userId: "",
- vendorUserId: "",
- });
- expect(await connectedToolkitsFor("")).toEqual([toolkit]);
-
- await clean();
-
- expect(await connectionsHeld()).toEqual([]);
- // And the row that was never this sweep's to take is exactly where it was. This is the assertion
- // a delete keyed on `user_id = ''` fails, and the only one here that it fails.
- expect(await connectedToolkitsFor("", [foreignToolkit])).toEqual([
- foreignToolkit,
- ]);
-});
-
/**
* REMOVING THE APP. The second act that has to end a brokered connection.
*
diff --git a/server/tests/composio-grants-for.test.ts b/server/tests/composio-grants-for.test.ts
index e8d89373..db7fcd6f 100644
--- a/server/tests/composio-grants-for.test.ts
+++ b/server/tests/composio-grants-for.test.ts
@@ -1,9 +1,5 @@
import { describe, expect, test } from "bun:test";
-import type {
- AuthorizationFlow,
- ConnectedAppBroker,
- GrantState,
-} from "../src/plugins/broker";
+import type { ConnectedAppBroker, GrantState } from "../src/plugins/broker";
import {
type ComposioVendor,
buildComposioClient,
@@ -664,35 +660,4 @@ describe("the declared sub-surface", () => {
expect(omitted.grantIsLocal).toBe(true);
expect(declared.authorizations).toBeNull();
});
-
- /**
- * THE OTHER HALF, AND IT IS ABOUT THE BROKER RATHER THAN ABOUT THE FLOW. This used to read
- * `expect(flow).not.toBeNull()` on an object literal three lines above it — true of every object
- * ever written, and silent on the one thing the test is named for: that a broker which RUNS the
- * flow carries it on the declared field, where a route's presence test finds it and reaches the
- * two members through it.
- */
- test("a broker that runs the flow declares the sub-surface instead", async () => {
- const flow: AuthorizationFlow = {
- status: async () => ({ status: "completed", userId: null, scopes: [] }),
- confirmReturn: async () => ({ mismatch: true }),
- };
-
- const declared: ConnectedAppBroker = { ...members, authorizations: flow };
-
- // The presence test a route makes, and then the flow itself, reached only through the field.
- expect(declared.authorizations).not.toBeNull();
- expect(declared.authorizations).toBe(flow);
- expect(await declared.authorizations?.status("auth_1")).toEqual({
- status: "completed",
- userId: null,
- scopes: [],
- });
- expect(
- await declared.authorizations?.confirmReturn({
- handle: "flow_1",
- vendorUserId: ACCOUNT.vendorUserId,
- }),
- ).toEqual({ mismatch: true });
- });
});
diff --git a/server/tests/computer-client.test.ts b/server/tests/computer-client.test.ts
index e7b6d891..7641e80b 100644
--- a/server/tests/computer-client.test.ts
+++ b/server/tests/computer-client.test.ts
@@ -413,55 +413,9 @@ describe("the caller's Stop", () => {
expect(error).toBeInstanceOf(ComputerUnavailableError);
expect(called).toBe(false);
});
-
- test("without one, the timeout still applies", async () => {
- let seen: AbortSignal | undefined;
- const client = clientWith((_url, init) => {
- seen = init?.signal ?? undefined;
- return ok({ action: "click" });
- });
-
- await client.click({ ref: "e1", snapshotId: 1 });
-
- // A caller that passes nothing must not end up with an unbounded request.
- expect(seen).toBeDefined();
- });
});
describe("the deadline a call is given", () => {
- test("a command outlasts the shell's own maximum; a browser action does not", async () => {
- /*
- * The shell's budget is 120s by default and 600s at most, and it reports `timedOut` itself. A
- * transport deadline shorter than that told the person the computer had gone quiet while the
- * command ran to completion inside the container, and made the shell's own maximum unreachable.
- */
- const deadlines: number[] = [];
- const fetchImpl = (async (_url: string, init?: RequestInit) => {
- // AbortSignal.timeout is not readable, so the deadline is observed by racing it.
- const signal = init?.signal;
- deadlines.push(signal ? 1 : 0);
- return new Response(JSON.stringify({ ok: true }), {
- headers: { "content-type": "application/json" },
- });
- }) as unknown as typeof fetch;
-
- const transport = createComputerTransport({ fetchImpl, timeoutMs: 45_000 });
-
- // Both calls succeed; what matters is that the override is accepted and passed down rather than
- // silently dropped, which a signature change could do without any test noticing.
- await transport.post("http://computer", "bot-1", "/click", {}, undefined);
- await transport.post(
- "http://computer",
- "bot-1",
- "/exec",
- {},
- undefined,
- 615_000,
- );
-
- expect(deadlines).toEqual([1, 1]);
- });
-
test("the override is what bounds the request, not the transport default", async () => {
// A 20ms transport default with a call that takes 60ms: without the override this rejects.
const slow = (async (_url: string, init?: RequestInit) => {
diff --git a/server/tests/connector-tokens-never-reach-computer.test.ts b/server/tests/connector-tokens-never-reach-computer.test.ts
index d99571a8..2c27c1c8 100644
--- a/server/tests/connector-tokens-never-reach-computer.test.ts
+++ b/server/tests/connector-tokens-never-reach-computer.test.ts
@@ -1,50 +1,7 @@
import { describe, expect, test } from "bun:test";
-import { readdir, readFile } from "node:fs/promises";
-import { join } from "node:path";
import { environmentFor } from "../../supervisor/src/environment";
-/**
- * "Connector tokens are never stored on the computer."
- *
- * Checked two ways. Structurally: nothing a Bot's computer runs (agent-computer) and nothing the
- * server sends it through (server/src/computer) can reach the credential vault or the connector
- * store. And at the one place a computer's environment is built: the supervisor forwards a fixed
- * list, so a deployment's secrets stay behind however many of them the server's own environment has.
- */
-const root = join(import.meta.dir, "..", "..");
-
-async function sources(directory: string): Promise<string[]> {
- const entries = await readdir(directory, { withFileTypes: true });
- const files = await Promise.all(
- entries.map((entry) =>
- entry.isDirectory()
- ? sources(join(directory, entry.name))
- : entry.name.endsWith(".ts")
- ? [join(directory, entry.name)]
- : [],
- ),
- );
- return files.flat();
-}
-
-const FORBIDDEN =
- /from\s+["'](?:\.\.\/)+(?:credentials|plugins\/[^"']*|passwords\/(?:store|service)|provider-oauth[^"']*|google-oauth-transport)["']/;
-
describe("connector tokens never reach a Bot's computer", () => {
- test("the computer and the server's computer module import no credential or connector code", async () => {
- const files = [
- ...(await sources(join(root, "agent-computer", "src"))),
- ...(await sources(join(root, "server", "src", "computer"))),
- ];
- expect(files.length).toBeGreaterThan(10);
- const offenders: string[] = [];
- for (const file of files) {
- const text = await readFile(file, "utf8");
- if (FORBIDDEN.test(text)) offenders.push(file);
- }
- expect(offenders).toEqual([]);
- });
-
test("a computer's environment carries none of the deployment's secrets", () => {
const placeholder = "placeholder-connector-value-0000";
const env = environmentFor("bot-1", {
diff --git a/server/tests/control-refusal-end-to-end.test.ts b/server/tests/control-refusal-end-to-end.test.ts
index 0ec79f11..b9be476e 100644
--- a/server/tests/control-refusal-end-to-end.test.ts
+++ b/server/tests/control-refusal-end-to-end.test.ts
@@ -155,20 +155,4 @@ describe("a refusal because a person has the wheel", () => {
expect(status).toBe(409);
expect(body.humanHasControl).toBe(true);
});
-
- test("the refusal is still audited as a refusal", async () => {
- // The gateway writes a row when a forwarded action fails. Telling the caller something new must
- // not quietly cost the trail the record that the action did not happen.
- const { rows } = await click(
- computerAnswering(
- {
- error: "A person has taken control of this computer.",
- humanHasControl: true,
- },
- 409,
- ),
- );
-
- expect(rows.length).toBeGreaterThan(0);
- });
});
diff --git a/server/tests/cull-sweep-wiring.test.ts b/server/tests/cull-sweep-wiring.test.ts
deleted file mode 100644
index 5c3d4164..00000000
--- a/server/tests/cull-sweep-wiring.test.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
-
-/**
- * What the sweep passes, asserted against the script's own source.
- *
- * The script cannot be imported to be tested: it opens a database and a computer provider at the top
- * level and runs a sweep as a side effect of loading. So the retention window it hands `purge` is the
- * one line in this fix that nothing executes, and every test around it passes the window itself,
- * which means they would all still be green with this line deleted.
- *
- * That is the failure this whole change is about, one level up: a value the caller never names
- * reaches nothing, and the sweep goes on looking like it worked. Read as text, the way
- * `tests/compose.test.ts` pins the variables Compose has to name, because the alternative is a fix
- * whose only load-bearing line is the untested one.
- *
- * WHAT THIS CANNOT SEE. It proves the argument is written and where its value comes from, not that
- * the sweep behaves. `computer-culler.integration.test.ts` owns the behaviour and runs the real
- * queue against a real database; this is only the wire between the two.
- */
-const script = readFileSync(
- join(import.meta.dir, "..", "scripts", "cull-idle-computers.ts"),
- "utf8",
-);
-
-test("the cull sweep keeps a finished suspension for the configured idle window", () => {
- expect(script).toContain("finishedOlderThanMs: config.computer.idleAfterMs");
-});
-
-/**
- * And that the other half still gets its day.
- *
- * The two windows exist because they are different questions. A sweep that passed the idle window for
- * both would turn a suspension that keeps failing into one retried every few minutes, which is the
- * regression this fix could most easily cause and the one nothing else would report.
- */
-test("and gives a suspension that gave up the longer window before it is tried again", () => {
- expect(script).toContain("olderThanMs: 24 * 60 * 60 * 1000");
-});
diff --git a/server/tests/database.test.ts b/server/tests/database.test.ts
deleted file mode 100644
index ee55ca9d..00000000
--- a/server/tests/database.test.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { expect, test } from "bun:test";
-import { createDatabase } from "../src/db/client";
-import { TEST_POOL } from "./support/database";
-
-test("creates a typed database boundary without opening a query", () => {
- const database = createDatabase(
- "postgres://openbot:openbot@localhost:5432/openbot",
- TEST_POOL,
- );
-
- expect(database.query.users).toBeDefined();
-});
diff --git a/server/tests/fixture-identity-distinct.test.ts b/server/tests/fixture-identity-distinct.test.ts
deleted file mode 100644
index 8c210de4..00000000
--- a/server/tests/fixture-identity-distinct.test.ts
+++ /dev/null
@@ -1,425 +0,0 @@
-// server/tests/fixture-identity-distinct.test.ts
-/**
- * Guard: an account fixture's LOCAL id and its VENDOR id are not the same value.
- *
- * WHY THIS EXISTS. An account ref carries two ids for two different people-in-two-systems:
- * `userId` is who the person is HERE, `vendorUserId` is who the broker knows them as. A broker that
- * asks the vendor under `userId` is asking about somebody else. Round 2's A8a found every one of the
- * 79 person fixtures in `composio-adapter.test.ts` spelling both as `"user_1"` — so no test could
- * tell the two apart, and five planted wrong-identity defects (`revoke`, `isConnected`,
- * `accountName`, `authorize`, `connectWithFields` each asking under `account.userId`) passed 245 of
- * 245 tests. A8a separated the ids and the same plants now redden 1 to 18 tests each. Nothing
- * stopped the collapse coming back; this does.
- *
- * WHAT IT SEES. Every object literal, in every `.ts`/`.tsx` file under the scanned roots, that
- * names BOTH fields of a pair in {@link PAIRS}. The two values are compared after resolving
- * same-file `const` bindings, so `vendorUserId: VENDOR_USER` with `const VENDOR_USER = "user_1"`
- * beside `userId: "user_1"` IS a collapse — that is A8a's exact shape, and a purely textual compare
- * would miss it. Shorthand (`{ userId, vendorUserId: userId }`) is read as the name it binds.
- *
- * WHAT IT DOES NOT SEE — the stated boundary, so nobody reads this as wider than it is:
- * - a value imported from another file is compared by NAME, not resolved;
- * - a `let`, a parameter, or a name bound more than once in the file is compared by name, not
- * value (two different parameters that receive the same string at runtime are invisible);
- * - an object built by spread (`{ ...base, vendorUserId: x }`) or by assignment after the fact —
- * only literals naming both fields are read;
- * - raw SQL (`INSERT … (user_id, vendor_user_id) VALUES …`) — strings are not parsed;
- * - production code: `server/src` is not scanned. See the note on `accountRefFor` below.
- *
- * NOT EVERY COLLAPSE IS A DEFECT, WHICH IS WHY THIS IS A RATCHET AND NOT A BAN. Production's
- * `accountRefFor` (`server/src/plugins/store.ts`) answers a Personal app with
- * `{ holder: "person", userId: actorId, vendorUserId: actorId }` — for a person, the vendor identity
- * IS the local id today. A store-level test that seeds a `brokered_connections` row or expects that
- * ref is right to collapse the two: it mirrors what production writes. A test that hands an account
- * STRAIGHT TO A BROKER is not — the broker's whole job there is to pick the right field, and a
- * collapsed fixture makes that choice untestable. The scan cannot tell those apart, so every
- * collapse standing today is recorded in {@link KNOWN_COLLAPSES}, keyed by path + quoted expression
- * with a count (never `path:line` — the line-keyed ALLOW list in `assertion-shape.test.ts` collided
- * three waves running; `sole-definition.test.ts`'s path-keyed list never has). Equality both ways:
- *
- * - MORE fails: a new collapse anywhere — including any file with no entry at all, which is
- * every broker-adapter suite today. Separate the ids; if the new site truly mirrors
- * `accountRefFor`'s person ref, raise that entry's count and say so in the commit.
- * - FEWER fails: a collapse was separated, so the list is stale. Lower or delete the entry.
- *
- * A SECOND RULE, ACROSS FIXTURES. Within one file, no literal id may be a local id in one fixture
- * and a vendor id in another. Two crossed fixtures are as blind as one collapsed one: a broker that
- * asks under the wrong field finds the other fixture's account and the test passes.
- */
-import { expect, test } from "bun:test";
-import { existsSync, readFileSync } from "node:fs";
-import { join } from "node:path";
-import ts from "typescript";
-import { sourceFiles } from "./support/source-scan";
-
-const REPO = join(import.meta.dir, "../..");
-
-/** Where fixtures live. Production is deliberately absent — see the module comment. */
-const ROOTS = ["server/tests", "app/tests"];
-
-/** One row per pair of fields that name the same person in two systems. Add pairs as rows. */
-const PAIRS: readonly { local: string; vendor: string }[] = [
- { local: "userId", vendor: "vendorUserId" },
- { local: "user_id", vendor: "vendor_user_id" },
-];
-
-/**
- * Collapses standing at `f4f6974b`, by file, as `"<local expr> | <vendor expr>": count`.
- *
- * RECORDED, NOT BLESSED. These are of three kinds, and only the first two are harmless:
- *
- * - ROWS seeded the way production writes them (`brokered_connections`, `pending_authorizations`
- * for a person, vendor id = actor id), and refs a fake `accountRefFor` answers in that shape.
- * - EXPECTATIONS of what a route handed a broker spy, after the real `accountRefFor` collapsed
- * the two — right for as long as production does.
- * - REFS FED STRAIGHT TO A STORE METHOD OR A BROKER — the A8a shape one layer up. The store reads
- * `account.vendorUserId` to find rows, and with both ids equal nothing in these files can tell
- * if it read `userId` instead. Known: `composio-connections.test.ts` (`askerId` into
- * `connectBrokeredWithFields`, `recheckBrokeredConnection`, `confirmBrokeredConnection`,
- * `disconnectBrokered`, `probeBrokeredConnection`), `composio-connection-kinds.test.ts`
- * (`PERSON_ACCOUNT`), `arcade-disconnect-cascade.test.ts` (`disconnectBrokered`),
- * `arcade-siblings.test.ts` (`siblingApps`), `store-vendor-vocabulary.test.ts`
- * (`recheckBrokeredConnection`), and `composio-broker-seam.test.ts` /
- * `test-network-guard.test.ts` (`broker.authorize`, whose subject there is transport, not
- * identity). Separating these is fix-cycle work; when one is separated this list goes red
- * until its entry is lowered, which is the point.
- *
- * Every broker-adapter suite (`composio-adapter`, `arcade-adapter*`, `arcade-*-engine`,
- * `composio-grants-for`, …) has NO entry, so its allowance is zero.
- */
-const KNOWN_COLLAPSES: Record<string, Record<string, number>> = {
- "server/tests/account-mode.integration.test.ts": {
- "`p1-${suite}` | `p1-${suite}`": 1,
- "`p2-${suite}` | `p2-${suite}`": 1,
- },
- "server/tests/arcade-authorize-route.test.ts": {
- "actor | actor": 1,
- },
- "server/tests/arcade-disconnect-cascade.test.ts": {
- "userId | userId": 2,
- },
- "server/tests/arcade-grants-route.test.ts": {
- "n.viewer | n.viewer": 2,
- },
- "server/tests/arcade-journey.integration.test.ts": {
- "ADMIN | ADMIN": 2,
- },
- "server/tests/arcade-siblings.test.ts": {
- "mine | mine": 1,
- "userId | userId": 5,
- },
- "server/tests/arcade-verify.test.ts": {
- "ACTOR | ACTOR": 6,
- "vendorUserId | vendorUserId": 1,
- },
- "server/tests/composio-broker-seam.test.ts": {
- '"u" | "u"': 1,
- },
- // The row Connect records for a person's held account, expected as the store writes it.
- "server/tests/composio-connect-adopts-held-account.test.ts": {
- "PERSON | PERSON": 1,
- },
- "server/tests/composio-connection-kinds.test.ts": {
- "person | person": 14,
- },
- "server/tests/composio-connections.test.ts": {
- '"" | ""': 3,
- "askerId | askerId": 59,
- "leaverId | leaverId": 4,
- },
- "server/tests/memory-defaults.integration.test.ts": {
- "owner | owner": 1,
- },
- "server/tests/plugin-routes.test.ts": {
- "ADMIN.id | ADMIN.id": 1,
- "DEV_ACTOR.id | DEV_ACTOR.id": 1,
- "actorId | actorId": 1,
- },
- "server/tests/plugin-store.integration.test.ts": {
- '"" | ""': 2,
- '"user-a" | "user-a"': 1,
- '"user-b" | "user-b"': 1,
- '"user_asker" | "user_asker"': 2,
- '"user_leaver" | "user_leaver"': 4,
- "userId | userId": 14,
- },
- "server/tests/remove-server-foreign-provenance.test.ts": {
- "userId | userId": 1,
- },
- "server/tests/routes-arcade-urls.test.ts": {
- '"admin-1" | "admin-1"': 1,
- "actorId | actorId": 1,
- },
- "server/tests/routes-vendor-vocabulary.test.ts": {
- "actorId | actorId": 1,
- },
- "server/tests/shared-brokered-schema.integration.test.ts": {
- "`a-${suite}` | `a-${suite}`": 2,
- "`b-${suite}` | `b-${suite}`": 1,
- },
- "server/tests/shared-brokered-store.integration.test.ts": {
- "asker | asker": 2,
- },
- "server/tests/store-scheme-sites.test.ts": {
- "userId | userId": 1,
- },
- "server/tests/store-vendor-vocabulary.test.ts": {
- '"person-1" | "person-1"': 2,
- },
- "server/tests/test-network-guard.test.ts": {
- '"u" | "u"': 1,
- },
- "server/tests/vendor-deadline-sync-throw.test.ts": {
- "actorId | actorId": 1,
- },
-};
-
-/** A literal that was a local id in one fixture and a vendor id in another, by file. */
-const KNOWN_CROSSINGS: Record<string, string[]> = {};
-
-type Site = {
- path: string;
- local: string;
- vendor: string;
- localValue: string;
- vendorValue: string;
-};
-
-/** Every `const NAME = <expr>` in the file whose NAME is bound exactly once there. */
-function constBindings(source: ts.SourceFile): Map<string, ts.Expression> {
- const seen = new Map<string, number>();
- const init = new Map<string, ts.Expression>();
- const bind = (name: ts.BindingName) => {
- if (ts.isIdentifier(name))
- seen.set(name.text, (seen.get(name.text) ?? 0) + 1);
- else
- for (const el of name.elements)
- if (!ts.isOmittedExpression(el)) bind(el.name);
- };
- const visit = (node: ts.Node) => {
- if (ts.isVariableDeclaration(node)) {
- bind(node.name);
- const isConst =
- ts.isVariableDeclarationList(node.parent) &&
- (node.parent.flags & ts.NodeFlags.Const) !== 0;
- if (isConst && ts.isIdentifier(node.name) && node.initializer) {
- init.set(node.name.text, node.initializer);
- }
- } else if (ts.isParameter(node)) bind(node.name);
- else if (
- (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) &&
- node.name
- ) {
- bind(node.name);
- }
- ts.forEachChild(node, visit);
- };
- visit(source);
- for (const [name, count] of seen) if (count > 1) init.delete(name);
- return init;
-}
-
-/** The value an expression stands for, as far as one file can say: a quoted string, or its text. */
-function resolve(
- expr: ts.Expression,
- source: ts.SourceFile,
- consts: Map<string, ts.Expression>,
- depth = 0,
-): string {
- if (depth > 8) return expr.getText(source);
- if (
- ts.isParenthesizedExpression(expr) ||
- ts.isAsExpression(expr) ||
- ts.isSatisfiesExpression(expr) ||
- ts.isNonNullExpression(expr)
- ) {
- return resolve(expr.expression, source, consts, depth + 1);
- }
- if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
- return JSON.stringify(expr.text);
- }
- if (ts.isIdentifier(expr)) {
- const bound = consts.get(expr.text);
- return bound ? resolve(bound, source, consts, depth + 1) : expr.text;
- }
- if (ts.isTemplateExpression(expr)) {
- const parts = [expr.head.text];
- for (const span of expr.templateSpans) {
- parts.push(`\${${resolve(span.expression, source, consts, depth + 1)}}`);
- parts.push(span.literal.text);
- }
- return `\`${parts.join("")}\``;
- }
- return expr.getText(source).replace(/\s+/g, " ");
-}
-
-/** Every object literal in `text` that names both fields of a pair, with both values resolved. */
-function pairSites(path: string, text: string): Site[] {
- const kind = path.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
- const source = ts.createSourceFile(
- path,
- text,
- ts.ScriptTarget.Latest,
- true,
- kind,
- );
- const consts = constBindings(source);
- const out: Site[] = [];
- const field = (node: ts.ObjectLiteralExpression, key: string) =>
- node.properties.find(
- (p) =>
- p.name !== undefined &&
- (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) &&
- p.name.text === key,
- );
- const readField = (
- p: ts.ObjectLiteralElementLike,
- ): [string, string] | undefined => {
- if (ts.isPropertyAssignment(p)) {
- return [
- p.initializer.getText(source).replace(/\s+/g, " "),
- resolve(p.initializer, source, consts),
- ];
- }
- if (ts.isShorthandPropertyAssignment(p)) {
- return [p.name.text, resolve(p.name, source, consts)];
- }
- return undefined;
- };
- const visit = (node: ts.Node) => {
- if (ts.isObjectLiteralExpression(node)) {
- for (const { local, vendor } of PAIRS) {
- const l = field(node, local);
- const v = field(node, vendor);
- const lv = l && readField(l);
- const vv = v && readField(v);
- if (lv && vv) {
- out.push({
- path,
- local: lv[0],
- vendor: vv[0],
- localValue: lv[1],
- vendorValue: vv[1],
- });
- }
- }
- }
- ts.forEachChild(node, visit);
- };
- visit(source);
- return out;
-}
-
-function scan(): Site[] {
- const out: Site[] = [];
- for (const root of ROOTS) {
- const full = join(REPO, root);
- if (!existsSync(full)) continue;
- for (const file of sourceFiles(full, [".ts", ".tsx"])) {
- out.push(
- ...pairSites(file.slice(REPO.length + 1), readFileSync(file, "utf8")),
- );
- }
- }
- return out;
-}
-
-const isCollapse = (s: Site) => s.localValue === s.vendorValue;
-const isLiteral = (v: string) => v.startsWith('"');
-
-/** Collapses by file, as `"<local expr> | <vendor expr>": count`. */
-function collapsesOf(sites: Site[]): Record<string, Record<string, number>> {
- const out: Record<string, Record<string, number>> = {};
- for (const s of sites.filter(isCollapse)) {
- const byExpr = out[s.path] ?? {};
- out[s.path] = byExpr;
- const key = `${s.local} | ${s.vendor}`;
- byExpr[key] = (byExpr[key] ?? 0) + 1;
- }
- return out;
-}
-
-/** Literal ids used as a local id in one distinct fixture and a vendor id in another, by file. */
-function crossingsOf(sites: Site[]): Record<string, string[]> {
- const byFile = new Map<
- string,
- { locals: Set<string>; vendors: Set<string> }
- >();
- for (const s of sites) {
- if (isCollapse(s)) continue;
- const f = byFile.get(s.path) ?? { locals: new Set(), vendors: new Set() };
- byFile.set(s.path, f);
- if (isLiteral(s.localValue)) f.locals.add(s.localValue);
- if (isLiteral(s.vendorValue)) f.vendors.add(s.vendorValue);
- }
- const out: Record<string, string[]> = {};
- for (const [path, { locals, vendors }] of byFile) {
- const both = [...locals].filter((v) => vendors.has(v)).sort();
- if (both.length > 0) out[path] = both;
- }
- return out;
-}
-
-const sites = scan();
-
-test("the scan reaches the fixtures it claims to cover", () => {
- // An enumerator that silently stopped seeing files would turn every rule below green.
- // A8a's suite alone holds 79 person fixtures naming both ids.
- const adapter = sites.filter(
- (s) => s.path === "server/tests/composio-adapter.test.ts",
- );
- expect(adapter.length).toBeGreaterThanOrEqual(79);
- expect(new Set(sites.map((s) => s.path)).size).toBeGreaterThanOrEqual(40);
-});
-
-test("no account fixture names its local id and its vendor id as the same value, beyond the record", () => {
- expect(collapsesOf(sites)).toEqual(KNOWN_COLLAPSES);
-});
-
-test("no literal id is a local id in one fixture and a vendor id in another, beyond the record", () => {
- expect(crossingsOf(sites)).toEqual(KNOWN_CROSSINGS);
-});
-
-test("positive control: A8a's collapse, spelled through a const, is seen", () => {
- const collapsed = pairSites(
- "x.test.ts",
- `const VENDOR_USER = "user_1";
- broker.revoke({ account: { holder: "person", userId: "user_1", vendorUserId: VENDOR_USER } });`,
- );
- expect(collapsesOf(collapsed)).toEqual({
- "x.test.ts": { '"user_1" | VENDOR_USER': 1 },
- });
- const separated = pairSites(
- "x.test.ts",
- `const VENDOR_USER = "composio_user_1";
- broker.revoke({ account: { holder: "person", userId: "user_1", vendorUserId: VENDOR_USER } });`,
- );
- expect(collapsesOf(separated)).toEqual({});
-});
-
-test("positive control: shorthand, snake_case, and crossed fixtures are seen", () => {
- const sitesOf = pairSites(
- "y.test.ts",
- `function hold(vendorUserId: string) { return { userId: vendorUserId, vendorUserId }; }
- const row = { user_id: \`u-\${suite}\`, vendor_user_id: \`u-\${suite}\` };
- const a = { userId: "alice", vendorUserId: "v_alice" };
- const b = { userId: "v_alice", vendorUserId: "v_bob" };`,
- );
- expect(collapsesOf(sitesOf)).toEqual({
- "y.test.ts": {
- "vendorUserId | vendorUserId": 1,
- "`u-${suite}` | `u-${suite}`": 1,
- },
- });
- expect(crossingsOf(sitesOf)).toEqual({ "y.test.ts": ['"v_alice"'] });
-});
-
-test("negative control: a name bound twice is not resolved through either binding", () => {
- // Two `const id` in different scopes: resolving either would invent a collapse or hide one.
- const sitesOf = pairSites(
- "z.test.ts",
- `{ const id = "a"; } { const id = "b"; }
- const ref = { userId: "a", vendorUserId: id };`,
- );
- expect(collapsesOf(sitesOf)).toEqual({});
-});
diff --git a/server/tests/jsonb-encoding.integration.test.ts b/server/tests/jsonb-encoding.integration.test.ts
index f2d37949..f5fe1638 100644
--- a/server/tests/jsonb-encoding.integration.test.ts
+++ b/server/tests/jsonb-encoding.integration.test.ts
@@ -67,15 +67,4 @@ describe("what a jsonb column actually stores", () => {
expect(row?.bot).toBe(marker);
// Left in place: the trail is append-only, so a test cannot tidy up after itself. One row.
});
-
- test("the whole trail is objects, not strings", async () => {
- // A deployment that has run the migration has no string-shaped payloads left. Written as a sweep
- // rather than a single row because the failure this guards against is partial by nature: a new
- // column added with drizzle's `jsonb` would pass every test above and fail only here.
- const [row] = await database.execute<{ strings: number }>(
- sql`select count(*)::int as strings from audit_events
- where jsonb_typeof(payload) <> 'object'`,
- );
- expect(row?.strings).toBe(0);
- });
});
diff --git a/server/tests/mastra-roster.test.ts b/server/tests/mastra-roster.test.ts
index 1d91d67f..f58fe3a0 100644
--- a/server/tests/mastra-roster.test.ts
+++ b/server/tests/mastra-roster.test.ts
@@ -78,34 +78,3 @@ describe("duplicating a Mastra Bot", () => {
});
});
});
-
-describe("which endpoints get this deployment's token", () => {
- test("the harness picked during setup gets it, not only the Bot in the box", async () => {
- /*
- * The must-not case, and it was live: the picked harness was registered, addressable and
- * routed to, and answered `401 unauthorised` to everything, because the token was attached by
- * matching one endpoint exactly. Its container is this deployment's own, so it is the same
- * relationship the Bot in the box has.
- */
- const managedAgent = {
- endpoint: new URL("http://127.0.0.1:4201/ag-ui"),
- token: "the-deployment-token",
- alsoRun: new URL("http://127.0.0.1:4206"),
- };
- // Trailing slashes are the trap: `URL` adds one, a stored address need not have one, and an
- // exact match then fails silently and the Bot answers 401.
- const same = (url: string) => url.replace(/\/+$/, "");
- const ourEndpoints = [managedAgent.endpoint, managedAgent.alsoRun]
- .filter((url): url is URL => url !== undefined)
- .map((url) => same(url.toString()));
-
- expect(ourEndpoints).toContain(same("http://127.0.0.1:4206"));
- expect(ourEndpoints).toContain(same("http://127.0.0.1:4201/ag-ui"));
- // And the stored row, which has no trailing slash, matches the URL that grew one.
- expect(ourEndpoints).toContain(same("http://127.0.0.1:4206/"));
- // Somebody else's address is still somebody else's.
- expect(ourEndpoints).not.toContain(
- same("https://someone-else.example/ag-ui"),
- );
- });
-});
diff --git a/server/tests/migration-journal.test.ts b/server/tests/migration-journal.test.ts
index 922f5f6d..c1e7289d 100644
--- a/server/tests/migration-journal.test.ts
+++ b/server/tests/migration-journal.test.ts
@@ -147,13 +147,6 @@ const declared = (tail: string): { type: string; notNull: boolean } => ({
notNull: /\bNOT NULL\b/i.test(tail),
});
-test("column declarations exclude the cast on a quoted JSON default", () => {
- expect(declared(" jsonb DEFAULT '{}'::jsonb NOT NULL")).toEqual({
- type: "jsonb",
- notNull: true,
- });
-});
-
/**
* The text between a `(` and the `)` that closes it, with nested parentheses and quoted strings
* kept whole.
@@ -314,45 +307,6 @@ const checkDisagreements = (
return problems;
};
-test("a CHECK body is read past the parentheses of its own roster", () => {
- expect(
- checksIn(
- `ALTER TABLE "t" ADD CONSTRAINT "t_check" CHECK ("t"."c" IN ('a', 'b'));`,
- ),
- ).toEqual([{ table: "t", name: "t_check", value: `"t"."c" IN ('a', 'b')` }]);
-});
-
-test("a CHECK declared inside CREATE TABLE is read as the table's own", () => {
- expect(
- checksIn(
- `CREATE TABLE "t" (\n\t"c" text NOT NULL,\n\tCONSTRAINT "t_check" CHECK ("t"."c" IN ('a'))\n);`,
- ),
- ).toEqual([{ table: "t", name: "t_check", value: `"t"."c" IN ('a')` }]);
-});
-
-test("a widened roster disagrees with the snapshot that records the narrow one", () => {
- const snapshot = (value: string): Snapshot => ({
- tables: {
- "public.t": {
- name: "t",
- checkConstraints: { t_check: { name: "t_check", value } },
- },
- },
- });
-
- expect(
- checkDisagreements(
- `ALTER TABLE "t" DROP CONSTRAINT "t_check";--> statement-breakpoint\nALTER TABLE "t" ADD CONSTRAINT "t_check" CHECK ("t"."c" IN ('a', 'b', 'c'));`,
- snapshot(`"t"."c" IN ('a')`),
- snapshot(`"t"."c" IN ('a', 'b')`),
- [],
- ),
- ).toEqual([
- `the snapshot changes CHECK "t_check" on "t", the migration never writes that predicate`,
- `the migration adds CHECK "t_check" on "t", the snapshot does not record that predicate`,
- ]);
-});
-
const everyIndexName = (snapshot: Snapshot) =>
new Set(
Object.values(snapshot.tables ?? {}).flatMap((table) =>
@@ -525,29 +479,6 @@ describe("the migration journal", () => {
expect(stampedAhead(await readJournal(), Date.now())).toEqual([]);
});
- test("would have caught the migration stamped a day past the one before it", () => {
- /*
- * The mistake from the header, reconstructed, because the check above can only see it on the
- * day it is made. `0012` was stamped `previous + 86_400_000` and then sat in the journal for
- * years; asking today whether it is in the future says no, and says nothing about whether the
- * guard works. So ask on the day it was written instead, which is the day CI would have run on
- * the change that introduced it, and pin the answer here where the clock cannot erode it.
- */
- const authored = 1_787_358_347_113;
- const entries: Entry[] = [
- { idx: 11, tag: "0011_drop_the_old_connector_tables", when: authored },
- {
- idx: 12,
- tag: "0012_truncate_is_not_a_way_around_append_only",
- when: authored + 86_400_000,
- },
- ];
-
- expect(stampedAhead(entries, authored)).toEqual([
- "0012_truncate_is_not_a_way_around_append_only is stamped 1787444747113, 86400000ms ahead of the clock",
- ]);
- });
-
test("has an entry for every migration file, and a file for every entry", async () => {
// A journal and a directory that disagree is the other way this goes wrong quietly: a file with
// no entry never runs, and an entry with no file stops `migrate` dead.
diff --git a/server/tests/pending-authorization-audit-ledger.test.ts b/server/tests/pending-authorization-audit-ledger.test.ts
deleted file mode 100644
index 85386a27..00000000
--- a/server/tests/pending-authorization-audit-ledger.test.ts
+++ /dev/null
@@ -1,794 +0,0 @@
-// server/tests/pending-authorization-audit-ledger.test.ts
-/**
- * Guard: every write to `pending_authorizations` has a RECORDED AUDIT DECISION. It names the event
- * it files, or it is recorded as debt, or it carries a waiver that argues why no event fits.
- *
- * WHY THIS EXISTS. This PR's subject is attributable consent: a mint/claim/complete lifecycle whose
- * return leg is bound to the attempt the signed-in person actually minted. Round 2 wave 3 (B5e)
- * counted the transitions that lifecycle can make and found that one in nine filed an audit row.
- * Nothing had ever forced the question "which event?" when a write was added, so the question was
- * never asked. This ledger asks it. A new write site with no entry below fails, and so does an
- * entry whose site is gone. Adding an unaudited transition is now something somebody does on
- * purpose and writes down.
- *
- * THREE DISPOSITIONS, AND TWO OF THEM MUST NOT BE CONFUSED.
- *
- * - `audited`: names an event in `auditEventTypes` and the function that files it. The guard
- * checks that the named function contains that event literal. When the filer is not the writer
- * itself, it also checks that a call to the filer sits next to the write.
- * - `debt`: this transition SHOULD be audited and is not. That is a finding, and it carries the
- * finding id. It follows the `typecheck-baseline.txt` discipline: converting a debt row into
- * `audited` and deleting the debt is always correct. Adding one is not. {@link DEBT_CEILING}
- * pins the count so a new debt row has to be argued for in the same diff that adds it.
- * - `waived`: NO audit event is appropriate here. That is a judgement, and the reason is written
- * down. "It is not audited today" is never a waiver. That is debt.
- *
- * HOW IT IS KEYED, AND WHY NOT `path:line`. `assertion-shape.test.ts` is keyed by line and collided
- * in three consecutive waves. Here:
- *
- * - A write STATEMENT is keyed by its enclosing function's name plus the quoted write
- * expression. A migration is keyed by its file name instead.
- * - A CALL SITE of a writing method is keyed by file + method + ordinal (source order). An anchor
- * string confirms that each ordinal is still the transition the ledger says it is. The nearest
- * same-method call to the anchor must be this one.
- * - A CASCADE is keyed by its constraint name.
- *
- * Moving code around, rewrapping a comment or adding a line above changes none of these keys.
- *
- * WHAT GREEN MEANS, AND WHAT IT DOES NOT. Read this before trusting it.
- *
- * 1. IT CHECKS THE DECLARATION, NOT THE FIRING. For `audited` rows it checks that the event exists,
- * that the named filer files it, and that the filer is called beside the write. It does not
- * prove the event fires on every path through that write, or that the payload is clean (no
- * bearer consent url, no live `auth_id`). The behavioural plants for that are in
- * `arcade-authorize-cancel.test.ts` (B5b) and the completion tests.
- * 2. IT CANNOT SEE A TRANSITION THAT WRITES NOTHING. B2c is the example: a cancel that LOST the
- * race to a completion deletes no row, so no scan of write sites can find it. Such non-writes
- * are listed BY HAND in {@link NON_WRITES}. The guard only checks that each listed one still
- * exists where it says, so the list cannot go stale silently. It DISCOVERS NOTHING. A new
- * silent branch that writes nothing stays invisible here.
- * 3. IT SEES WRITES SPELLED THROUGH THE DRIZZLE SYMBOL OR THE LITERAL TABLE NAME. A table name
- * assembled at runtime (`sql.raw`, string concatenation) or a writer method passed by
- * reference is outside it. An aliased import of the table symbol, and a writer method named
- * without being called, are both refused outright rather than missed.
- * 4. CASCADES ARE READ FROM `server/drizzle/*.sql`, which is what the database runs. A schema
- * edit with no migration is a different defect, and this guard does not look for it.
- */
-import { expect, test } from "bun:test";
-import { existsSync, readFileSync } from "node:fs";
-import { basename, join } from "node:path";
-import { auditEventTypes } from "../src/audit";
-import { sourceFiles, stripComments } from "./support/source-scan";
-
-const REPO = join(import.meta.dir, "../..");
-
-/** TypeScript trees that can hold a write. Tests are excluded by file name below. */
-const TS_ROOTS = [
- "server/src",
- "server/scripts",
- "scripts",
- "worker",
- "shared",
-];
-const MIGRATIONS = "server/drizzle";
-
-type AuditEvent = (typeof auditEventTypes)[number];
-
-type Disposition =
- | { audited: AuditEvent; filedBy: string }
- | { debt: string; note: string }
- | { waived: string };
-
-type Transition = { name: string } & Disposition;
-
-/*
- * ─── THE LEDGER ──────────────────────────────────────────────────────────────────────────────
- */
-
-/**
- * Every statement that writes the table, keyed `<enclosing function or migration file> :: <write
- * expression>`.
- *
- * A row whose transitions depend on who called it says so: `decidedAtCallers`. That is not a pass.
- * It obliges every call of that function to appear in {@link CALL_SITES} with its own disposition,
- * and the guard enforces that.
- */
-const STATEMENTS: Record<
- string,
- { decidedAtCallers: true } | { transitions: Transition[] }
-> = {
- // The claim INSERT and the ON CONFLICT re-claim of an expired or settled row are one statement.
- // Their dispositions are recorded at the one call site.
- "claimAuthorizationAttempt :: INSERT INTO pending_authorizations": {
- decidedAtCallers: true,
- },
- "recordAuthorizationMint :: .update(pendingAuthorizations)": {
- decidedAtCallers: true,
- },
- // One DELETE behind three different endings: two mint-failure clean-ups and the person's cancel.
- "discardAuthorizationAttempt :: .delete(pendingAuthorizations)": {
- decidedAtCallers: true,
- },
- // The one statement behind failed, unreconciled and withdrawn; see DELEGATIONS.
- "closeAuthorizationAttempt :: .update(pendingAuthorizations)": {
- decidedAtCallers: true,
- },
- "completeAuthorizationAttempt :: UPDATE pending_authorizations": {
- decidedAtCallers: true,
- },
-};
-
-/**
- * Store-internal delegation: `from` is called ONLY by the listed wrappers. Every call of a wrapper
- * then needs a {@link CALL_SITES} row. If any other function calls `from`, that call is undeclared
- * and fails.
- */
-const DELEGATIONS: Record<string, string[]> = {
- closeAuthorizationAttempt: [
- "failAuthorizationAttempt",
- "markAuthorizationUnreconciled",
- "markAuthorizationWithdrawn",
- ],
-};
-
-/**
- * Every call of a writing method, keyed `<file> :: <method>`, IN SOURCE ORDER. Each entry has an
- * `anchor`: a string near the call that names the branch. The call nearest the anchor must be that
- * ordinal, so two calls cannot swap transitions without the guard noticing.
- */
-const CALL_SITES: Record<
- string,
- { anchor: string; transitions: Transition[] }[]
-> = {
- "server/src/plugins/route-groups/connections.ts :: claimAuthorizationAttempt":
- [
- {
- anchor: "if (!claim.claimed)",
- transitions: [
- {
- name: "claim (a person starts an authorization)",
- debt: "B5e",
- note: "The moment a signed-in person starts a consent leaves no row on the trail, so nothing records who started which attempt.",
- },
- {
- name: "expiry overwrite (re-claim silently replaces an expired or settled attempt)",
- debt: "B5e",
- note: "An attempt that expired while still live is never recorded as having ended. The next claim's ON CONFLICT DO UPDATE erases it.",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: discardAuthorizationAttempt":
- [
- {
- anchor: "arcade-refused-attempt-not-cleared",
- transitions: [
- {
- name: "discard after the vendor refused the mint",
- debt: "B5e",
- note: "A started attempt ends with only a console line on cleanup failure. A refusal on a consent lifecycle should be on the trail, as `mcp.callback_refused` and `session.refused` are elsewhere.",
- },
- ],
- },
- {
- anchor: "arcade-mint-not-recorded",
- transitions: [
- {
- name: "discard after the mint succeeded but could not be recorded",
- debt: "B5e",
- note: "A flow is LIVE at the vendor and the only record is the `arcade-mint-not-recorded` console line. This is the strongest case for an event in the ledger.",
- },
- ],
- },
- {
- anchor: "const cancelled = await store.discardAuthorizationAttempt",
- transitions: [
- {
- name: "withdrawn by the person (cancel)",
- audited: "mcp.authorization_cancelled",
- filedBy: "recordAuthorizationCancelled",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: recordAuthorizationMint": [
- {
- anchor: "authId: minted.authorizationId",
- transitions: [
- {
- name: "mint recorded (attempt bound to the vendor's authorization)",
- debt: "B5e",
- note: "The binding the return leg is checked against is written without a trail row. The `false` this call can answer is its own hand-listed transition in NON_WRITES.",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: failAuthorizationAttempt":
- [
- {
- anchor: 'settled.status === "failed"',
- transitions: [
- {
- name: "failed (the vendor reported the consent failed)",
- debt: "B5e",
- note: "A terminal verdict on the attempt with no trail row.",
- },
- ],
- },
- {
- anchor: "settled.userId !== attempt.vendorUserId",
- transitions: [
- {
- name: "failed (the consent completed for an identity that is not the attempt's)",
- debt: "B5e",
- note: "A return leg that came back bound to somebody else is the exact attribution failure this lifecycle exists to refuse, and the refusal leaves no row.",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: markAuthorizationWithdrawn":
- [
- {
- anchor: "if (withdrawn)",
- transitions: [
- {
- name: "withdrawn (context changed; the vendor withdrew the retired grant)",
- debt: "B5e",
- note: "Only indirectly audited. `clearWithdrawnAccount` files `mcp.account_disconnected` rows for what it cleared, but the verdict on the attempt itself is not filed.",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: markAuthorizationUnreconciled":
- [
- {
- anchor: "arcade-completion-not-permitted",
- transitions: [
- {
- name: "unreconciled (the person may no longer act on the app's account; nothing withdrawn)",
- debt: "B5e",
- note: "A consent live at the vendor that this deployment closed without recording or withdrawing — most often an administrator demoted mid-consent on a Shared app. The only record is a console line.",
- },
- ],
- },
- {
- anchor: "else await store.markAuthorizationUnreconciled",
- transitions: [
- {
- name: "unreconciled (context changed; withdrawing the retired grant was not confirmed)",
- debt: "B5e",
- note: "The case where a grant may still be live at the vendor, and the only record is a console line.",
- },
- ],
- },
- ],
- "server/src/plugins/route-groups/connections.ts :: completeAuthorizationAttempt":
- [
- {
- anchor: "recorded = claimed",
- transitions: [
- {
- name: "completed",
- audited: "mcp.account_connected",
- filedBy: "completeAuthorizationAttempt",
- },
- ],
- },
- ],
-};
-
-/** Every foreign key that deletes rows of this table when its parent goes, keyed by constraint. */
-const CASCADES: Record<string, Transition> = {
- pending_authorizations_server_id_mcp_servers_id_fk: {
- name: "cascade delete when the app's server row is removed",
- debt: "B5e",
- note: "`removeServer` files `configuration.changed` (`mcp_server_removed`) and names the grants it released. It does not name an in-flight attempt, which may already be consented at the vendor.",
- },
- pending_authorizations_actor_id_users_id_fk: {
- name: "cascade delete when the attempt's actor is deleted",
- debt: "B5e",
- note: "`retireConnectionsFor` files rows for the connections it retires. An attempt that dies with its actor, possibly minted and live at the vendor, is not among them.",
- },
- // `pending_authorizations_user_id_users_id_fk` was a third row here (debt B5e) until an earlier
- // draft of this table's migration dropped it: with nothing making `user_id` equal `actor_id`, it let one person's deletion take an
- // attempt a DIFFERENT person had started. `pending_authorizations_user_is_actor_check` now holds
- // the equality and the actor key above is the only cascade from `users`. Removed with the key,
- // and DEBT_CEILING lowered with it — not relabelled.
-};
-
-/**
- * Transitions that WRITE NOTHING and so cannot be found by a scan. They are listed by hand, and
- * each is checked only for still existing at its anchor. See boundary 2 in the file header.
- */
-const NON_WRITES: Record<
- string,
- { file: string; anchor: string } & Transition
-> = {
- "cancel that lost the race to a completion": {
- file: "server/src/plugins/route-groups/connections.ts",
- anchor: "That authorization finished before it could be cancelled",
- name: "cancel refused because the attempt had already completed",
- debt: "B2c",
- note: "The person asked to retract consent and the consent stood. The 409 tells them, and the trail records nothing about the request. The discard deleted nothing, so no write site exists for this guard to find.",
- },
- "completion that found its attempt already cancelled": {
- file: "server/src/plugins/route-groups/connections.ts",
- anchor: 'return refusedWith("cancelled")',
- name: "completion claimed nothing because the attempt was cancelled during the return leg",
- waived:
- "This branch ends no attempt: the cancel's deletion already ended it and filed `mcp.authorization_cancelled`, so a second row would record the same withdrawal twice. What the branch adds is a vendor-side withdrawal of the grant the return carried, or, where that would end more than the cancelled consent, an `arcade-cancelled-grant-left-live` line and an `mcp.cancelled_grant_left_live` row — which records the grant left live, not the attempt's ending.",
- },
- "mint that found its attempt already cancelled": {
- file: "server/src/plugins/route-groups/connections.ts",
- anchor: "That authorization was cancelled before it started",
- name: "mint declined because the attempt was cancelled while the vendor was minting (B5d)",
- waived:
- "This branch ends no attempt: the attempt it would describe was already ended by the person's cancel, and that cancel filed `mcp.authorization_cancelled` for it. A second row would record the same withdrawal twice. What the branch adds is a refusal to hand out the consent url, and that url, like the `ar_...`, must never reach the trail.",
- },
-};
-
-/**
- * The most debt rows the ledger may hold: transitions plus cascades plus non-writes. This may only
- * go DOWN. A fix that converts a row lowers it in the same diff. A new debt row has to raise it,
- * and that edit is the record that somebody decided to add one.
- */
-const DEBT_CEILING = 13;
-
-/*
- * ─── THE SCAN ────────────────────────────────────────────────────────────────────────────────
- */
-
-/** A named function, method or `const x = async` binding, i.e. what "enclosing function" means. */
-const DEFINITION =
- /(?:\basync\s+(?:function\s*\*?\s*)?([A-Za-z_$][\w$]*)\s*\(|\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\b|function\b)|\bfunction\s*\*?\s*([A-Za-z_$][\w$]*)\s*\()/g;
-
-type Definition = { name: string; at: number };
-
-function definitionsIn(code: string): Definition[] {
- const out: Definition[] = [];
- for (const m of code.matchAll(DEFINITION)) {
- const name = m[1] ?? m[2] ?? m[3];
- if (name && name !== "function") out.push({ name, at: m.index ?? 0 });
- }
- return out;
-}
-
-function enclosing(defs: Definition[], at: number): string {
- let name = "<module>";
- for (const def of defs) {
- if (def.at > at) break;
- name = def.name;
- }
- return name;
-}
-
-/** From a definition's header to the next definition: the text the function's body lives in. */
-function spanOf(code: string, defs: Definition[], name: string): string {
- const index = defs.findIndex((def) => def.name === name);
- if (index === -1) return "";
- return code.slice(defs[index].at, defs[index + 1]?.at ?? code.length);
-}
-
-function lineAt(code: string, at: number): number {
- return code.slice(0, at).split("\n").length;
-}
-
-/** Not a test, not a declaration file. */
-function isSource(path: string): boolean {
- return !/\.(test|spec)\.tsx?$|\.d\.ts$/.test(path);
-}
-
-type Scanned = { path: string; code: string; defs: Definition[] };
-
-function scanTs(): Scanned[] {
- const out: Scanned[] = [];
- for (const root of TS_ROOTS) {
- const full = join(REPO, root);
- if (!existsSync(full)) continue;
- for (const file of sourceFiles(full, [".ts", ".tsx"])) {
- if (!isSource(file) || file.includes("/node_modules/")) continue;
- const code = stripComments(readFileSync(file, "utf8"));
- out.push({
- path: file.slice(REPO.length + 1),
- code,
- defs: definitionsIn(code),
- });
- }
- }
- return out;
-}
-
-/** The SQL of every migration with `--` line comments blanked, per file. */
-function scanSql(): { file: string; sql: string }[] {
- return sourceFiles(join(REPO, MIGRATIONS), [".sql"]).map((file) => ({
- file: basename(file),
- sql: readFileSync(file, "utf8").replace(/--(?!>)[^\n]*/g, ""),
- }));
-}
-
-/** A write through the drizzle symbol, a raw statement or an interpolated symbol. */
-const TS_WRITE =
- /\.\s*(insert|update|delete)\s*\(\s*pendingAuthorizations\s*\)|\b(INSERT\s+INTO|UPDATE|DELETE\s+FROM|TRUNCATE(?:\s+TABLE)?)\s+(?:"?pending_authorizations"?|\$\{\s*pendingAuthorizations\s*\})(?![\w])/gi;
-
-const SQL_WRITE =
- /\b(INSERT\s+INTO|UPDATE|DELETE\s+FROM|TRUNCATE(?:\s+TABLE)?)\s+("?pending_authorizations"?)(?![\w])/gi;
-
-/** How an interpolated table symbol is spelled in a key: the `${…}` of a `sql` template. */
-const INTERPOLATED = `$${"{"}pendingAuthorizations}`;
-
-/** The ledger key of one TypeScript write: the enclosing function and the write, normalized. */
-function tsWriteKey(defs: Definition[], match: RegExpMatchArray): string {
- const expression = match[1]
- ? `.${match[1].toLowerCase()}(pendingAuthorizations)`
- : `${match[2].toUpperCase().replace(/\s+/g, " ")} ${
- match[0].includes(INTERPOLATED.slice(0, 2))
- ? INTERPOLATED
- : "pending_authorizations"
- }`;
- return `${enclosing(defs, match.index ?? 0)} :: ${expression}`;
-}
-
-function findWriteStatements(
- files: Scanned[],
- migrations: { file: string; sql: string }[],
-): string[] {
- const out: string[] = [];
- for (const { code, defs } of files) {
- for (const match of code.matchAll(TS_WRITE))
- out.push(tsWriteKey(defs, match));
- }
- for (const { file, sql } of migrations) {
- for (const match of sql.matchAll(SQL_WRITE)) {
- // CREATE TABLE and ALTER TABLE are DDL; only DML is a transition.
- out.push(
- `${file} :: ${match[1].toUpperCase().replace(/\s+/g, " ")} ${match[2]}`,
- );
- }
- }
- return out.sort();
-}
-
-/** Every `ON DELETE` other than `restrict`/`no action` on a foreign key OF this table. */
-function findCascades(migrations: { file: string; sql: string }[]): string[] {
- const live = new Set<string>();
- for (const { sql } of migrations) {
- for (const stmt of sql.split(/;|-->\s*statement-breakpoint/)) {
- const add =
- /ALTER\s+TABLE\s+"?pending_authorizations"?\s+ADD\s+CONSTRAINT\s+"([^"]+)"\s+FOREIGN\s+KEY[\s\S]*ON\s+DELETE\s+(cascade|set\s+null|set\s+default)/i.exec(
- stmt,
- );
- if (add) live.add(add[1]);
- const drop =
- /ALTER\s+TABLE\s+"?pending_authorizations"?\s+DROP\s+CONSTRAINT\s+(?:IF\s+EXISTS\s+)?"([^"]+)"/i.exec(
- stmt,
- );
- if (drop) live.delete(drop[1]);
- // A foreign key declared inline in CREATE TABLE.
- if (/CREATE\s+TABLE\s+"?pending_authorizations"?/i.test(stmt)) {
- for (const inline of stmt.matchAll(
- /CONSTRAINT\s+"([^"]+)"\s+FOREIGN\s+KEY[^,]*ON\s+DELETE\s+(?:cascade|set\s+null|set\s+default)/gi,
- )) {
- live.add(inline[1]);
- }
- }
- }
- }
- return [...live].sort();
-}
-
-/** Writer method names whose calls are transitions: statement sites decided at callers, plus wrappers. */
-function writerMethods(): string[] {
- const names = new Set<string>();
- for (const [key, entry] of Object.entries(STATEMENTS)) {
- if ("decidedAtCallers" in entry) names.add(key.split(" :: ")[0]);
- }
- for (const [from, via] of Object.entries(DELEGATIONS)) {
- names.delete(from);
- for (const wrapper of via) names.add(wrapper);
- }
- return [...names].sort();
-}
-
-type Call = { path: string; method: string; line: number; enclosing: string };
-
-/**
- * Every call of `names`, and every non-call mention of them (a method passed by reference is
- * a write the ledger cannot follow, so it is reported rather than missed).
- */
-function findCalls(
- files: Scanned[],
- names: string[],
-): { calls: Call[]; references: string[] } {
- const calls: Call[] = [];
- const references: string[] = [];
- for (const { path, code, defs } of files) {
- for (const method of names) {
- for (const m of code.matchAll(
- new RegExp(`(?<![\\w$])${method}(?![\\w$])`, "g"),
- )) {
- const at = m.index ?? 0;
- const before = code.slice(Math.max(0, at - 40), at);
- const after = code.slice(at + method.length);
- if (/(?:\basync|\bfunction\s*\*?|\b(?:const|let|var))\s+$/.test(before))
- continue; // its own definition
- if (/^\s*\(/.test(after)) {
- calls.push({
- path,
- method,
- line: lineAt(code, at),
- enclosing: enclosing(defs, at),
- });
- } else if (!/^\s*:/.test(after) && !/["'`]$/.test(before)) {
- // Not a call, not a property key or type member, not a string: a reference.
- references.push(`${path}:${lineAt(code, at)} ${method}`);
- }
- }
- }
- }
- return { calls, references };
-}
-
-function dispositionsOf(): Transition[] {
- return [
- ...Object.values(STATEMENTS).flatMap((entry) =>
- "transitions" in entry ? entry.transitions : [],
- ),
- ...Object.values(CALL_SITES).flatMap((sites) =>
- sites.flatMap((site) => site.transitions),
- ),
- ...Object.values(CASCADES),
- ...Object.values(NON_WRITES),
- ];
-}
-
-/*
- * ─── THE CHECKS ──────────────────────────────────────────────────────────────────────────────
- */
-
-/** How far, in lines, an anchor or a filer call may sit from the write it belongs to. */
-const ANCHOR_WINDOW = 20;
-
-const files = scanTs();
-const migrations = scanSql();
-
-test("every write statement against pending_authorizations is in the ledger, and every ledger statement still exists", () => {
- expect(findWriteStatements(files, migrations)).toEqual(
- Object.keys(STATEMENTS).sort(),
- );
-});
-
-test("the table symbol is never imported under another name, which would hide its writes", () => {
- const aliased = files
- .filter(({ code }) =>
- /\bpendingAuthorizations\s+as\s+[\w$]+|=\s*pendingAuthorizations\s*[;,\n]/.test(
- code,
- ),
- )
- .map(({ path }) => path);
- expect(aliased).toEqual([]);
-});
-
-test("every cascade that deletes attempts is in the ledger", () => {
- expect(findCascades(migrations)).toEqual(Object.keys(CASCADES).sort());
-});
-
-test("store-internal delegation goes only through the declared wrappers", () => {
- for (const [from, via] of Object.entries(DELEGATIONS)) {
- const { calls } = findCalls(files, [from]);
- expect(calls.map((call) => call.enclosing).sort()).toEqual([...via].sort());
- }
-});
-
-test("every call of a writing method has a disposition, in source order, at its anchor", () => {
- const methods = writerMethods();
- const { calls, references } = findCalls(files, methods);
- // A writer passed by reference escapes the call-site count; refuse it rather than miss it.
- expect(references).toEqual([]);
-
- const grouped = new Map<string, Call[]>();
- for (const call of calls) {
- const key = `${call.path} :: ${call.method}`;
- grouped.set(key, [...(grouped.get(key) ?? []), call]);
- }
- expect([...grouped.keys()].sort()).toEqual(Object.keys(CALL_SITES).sort());
-
- for (const [key, sites] of Object.entries(CALL_SITES)) {
- const found = (grouped.get(key) ?? []).sort((a, b) => a.line - b.line);
- expect({ key, count: found.length }).toEqual({ key, count: sites.length });
- const [path] = key.split(" :: ");
- const lines = (files.find((file) => file.path === path)?.code ?? "").split(
- "\n",
- );
- sites.forEach((site, ordinal) => {
- expect({
- key,
- ordinal,
- transitions: site.transitions.length > 0,
- }).toEqual({
- key,
- ordinal,
- transitions: true,
- });
- // The call NEAREST to some occurrence of the anchor must be this ordinal.
- const nearestToAnchor = lines.flatMap((text, index) => {
- if (!text.includes(site.anchor)) return [];
- const line = index + 1;
- const nearest = found.reduce(
- (best, call, i) =>
- Math.abs(call.line - line) < Math.abs(found[best].line - line)
- ? i
- : best,
- 0,
- );
- return Math.abs(found[nearest].line - line) <= ANCHOR_WINDOW
- ? [nearest]
- : [];
- });
- expect({
- key,
- ordinal,
- anchor: site.anchor,
- at: nearestToAnchor.includes(ordinal),
- }).toEqual({ key, ordinal, anchor: site.anchor, at: true });
-
- // An audited transition whose filer is not the writer must call the filer beside the write.
- for (const transition of site.transitions) {
- if (!("audited" in transition)) continue;
- if (transition.filedBy === key.split(" :: ")[1]) continue;
- const call = found[ordinal];
- const window = lines
- .slice(Math.max(0, call.line - 1), call.line - 1 + ANCHOR_WINDOW)
- .join("\n");
- expect({
- transition: transition.name,
- filerCalledAfterWrite: new RegExp(
- `(?<![\\w$])${transition.filedBy}\\s*\\(`,
- ).test(window),
- }).toEqual({
- transition: transition.name,
- filerCalledAfterWrite: true,
- });
- }
- });
- }
-});
-
-test("every audited transition names a real event, and its filer files exactly that event", () => {
- for (const transition of dispositionsOf()) {
- if (!("audited" in transition)) continue;
- expect(auditEventTypes).toContain(transition.audited);
- const filers = files.filter(({ defs }) =>
- defs.some((def) => def.name === transition.filedBy),
- );
- const filesIt = filers.map(({ code, defs }) =>
- spanOf(code, defs, transition.filedBy).includes(
- `eventType: "${transition.audited}"`,
- ),
- );
- expect({
- transition: transition.name,
- filesIt: filesIt.includes(true),
- }).toEqual({
- transition: transition.name,
- filesIt: true,
- });
- }
-});
-
-test("a waiver argues, and a debt names its finding", () => {
- const all = dispositionsOf();
- // A reason, not a label. "unaudited", "todo" and "n/a" are debt pretending to be judgement.
- const thinWaivers = all.flatMap((t) =>
- "waived" in t &&
- (t.waived.length <= 80 ||
- /^(todo|n\/?a|unaudited|none|tbd)\b/i.test(t.waived))
- ? [t.name]
- : [],
- );
- expect(thinWaivers).toEqual([]);
- const unnamedDebts = all.flatMap((t) =>
- "debt" in t && (!/^[A-Z]\d+[a-z]?$/.test(t.debt) || t.note.length <= 20)
- ? [t.name]
- : [],
- );
- expect(unnamedDebts).toEqual([]);
-});
-
-test("debt only goes down", () => {
- const debts = dispositionsOf().filter((t) => "debt" in t).length;
- // Equality, not <=: a converted row must lower the ceiling in the same diff, so it cannot
- // quietly make room for a new debt elsewhere.
- expect(debts).toBe(DEBT_CEILING);
-});
-
-test("every hand-listed non-write still exists where the ledger says", () => {
- for (const [key, entry] of Object.entries(NON_WRITES)) {
- const code = files.find((file) => file.path === entry.file)?.code ?? "";
- expect({ key, present: code.includes(entry.anchor) }).toEqual({
- key,
- present: true,
- });
- }
-});
-
-/*
- * ─── THE SCANNER'S OWN CONTROLS ──────────────────────────────────────────────────────────────
- * The checks above prove the ledger matches the tree. These prove the scanner would SEE a write
- * spelled each way it claims to, so a green above cannot mean "the pattern matches nothing".
- */
-
-test("the scanner sees every spelling of a write it claims to, and no read", () => {
- const plant = (code: string): Scanned => ({
- path: "planted.ts",
- code,
- defs: definitionsIn(code),
- });
- const writes = [
- "async a() { await db.insert(pendingAuthorizations).values({}); }",
- "async b() { await db\n .update( pendingAuthorizations )\n .set({}); }",
- "async c() { await tx.delete(pendingAuthorizations); }",
- "async d() { await db.execute(sql`INSERT INTO pending_authorizations (x) VALUES (1)`); }",
- "async e() { await db.execute(sql`update pending_authorizations set x = 1`); }",
- 'async f() { await db.execute(sql`DELETE FROM "pending_authorizations" WHERE 1`); }',
- `async g() { await db.execute(sql\`DELETE FROM ${INTERPOLATED} WHERE 1\`); }`,
- "const h = async () => { await db.execute(sql`TRUNCATE pending_authorizations`); };",
- ];
- expect(findWriteStatements(writes.map(plant), [])).toEqual([
- "a :: .insert(pendingAuthorizations)",
- "b :: .update(pendingAuthorizations)",
- "c :: .delete(pendingAuthorizations)",
- "d :: INSERT INTO pending_authorizations",
- "e :: UPDATE pending_authorizations",
- "f :: DELETE FROM pending_authorizations",
- `g :: DELETE FROM ${INTERPOLATED}`,
- "h :: TRUNCATE pending_authorizations",
- ]);
- const reads = [
- "async r() { await db.select().from(pendingAuthorizations); }",
- "async s() { await db.execute(sql`SELECT * FROM pending_authorizations`); }",
- "async t() { await db.update(pendingAuthorizationsArchive).set({}); }",
- "async u() { await db.execute(sql`UPDATE pending_authorizations_log SET x = 1`); }",
- ];
- expect(findWriteStatements(reads.map(plant), [])).toEqual([]);
- expect(
- findWriteStatements(
- [],
- [
- {
- file: "9999_x.sql",
- sql: 'CREATE TABLE "pending_authorizations" (x text);\nDELETE FROM "pending_authorizations" WHERE true;',
- },
- ],
- ),
- ).toEqual(['9999_x.sql :: DELETE FROM "pending_authorizations"']);
-});
-
-test("the cascade scan sees an added cascade and forgets a dropped one", () => {
- expect(
- findCascades([
- {
- file: "1.sql",
- sql: 'ALTER TABLE "pending_authorizations" ADD CONSTRAINT "k1" FOREIGN KEY ("a") REFERENCES "public"."x"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint\nALTER TABLE "pending_authorizations" ADD CONSTRAINT "k2" FOREIGN KEY ("b") REFERENCES "public"."y"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint\nALTER TABLE "pending_authorizations" ADD CONSTRAINT "k3" FOREIGN KEY ("c") REFERENCES "public"."z"("id") ON DELETE restrict ON UPDATE no action;',
- },
- {
- file: "2.sql",
- sql: 'ALTER TABLE "pending_authorizations" DROP CONSTRAINT "k1";',
- },
- ]),
- ).toEqual(["k2"]);
-});
-
-test("a writer called, passed by reference, or defined are told apart", () => {
- const code = [
- "async discardAuthorizationAttempt(input) {}",
- "await store.discardAuthorizationAttempt({ a: 1 });",
- "await store\n .discardAuthorizationAttempt({ a: 1 });",
- "promise.then(store.discardAuthorizationAttempt);",
- ].join("\n");
- const { calls, references } = findCalls(
- [{ path: "p.ts", code, defs: definitionsIn(code) }],
- ["discardAuthorizationAttempt"],
- );
- expect(calls.map((call) => call.line)).toEqual([2, 4]);
- expect(references).toEqual(["p.ts:5 discardAuthorizationAttempt"]);
-});
diff --git a/server/tests/people-paging.integration.test.ts b/server/tests/people-paging.integration.test.ts
index f6153961..95ea6695 100644
--- a/server/tests/people-paging.integration.test.ts
+++ b/server/tests/people-paging.integration.test.ts
@@ -145,26 +145,6 @@ describe("reading the people in a deployment", () => {
expect(byAddress.people.map((one) => one.id)).toEqual([wanted]);
});
- test("a search for a wildcard finds that, not everything", async () => {
- // `%` and `_` are LIKE syntax. Unescaped, searching for `100%` returns the deployment.
- await person(0, new Date(), "Ninety _ Percent");
- await person(1, new Date(Date.now() - 1000), "Somebody Else");
-
- const result = await store.list({ search: "_ Percent", limit: 10 });
- expect(result.people).toHaveLength(1);
- });
-
- test("a caller cannot ask for the whole deployment in one page", async () => {
- // The limit arrives over HTTP. A ceiling here is the thing that makes paging a property of the
- // endpoint rather than a suggestion to the client.
- for (let index = 0; index < 3; index += 1) {
- await person(index, new Date(Date.now() - index * 1000));
- }
-
- const asked = await store.list({ limit: 100_000 });
- expect(asked.people.length).toBeLessThanOrEqual(200);
- });
-
test("a nonsense cursor reads as the first page rather than an error", async () => {
// A stale link or a hand-edited URL. There is nothing here worth refusing over, and the first
// page is the honest answer to "I do not know where you were".
@@ -174,6 +154,47 @@ describe("reading the people in a deployment", () => {
expect(result.people.length).toBeGreaterThan(0);
});
+ test("search treats underscores and percent signs as literal characters", async () => {
+ const underscore = await person(0, new Date(), "Ninety_ Percent");
+ await person(1, new Date(), "NinetyX Percent");
+ const percent = await person(2, new Date(), "Ninety% Percent");
+
+ for (const [search, wanted] of [
+ ["Ninety_ Percent", underscore],
+ ["Ninety% Percent", percent],
+ ]) {
+ const result = await store.list({ search, limit: 10 });
+ expect(result.people.map((one) => one.id)).toEqual([wanted]);
+ }
+ });
+
+ test("caps an oversized page at 200 and leaves the rest reachable", async () => {
+ const base = Date.now();
+ const people = Array.from({ length: 201 }, (_, index) => ({
+ id: `${PREFIX}cap-${String(index).padStart(3, "0")}`,
+ email: `${PREFIX}cap-${index}@openbot.test`,
+ name: `Page cap fixture ${index}`,
+ emailVerified: true,
+ lastSignedInAt: new Date(base - index * 1000),
+ }));
+ ids.push(...people.map((one) => one.id));
+ await database.insert(users).values(people);
+
+ const first = await store.list({ search: `${PREFIX}cap-`, limit: 100_000 });
+ expect(first.people.map((one) => one.id)).toEqual(
+ people.slice(0, 200).map((one) => one.id),
+ );
+ if (!first.nextCursor)
+ throw new Error("Expected a cursor for the 201st person.");
+ const last = await store.list({
+ search: `${PREFIX}cap-`,
+ limit: 100_000,
+ cursor: first.nextCursor,
+ });
+ expect(last.people.map((one) => one.id)).toEqual([people[200]?.id]);
+ expect(last.nextCursor).toBeNull();
+ });
+
test("finding one person does not read the deployment", async () => {
const base = Date.now();
const wanted = await person(0, new Date(base));
diff --git a/server/tests/plugin-oauth.test.ts b/server/tests/plugin-oauth.test.ts
index 58e7a2a5..7b052737 100644
--- a/server/tests/plugin-oauth.test.ts
+++ b/server/tests/plugin-oauth.test.ts
@@ -221,14 +221,13 @@ describe("PKCE", () => {
expect(createVerifier()).not.toBe(createVerifier());
});
- test("a challenge is the S256 of the verifier, not the verifier", () => {
- // `plain` would make the challenge worthless: anybody who intercepted the authorization request
- // would hold the value needed to redeem the code.
- const verifier = "a".repeat(43);
- const challenge = challengeFor(verifier);
- expect(challenge).not.toBe(verifier);
- expect(challenge).toMatch(/^[A-Za-z0-9\-_]+$/);
+ test("derives the S256 challenge from the verifier", () => {
+ // RFC 7636 Appendix B: https://www.rfc-editor.org/rfc/rfc7636#appendix-B
+ const verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk";
+ const challenge = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM";
expect(challengeFor(verifier)).toBe(challenge);
+ // Also reject an implementation that always returns the published example.
+ expect(challengeFor("a".repeat(43))).not.toBe(challenge);
});
});
diff --git a/server/tests/plugin-store.integration.test.ts b/server/tests/plugin-store.integration.test.ts
index 342559f8..25c3c37c 100644
--- a/server/tests/plugin-store.integration.test.ts
+++ b/server/tests/plugin-store.integration.test.ts
@@ -8,8 +8,6 @@ import {
test,
} from "bun:test";
import { randomUUID } from "node:crypto";
-import { readdirSync, readFileSync } from "node:fs";
-import { join } from "node:path";
import { MCPMock, type MCPToolDefinition } from "@copilotkit/aimock/mcp";
import { readConnectPrompt } from "@openbot/shared/connect-prompt";
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
@@ -6740,65 +6738,6 @@ describe("a query of this deployment's own that failed", () => {
expect(failure).not.toContain("params:");
expect(failure).not.toContain("mcp_user_credentials");
});
-
- /**
- * AND THE ONE REMAINING SITE THAT ASKS NOTHING, read as text because nothing can drive it.
- *
- * WHY THERE IS NO BEHAVIOURAL TEST FOR THIS ONE, and why that is a reason to assert it rather
- * than to leave it. `refreshTools`' vendor `catch` opens with `isDeploymentFault`, which answers
- * true for a query failure, so every arrival whose message is a statement is raised before the
- * line below it can copy one. What that line can still be handed is a WRAPPER: `composio.ts`'s
- * `listTools` catches whatever the client threw and rethrows `new Error(listingSentence(...))`,
- * and `listingSentence` falls through to the thrown message verbatim. A wrapper has no `query`
- * and no `params` of its own, so it is not on the shelf and it is not a query failure by shape —
- * it is simply a message this deployment has stopped asking any question about. Nothing reachable
- * puts a statement inside one today, which is exactly the sentence that was true of the credential
- * envelope before the rotation path started writing one.
- *
- * SO WHAT IS ASSERTED IS THAT THE DOOR IS THE ONLY WAY THROUGH. `db/query-failure.ts` exists to be
- * the single place the question is asked; a site reading `.message` directly is a second answer to
- * it, and the last two leaks in this review were both a second answer that had drifted. The test
- * above owns the behaviour of the reachable path; this owns the shape of every path.
- */
- test("no recording site in the plugin store reads a caught message without asking", () => {
- // Every file the store is made of: the assembly in `store.ts` and the modules it was split into.
- const plugins = join(import.meta.dir, "..", "src", "plugins");
- const files = [
- "store.ts",
- ...readdirSync(join(plugins, "plugin-store"))
- .filter((name) => name.endsWith(".ts"))
- .map((name) => `plugin-store/${name}`),
- ];
- /*
- * Comments blanked rather than removed, because these files argue about `error.message` at
- * length — the prose naming the hazard must not be mistaken for the hazard, and the line
- * numbers reported below have to stay each file's own so a failure names where to look.
- */
- const code = files.map((file) => ({
- file,
- code: readFileSync(join(plugins, file), "utf8")
- .replace(/\/\*[\s\S]*?\*\//g, (block) => block.replace(/[^\n]/g, " "))
- .replace(/^([^\n"'`]*?)\/\/.*$/gm, "$1"),
- }));
-
- // Listed rather than matched, so a failure prints the line to correct instead of the file.
- expect(
- code.flatMap(({ file, code: text }) =>
- text
- .split("\n")
- .flatMap((line, index) =>
- /\berror\.message\b/.test(line)
- ? [`${file}:${index + 1}: ${line.trim()}`]
- : [],
- ),
- ),
- ).toEqual([]);
- // And the door is genuinely in use, so the assertion above cannot be satisfied by deleting the
- // read altogether and saying nothing.
- expect(code.map(({ code: text }) => text).join("\n")).toMatch(
- /\b(withoutStatement|reasonWithoutStatement)\(/,
- );
- });
});
/**
diff --git a/server/tests/shared-use-arcade-urls.test.ts b/server/tests/shared-use-arcade-urls.test.ts
index cc5946a5..1a06def6 100644
--- a/server/tests/shared-use-arcade-urls.test.ts
+++ b/server/tests/shared-use-arcade-urls.test.ts
@@ -107,13 +107,5 @@ for (const provider of ["arcade", "composio"] as const) {
expect(await store.botsHolding(lowId)).toEqual([bot]);
expect(await store.botsHolding(highId)).toEqual([bot]);
});
-
- test("an approval filed through either row is one fact", async () => {
- await seed(provider);
- const store = createSharedUseStore(database, provider);
- expect(await store.approvalFor(bot, highId)).toEqual(
- await store.approvalFor(bot, lowId),
- );
- });
});
}
diff --git a/server/tests/sole-definition.test.ts b/server/tests/sole-definition.test.ts
deleted file mode 100644
index 32517038..00000000
--- a/server/tests/sole-definition.test.ts
+++ /dev/null
@@ -1,553 +0,0 @@
-// server/tests/sole-definition.test.ts
-/**
- * Guard: a decision that has been named once has EXACTLY ONE DEFINITION in this repo.
- *
- * WHY THIS EXISTS. The recurring defect across both review rounds is not a wrong line; it is a
- * right line that never reached its siblings. A fix lands at the site the reviewer pointed at, the
- * same decision stays spelled out two files away, and the next round finds it again. A round-1 DRY
- * sweep already REPORTED exactly this — `scopesOf` written four times, the brokered-provenance test
- * written in three places — and a report is not a check: nothing failed, so nothing changed, and
- * the duplicates are all still here to be read below.
- *
- * So the report is made BINDING. Each entry in {@link TRACKED} names a decision and every spelling
- * it currently answers to; the scan collects every definition of those spellings across the repo's
- * sources and compares the list against what is recorded. A symbol with no entry in
- * {@link KNOWN_DUPLICATES} must have exactly one definition. A symbol with an entry must have
- * exactly the definitions recorded there — not fewer and not more. Both directions matter:
- *
- * - MORE fails the day somebody re-spells a tracked decision in a fifth file, which is the defect
- * this exists to stop.
- * - FEWER fails the day the fix cycle collapses a duplicate, which is not a regression but does
- * mean the list is now stale. The failure says so and names the site to delete. That is how the
- * list burns down to empty instead of quietly outliving the debt it records.
- *
- * LANDING GREEN IS DELIBERATE. Every duplicate standing today is recorded in {@link KNOWN_DUPLICATES}
- * with the finding that owns it, so this guard is green on arrival and collapsing the duplicates
- * stays with the fix cycle where a reviewer can see each merge argued for. A guard that lands red
- * gets skipped; a guard that lands green and goes red on the next re-spelling gets read.
- *
- * WHAT THE PATTERN SEES, AND WHAT IT DOES NOT. A definition is a `function`, `const`, `let`, `var`
- * or `class` binding of the name, through the shared scanner so comments are blanked (a `{@link
- * scopesOf}` in a docblock is prose, not a home) and a prettier-wrapped definition is still one
- * line. It does NOT see a name bound as an object property (`{ scopesOf: (x) => … }`), a method, or
- * a re-export alias: those spellings do not occur for the tracked names today, and widening the
- * pattern speculatively would buy false positives on every unrelated `scopesOf:` key. The names
- * list is the escape hatch instead — a decision re-spelled under a NEW name, like `isBrokered` for
- * `brokeredProvenance`, is added as an alias of the decision it duplicates, which is the only
- * reason an alias list exists at all.
- *
- * TEST FILES ARE NOT SCANNED. A `const lookup = async (hash) => …` inside a test is a fixture with
- * a short life and a local meaning, not a second home for a production decision.
- */
-import { expect, test } from "bun:test";
-import { existsSync, readFileSync } from "node:fs";
-import { join } from "node:path";
-import {
- logicalLines,
- sourceFiles,
- stripComments,
-} from "./support/source-scan";
-
-const REPO = join(import.meta.dir, "../..");
-
-/** The source trees a production decision can live in. Tests are excluded below, by file name. */
-const ROOTS = [
- "app/src",
- "server/src",
- "shared",
- "worker",
- "scripts",
- "desktop/src",
- "mobile/src",
-];
-
-/**
- * A decision, every name it is currently spelled under, and — for one that is NOT in
- * {@link KNOWN_DUPLICATES} — the single file that is its home.
- *
- * The home is written down rather than inferred so the failure reads as a diff of two file lists:
- * "expected [lookup.ts], received [lookup.ts, access.ts]" names the offending file, where a bare
- * length assertion would only say "expected 1, received 2" and leave the reader to go find it.
- */
-type Tracked = { decision: string; names: string[]; home?: string };
-
-const TRACKED: Tracked[] = [
- /*
- * Is this row's provenance a broker's? Spelled as a named predicate twice and open-coded as the
- * same two-arm literal comparison a third time, under a different name, on the page that lists
- * the accounts those rows produce.
- */
- {
- decision: "brokered-provenance",
- names: ["brokeredProvenance", "isBrokered"],
- },
- /*
- * The scopes a grant/tool/config carries, read out of a shape whose field is not guaranteed.
- * Four definitions, three of them in the plugins directory.
- */
- { decision: "scopes-of", names: ["scopesOf"] },
- /*
- * The prototype-safe keyed read extracted by CL-6. Tracked from the day it lands, so the table
- * lookup never acquires a second home the way the two above did.
- */
- {
- decision: "keyed-lookup",
- names: ["keyedLookup"],
- home: "app/src/lib/lookup.ts",
- },
- /*
- * Decisions this cycle made single-source, tracked by NAME from here on (lever L5). Each had
- * exactly one definition when this landed. A name entry stops the decision being re-DEFINED under
- * the same name; a re-spelling of its BODY under another name is what {@link SPELLED} below is for.
- */
- /* The three sibling-cascade rules, extracted in round 2 (A5) and routed to by all callers (A5a). */
- {
- decision: "sibling-cascade-rules",
- names: ["clearEndedSiblings"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- /*
- * Rule 1's one spelling, the sibling judgement without the delete, and the asked app's trail
- * claim — the three K5 made single-source so the trail and the deletion judge a key app once.
- */
- {
- decision: "consent-revoke-reaches",
- names: ["consentRevokeReaches"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- {
- decision: "siblings-ended-by",
- names: ["siblingsEndedBy"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- {
- decision: "vendor-revocation-claim",
- names: ["vendorRevocationClaim"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- /* Which apps a revoke ends besides the one it names: "the one place that answers it". */
- {
- decision: "sibling-resolution",
- names: ["resolveSiblings"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- /* Whether an app is a key, consent or neither, read off `mcp_servers`; every rule 1 asks it. */
- {
- decision: "brokered-app-kind",
- names: ["brokeredAppKind"],
- home: "server/src/plugins/plugin-store/context.ts",
- },
- /* The migrator's journal table, named once (C4). Its literal spellings are in SPELLED below. */
- {
- decision: "migrations-journal",
- names: ["MIGRATIONS_JOURNAL"],
- home: "server/src/db/apply-migrations.ts",
- },
- /* The migrator's high-water mark, "the single source for the mark" (C3). */
- {
- decision: "migrator-high-water-mark",
- names: ["migratorHighWaterMark"],
- home: "server/src/db/migration-reach.ts",
- },
-];
-
-/**
- * The duplicates standing when this guard landed, each with the finding that owns collapsing it.
- *
- * Keyed by decision. The list is the debt, written down: when a finding below is fixed, its sites
- * come out of this list in the same commit, and the guard goes red if they do not.
- */
-const KNOWN_DUPLICATES: Record<
- string,
- { finding: string; why: string; sites: string[] }
-> = {
- "brokered-provenance": {
- finding: "round-1 DRY sweep (`brokeredProvenance` defined 2x) + G-series",
- why: "One predicate for the app and one for the server, plus the same two-arm literal open-coded as `isBrokered` in the Connections page's helpers (`lib/plugins/listed.ts`); collapsing them is a cross-package move the fix cycle owns.",
- sites: [
- "app/src/lib/plugins/listed.ts",
- "app/src/lib/plugins/provider-vocabulary.ts",
- "server/src/plugins/access.ts",
- ],
- },
- "scopes-of": {
- finding: "round-1 DRY sweep (`scopesOf` defined 4x)",
- why: "Four readers of the same `scopes` field with four input shapes; merging them means agreeing one shape, which is a behavioural decision and stays in the fix cycle.",
- sites: [
- "app/src/lib/plugins/grants.ts",
- "server/src/plugins/arcade-adapter.ts",
- "server/src/plugins/arcade.ts",
- "server/src/plugins/composio-vendor.ts",
- ],
- },
-};
-
-/** A binding of `name`, not a call of it and not a mention of it in prose. */
-function definitionPattern(name: string): RegExp {
- return new RegExp(
- `(?:^|[^.\\w$])(?:export\\s+)?(?:default\\s+)?(?:async\\s+)?(?:function\\s*\\*?|const|let|var|class)\\s+${name}(?![\\w$])`,
- );
-}
-
-/** Not a test, not a type declaration: a file a production decision can be defined in. */
-function isSource(path: string): boolean {
- return !/\.(test|spec)\.tsx?$|\.d\.ts$/.test(path);
-}
-
-/**
- * Every source file in the repo where one of `names` is bound, one entry per binding.
- *
- * PATHS, NOT `path:line`, on purpose. A list carrying line numbers goes red when somebody rewraps
- * a comment three functions above a definition, and a guard that fails for a reason unrelated to
- * what it guards is one people learn to re-baseline without reading. A second definition in the
- * SAME file still shows up, as that path listed twice.
- */
-function definitionsOf(names: string[]): string[] {
- const patterns = names.map(definitionPattern);
- const out: string[] = [];
- for (const root of ROOTS) {
- const full = join(REPO, root);
- if (!existsSync(full)) continue;
- for (const file of sourceFiles(full, [".ts", ".tsx"])) {
- if (!isSource(file)) continue;
- for (const { text } of logicalLines(readFileSync(file, "utf8"))) {
- if (patterns.some((re) => re.test(text))) {
- out.push(file.slice(REPO.length + 1));
- }
- }
- }
- }
- return out.sort();
-}
-
-for (const { decision, names, home } of TRACKED) {
- test(`"${decision}" has one definition, or exactly the duplicates on record`, () => {
- const found = definitionsOf(names);
- const known = KNOWN_DUPLICATES[decision];
- if (known) {
- // Recorded debt. Equality both ways: a new re-spelling fails, and so does a collapse that
- // did not also delete the site from the list above.
- expect(found).toEqual([...known.sites].sort());
- return;
- }
- // No recorded debt: one home, and the diff names any file that became a second one.
- expect(found).toEqual(home ? [home] : []);
- });
-}
-
-/**
- * Every spelling the name scan must catch, and every one it must not.
- *
- * The guard's own positive control plants a duplicate in a real file, which proves the walk reaches
- * it. This proves the other half: that what the walk hands the pattern is read as a definition when
- * it is one and as a call when it is not. Without this, the guard could be green because the
- * pattern matches nothing at all.
- */
-test("a definition is matched, and a call or a mention is not", () => {
- const re = definitionPattern("keyedLookup");
- const definitions = [
- "function keyedLookup(map, key) {",
- "export function keyedLookup(map, key) {",
- " const keyedLookup = (map, key) => map.get(key);",
- "export const keyedLookup = (m, k) => m.get(k);",
- "let keyedLookup;",
- "var keyedLookup = 1;",
- "class keyedLookup {}",
- "export async function keyedLookup(m, k) {",
- ];
- for (const line of definitions) expect(re.test(line)).toBe(true);
- const notDefinitions = [
- " return keyedLookup(MARKS, key) ?? IconPlug;",
- 'import { keyedLookup } from "@/lib/lookup";',
- "const mark = utils.keyedLookup(MARKS, key);",
- " * see {@link keyedLookup} for why this is a Map",
- "const keyedLookupTable = new Map();",
- "function keyedLookupTable() {}",
- ];
- for (const line of notDefinitions) expect(re.test(line)).toBe(false);
-});
-
-/*
- * ─── SPELLINGS: a decision re-written under no name at all (lever L5, class K5) ───────────────────
- *
- * The name table above catches a decision DEFINED twice. It cannot catch the shape this cycle kept
- * re-opening: a rule or a name made single-source in one place and then written out again, inline,
- * somewhere that never binds a name to it — `retireConnectionsFor` re-spelling the sibling rules
- * `clearEndedSiblings` owns (A5b), `removeServer` deciding a key app's revoke answer its own way
- * where `disconnectBrokered` already had (A5c), a migrations-table name chosen by a tool's default
- * where `MIGRATIONS_JOURNAL` had already chosen it (C4n).
- *
- * So each entry below is a decision and the TEXT that spells it: a pattern matched against every
- * logical line of every source file, comments stripped first, so prose that DESCRIBES the rule (and
- * this codebase describes its rules at length) is not a spelling of it. The comparison is the one
- * the name table makes, in the same two directions and keyed the same way — by PATH, a file listed
- * once per logical line that spells the decision — against either the home or the debt on record.
- *
- * WHAT A PATH KEY CANNOT SAY. Two spellings in one file are that path listed twice; which of the two
- * is the home is not something a path can carry. For A5c the second spelling was in the SAME file as
- * the first (`plugin-store/connections.ts`; both A5b and A5c were in `plugins/store.ts` before #784
- * split it; K5 collapsed both into `context.ts`), so the guard holds the COUNT: a second spelling
- * anywhere, the home's own file included, goes red; collapsing one goes red until the list drops a
- * line. Moving the
- * spelling from the owning function into a sibling function of the same file does not. That is the
- * price of not going red on a rewrapped comment, and the same price the name table already pays.
- */
-
-/**
- * The name table's roots, plus the two places a MIGRATION decision is made that a production
- * runtime decision is not: the server's own scripts (`server/scripts/migrate.ts` is what a
- * deployment runs) and `server/drizzle.config.ts` (what `drizzle-kit` reads). The name table's own
- * {@link ROOTS} miss both; widening it is left to whoever owns that list.
- */
-const SPELLING_ROOTS = [...ROOTS, "server/scripts", "server/drizzle.config.ts"];
-
-/** Every source file under each root; a root that is a file is itself. */
-function spellingFiles(): string[] {
- const out: string[] = [];
- for (const root of SPELLING_ROOTS) {
- const full = join(REPO, root);
- if (!existsSync(full)) continue;
- if (/\.tsx?$/.test(full)) out.push(full);
- else out.push(...sourceFiles(full, [".ts", ".tsx"]));
- }
- return out.filter(isSource);
-}
-
-/**
- * A decision, the text that spells it, and — for one with no entry in
- * {@link KNOWN_SECOND_SPELLINGS} — the paths of its home, once per logical line that spells it.
- *
- * The home is a LIST because a decision can rightly take more than one LOGICAL line in its own
- * file. (The journal's schema and table are two physical lines but one logical line: a line ending
- * in `,` is joined to the next by {@link logicalLines}, so the object counts once.)
- */
-type Spelled = { decision: string; patterns: RegExp[]; home: string[] };
-
-const SPELLED: Spelled[] = [
- /*
- * The migrator's journal, as a literal. `MIGRATIONS_JOURNAL` is the one place a schema or table
- * name is written; anything else either reads that object or is a second answer to the question
- * the reach check and `migrate()` must answer identically (C4).
- */
- {
- decision: "migrations-journal-literal",
- patterns: [
- /__drizzle_migrations/,
- /\bmigrations(?:Schema|Table)\s*:\s*["'`]/,
- // drizzle-kit's own spelling of the same two fields, in a `migrations: { … }` config block.
- /\bmigrations\s*:\s*\{[^}]*\b(?:schema|table)\s*:\s*["'`]/,
- ],
- home: ["server/src/db/apply-migrations.ts"],
- },
- /*
- * THE SIBLING-CASCADE RULES: which of a revoke's siblings it ended. Spelled as a walk over a
- * {@link resolveSiblings} answer, because every spelling of the three rules is one — rule 1 and
- * rule 3 are each a `continue` inside that walk, rule 2 the guard before it. `siblingsEndedBy`
- * is the one walk (rules 1 and 2); `clearEndedSiblings` adds rule 3 and the delete over its
- * answer, and `retireConnectionsFor` files `endedWith` from the same answer (K5). A site that
- * needs the rules asks one of those rather than walking the set itself.
- */
- {
- decision: "sibling-cascade-walk",
- patterns: [
- /\bfor\s*\(\s*(?:const|let|var)\s+[\w$]+\s+of\s+[^;]*\bsiblings\b/,
- // A MEMBER `.siblings` only: a bare `siblings` local is also how `shared-use-store.ts` names
- // the rows of one app at one url, which is not a revoke's answer and not this decision.
- /\.siblings\s*(?:\?\.|\.)\s*(?:forEach|map|flatMap|filter|reduce|some|every|find)\s*\(/,
- ],
- home: ["server/src/plugins/plugin-store/context.ts"],
- },
- /*
- * WHAT THE TRAIL SAYS WAS ASKED OF THE VENDOR, for the app an act was ABOUT. A key app's answer
- * is `false` — nothing was asked of any vendor about a credential this deployment holds — and
- * `vendorRevocationClaim` spells that once, as a payload fragment every writer of an asked app's
- * row spreads (`disconnectBrokered`, `removeServer`, `retireConnectionsFor`; K5 moved the home
- * here from `disconnectBrokered`'s `askedIsKey ? false : ended`). A writer that computes
- * the field from anything else is a second answer to the same question. A constant `true` or
- * `false` is not a computation and is not matched: `clearEndedSiblings` writes `true` on rows
- * rule 1 has already kept key apps out of, and the vault loops write `false` about secrets.
- */
- {
- decision: "key-app-revoke-answer",
- patterns: [
- /\bvendorRevocationRequested\s*[:=]\s*(?!true\b|false\b|boolean\b)\S/,
- ],
- home: ["server/src/plugins/plugin-store/context.ts"],
- },
-];
-
-/**
- * The second spellings standing when L5 landed, each with the open finding that owns collapsing it.
- *
- * THE SAME DISCIPLINE AS `typecheck-baseline.txt`: every site past the home is a real defect, not a
- * thing that is fine. Collapsing one and deleting its line is always correct, and the guard goes red
- * until the line is deleted. Adding a line is not: a new site is code written today re-spelling a
- * decision somebody already made, and this exists to say so.
- */
-const KNOWN_SECOND_SPELLINGS: Record<
- string,
- { finding: string; why: string; sites: string[] }
-> = {
- /*
- * EMPTY SINCE ROUND 2, K5. Both entries L5 landed with were collapsed into one home each in
- * `plugin-store/context.ts`: "sibling-cascade-walk" (A5b — `retireConnectionsFor`'s own walk,
- * without rule 1) now asks `siblingsEndedBy`, and "key-app-revoke-answer" (A5c, L5-a —
- * `removeServer` and `retireConnectionsFor` passing a key app's raw vendor answer through) now
- * asks `vendorRevocationClaim`, as `disconnectBrokered` does. A new entry here is a new defect.
- */
-};
-
-/** Every source file in which one of `patterns` matches a logical line, comments stripped. */
-function spellingsOf(patterns: RegExp[]): string[] {
- const out: string[] = [];
- for (const file of spellingFiles()) {
- const code = stripComments(readFileSync(file, "utf8"));
- for (const { text } of logicalLines(code)) {
- if (patterns.some((re) => re.test(text))) {
- out.push(file.slice(REPO.length + 1));
- }
- }
- }
- return out.sort();
-}
-
-for (const { decision, patterns, home } of SPELLED) {
- test(`"${decision}" is spelled only at its home, or exactly the second spellings on record`, () => {
- const found = spellingsOf(patterns);
- const known = KNOWN_SECOND_SPELLINGS[decision];
- // Recorded debt: equality both ways, as for the name table. With none, the home and only it.
- expect(found).toEqual([...(known ? known.sites : home)].sort());
- });
-}
-
-/*
- * ─── IMPLICIT SPELLINGS: a consumer that names nothing, and so takes a tool's default ────────────
- *
- * No pattern can match text that is not there. `drizzle.config.ts` names no migrations table, so
- * `drizzle-kit migrate` uses drizzle-kit's OWN default — which happens today to be the same schema
- * and table `MIGRATIONS_JOURNAL` names, and which nothing in this repository decides. That is a
- * second spelling the literal scan above is blind to by construction (C4n), and the day either side
- * changes, the reach check reads one table and the CLI writes another.
- *
- * So the condition is stated the other way round: every file that hands migrations to a migrator —
- * imports `drizzle-kit`, or a `drizzle-orm/<driver>/migrator` — must REFERENCE the constant in code.
- * One that does not is taking somebody else's default. Consumers are discovered, not listed, so a
- * new migrator entry point is held to this the day it lands.
- */
-const JOURNAL_CONSUMER =
- /\bfrom\s+["'](?:drizzle-kit|drizzle-orm\/[\w-]+\/migrator)["']/;
-const JOURNAL_REFERENCE = /\bMIGRATIONS_JOURNAL\b/;
-
-/** Consumers that take a default instead of naming the journal, recorded as the debt they are. */
-const KNOWN_DEFAULT_TAKERS: { finding: string; sites: string[] } = {
- finding: "C4n (round 2, wave 3) — open",
- sites: ["server/drizzle.config.ts"],
-};
-
-/** Every migrator consumer whose CODE (comments stripped) never mentions the journal constant. */
-function defaultTakers(): string[] {
- const out: string[] = [];
- for (const file of spellingFiles()) {
- const code = stripComments(readFileSync(file, "utf8"));
- if (JOURNAL_CONSUMER.test(code) && !JOURNAL_REFERENCE.test(code)) {
- out.push(file.slice(REPO.length + 1));
- }
- }
- return out.sort();
-}
-
-test("every migrator consumer names MIGRATIONS_JOURNAL, or is a default-taker on record", () => {
- expect(defaultTakers()).toEqual([...KNOWN_DEFAULT_TAKERS.sites].sort());
-});
-
-/**
- * The spelling patterns' own positive and negative controls, for the reason the name pattern has
- * one: a guard can be green because its pattern matches nothing at all.
- */
-test("a spelling is matched, and a mention, a read or a type is not", () => {
- const cases: Record<string, { spells: string[]; doesNot: string[] }> = {
- "migrations-journal-literal": {
- spells: [
- ' migrationsTable: "__drizzle_migrations",',
- ' migrationsSchema: "drizzle",',
- 'migrations: { schema: "drizzle", table: "journal" },',
- "select * from drizzle.__drizzle_migrations",
- ],
- doesNot: [
- " migrationsSchema: string;",
- " migrations: { schema: MIGRATIONS_JOURNAL.migrationsSchema },",
- "from client(MIGRATIONS_JOURNAL.migrationsTable)",
- ],
- },
- "sibling-cascade-walk": {
- spells: [
- "for (const app of new Set(input.siblings)) {",
- "for (const app of endedBesides.get(entry.toolkit)?.siblings ?? []) {",
- "for (let app of siblings) {",
- "resolved.siblings.forEach((app) => {",
- "input.siblings.filter((app) => app !== toolkit)",
- ],
- doesNot: [
- "await clearEndedSiblings({ siblings, account, endedWith: toolkit });",
- "siblings: input.siblings,",
- "const { siblings, unanswered } = await resolveSiblings(x);",
- "for (const connection of brokered) {",
- "const ids = siblings.map((sibling) => sibling.id);",
- ],
- },
- "key-app-revoke-answer": {
- spells: [
- "const vendorRevocationRequested = askedIsKey ? false : ended;",
- "vendorRevocationRequested: vendorRevocationRequested[index] ?? false,",
- "vendorRevocationRequested: connection.requested || Boolean(endedBy),",
- "vendorRevocationRequested: ended,",
- ],
- doesNot: [
- "vendorRevocationRequested: true,",
- "vendorRevocationRequested: false,",
- "}): Promise<{ vendorRevocationRequested: boolean }> {",
- "const vendorRevocationRequested: boolean[] = [];",
- "vendorRevocationRequested?: boolean;",
- "return { vendorRevocationRequested };",
- ],
- },
- };
- for (const { decision, patterns } of SPELLED) {
- const { spells, doesNot } = cases[decision] ?? { spells: [], doesNot: [] };
- // Every entry has controls: an entry added without them fails here rather than going unproven.
- expect(spells.length).toBeGreaterThan(0);
- for (const line of spells) {
- expect({
- decision,
- line,
- hit: patterns.some((re) => re.test(line)),
- }).toEqual({
- decision,
- line,
- hit: true,
- });
- }
- for (const line of doesNot) {
- expect({
- decision,
- line,
- hit: patterns.some((re) => re.test(line)),
- }).toEqual({
- decision,
- line,
- hit: false,
- });
- }
- }
- expect(
- JOURNAL_CONSUMER.test('import { defineConfig } from "drizzle-kit";'),
- ).toBe(true);
- expect(
- JOURNAL_CONSUMER.test(
- 'import { migrate } from "drizzle-orm/postgres-js/migrator";',
- ),
- ).toBe(true);
- expect(
- JOURNAL_CONSUMER.test('import { drizzle } from "drizzle-orm/postgres-js";'),
- ).toBe(false);
-});
diff --git a/server/tests/store-scheme-sites.test.ts b/server/tests/store-scheme-sites.test.ts
index 10b1408a..dc796214 100644
--- a/server/tests/store-scheme-sites.test.ts
+++ b/server/tests/store-scheme-sites.test.ts
@@ -1,15 +1,9 @@
/**
- * `store.ts`'s last vendor-scheme sites, read through the shared record instead of a literal.
- *
- * Four of them, and they fail differently: the connections listing drops every row on a non-Composio
- * broker, the probe dials a vendor this deployment may hold no key for, the screen-name reservation
- * covers only one of the two static routes, and `shared-use-store.ts` spells the scheme a second
- * time. Each has its own test below, and each Composio behaviour is asserted unchanged beside it.
+ * Broker-specific store behavior: connection listings, probes and reserved screen names
+ * use the configured provider, and adding an app preserves its scheme.
*/
import { afterAll, afterEach, expect, test } from "bun:test";
import { randomUUID } from "node:crypto";
-import { readFileSync } from "node:fs";
-import { join } from "node:path";
import { inArray, like } from "drizzle-orm";
import { createAuditStore } from "../src/audit";
import { createDatabase } from "../src/db/client";
@@ -26,7 +20,6 @@ import {
createPluginStore,
} from "../src/plugins/store";
import { TEST_POOL, testDatabaseUrl } from "./support/database";
-import { stripComments } from "./support/source-scan";
import { stubBroker } from "./support/stub-broker";
const database = createDatabase(testDatabaseUrl(), TEST_POOL);
@@ -270,21 +263,6 @@ test("the brokered id-prefix refusal is untouched by the screen-name one", async
);
});
-/* (e) One table, one spelling: `shared-use-store.ts` reads the record rather than rebuilding it. */
-test("shared-use-store derives its scheme from BROKERED_PROFILE and nowhere else", () => {
- const source = readFileSync(
- join(import.meta.dir, "../src/plugins/shared-use-store.ts"),
- "utf8",
- );
- // The shared stripper, which blanks a comment where it stands instead of dropping the line it
- // sits on: a trailing `// note` used to take its own code with it, so the assertion below could
- // have failed on a line that carries the derivation it is looking for.
- const code = stripComments(source);
- expect(code).toContain("BROKERED_PROFILE[provider].scheme");
- // The local derivation 4.5 could not avoid, now that the record is reachable.
- expect(code).not.toMatch(/\$\{provider\}:\/\//);
-});
-
/* And `addBrokeredApp` keeps writing at the record's scheme, which is where the record came from. */
for (const provider of ["composio", "arcade"] as const) {
test(`addBrokeredApp still writes a ${provider} row at the record's scheme`, async () => {
diff --git a/server/tests/support/stub-broker.ts b/server/tests/support/stub-broker.ts
index 16aadc51..feb86c82 100644
--- a/server/tests/support/stub-broker.ts
+++ b/server/tests/support/stub-broker.ts
@@ -8,7 +8,7 @@
* - CAST PAST THE TYPE. `{ … } as unknown as ConnectedAppBroker` or `{} as ConnectedAppBroker`
* makes a stub that omits `revoke` and `revokeAccount` compile. The compiler's guarantee is
* gone exactly as it was when a broken `import type` degraded the type to `any` (round-2 C8).
- * `broker-stub-ratchet.test.ts` stops new casts; this factory is what to write instead.
+ * Use this factory instead so missing methods remain type errors.
* - A PLAUSIBLE DEFAULT. `revokeAccount: async () => {}` type-checks and answers "done" for a
* revoke that never happened. A test can then pass on a fiction, and the revoke seam is the
* one this PR's Claim 2 is about.
diff --git a/server/tests/tenant-package.test.ts b/server/tests/tenant-package.test.ts
index 1bc67128..8f914019 100644
--- a/server/tests/tenant-package.test.ts
+++ b/server/tests/tenant-package.test.ts
@@ -1,5 +1,8 @@
import { afterAll, afterEach, describe, expect, test } from "bun:test";
import { randomUUID } from "node:crypto";
+import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { and, eq } from "drizzle-orm";
import { createAgentProfileStore } from "../src/agents/profile-store";
@@ -1121,6 +1124,42 @@ describe("expanding a package file against the environment", () => {
* cases below are the ones that decide whether that is safe to seed.
*/
describe("skills a package ships", () => {
+ test("editing only skills.yaml changes the loaded package checksum", async () => {
+ const directory = await mkdtemp(join(tmpdir(), "openbot-skills-checksum-"));
+ try {
+ await cp(
+ fileURLToPath(new URL("../../examples/fintech", import.meta.url)),
+ directory,
+ { recursive: true },
+ );
+ const skillsPath = join(directory, "skills.yaml");
+ const original = await readFile(skillsPath, "utf8");
+ const before = await loadTenantPackage(directory);
+ expect((await loadTenantPackage(directory)).checksum).toBe(
+ before.checksum,
+ );
+
+ await writeFile(
+ skillsPath,
+ `${original}\n - slug: checksum-fixture\n title: Checksum fixture\n summary: Added instruction.\n instructions: Read the revised policy.\n`,
+ "utf8",
+ );
+ const after = await loadTenantPackage(directory);
+ expect(after.skills).toHaveLength(before.skills.length + 1);
+ expect(after.skills.at(-1)?.instructions).toBe(
+ "Read the revised policy.",
+ );
+ expect(after.checksum).not.toBe(before.checksum);
+
+ await writeFile(skillsPath, original, "utf8");
+ expect((await loadTenantPackage(directory)).checksum).toBe(
+ before.checksum,
+ );
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+ });
+
const base = {
brand: "tenant: { id: fintech, product_name: Ledgerline }",
agents:
@@ -1244,21 +1283,6 @@ describe("skills a package ships", () => {
}),
).toThrow("skill.instructions must be a non-empty string");
});
-
- test("editing the skills file changes the package checksum", () => {
- // Otherwise a deployment reports itself unchanged after its skills were rewritten, and never
- // reseeds them.
- const one = validateTenantPackage({ ...base, skills: "skills: []" });
- const two = validateTenantPackage({
- ...base,
- skills: `skills:
- - slug: triage
- title: Triage
- summary: Triage.
- instructions: Triage.`,
- });
- expect(one.skills).not.toEqual(two.skills);
- });
});
/**
diff --git a/server/tests/test-network-guard.test.ts b/server/tests/test-network-guard.test.ts
index 339e5a56..9fe05679 100644
--- a/server/tests/test-network-guard.test.ts
+++ b/server/tests/test-network-guard.test.ts
@@ -298,14 +298,10 @@ describe("the test network guard lets the suite reach what the suite owns", () =
describe("the test network guard judges a socket by the address it reaches", () => {
/** A `lookup` that answers one address, in both shapes the runtime asks for (Bun asks `all`). */
function answering(address: string): net.LookupFunction {
- return ((
- _host: string,
- options: { all?: boolean } | undefined,
- callback: (...args: unknown[]) => void,
- ) =>
- options?.all
+ return (_host, options, callback) =>
+ options.all
? callback(null, [{ address, family: 4 }])
- : callback(null, address, 4)) as unknown as net.LookupFunction;
+ : callback(null, address, 4);
}
/** Settles on connect, on a short wait (an unroutable address may hang), or rejects on error. */
diff --git a/server/tests/ts-expect-error-coverage.test.ts b/server/tests/ts-expect-error-coverage.test.ts
deleted file mode 100644
index 453313d6..00000000
--- a/server/tests/ts-expect-error-coverage.test.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-// server/tests/ts-expect-error-coverage.test.ts
-/**
- * Guard: every test file under `server/tests` that carries a ts-expect-error directive must be named
- * in `server/tsconfig.json`'s `include`.
- *
- * AN UNINCLUDED DIRECTIVE IS NOT A WEAKER ASSERTION, IT IS NO ASSERTION. The directive says "the next
- * line must fail to compile", and the only thing that ever checks that is `tsc`. `include` names
- * `src`, `scripts` and a handful of test files, and the rest of `tests` is type-checked by nothing,
- * so a directive in a file not named there sits in the source asserting nothing while reading to the
- * next maintainer as coverage. The wrong-way-round call it guards can compile cleanly for good and no
- * one hears about it.
- *
- * So the convention is: a test file whose subject is a TYPE is named in `include`, one file and not
- * the directory (see the comment in the tsconfig). This guard is what makes that enforceable rather
- * than remembered. It fails naming each file that is not covered, as `file:line`.
- *
- * Like `brokered-provenance.test.ts` it reads text and imports nothing from the code it guards. The
- * tsconfig is JSONC (its comments are the point), so the comments are stripped with a scan that
- * respects strings before it is parsed.
- */
-import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
-import { join, relative, resolve } from "node:path";
-import { sourceFiles, stripComments } from "./support/source-scan";
-
-const SERVER_DIR = resolve(import.meta.dir, "..");
-const TESTS_DIR = join(SERVER_DIR, "tests");
-
-/** The directive, in either comment form. A bare mention in prose does not match. */
-const DIRECTIVE = /(\/\/|\/\*)\s*@ts-expect-error\b/;
-
-function readInclude(): string[] {
- const raw = readFileSync(join(SERVER_DIR, "tsconfig.json"), "utf8");
- // The shared stripper does the JSONC: it leaves string contents (and their slashes) alone, and
- // blanks a comment in place rather than deleting it, which JSON.parse does not care about and a
- // reader comparing the text to the file does.
- const include = JSON.parse(stripComments(raw)).include;
- if (!Array.isArray(include)) throw new Error("tsconfig.json has no include");
- return include.map((p: string) => resolve(SERVER_DIR, p));
-}
-
-/** Covered when named exactly, or when it sits under an included directory. */
-function isCovered(file: string, include: string[]): boolean {
- return include.some((p) => file === p || file.startsWith(`${p}/`));
-}
-
-test("every test file carrying a ts-expect-error directive is named in tsconfig include", () => {
- const include = readInclude();
- const offenders: string[] = [];
- // The shared scanner's walk. Its comment stripper is used above for the JSONC and deliberately
- // NOT here: the directive IS a comment, and it binds to the physical line below it, so this is
- // the one scan that stays on physical lines rather than logical ones.
- for (const file of sourceFiles(TESTS_DIR, [".ts", ".tsx"])) {
- if (isCovered(file, include)) continue;
- readFileSync(file, "utf8")
- .split("\n")
- .forEach((line, i) => {
- if (DIRECTIVE.test(line)) {
- offenders.push(`${relative(SERVER_DIR, file)}:${i + 1}`);
- }
- });
- }
- expect(offenders).toEqual([]);
-});
-
-test("the directive pattern takes both comment forms and leaves prose", () => {
- // The fixtures are assembled so this file does not itself contain the directive it scans for.
- const d = "@ts-expect" + "-error";
- expect(DIRECTIVE.test(` // ${d} the call`)).toBe(true);
- expect(DIRECTIVE.test(`x(); /* ${d} */`)).toBe(true);
- expect(
- DIRECTIVE.test(" * the ts-expect-error directive is checked by tsc"),
- ).toBe(false);
-});
diff --git a/shared/harnesses.test.ts b/shared/harnesses.test.ts
index 098b593b..d7221fec 100644
--- a/shared/harnesses.test.ts
+++ b/shared/harnesses.test.ts
@@ -75,7 +75,7 @@ test("every named mark is vendored where both apps look for it", async () => {
}
});
-test("every row an image publishes names the directory it is built from", () => {
+test("CrewAI uses its expected image, health endpoint and port", () => {
const crewai = HARNESSES.find((h) => h.id === "crewai");
expect(crewai?.image).toBe("agent-crewai");
expect(crewai?.healthPath).toBe("/health");
diff --git a/tests/clean-checkout.test.ts b/tests/clean-checkout.test.ts
index 9db3d571..e3275ec1 100644
--- a/tests/clean-checkout.test.ts
+++ b/tests/clean-checkout.test.ts
@@ -2,55 +2,11 @@ import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
-/**
- * What a clone can do before anybody has configured it.
- *
- * Everything here is a property of the repository rather than of the machine it was cloned onto, and
- * each one has already shipped broken once: a dependency only a non-workspace package declared, so
- * nothing at the root resolved it, and a tenant package that named an environment variable, so
- * loading it needed a `.env` that a clone does not have. Both left `bun run test` failing for
- * everybody except the person who added them, whose checkout was already configured.
- */
+/** The example package must load before a fresh checkout has a .env file. */
const root = join(import.meta.dir, "..");
-function manifest(path: string) {
- return JSON.parse(readFileSync(join(root, path, "package.json"), "utf8")) as {
- workspaces?: string[];
- dependencies?: Record<string, string>;
- devDependencies?: Record<string, string>;
- };
-}
-
-const rootManifest = manifest(".");
-const workspaces = rootManifest.workspaces ?? [];
-
-/** Packages with their own manifest that the root install does not reach. */
-const OUTSIDE_THE_WORKSPACES = ["agent-computer", "supervisor"] as const;
-
describe("a clone that has only run bun install", () => {
- test.each(OUTSIDE_THE_WORKSPACES)(
- "can resolve everything %s imports in its tests",
- (packageName) => {
- // These are not workspace members, so their own node_modules is never installed by the root.
- // Anything their tested source imports has to be resolvable from the root instead.
- expect(workspaces).not.toContain(packageName);
-
- const declared = Object.keys(manifest(packageName).dependencies ?? {});
- const rootHas = {
- ...(rootManifest.dependencies ?? {}),
- ...(rootManifest.devDependencies ?? {}),
- };
-
- // Only what the root test run actually loads. Playwright is imported by the service entry
- // point, which no test imports, and it is installed inside the container image instead.
- const loadedByTests = declared.filter((name) => name === "yaml");
- for (const name of loadedByTests) {
- expect(rootHas).toHaveProperty(name);
- }
- },
- );
-
test("can read the example tenant package with nothing set", () => {
// `pretest` loads this package, so a name here with no fallback fails the suite before a single
// test runs.
@@ -70,11 +26,4 @@ describe("a clone that has only run bun install", () => {
).toBe(true);
}
});
-
- test("keeps every .env variant out of the repository", () => {
- // A backup taken beside .env carried live keys into a commit once.
- const ignored = readFileSync(join(root, ".gitignore"), "utf8");
- expect(ignored).toContain(".env.*");
- expect(ignored).toContain("!.env.example");
- });
});
diff --git a/tests/compose.test.ts b/tests/compose.test.ts
index 1f14040c..231ca575 100644
--- a/tests/compose.test.ts
+++ b/tests/compose.test.ts
@@ -489,21 +489,12 @@ test("enables pgvector before creating vector columns", () => {
expect(firstVectorColumn).toBeGreaterThan(extension);
});
-test("runs migrations after PostgreSQL becomes healthy", () => {
- const compose = composeFile();
-
- expect(compose).toContain("migrate:");
- expect(compose).toContain("condition: service_healthy");
- /*
- * THE SERVER'S OWN MIGRATOR, NOT `drizzle-kit migrate`, AND THE DIFFERENCE IS THE POINT.
- *
- * `drizzle-kit` will skip a migration stamped below what the database has already recorded and
- * still report success — the exact outcome `server/src/db/migration-reach.ts` exists to refuse,
- * and a developer's database is one of the places it happens. `compose.yml` says the same thing
- * at the service itself. Asserting the command here is what stops the stack quietly going back
- * to the migrator that cannot see that case.
- */
- expect(compose).toContain('"bun", "scripts/migrate.ts"');
+test("runs the server migrator after PostgreSQL becomes healthy", () => {
+ const services = composeServices();
+ expect(services.migrate.command).toEqual(["bun", "scripts/migrate.ts"]);
+ expect(services.migrate.depends_on?.postgres).toEqual({
+ condition: "service_healthy",
+ });
});
test("builds the deployment image with Playwright's Chromium payload only", () => {
diff --git a/tests/workspace.test.ts b/tests/workspace.test.ts
index 188a39c0..99bd8b16 100644
--- a/tests/workspace.test.ts
+++ b/tests/workspace.test.ts
@@ -62,14 +62,4 @@ describe("OpenBot workspace", () => {
packagesStartedBy(manifest.scripts.build, manifest.workspaces),
).toEqual(manifest.workspaces);
});
-
- test("scripts/start.sh is what starts the routines worker", () => {
- const startScript = readFileSync(
- join(repositoryRoot, "scripts", "start.sh"),
- "utf8",
- );
-
- expect(startScript).toContain("bun worker/src/index.ts");
- expect(startScript).toContain("WORKER_SHARED_SECRET=");
- });
});