Skip to content

Commit dc324f6

Browse files
committed
test: add CLI startup speed regression test
Guards against heavy imports (matplotlib, torch, scipy) leaking into the CLI entrypoint via GlobalConfig. Fails if dimos --help takes >8s.
1 parent daa5d6f commit dc324f6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2025-2026 Dimensional Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Guard against import-time regressions in the CLI entrypoint.
16+
17+
`dimos --help` should never pull in heavy ML/viz libraries. If it does,
18+
startup time balloons from <2s to >5s, which is a terrible UX.
19+
"""
20+
21+
import subprocess
22+
import sys
23+
import time
24+
25+
import pytest
26+
27+
# CI runners are slower — give generous headroom but still catch gross regressions.
28+
HELP_TIMEOUT_SECONDS = 8
29+
30+
31+
def test_help_does_not_import_heavy_deps() -> None:
32+
"""GlobalConfig import must not drag in matplotlib, torch, or scipy."""
33+
result = subprocess.run(
34+
[
35+
sys.executable,
36+
"-c",
37+
(
38+
"import sys; "
39+
"from dimos.core.global_config import GlobalConfig; "
40+
"bad = [m for m in ('matplotlib', 'torch', 'scipy') if m in sys.modules]; "
41+
"assert not bad, f'Heavy deps imported: {bad}'"
42+
),
43+
],
44+
capture_output=True,
45+
text=True,
46+
timeout=30,
47+
)
48+
assert result.returncode == 0, f"Heavy deps leaked into GlobalConfig import:\n{result.stderr}"
49+
50+
51+
def test_help_startup_time() -> None:
52+
"""`dimos --help` must finish in under {HELP_TIMEOUT_SECONDS}s."""
53+
start = time.monotonic()
54+
result = subprocess.run(
55+
[sys.executable, "-m", "dimos.robot.cli.dimos", "--help"],
56+
capture_output=True,
57+
text=True,
58+
timeout=HELP_TIMEOUT_SECONDS + 5, # hard kill safety margin
59+
)
60+
elapsed = time.monotonic() - start
61+
assert result.returncode == 0, f"dimos --help failed:\n{result.stderr}"
62+
assert elapsed < HELP_TIMEOUT_SECONDS, (
63+
f"dimos --help took {elapsed:.1f}s (limit: {HELP_TIMEOUT_SECONDS}s). "
64+
f"Check for heavy imports in the CLI entrypoint or GlobalConfig."
65+
)

0 commit comments

Comments
 (0)