Skip to content

Commit 7b7ef12

Browse files
OGsijiclaude
andcommitted
fix: ask local-vs-GitHub explicitly in init --interactive instead of guessing
Guessing from the path's shape ("/" present, doesn't start with "." or "/") always misfired on the wizard's own suggested default ("app/models"), misreading it as a GitHub org/repo. The wizard now asks explicitly up front, and asks for the repo and the path within it as separate prompts instead of parsing them out of one ambiguous string. Bump to 1.1.3 -- 1.1.2 was only ever published to TestPyPI and never released to production PyPI, so this supersedes it rather than following it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent bf60d56 commit 7b7ef12

6 files changed

Lines changed: 84 additions & 81 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [1.1.2] - 2026-07-03
10+
## [1.1.3] - 2026-07-03
11+
12+
Supersedes 1.1.2, which was only ever published to TestPyPI for verification
13+
and never released to production PyPI.
1114

1215
### Fixed
1316
- **`table=True` SQLModel classes were incorrectly evaluated as required API
@@ -19,13 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1922
name**, instead of only the class-name-derived guess. A class like
2023
`VideoViewed` with `__tablename__ = "int_unified_video_viewed"` now matches
2124
its real source model without needing a manual `mapping.tables` entry.
22-
- **`init --interactive`'s local-vs-GitHub-repo detection misfired on the
23-
tool's own suggested default.** Any two-segment relative local path (e.g.
24-
`app/models`, the FastAPI prompt's default) is syntactically identical to
25-
a GitHub `org/repo` string, and was always guessed as a repo, producing a
26-
nonsensical `app/models/app/models` GitHub target. Existence on disk is
27-
now checked first; the GitHub guess is only made — and now with an
28-
explicit confirmation prompt — when the path doesn't exist locally.
25+
- **`init --interactive` no longer guesses local vs. GitHub from the path's
26+
shape.** A local relative path like `app/models` (the wizard's own
27+
suggested default) is syntactically identical to a GitHub `org/repo`
28+
string, and was always guessed as a repo, producing a nonsensical
29+
`app/models/app/models` GitHub target. The wizard now asks explicitly
30+
("local project or a different GitHub repo?") before asking for the
31+
path, and asks for the repo and the path within it as separate prompts.
2932

3033
### Added
3134
- `init --interactive` and `contract-validator test` now verify a configured

‎README.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ avoids the sharp edges:
6767
```bash
6868
contract-validator init --interactive
6969
```
70-
You'll be asked three things: where your dbt project is, which API
71-
framework you use, and where your Pydantic/SQLModel models live (a local
72-
path, or `org/repo` / `org/repo/path/to/models` for GitHub). If you point
73-
it at a GitHub path, it now checks the path actually exists before writing
74-
the config — so a typo surfaces here instead of at `validate` time.
70+
You'll be asked: where your dbt project is, which API framework you use,
71+
whether your models live in this local project or a different GitHub
72+
repo, and then the local path (or the `org/repo` + path within it). It's
73+
asked explicitly rather than guessed from the path's shape — a local path
74+
like `app/models` is syntactically identical to a GitHub `org/repo`
75+
string, so there's no reliable way to infer which one you mean. If you
76+
pick GitHub, it checks the path actually exists before writing the
77+
config — so a typo surfaces here instead of at `validate` time.
7578

7679
`init` refuses to touch an existing `.retl-validator.yml` or workflow
7780
file — it won't clobber hand-added `mapping` entries just because you

‎data_contract_validator/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
your data pipelines and API frameworks.
66
"""
77

8-
__version__ = "1.1.2"
8+
__version__ = "1.1.3"
99
__author__ = "Ogunniran Siji"
1010
__email__ = "ogunniransiji@gmail.com"
1111

‎data_contract_validator/cli.py‎

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def init(interactive: bool, framework: str, dbt_path: str, output_dir: str, forc
120120

121121
def _interactive_setup() -> Dict[str, Any]:
122122
"""Interactive setup wizard with directory support."""
123-
click.echo("📋 Quick Setup (3 questions):")
123+
click.echo("📋 Quick Setup (a handful of questions):")
124124
click.echo()
125125

126126
# Question 1: DBT project location
@@ -148,57 +148,46 @@ def _interactive_setup() -> Dict[str, Any]:
148148
show_default=True,
149149
)
150150

151-
# Question 3: API models location with directory support
152-
click.echo()
153151
if framework == "fastapi":
154152
default_path = "app/models" # Default to directory
155-
prompt_text = "3️⃣ Where are your Pydantic models? (file or directory)"
156-
help_text = (
157-
" 💡 Examples: 'app/models.py' (single file) or 'app/models' (directory)"
158-
)
153+
location_noun = "Pydantic models"
159154
elif framework == "django":
160155
default_path = "models.py"
161-
prompt_text = "3️⃣ Where are your Django models?"
162-
help_text = " 💡 Examples: 'myapp/models.py' or 'models'"
156+
location_noun = "Django models"
163157
else:
164158
default_path = "models"
165-
prompt_text = "3️⃣ Where are your API models?"
166-
help_text = " 💡 Can be a file (models.py) or directory (models/)"
167-
168-
click.echo(help_text)
169-
api_location = click.prompt(prompt_text, default=default_path, show_default=True)
170-
171-
# Auto-detect if it's local file/directory or GitHub repo. A local
172-
# relative path like "app/models" is syntactically identical to a GitHub
173-
# "org/repo" string, so check disk first -- and only ask when it's
174-
# genuinely ambiguous (doesn't exist locally, but still looks like it
175-
# could be either).
176-
local_path = Path(api_location)
177-
looks_like_repo = "/" in api_location and not api_location.startswith((".", "/"))
178-
179-
if local_path.exists():
180-
is_github_repo = False
181-
elif looks_like_repo:
182-
is_github_repo = click.confirm(
183-
f" '{api_location}' doesn't exist locally — is this a GitHub "
184-
f"repo (org/repo) rather than a local path?",
185-
default=True,
159+
location_noun = "API models"
160+
161+
# Question 3: local vs. GitHub -- asked explicitly rather than guessed
162+
# from the path's shape. A local relative path like "app/models" (the
163+
# default above) is syntactically identical to a GitHub "org/repo"
164+
# string, so there's no reliable way to infer this from the string
165+
# alone; asking up front avoids the wizard silently misreading its own
166+
# suggested default as a repo.
167+
click.echo()
168+
location_kind = click.prompt(
169+
f"3️⃣ Are your {location_noun} in this local project, or a different GitHub repo?",
170+
type=click.Choice(["local", "github"]),
171+
default="local",
172+
show_default=True,
173+
)
174+
175+
click.echo()
176+
if location_kind == "github":
177+
repo = click.prompt(
178+
"4️⃣ GitHub repo (org/repo)", default="", show_default=False
179+
)
180+
while "/" not in repo or repo.count("/") != 1:
181+
click.echo(" ⚠️ Expected the form 'org/repo', e.g. 'my-org/my-api'")
182+
repo = click.prompt("4️⃣ GitHub repo (org/repo)")
183+
184+
path = click.prompt(
185+
f" Path to your {location_noun} within {repo} (file or directory)",
186+
default=default_path,
187+
show_default=True,
186188
)
187-
else:
188-
is_github_repo = False
189-
190-
if is_github_repo:
191-
# Format: "org/repo" or "org/repo/path/to/models"
192-
parts = api_location.split("/")
193-
if len(parts) >= 2:
194-
repo = "/".join(parts[:2])
195-
path = "/".join(parts[2:]) if len(parts) > 2 else "app/models"
196-
else:
197-
repo = api_location
198-
path = "app/models"
199189

200190
api_config = {"type": "github", "repo": repo, "path": path}
201-
click.echo(f" 🐙 GitHub repo detected: {repo}/{path}")
202191

203192
token = os.environ.get("GITHUB_TOKEN")
204193
exists = _github_path_exists(repo, path, token)
@@ -214,9 +203,15 @@ def _interactive_setup() -> Dict[str, Any]:
214203
# exists is None -> couldn't verify (network issue); stay silent rather
215204
# than block setup on something that isn't actually wrong.
216205
else:
206+
api_location = click.prompt(
207+
f"4️⃣ Where are your {location_noun}? (file or directory)",
208+
default=default_path,
209+
show_default=True,
210+
)
217211
api_config = {"type": "local", "path": api_location}
218212

219213
# Check if local file/directory exists and provide feedback
214+
local_path = Path(api_location)
220215
if local_path.exists():
221216
if local_path.is_file():
222217
click.echo(f" ✅ Local file found: {api_location}")
@@ -240,10 +235,10 @@ def _interactive_setup() -> Dict[str, Any]:
240235
if not click.confirm(" Continue anyway?"):
241236
sys.exit(1)
242237

243-
# New question about manifest parsing
238+
# Question 5: manifest parsing
244239
click.echo()
245240
disable_manifest = click.confirm(
246-
"4️⃣ Disable manifest.json parsing? (recommended if you have CTE-based models)",
241+
"5️⃣ Disable manifest.json parsing? (recommended if you have CTE-based models)",
247242
default=True,
248243
)
249244

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "data-contract-validator"
7-
version = "1.1.2"
7+
version = "1.1.3"
88
description = "Validate data contracts between dbt models and FastAPI/Pydantic APIs with accurate, low-false-positive schema checks"
99
readme = "README.md"
1010
license = {text = "MIT"}

‎tests/test_cli.py‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ def test_force_overwrites_existing_config(self, tmp_path):
9797
assert config_file.read_text() != "version: '1.0'\ncustom: hand-edited\n"
9898

9999

100-
class TestInteractiveSetupLocalVsGithubDetection:
101-
"""A local relative path like 'app/models' -- the tool's own suggested
102-
default for the Pydantic-models prompt -- is syntactically identical to
103-
a GitHub 'org/repo' string. Regression coverage for it being silently
104-
misdetected as a repo (producing a nonsensical 'app/models/app/models'
105-
GitHub target) when the directory actually exists on disk."""
106-
107-
def test_existing_local_directory_is_not_treated_as_github_repo(
100+
class TestInteractiveSetupAsksLocalOrGithubExplicitly:
101+
"""The wizard asks 'local or GitHub?' explicitly instead of guessing
102+
from the path's shape. Guessing based on the presence of '/' previously
103+
misdetected the tool's own suggested default ('app/models') as a GitHub
104+
'org/repo' string, producing a nonsensical 'app/models/app/models'
105+
target -- asking up front removes the ambiguity entirely."""
106+
107+
def test_local_choice_produces_local_config_for_default_path(
108108
self, tmp_path, monkeypatch
109109
):
110110
(tmp_path / "app" / "models").mkdir(parents=True)
@@ -113,36 +113,38 @@ def test_existing_local_directory_is_not_treated_as_github_repo(
113113
)
114114
monkeypatch.chdir(tmp_path)
115115

116-
# Prompts in order: dbt path (default "."), "continue anyway" (no
117-
# dbt_project.yml here), framework (default fastapi), models
118-
# location (default "app/models"), disable_manifest (default yes).
116+
# Prompts: dbt path, continue-anyway (no dbt_project.yml here),
117+
# framework, local-or-github (default "local"), models location
118+
# (default "app/models"), disable_manifest.
119119
result = CliRunner().invoke(
120120
cli,
121121
["init", "--interactive", "--output-dir", str(tmp_path)],
122-
input="\ny\n\n\n\n",
122+
input="\ny\n\n\n\n\n",
123123
)
124124

125125
assert result.exit_code == 0, result.output
126126
config = yaml.safe_load((tmp_path / ".retl-validator.yml").read_text())
127127
assert config["target"]["fastapi"] == {"type": "local", "path": "app/models"}
128128

129-
def test_nonexistent_ambiguous_path_asks_before_guessing_github(
130-
self, tmp_path, monkeypatch
129+
@patch("data_contract_validator.cli._github_path_exists", return_value=None)
130+
def test_github_choice_asks_for_repo_and_path_separately(
131+
self, mock_exists, tmp_path, monkeypatch
131132
):
132133
monkeypatch.chdir(tmp_path)
133134

134-
# Prompts: dbt path, continue-anyway (no dbt_project.yml), framework,
135-
# models location (app/models, which doesn't exist here), the new
136-
# "is this a GitHub repo?" disambiguation (answer "n"), then
137-
# continue-anyway again (local path still doesn't exist), then
135+
# Prompts: dbt path, continue-anyway, framework, local-or-github
136+
# ("github"), repo (org/repo), path within repo (default), then
138137
# disable_manifest.
139138
result = CliRunner().invoke(
140139
cli,
141140
["init", "--interactive", "--output-dir", str(tmp_path)],
142-
input="\ny\n\n\nn\ny\n\n",
141+
input="\ny\n\ngithub\nmy-org/my-api\n\n\n",
143142
)
144143

145144
assert result.exit_code == 0, result.output
146-
assert "is this a GitHub" in result.output
147145
config = yaml.safe_load((tmp_path / ".retl-validator.yml").read_text())
148-
assert config["target"]["fastapi"]["type"] == "local"
146+
assert config["target"]["fastapi"] == {
147+
"type": "github",
148+
"repo": "my-org/my-api",
149+
"path": "app/models",
150+
}

0 commit comments

Comments
 (0)