Move machine.py and neopixel.py into a tracked /lib/ at the repo root and auto-copy them into WORKSPACE_ROOT/lib whenever files are missing, so empty volumes and fresh per-user workspaces always have the read-only stubs available to Jedi and Pyodide. Allow all users to browse lib/ in the UI (writes still gated by the API), and add tests covering initial seeding and re-population after the dir is wiped. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import importlib
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
def test_load_env_file_sets_missing_keys_only(tmp_path, monkeypatch):
|
|
import editor_app.config as config
|
|
|
|
env_file = tmp_path / ".env"
|
|
env_file.write_text(
|
|
"# comment\nFOO=bar\nBAZ='quoted'\nEXISTING=from_file\n", encoding="utf-8"
|
|
)
|
|
|
|
monkeypatch.setenv("EXISTING", "kept")
|
|
monkeypatch.delenv("FOO", raising=False)
|
|
monkeypatch.delenv("BAZ", raising=False)
|
|
|
|
config.load_env_file(env_file)
|
|
|
|
assert __import__("os").environ["FOO"] == "bar"
|
|
assert __import__("os").environ["BAZ"] == "quoted"
|
|
assert __import__("os").environ["EXISTING"] == "kept"
|
|
|
|
|
|
def test_load_env_file_ignores_missing_file(tmp_path):
|
|
import editor_app.config as config
|
|
|
|
config.load_env_file(tmp_path / "missing.env")
|
|
|
|
|
|
def test_collect_python_sources_skips_hidden_and_binary(tmp_path):
|
|
import editor_app.config as config
|
|
import editor_app.services.filesystem as filesystem
|
|
|
|
(tmp_path / "code").mkdir()
|
|
(tmp_path / "code" / "ok.py").write_text("a = 1\n", encoding="utf-8")
|
|
(tmp_path / "code" / ".venv").mkdir()
|
|
(tmp_path / "code" / ".venv" / "skip.py").write_text("x\n", encoding="utf-8")
|
|
(tmp_path / "bad.py").write_bytes(b"\xff\xff")
|
|
|
|
config.WORKSPACE_ROOT = tmp_path
|
|
out = filesystem.collect_python_sources()
|
|
assert out["code/ok.py"] == "a = 1\n"
|
|
assert "bad.py" not in out
|
|
assert "lib/machine.py" in out, "shared lib stubs should always be merged for Jedi / Pyodide"
|