Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

perf(ci): run tests with temp files in RAM and parse the package once (#339)

Rufus75e31638496f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 155afa1d..09e6b574 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -83,12 +83,20 @@ jobs:
# pytest-xdist: one worker per core (4 on ubuntu-latest). `loadfile` keeps
# each test module on a single worker, so module-level state behaves as in
# a serial run.
+ #
+ # TMPDIR on tmpfs: most tests build a fresh SQLite file under tmp_path,
+ # and every CREATE/ALTER commits with a disk sync. In RAM those syncs are
+ # free, which more than halves the run; each test still gets its own file.
- name: Run unit tests
+ env:
+ TMPDIR: /dev/shm
run: cd packages/core && uv run pytest tests/unit/ -n auto --dist loadfile --tb=short
# Route-level tests against a temp SQLite DB, with the model calls
# stubbed; no API key needed. Left out of CI, one rotted unnoticed.
- name: Run integration tests
+ env:
+ TMPDIR: /dev/shm
run: cd packages/core && uv run pytest tests/integration/ -n auto --dist loadfile --tb=short
ui-typecheck:
diff --git a/Makefile b/Makefile
index 4db9ec50..d8c3d08c 100644
--- a/Makefile
+++ b/Makefile
@@ -54,10 +54,16 @@ lint:
# Everything CI checks, in one command. Unsets the two env vars that make
# full-app tests 401 or fail at import (see CLAUDE.md -> Testing), builds the
-# UI only when packages/ui differs from BASE, then runs the PR rules.
+# UI only when packages/ui differs from BASE, then runs the PR rules. Test
+# temp files go to RAM when /dev/shm (Linux) has 2 GB free, as in CI: the
+# per-test SQLite setup is mostly disk syncs, and tmpfs makes them free. A run
+# peaks near 1 GB, so a small /dev/shm (Docker's default is 64 MB) falls back to
+# $TMPDIR or /tmp. Set TEST_TMPDIR to choose.
BASE ?= origin/main
+TEST_TMPDIR ?= $(shell free=$$(df -Pk /dev/shm 2>/dev/null | awk 'NR==2 {print $$4}'); \
+ if [ "$${free:-0}" -ge 2097152 ]; then echo /dev/shm; else echo "$${TMPDIR:-/tmp}"; fi)
check: lint
- cd packages/core && env -u BACKEND_SHARED_SECRET -u OE_PUBLIC_DEPLOYMENT \
+ cd packages/core && env -u BACKEND_SHARED_SECRET -u OE_PUBLIC_DEPLOYMENT TMPDIR=$(TEST_TMPDIR) \
uv run pytest tests/unit/ tests/integration/ -n auto --dist loadfile -q
@if ! git diff --quiet $$(git merge-base $(BASE) HEAD) -- packages/ui \
|| [ -n "$$(git ls-files --others --exclude-standard packages/ui)" ]; then \
diff --git a/packages/core/pyproject.toml b/packages/core/pyproject.toml
index d5dc98ca..dd1f3a90 100644
--- a/packages/core/pyproject.toml
+++ b/packages/core/pyproject.toml
@@ -113,6 +113,10 @@ explicit = true
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
+# A run leaves close to 1 GB of temp files, and CI and `make check` put them
+# in RAM (/dev/shm). Keep only the failed tests' directories, not the last
+# three runs' worth.
+tmp_path_retention_policy = "failed"
[dependency-groups]
dev = [
diff --git a/packages/core/tests/unit/test_delegation_reply_send.py b/packages/core/tests/unit/test_delegation_reply_send.py
index 6a7392e0..e77cfc96 100644
--- a/packages/core/tests/unit/test_delegation_reply_send.py
+++ b/packages/core/tests/unit/test_delegation_reply_send.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import ast
import asyncio
+import functools
import sqlite3
from datetime import timedelta
from pathlib import Path
@@ -366,43 +367,49 @@ def test_the_reconciler_leaves_a_card_being_sent_alone(owner: Any, models: dict[
_ROOT = Path(openexecutive.__file__).parent
-def _trees() -> list[tuple[str, ast.AST]]:
- return [
- (path.relative_to(_ROOT).as_posix(), ast.parse(path.read_text(), filename=str(path)))
- for path in _ROOT.rglob("*.py")
- ]
+def _index() -> tuple[dict[str, set[str]], dict[str, set[str]]]:
+ """One pass over every module under openexecutive/, shared by every lookup
+ in this file: re-parsing the package for each lookup made these the
+ slowest tests in the suite.
+
+ Returns (names, imports). ``names`` maps each name used in code (a call,
+ an attribute, an imported name) to the files that use it. ``imports`` maps
+ each module (openexecutive.a.b) to the files that import it, however it is
+ spelled: ``import a.b``, ``from a.b import x`` or ``from a import b``.
+ Paths are relative to the package."""
+ names: dict[str, set[str]] = {}
+ imports: dict[str, set[str]] = {}
+ for path in _ROOT.rglob("*.py"):
+ rel = path.relative_to(_ROOT).as_posix()
+ for node in ast.walk(ast.parse(path.read_text(), filename=str(path))):
+ if isinstance(node, ast.Attribute):
+ names.setdefault(node.attr, set()).add(rel)
+ elif isinstance(node, ast.Name):
+ names.setdefault(node.id, set()).add(rel)
+ elif isinstance(node, ast.ImportFrom):
+ for alias in node.names:
+ names.setdefault(alias.name, set()).add(rel)
+ if node.module is not None:
+ imports.setdefault(node.module, set()).add(rel)
+ for alias in node.names:
+ imports.setdefault(f"{node.module}.{alias.name}", set()).add(rel)
+ elif isinstance(node, ast.Import):
+ for alias in node.names:
+ imports.setdefault(alias.name, set()).add(rel)
+ return names, imports
def _uses(name: str) -> set[str]:
"""Files under openexecutive/ that name ``name`` in code (a call, an
attribute, an imported name), relative to the package."""
- found: set[str] = set()
- for rel, tree in _trees():
- for node in ast.walk(tree):
- if (
- (isinstance(node, ast.Attribute) and node.attr == name)
- or (isinstance(node, ast.Name) and node.id == name)
- or (isinstance(node, ast.ImportFrom) and any(a.name == name for a in node.names))
- ):
- found.add(rel)
- return found
+ return set(_index()[0].get(name, set()))
def _importers(module: str) -> set[str]:
"""Files under openexecutive/ that import ``module`` (openexecutive.a.b),
however it is spelled."""
- package, _, leaf = module.rpartition(".")
- found: set[str] = set()
- for rel, tree in _trees():
- for node in ast.walk(tree):
- if (
- (isinstance(node, ast.ImportFrom) and node.module == module)
- or (isinstance(node, ast.ImportFrom) and node.module == package
- and any(a.name == leaf for a in node.names))
- or (isinstance(node, ast.Import) and any(a.name == module for a in node.names))
- ):
- found.add(rel)
- return found
+ return set(_index()[1].get(module, set()))
def test_only_the_send_path_sends_and_only_the_approve_route_reaches_it() -> None: