Answer stability round 1: 1 🔴, 4 🟡 (0 misread); keep credentials out of questions, stop a clone that waits, ask where a file is in the way

This commit is contained in:
2026-11-18 13:19:55 +01:00
parent 59e176743f
commit 901a7d698f
5 changed files with 63 additions and 42 deletions
+26 -8
View File
@@ -17,6 +17,7 @@ class FakeGit:
def __init__(self, origins: dict[str, str | Failure], refused: str | None = None) -> None:
self.origins, self.refused = origins, refused
self.cloned: list[tuple[str, str]] = []
self.clone_timeouts: list[float | None] = []
def __call__(self, *args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False, errors: str = "strict") -> str | Failure:
if args[:3] == ("remote", "get-url", "origin"):
@@ -25,6 +26,7 @@ class FakeGit:
if args[2] == self.refused:
return Failure("git clone: repository not found")
self.cloned.append((args[2], args[3]))
self.clone_timeouts.append(timeout)
pathlib.Path(args[3], ".git").mkdir(parents=True)
return ""
@@ -71,7 +73,8 @@ class LocateTest(unittest.TestCase):
asked = self.unsure(git)
clone = self.home / "clones" / "ledger"
self.assertEqual(git.cloned, [("git@github.com:acme/ledger", str(clone))])
self.assertEqual(asked, f"{clone} was cloned, but no project config names it. Write {self.projects}/<key>/config.toml with `checkout = \"{clone}\"`, as `project-config --help` shows, and run do-epic again.")
self.assertIn(f"{clone} was cloned, but no project config names it", asked)
self.assertIn(f"{self.projects}/<key>/config.toml with `checkout = \"{clone}\"`", asked)
self.assertEqual(self.unsure(git), asked.replace("was cloned", "holds the repo"), "the second ask finds the clone and clones nothing")
self.assertEqual(len(git.cloned), 1)
@@ -86,7 +89,7 @@ class LocateTest(unittest.TestCase):
def test_asks_where_the_other_repos_differ_only_by_owner(self) -> None:
self.configure()
self.origins[str(self.payments)] = "git@github.com:other/payments"
self.assertIn("more than one place", self.unsure(FakeGit(self.origins)))
self.assertIn("more than one host or owner", self.unsure(FakeGit(self.origins)))
def test_asks_where_no_other_repo_shows_where_to_clone_from(self) -> None:
self.configure()
@@ -99,7 +102,7 @@ class LocateTest(unittest.TestCase):
self.origins[str(self.billing)] = Failure("git remote: no such remote 'origin'")
self.assertIn(f"cannot read the origin of {self.billing}: git remote: no such remote 'origin'", self.unsure(FakeGit(self.origins)))
self.origins[str(self.billing)] = "billing"
self.assertIn(f"{self.billing} has an origin, billing, with no place to put another repo in", self.unsure(FakeGit(self.origins)))
self.assertIn(f"{self.billing} has an origin, billing, with no host and owner to put another repo under", self.unsure(FakeGit(self.origins)))
def test_asks_where_the_clone_fails_naming_the_url_and_the_reason(self) -> None:
self.configure()
@@ -131,13 +134,28 @@ class LocateTest(unittest.TestCase):
self.assertIn("is not an https, ssh or scp-style address", self.unsure(git))
self.assertEqual(git.cloned, [])
def test_leaves_the_credentials_of_an_origin_out_of_a_question(self) -> None:
def test_clones_and_asks_without_the_credentials_an_origin_holds(self) -> None:
self.configure()
self.origins[str(self.billing)] = "https://bot:s3cret@gitea.larvit.se/acme/billing"
self.origins[str(self.payments)] = "https://bot:s3cret@gitea.larvit.se/acme/payments"
asked = self.unsure(FakeGit(self.origins))
self.assertIn("https://gitea.larvit.se/acme/ledger is not an https", asked)
self.assertNotIn("s3cret", asked)
self.origins[str(self.payments)] = "https://other:t0ken@gitea.larvit.se/acme/payments.git"
git = FakeGit(self.origins)
self.assertIsInstance(self.locate(git), Located)
self.assertEqual(git.cloned, [("https://gitea.larvit.se/acme/ledger", str(self.home / "code" / "ledger"))])
self.origins[str(self.payments)] = "https://other:t0ken@gitea.larvit.se/acme/payments"
self.origins[str(self.billing)] = "https://bot:s3cret@gitea.larvit.se"
self.assertNotIn("s3cret", self.unsure(FakeGit(self.origins), "stock"))
def test_stops_a_clone_that_waits_for_a_prompt(self) -> None:
self.configure()
git = FakeGit(self.origins)
self.locate(git)
self.assertEqual(git.clone_timeouts, [600])
def test_asks_where_the_place_to_clone_into_is_a_file(self) -> None:
self.configure()
(self.home / "code").mkdir()
(self.home / "code" / "ledger").write_text("x", encoding="utf-8")
self.assertIn("exists and is not a git checkout", self.unsure(FakeGit(self.origins)))
def test_fails_with_the_config_failure_where_a_config_cannot_be_read(self) -> None:
(self.projects / "broken").mkdir(parents=True)