Ship MicroPython stubs from repo lib/ and seed workspace lib on startup

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>
This commit is contained in:
2026-05-10 02:59:34 +12:00
parent f7892dd31b
commit a2318f2244
14 changed files with 146 additions and 181 deletions

View File

@@ -1,4 +1,5 @@
import importlib
import shutil
from pathlib import Path
import pytest
@@ -19,6 +20,24 @@ def test_editor_route_serves_editor_html(client):
assert "Python Editor" in response.text
def test_workspace_lib_seeded_from_bundle_on_startup(client, tmp_path):
"""Populate WORKSPACE_ROOT/lib with shipped stubs when absent (empty volume / fresh tmp)."""
lib_dir = tmp_path / "lib"
assert (lib_dir / "machine.py").is_file()
assert (lib_dir / "neopixel.py").is_file()
assert len((lib_dir / "machine.py").read_text(encoding="utf-8")) > 0
def test_workspace_lib_repops_when_removed_after_startup(client, tmp_path):
"""Touching lib via the API restores bundled stubs after the workspace lib dir is wiped."""
lib_dir = tmp_path / "lib"
assert (lib_dir / "machine.py").is_file()
shutil.rmtree(lib_dir)
resp = client.get("/api/file/lib/machine.py")
assert resp.status_code == 200
assert (lib_dir / "machine.py").is_file()
def test_list_files_hides_dotfiles_and_reports_sizes(client, tmp_path):
(tmp_path / ".hidden.txt").write_text("secret", encoding="utf-8")
(tmp_path / "visible.txt").write_text("hello", encoding="utf-8")

View File

@@ -43,3 +43,4 @@ def test_collect_python_sources_skips_hidden_and_binary(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"