diff --git a/README.md b/README.md index 5402214..9db5dd4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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). diff --git a/tests/test_scaffold.py b/tests/test_scaffold.py index b603121..0c3c134 100644 --- a/tests/test_scaffold.py +++ b/tests/test_scaffold.py @@ -1,3 +1,4 @@ +import json import tempfile import unittest from pathlib import Path @@ -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") diff --git a/tests_integration/test_e2e_workspace.py b/tests_integration/test_e2e_workspace.py index 0086b3a..178a211 100644 --- a/tests_integration/test_e2e_workspace.py +++ b/tests_integration/test_e2e_workspace.py @@ -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__": diff --git a/tests_integration/test_packaging.py b/tests_integration/test_packaging.py new file mode 100644 index 0000000..50c0452 --- /dev/null +++ b/tests_integration/test_packaging.py @@ -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()