spin-up-dev-project 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.pyc
3
+ dist/
4
+ .venv/
5
+ .pytest_cache/
6
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lorenzo Wood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.5
2
+ Name: spin-up-dev-project
3
+ Version: 0.1.0
4
+ Summary: Spin up a new project: directory, README, git repo, private GitHub repo, then launch your coding agent.
5
+ Project-URL: Homepage, https://github.com/lorenzowood/spin-up
6
+ Project-URL: Issues, https://github.com/lorenzowood/spin-up/issues
7
+ Author: Lorenzo Wood
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: cli,coding-agent,git,github,scaffold
11
+ Classifier: Environment :: Console
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Version Control :: Git
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # spin-up
18
+
19
+ Start a new project in one command: create the directory, drop in a placeholder
20
+ `README.md`, `git init`, commit, create a **private** GitHub repo, push, and then
21
+ launch your coding agent inside it.
22
+
23
+ ```console
24
+ $ spin-up claude ~/Projects/local-ai-library
25
+ Created https://github.com/you/local-ai-library (private)
26
+ # ...and Claude Code starts in ~/Projects/local-ai-library
27
+ ```
28
+
29
+ ## Requirements
30
+
31
+ - Python 3.10+
32
+ - [`git`](https://git-scm.com/)
33
+ - the [GitHub CLI](https://cli.github.com/) (`gh`), authenticated (`gh auth login`).
34
+ spin-up checks this on every run, and creates repos under the account `gh` is
35
+ logged in as, so there is no owner to configure
36
+ - whichever coding agent(s) you want to launch
37
+
38
+ ## Install
39
+
40
+ The PyPI package is `spin-up-dev-project`; the command it installs is `spin-up`.
41
+
42
+ ```console
43
+ uv tool install spin-up-dev-project # or: pipx install spin-up-dev-project
44
+ ```
45
+
46
+ ## Configure agents
47
+
48
+ Create `~/.config/spin-up` mapping a key to the command that starts your agent,
49
+ one per line (blank lines and `#` comments are ignored):
50
+
51
+ ```
52
+ claude: claude --dangerously-skip-permissions
53
+ cursor: cursor-agent
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```
59
+ spin-up [-y] [--owner OWNER] <agent> <directory> [<name>]
60
+ ```
61
+
62
+ | Argument | Meaning |
63
+ | --- | --- |
64
+ | `agent` | A key from `~/.config/spin-up`. |
65
+ | `directory` | The directory to create. It **must not already exist**. Its basename is the repo name. |
66
+ | `name` | Optional title for the README's `# H1`. Defaults to the directory name. |
67
+ | `--owner` | GitHub owner for the new repo. Defaults to the user `gh` is logged in as. |
68
+ | `-y`, `--yes` | Don't ask for confirmation when possibly-related repos are found. |
69
+
70
+ What it does, in order:
71
+
72
+ 1. Checks the agent is configured and its command is on `PATH`, that the
73
+ directory doesn't exist, and that `gh` is authenticated. Nothing is created if any check fails.
74
+ 2. Lists your GitHub repos and looks for ones that might be related (see below).
75
+ If any are found it prints them and asks `Continue with spin-up of <directory>?`.
76
+ 3. Creates the directory and `README.md`, runs `git init -b main`, and commits.
77
+ 4. Creates the **private** repo `<owner>/<directory-name>` and pushes.
78
+ 5. Replaces itself with the agent command, running in the new directory.
79
+
80
+ ### Related-repo check
81
+
82
+ To avoid starting a project you already have, the directory name is split on
83
+ `-`, `_`, `.` and spaces; words are lower-cased and singularised
84
+ (`libraries` → `library`); common stop words (`the`, `a`, `of`, `and`, …) are
85
+ dropped. Any existing repo whose name shares at least one remaining word is
86
+ listed as possibly related. Only repo *names* are compared, and singularisation
87
+ is a small rule-based English heuristic rather than a full dictionary.
88
+
89
+ ## Development
90
+
91
+ ```console
92
+ uv run --with pytest --with-editable . pytest
93
+ ```
94
+
95
+ The tests use real `git` and a fake `gh` on `PATH`, so they never touch GitHub.
96
+
97
+ ## Licence
98
+
99
+ MIT
@@ -0,0 +1,83 @@
1
+ # spin-up
2
+
3
+ Start a new project in one command: create the directory, drop in a placeholder
4
+ `README.md`, `git init`, commit, create a **private** GitHub repo, push, and then
5
+ launch your coding agent inside it.
6
+
7
+ ```console
8
+ $ spin-up claude ~/Projects/local-ai-library
9
+ Created https://github.com/you/local-ai-library (private)
10
+ # ...and Claude Code starts in ~/Projects/local-ai-library
11
+ ```
12
+
13
+ ## Requirements
14
+
15
+ - Python 3.10+
16
+ - [`git`](https://git-scm.com/)
17
+ - the [GitHub CLI](https://cli.github.com/) (`gh`), authenticated (`gh auth login`).
18
+ spin-up checks this on every run, and creates repos under the account `gh` is
19
+ logged in as, so there is no owner to configure
20
+ - whichever coding agent(s) you want to launch
21
+
22
+ ## Install
23
+
24
+ The PyPI package is `spin-up-dev-project`; the command it installs is `spin-up`.
25
+
26
+ ```console
27
+ uv tool install spin-up-dev-project # or: pipx install spin-up-dev-project
28
+ ```
29
+
30
+ ## Configure agents
31
+
32
+ Create `~/.config/spin-up` mapping a key to the command that starts your agent,
33
+ one per line (blank lines and `#` comments are ignored):
34
+
35
+ ```
36
+ claude: claude --dangerously-skip-permissions
37
+ cursor: cursor-agent
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```
43
+ spin-up [-y] [--owner OWNER] <agent> <directory> [<name>]
44
+ ```
45
+
46
+ | Argument | Meaning |
47
+ | --- | --- |
48
+ | `agent` | A key from `~/.config/spin-up`. |
49
+ | `directory` | The directory to create. It **must not already exist**. Its basename is the repo name. |
50
+ | `name` | Optional title for the README's `# H1`. Defaults to the directory name. |
51
+ | `--owner` | GitHub owner for the new repo. Defaults to the user `gh` is logged in as. |
52
+ | `-y`, `--yes` | Don't ask for confirmation when possibly-related repos are found. |
53
+
54
+ What it does, in order:
55
+
56
+ 1. Checks the agent is configured and its command is on `PATH`, that the
57
+ directory doesn't exist, and that `gh` is authenticated. Nothing is created if any check fails.
58
+ 2. Lists your GitHub repos and looks for ones that might be related (see below).
59
+ If any are found it prints them and asks `Continue with spin-up of <directory>?`.
60
+ 3. Creates the directory and `README.md`, runs `git init -b main`, and commits.
61
+ 4. Creates the **private** repo `<owner>/<directory-name>` and pushes.
62
+ 5. Replaces itself with the agent command, running in the new directory.
63
+
64
+ ### Related-repo check
65
+
66
+ To avoid starting a project you already have, the directory name is split on
67
+ `-`, `_`, `.` and spaces; words are lower-cased and singularised
68
+ (`libraries` → `library`); common stop words (`the`, `a`, `of`, `and`, …) are
69
+ dropped. Any existing repo whose name shares at least one remaining word is
70
+ listed as possibly related. Only repo *names* are compared, and singularisation
71
+ is a small rule-based English heuristic rather than a full dictionary.
72
+
73
+ ## Development
74
+
75
+ ```console
76
+ uv run --with pytest --with-editable . pytest
77
+ ```
78
+
79
+ The tests use real `git` and a fake `gh` on `PATH`, so they never touch GitHub.
80
+
81
+ ## Licence
82
+
83
+ MIT
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "spin-up-dev-project"
7
+ version = "0.1.0"
8
+ description = "Spin up a new project: directory, README, git repo, private GitHub repo, then launch your coding agent."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "Lorenzo Wood" }]
13
+ keywords = ["git", "github", "scaffold", "cli", "coding-agent"]
14
+ classifiers = [
15
+ "Environment :: Console",
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Software Development :: Version Control :: Git",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/lorenzowood/spin-up"
22
+ Issues = "https://github.com/lorenzowood/spin-up/issues"
23
+
24
+ [project.scripts]
25
+ spin-up = "spin_up.cli:main"
26
+
27
+ [tool.hatch.build.targets.wheel]
28
+ packages = ["src/spin_up"]
29
+
30
+ [tool.pytest.ini_options]
31
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """spin-up: scaffold a project, create its private GitHub repo, launch an agent."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,132 @@
1
+ """The ``spin-up`` command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import os
8
+ import shutil
9
+ import subprocess
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ from . import __version__
14
+ from .config import SpinUpError, load_agents
15
+ from .related import find_related
16
+
17
+
18
+ def run(cmd: list[str], cwd: Path | None = None) -> str:
19
+ """Run a command, returning stdout; raise SpinUpError with stderr on failure."""
20
+ try:
21
+ proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
22
+ except FileNotFoundError:
23
+ raise SpinUpError(f"{cmd[0]!r} not found on PATH") from None
24
+ if proc.returncode != 0:
25
+ detail = (proc.stderr or proc.stdout).strip()
26
+ raise SpinUpError(f"{' '.join(cmd)} failed:\n{detail}")
27
+ return proc.stdout
28
+
29
+
30
+ def check_gh_auth() -> None:
31
+ try:
32
+ run(["gh", "auth", "status"])
33
+ except SpinUpError:
34
+ raise SpinUpError("gh is not authenticated; run `gh auth login` first") from None
35
+
36
+
37
+ def github_user() -> str:
38
+ return run(["gh", "api", "user", "--jq", ".login"]).strip()
39
+
40
+
41
+ def list_repo_names(owner: str) -> list[str]:
42
+ out = run(["gh", "repo", "list", owner, "--limit", "1000", "--json", "name"])
43
+ return [r["name"] for r in json.loads(out or "[]")]
44
+
45
+
46
+ def confirm(question: str) -> bool:
47
+ try:
48
+ return input(question + " [y/N] ").strip().lower() in ("y", "yes")
49
+ except EOFError:
50
+ return False
51
+
52
+
53
+ def launch_agent(argv: list[str], cwd: Path) -> None:
54
+ """Replace this process with the agent, running in the new project directory."""
55
+ os.chdir(cwd)
56
+ os.execvp(argv[0], argv)
57
+
58
+
59
+ def spin_up(
60
+ agent: str,
61
+ directory: str,
62
+ title: str | None = None,
63
+ owner: str | None = None,
64
+ assume_yes: bool = False,
65
+ ) -> None:
66
+ agents = load_agents()
67
+ if agent not in agents:
68
+ known = ", ".join(sorted(agents)) or "none"
69
+ raise SpinUpError(f"unknown agent {agent!r} (configured: {known})")
70
+ agent_argv = agents[agent]
71
+ if shutil.which(agent_argv[0]) is None:
72
+ raise SpinUpError(f"agent command {agent_argv[0]!r} not found on PATH")
73
+
74
+ path = Path(directory).expanduser()
75
+ if path.exists():
76
+ raise SpinUpError(f"{path} already exists")
77
+ name = path.name
78
+ if not name:
79
+ raise SpinUpError(f"cannot derive a repository name from {directory!r}")
80
+ for tool in ("git", "gh"):
81
+ if shutil.which(tool) is None:
82
+ raise SpinUpError(f"{tool!r} not found on PATH")
83
+
84
+ check_gh_auth()
85
+ owner = owner or github_user()
86
+ related = find_related(name, list_repo_names(owner))
87
+ if related:
88
+ print("The following may be related:")
89
+ for repo in related:
90
+ print(f" {owner}/{repo}")
91
+ if not assume_yes and not confirm(f"Continue with spin-up of {directory}?"):
92
+ print("Aborted.")
93
+ raise SystemExit(1)
94
+
95
+ path.mkdir(parents=True)
96
+ (path / "README.md").write_text(f"# {title or name}\n\nPlaceholder.\n")
97
+ run(["git", "init", "-b", "main"], cwd=path)
98
+ run(["git", "add", "README.md"], cwd=path)
99
+ run(["git", "commit", "-m", "Add placeholder README"], cwd=path)
100
+ run(
101
+ ["gh", "repo", "create", f"{owner}/{name}", "--private",
102
+ "--source=.", "--remote=origin", "--push"],
103
+ cwd=path,
104
+ )
105
+ print(f"Created https://github.com/{owner}/{name} (private)")
106
+ launch_agent(agent_argv, path)
107
+
108
+
109
+ def main(argv: list[str] | None = None) -> int:
110
+ parser = argparse.ArgumentParser(
111
+ prog="spin-up",
112
+ description="Create a directory, placeholder README, git repo and private "
113
+ "GitHub repo, then launch a coding agent in it.",
114
+ )
115
+ parser.add_argument("agent", help="agent key from ~/.config/spin-up")
116
+ parser.add_argument("directory", help="new directory to create (must not exist)")
117
+ parser.add_argument("name", nargs="?", help="title for the README's H1 (default: directory name)")
118
+ parser.add_argument("--owner", help="GitHub owner (default: the authenticated gh user)")
119
+ parser.add_argument("-y", "--yes", action="store_true",
120
+ help="don't prompt when possibly-related repos are found")
121
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
122
+ args = parser.parse_args(argv)
123
+ try:
124
+ spin_up(args.agent, args.directory, args.name, args.owner, args.yes)
125
+ except SpinUpError as exc:
126
+ print(f"spin-up: {exc}", file=sys.stderr)
127
+ return 1
128
+ return 0
129
+
130
+
131
+ if __name__ == "__main__":
132
+ sys.exit(main())
@@ -0,0 +1,50 @@
1
+ """Agent configuration: ``~/.config/spin-up`` maps agent keys to commands.
2
+
3
+ Format, one agent per line (blank lines and ``#`` comments are ignored)::
4
+
5
+ claude: claude --dangerously-skip-permissions
6
+ cursor: cursor-agent
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import shlex
12
+ from pathlib import Path
13
+
14
+ CONFIG_PATH = Path("~/.config/spin-up").expanduser()
15
+
16
+
17
+ class SpinUpError(Exception):
18
+ """A user-facing error: printed without a traceback."""
19
+
20
+
21
+ def parse_config(text: str) -> dict[str, list[str]]:
22
+ """Parse config text into ``{agent: argv}``."""
23
+ agents: dict[str, list[str]] = {}
24
+ for lineno, raw in enumerate(text.splitlines(), start=1):
25
+ line = raw.strip()
26
+ if not line or line.startswith("#"):
27
+ continue
28
+ key, sep, command = line.partition(":")
29
+ key, command = key.strip(), command.strip()
30
+ if not sep or not key or not command:
31
+ raise SpinUpError(f"config line {lineno}: expected 'agent: command', got {raw!r}")
32
+ try:
33
+ argv = shlex.split(command)
34
+ except ValueError as exc:
35
+ raise SpinUpError(f"config line {lineno}: {exc}") from exc
36
+ agents[key] = argv
37
+ return agents
38
+
39
+
40
+ def load_agents(path: Path | None = None) -> dict[str, list[str]]:
41
+ path = path or CONFIG_PATH
42
+ try:
43
+ text = path.read_text()
44
+ except FileNotFoundError:
45
+ raise SpinUpError(
46
+ f"no config file at {path}. Create it with lines like:\n"
47
+ " claude: claude --dangerously-skip-permissions\n"
48
+ " cursor: cursor-agent"
49
+ ) from None
50
+ return parse_config(text)
@@ -0,0 +1,54 @@
1
+ """Find existing repos whose names look related to a new project's name."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ STOP_WORDS = frozenset(
8
+ """a an the and or but of for to in on at by with from into over as is it
9
+ my your our their this that""".split()
10
+ )
11
+
12
+ _IRREGULAR = {
13
+ "people": "person",
14
+ "children": "child",
15
+ "men": "man",
16
+ "women": "woman",
17
+ "mice": "mouse",
18
+ "indices": "index",
19
+ "analyses": "analysis",
20
+ }
21
+
22
+
23
+ def singularize(word: str) -> str:
24
+ """Rule-based English singularisation (good enough for matching names)."""
25
+ w = word.lower()
26
+ if w in _IRREGULAR:
27
+ return _IRREGULAR[w]
28
+ if len(w) <= 3 or w.endswith(("ss", "us", "is")):
29
+ return w
30
+ if w.endswith("ies") and len(w) > 4:
31
+ return w[:-3] + "y"
32
+ if w.endswith(("sses", "xes", "ches", "shes", "zes")):
33
+ return w[:-2]
34
+ if w.endswith("s"):
35
+ return w[:-1]
36
+ return w
37
+
38
+
39
+ def keywords(name: str) -> set[str]:
40
+ """Split a hyphen/underscore/space separated name into singular, non-stop words."""
41
+ words = (w for w in re.split(r"[-_.\s]+", name.lower()) if w)
42
+ return {singularize(w) for w in words if w not in STOP_WORDS}
43
+
44
+
45
+ def find_related(name: str, repo_names: list[str]) -> list[str]:
46
+ """Repos sharing at least one keyword with ``name`` (excluding an exact match)."""
47
+ wanted = keywords(name)
48
+ if not wanted:
49
+ return []
50
+ return [
51
+ repo
52
+ for repo in repo_names
53
+ if repo.lower() != name.lower() and wanted & keywords(repo)
54
+ ]
@@ -0,0 +1,174 @@
1
+ """End-to-end tests: real git, a fake `gh` on PATH, and a recorded agent launch."""
2
+
3
+ import json
4
+ import stat
5
+ import subprocess
6
+
7
+ import pytest
8
+
9
+ from spin_up import cli, config
10
+
11
+ FAKE_GH = """#!/bin/sh
12
+ echo "$@" >> "$FAKE_GH_LOG"
13
+ case "$1 $2" in
14
+ "auth status") [ -z "$FAKE_GH_UNAUTH" ] || { echo "not logged in" >&2; exit 1; } ;;
15
+ "api user") echo lorenzowood ;;
16
+ "repo list") cat "$FAKE_GH_REPOS" ;;
17
+ esac
18
+ """
19
+
20
+
21
+ @pytest.fixture
22
+ def env(tmp_path, monkeypatch):
23
+ bindir = tmp_path / "bin"
24
+ bindir.mkdir()
25
+ gh = bindir / "gh"
26
+ gh.write_text(FAKE_GH)
27
+ gh.chmod(gh.stat().st_mode | stat.S_IEXEC)
28
+ fake_agent = bindir / "fakeagent"
29
+ fake_agent.write_text("#!/bin/sh\n")
30
+ fake_agent.chmod(fake_agent.stat().st_mode | stat.S_IEXEC)
31
+
32
+ log = tmp_path / "gh.log"
33
+ repos = tmp_path / "repos.json"
34
+ repos.write_text("[]")
35
+ cfg = tmp_path / "config"
36
+ cfg.write_text("fake: fakeagent --flag\n")
37
+
38
+ monkeypatch.setenv("PATH", f"{bindir}:/usr/bin:/bin")
39
+ monkeypatch.setenv("FAKE_GH_LOG", str(log))
40
+ monkeypatch.setenv("FAKE_GH_REPOS", str(repos))
41
+ for var, val in {"NAME": "T", "EMAIL": "t@example.com"}.items():
42
+ monkeypatch.setenv(f"GIT_AUTHOR_{var}", val)
43
+ monkeypatch.setenv(f"GIT_COMMITTER_{var}", val)
44
+ monkeypatch.setattr(config, "CONFIG_PATH", cfg)
45
+
46
+ launched = []
47
+ monkeypatch.setattr(cli, "launch_agent", lambda argv, cwd: launched.append((argv, cwd)))
48
+
49
+ class Env:
50
+ pass
51
+
52
+ e = Env()
53
+ e.tmp, e.log, e.launched = tmp_path, log, launched
54
+ e.set_repos = lambda names: repos.write_text(json.dumps([{"name": n} for n in names]))
55
+ e.gh_calls = lambda: log.read_text().splitlines() if log.exists() else []
56
+ return e
57
+
58
+
59
+ def git(path, *args):
60
+ return subprocess.run(["git", *args], cwd=path, capture_output=True, text=True, check=True).stdout
61
+
62
+
63
+ def test_happy_path(env):
64
+ target = env.tmp / "proj" / "my-new-thing"
65
+ assert cli.main(["fake", str(target)]) == 0
66
+
67
+ assert (target / "README.md").read_text() == "# my-new-thing\n\nPlaceholder.\n"
68
+ assert git(target, "rev-parse", "--abbrev-ref", "HEAD").strip() == "main"
69
+ assert git(target, "log", "--format=%s").strip() == "Add placeholder README"
70
+ assert git(target, "status", "--porcelain") == ""
71
+
72
+ create = [c for c in env.gh_calls() if c.startswith("repo create")]
73
+ assert create == ["repo create lorenzowood/my-new-thing --private --source=. --remote=origin --push"]
74
+ assert env.launched == [(["fakeagent", "--flag"], target)]
75
+
76
+
77
+ def test_name_argument_sets_h1(env):
78
+ target = env.tmp / "thing"
79
+ assert cli.main(["fake", str(target), "My Fancy Thing"]) == 0
80
+ assert (target / "README.md").read_text().startswith("# My Fancy Thing\n")
81
+
82
+
83
+ def test_fails_if_directory_exists_and_does_nothing(env):
84
+ target = env.tmp / "exists"
85
+ target.mkdir()
86
+ assert cli.main(["fake", str(target)]) == 1
87
+ assert list(target.iterdir()) == []
88
+ assert env.gh_calls() == []
89
+ assert env.launched == []
90
+
91
+
92
+ def test_unknown_agent(env, capsys):
93
+ assert cli.main(["nope", str(env.tmp / "x")]) == 1
94
+ assert "unknown agent 'nope'" in capsys.readouterr().err
95
+ assert not (env.tmp / "x").exists()
96
+
97
+
98
+ def test_agent_command_missing_fails_before_creating_anything(env):
99
+ (env.tmp / "config").write_text("ghost: not-a-real-command\n")
100
+ assert cli.main(["ghost", str(env.tmp / "x")]) == 1
101
+ assert not (env.tmp / "x").exists()
102
+ assert env.gh_calls() == []
103
+
104
+
105
+ def test_related_repos_listed_and_declined(env, capsys, monkeypatch):
106
+ env.set_repos(["local-model-zoo", "garden"])
107
+ asked = []
108
+ monkeypatch.setattr(cli, "confirm", lambda q: asked.append(q) or False)
109
+ target = env.tmp / "local-ai-library"
110
+
111
+ with pytest.raises(SystemExit) as exc:
112
+ cli.main(["fake", str(target)])
113
+
114
+ assert exc.value.code == 1
115
+ out = capsys.readouterr().out
116
+ assert "The following may be related:" in out
117
+ assert "lorenzowood/local-model-zoo" in out
118
+ assert "garden" not in out
119
+ assert asked == [f"Continue with spin-up of {target}?"]
120
+ assert not target.exists()
121
+ assert not any(c.startswith("repo create") for c in env.gh_calls())
122
+
123
+
124
+ def test_related_repos_accepted_continues(env, monkeypatch):
125
+ env.set_repos(["local-model-zoo"])
126
+ monkeypatch.setattr(cli, "confirm", lambda q: True)
127
+ target = env.tmp / "local-ai-library"
128
+ assert cli.main(["fake", str(target)]) == 0
129
+ assert (target / "README.md").exists()
130
+ assert env.launched
131
+
132
+
133
+ def test_yes_flag_skips_prompt(env, monkeypatch):
134
+ env.set_repos(["local-model-zoo"])
135
+ monkeypatch.setattr(cli, "confirm", lambda q: pytest.fail("should not prompt"))
136
+ assert cli.main(["fake", str(env.tmp / "local-ai-library"), "--yes"]) == 0
137
+
138
+
139
+ def test_no_prompt_when_nothing_related(env, monkeypatch):
140
+ env.set_repos(["garden"])
141
+ monkeypatch.setattr(cli, "confirm", lambda q: pytest.fail("should not prompt"))
142
+ assert cli.main(["fake", str(env.tmp / "local-ai-library")]) == 0
143
+
144
+
145
+ def test_owner_override_used_for_listing_and_creation(env):
146
+ assert cli.main(["fake", str(env.tmp / "thing"), "--owner", "someorg"]) == 0
147
+ calls = env.gh_calls()
148
+ assert not any(c.startswith("api user") for c in calls)
149
+ assert any(c.startswith("repo list someorg") for c in calls)
150
+ assert any(c.startswith("repo create someorg/thing --private") for c in calls)
151
+
152
+
153
+ def test_confirm_treats_eof_as_no(monkeypatch):
154
+ def raise_eof(_):
155
+ raise EOFError
156
+
157
+ monkeypatch.setattr("builtins.input", raise_eof)
158
+ assert cli.confirm("ok?") is False
159
+
160
+
161
+ def test_unauthenticated_gh_fails_before_creating_anything(env, monkeypatch, capsys):
162
+ monkeypatch.setenv("FAKE_GH_UNAUTH", "1")
163
+ target = env.tmp / "thing"
164
+ assert cli.main(["fake", str(target)]) == 1
165
+ assert "gh auth login" in capsys.readouterr().err
166
+ assert not target.exists()
167
+ assert not any(c.startswith("repo ") for c in env.gh_calls())
168
+
169
+
170
+ def test_owner_is_taken_from_authenticated_user_not_hardcoded(env, monkeypatch):
171
+ # The fake gh reports "lorenzowood"; nothing in the package should name an owner itself.
172
+ import pathlib, spin_up
173
+ src = "".join(p.read_text() for p in pathlib.Path(spin_up.__file__).parent.glob("*.py"))
174
+ assert "lorenzowood" not in src
@@ -0,0 +1,41 @@
1
+ import pytest
2
+
3
+ from spin_up import config
4
+ from spin_up.config import SpinUpError, load_agents, parse_config
5
+
6
+
7
+ def test_parse_config_basic():
8
+ text = """
9
+ # my agents
10
+ claude: claude --dangerously-skip-permissions
11
+
12
+ cursor: cursor-agent
13
+ """
14
+ assert parse_config(text) == {
15
+ "claude": ["claude", "--dangerously-skip-permissions"],
16
+ "cursor": ["cursor-agent"],
17
+ }
18
+
19
+
20
+ def test_parse_config_respects_quoting_and_colons_in_command():
21
+ assert parse_config('x: tool --msg "hello world" --url http://a:1') == {
22
+ "x": ["tool", "--msg", "hello world", "--url", "http://a:1"]
23
+ }
24
+
25
+
26
+ @pytest.mark.parametrize("bad", ["justakey", ": cmd", "key:", 'k: "unterminated'])
27
+ def test_parse_config_rejects_bad_lines(bad):
28
+ with pytest.raises(SpinUpError):
29
+ parse_config(bad)
30
+
31
+
32
+ def test_load_agents_missing_file_explains(tmp_path):
33
+ with pytest.raises(SpinUpError, match="no config file"):
34
+ load_agents(tmp_path / "nope")
35
+
36
+
37
+ def test_load_agents_default_path(tmp_path, monkeypatch):
38
+ cfg = tmp_path / "spin-up"
39
+ cfg.write_text("a: echo hi\n")
40
+ monkeypatch.setattr(config, "CONFIG_PATH", cfg)
41
+ assert load_agents() == {"a": ["echo", "hi"]}
@@ -0,0 +1,52 @@
1
+ import pytest
2
+
3
+ from spin_up.related import find_related, keywords, singularize
4
+
5
+
6
+ @pytest.mark.parametrize(
7
+ "word,expected",
8
+ [
9
+ ("libraries", "library"),
10
+ ("models", "model"),
11
+ ("boxes", "box"),
12
+ ("watches", "watch"),
13
+ ("classes", "class"),
14
+ ("people", "person"),
15
+ ("status", "status"),
16
+ ("analysis", "analysis"),
17
+ ("ai", "ai"),
18
+ ("local", "local"),
19
+ ],
20
+ )
21
+ def test_singularize(word, expected):
22
+ assert singularize(word) == expected
23
+
24
+
25
+ def test_keywords_split_singularize_and_drop_stop_words():
26
+ assert keywords("the-local-ai-libraries") == {"local", "ai", "library"}
27
+ assert keywords("a_tool_for_the_dogs") == {"tool", "dog"}
28
+
29
+
30
+ def test_keywords_empty_when_only_stop_words():
31
+ assert keywords("the-a-of") == set()
32
+
33
+
34
+ def test_find_related_matches_plural_and_singular():
35
+ repos = ["ai-notes", "local-model-zoo", "garden", "Library-Tools"]
36
+ assert find_related("local-ai-libraries", repos) == [
37
+ "ai-notes",
38
+ "local-model-zoo",
39
+ "Library-Tools",
40
+ ]
41
+
42
+
43
+ def test_find_related_ignores_stop_word_overlap():
44
+ assert find_related("the-garden", ["the-shed", "a-pond"]) == []
45
+
46
+
47
+ def test_find_related_excludes_exact_name():
48
+ assert find_related("foo-bar", ["foo-bar", "bar-baz"]) == ["bar-baz"]
49
+
50
+
51
+ def test_find_related_nothing_when_no_keywords():
52
+ assert find_related("the-a", ["the-a", "anything"]) == []
@@ -0,0 +1,8 @@
1
+ version = 1
2
+ revision = 3
3
+ requires-python = ">=3.10"
4
+
5
+ [[package]]
6
+ name = "spin-up-dev-project"
7
+ version = "0.1.0"
8
+ source = { editable = "." }