From f408ff1ff95ce6e512810ccb10695f773fe5a8b9 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 28 Jun 2026 08:47:30 +0900 Subject: test(util/git): port interactive Bitbucket OAuth runCommand test Implement the four privateBitbucketWithOauthProvider cases that were stubbed as an ignored todo!(). Extend IOStub with per-question askAndHideAnswer responses and auth pre-seeding so the stateful OAuth flow can be driven without willReturnCallback, and inject a mock HttpDownloader plus no-op config sources to mirror PHPUnit's Config mock. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/tests/common/io_stub.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'crates/shirabe/tests/common/io_stub.rs') diff --git a/crates/shirabe/tests/common/io_stub.rs b/crates/shirabe/tests/common/io_stub.rs index 9318d45..b57dd0c 100644 --- a/crates/shirabe/tests/common/io_stub.rs +++ b/crates/shirabe/tests/common/io_stub.rs @@ -29,6 +29,10 @@ pub struct IOStub { ask: Option, ask_confirmation: Option, ask_and_hide_answer: Option>, + // Keyed `askAndHideAnswer` replies, mirroring tests whose willReturnCallback + // switches on the question string. Unknown questions return `''` like PHP's + // `switch` default. + ask_and_hide_answer_responses: Option>, } impl IOStub { @@ -79,6 +83,29 @@ impl IOStub { self.ask_and_hide_answer = Some(value); self } + pub fn with_ask_and_hide_answer_responses( + mut self, + value: indexmap::IndexMap, + ) -> Self { + self.ask_and_hide_answer_responses = Some(value); + self + } + + // Pre-seeds the in-memory auth store, equivalent to a willReturnCallback that + // reads a captured `$initial_config`. Reads delegate to `BaseIO` as long as the + // `with_has_authentication`/`with_get_authentication` overrides are left unset. + pub fn with_authentication( + mut self, + repository_name: impl Into, + username: impl Into, + password: Option, + ) -> Self { + let mut auth = indexmap::IndexMap::new(); + auth.insert("username".to_string(), Some(username.into())); + auth.insert("password".to_string(), password); + self.authentications.insert(repository_name.into(), auth); + self + } } impl IOInterfaceImmutable for IOStub { @@ -127,7 +154,10 @@ impl IOInterfaceImmutable for IOStub { ) -> anyhow::Result { Ok(default) } - fn ask_and_hide_answer(&self, _question: String) -> Option { + fn ask_and_hide_answer(&self, question: String) -> Option { + if let Some(responses) = &self.ask_and_hide_answer_responses { + return Some(responses.get(&question).cloned().unwrap_or_default()); + } self.ask_and_hide_answer.clone().unwrap_or(None) } fn select( -- cgit v1.3.1