8000 test(scaffold): cover .mcp.json and guard the packaged payload by bjoaquinc · Pull Request #29 · dlt-hub/dlthub-init · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Scaffold a [dltHub](https://dlthub.com) workspace into a new or existing directory.

`dlthub-init` lays down the files of a minimal dltHub workspace — `pyproject.toml`,
a locked `uv.lock`, and the `.dlt/` configuration — and optionally creates the
virtual environment. That is all it does: it does not log in, run a pipeline, or
a locked `uv.lock`, the `.dlt/` configuration, and a `.mcp.json` registering the
dlt workspace MCP server — and optionally creates the virtual environment. That is all it does: it does not log in, run a pipeline, or
install agent toolkits.

Unlike `dlthub-start`, it is safe to run inside an existing repository. It is
Expand Down Expand Up @@ -41,8 +41,8 @@ install dependencies with `uv`.
- The run stops only if `.dlt/.workspace` already exists — the directory is
already a dltHub workspace (override with `--force`).
- Otherwise existing files are **left alone** and reported as skipped: your
`pyproject.toml`, `.dlt/config.toml`, and `.dlt/secrets.toml` are never
overwritten, and `.gitignore` is skipped (or **merged** with `--merge`).
`pyproject.toml`, `.dlt/config.toml`, `.dlt/secrets.toml`, and `.mcp.json` are
never overwritten, and `.gitignore` is skipped (or **merged** with `--merge`).
- `uv.lock` is written only when `pyproject.toml` is created, so the lockfile
always matches the workspace's dependencies.
- `--force` overwrites the generated files (never secrets).
Expand Down
8 changes: 8 additions & 0 deletions tests/test_scaffold.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import tempfile
import unittest
from pathlib import Path
Expand Down Expand Up @@ -53,6 +54,13 @@ def test_writes_all_payload_files(self):
for relative in EXPECTED:
self.assertTrue((self.project_dir / relative).exists(), relative)

def test_mcp_json_registers_workspace_server(self):
apply_scaffold(self.project_dir, scaffold=SCAFFOLD, flags=Flags())
config = json.loads((self.project_dir / ".mcp.json").read_text(encoding="utf-8"))
server = config["mcpServers"]["dlt-workspace-mcp"]
self.assertEqual(server["command"], "uv")
self.assertEqual(server["args"], ["run", "dlthub", "ai", "mcp", "--stdio"])

def test_pyproject_name_is_static(self):
apply_scaffold(self.project_dir, scaffold=SCAFFOLD, flags=Flags())
content = (self.project_dir / "pyproject.toml").read_text(encoding="utf-8")
Expand Down
1 change: 1 addition & 0 deletions tests_integration/test_e2e_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_yes_scaffolds_and_syncs(self):
self.assertTrue((self.project_dir / "pyproject.toml").exists())
self.assertTrue((self.project_dir / ".venv" / "pyvenv.cfg").exists())
self.assertTrue((self.project_dir / ".agents" / "skills").is_dir())
self.assertTrue((self.project_dir / ".mcp.json").exists())


if __name__ == "__main__":
Expand Down
39 changes: 39 additions & 0 deletions tests_integration/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import subprocess
import tempfile
import unittest
import zipfile
from pathlib import Path

from dlthub_init.scaffold import enumerate_payload
from dlthub_init.uv import find_uv

REPO_ROOT = Path(__file__).resolve().parents[1]
SCAFFOLD = "minimal_workspace"
WHEEL_SCAFFOLD_DIR = f"dlthub_init/scaffolds/{SCAFFOLD}"


class WheelPayloadTest(unittest.TestCase):
# enumerate_payload walks the source tree, so every other test passes even when
# the build drops a payload file. Most of the payload is dotfiles, which build
# backends are prone to exclude silently.
def test_wheel_ships_every_scaffold_file(self):
uv = find_uv()
if uv is None:
self.skipTest("uv is not installed")
with tempfile.TemporaryDirectory() as out_dir:
subprocess.run(
[uv, "build", "--wheel", "--out-dir", out_dir],
cwd=REPO_ROOT,
check=True,
capture_output=True,
)
wheel = next(Path(out_dir).glob("*.whl"))
with zipfile.ZipFile(wheel) as archive:
shipped = set(archive.namelist())

expected = {f"{WHEEL_SCAFFOLD_DIR}/{relative.as_posix()}" for relative in enumerate_payload(SCAFFOLD)}
self.assertEqual(sorted(expected - shipped), [])


if __name__ == "__main__":
unittest.main()
Loading
0