test: a VCS registry entry owns an OAuth2 builder only when it has a flow

The registry test required a callable builder on every provider, an
invariant Origin deliberately broke: it has no OAuth2 user flow, so it
registers none. The loop now checks the builder only where one exists,
and a dedicated test pins Origin's absence - oauth2FromProvider('origin')
must fail loudly rather than hand out a half-configured client.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Matej BačoandClaude Fable 5 committed 2026-08-19 16:21:21 +02:00
1 parent 27d92edd34
commit a746d26d41
1 file changed
+20 -1
+20 -1
View File
@@ -31,7 +31,11 @@ final class FactoryTest extends TestCase
foreach ($registry as $key => $entry) {
$this->assertTrue(\is_subclass_of($entry['adapter'], Git::class), "Adapter for '{$key}' must extend Git");
$this->assertIsCallable($entry['oauth2'], "OAuth2 builder for '{$key}' must be callable");
// A provider with an OAuth2 user flow registers a builder; an
// app-only provider (Origin) deliberately registers none.
if (isset($entry['oauth2'])) {
$this->assertIsCallable($entry['oauth2'], "OAuth2 builder for '{$key}' must be callable");
}
$this->assertNotEmpty($entry['variables'], "Variables missing for '{$key}'");
foreach ($entry['variables'] as $name => $variable) {
$this->assertStringStartsWith('_APP_VCS_', $variable['envVariable'] ?? '', "Env variable for '{$name}' missing or invalid for '{$key}'");
@@ -39,6 +43,21 @@ final class FactoryTest extends TestCase
}
}
public function testOriginRegistersNoOAuth2(): void
{
// Origin has no OAuth2 user flow: installs are approved on Cursor and
// confirmed by a signed receipt the adapter verifies itself, so the
// registry deliberately carries no builder and oauth2FromProvider()
// fails loudly instead of handing out a half-configured client.
$registry = Config::getParam('vcs', []);
$this->assertArrayHasKey('origin', $registry);
$this->assertArrayNotHasKey('oauth2', $registry['origin']);
$factory = new Factory($this->cache(), $registry);
$this->expectException(Exception::class);
$factory->oauth2FromProvider('origin');
}
public function testOauth2FromProviderUnknownThrows(): void
{
$factory = new Factory($this->cache(), ['github' => $this->githubEntry()]);