Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
protected function resolveToolSelection(array $detectionMap, string $toolRequiringConfirmation): ?string
{
$detected = $this->getFactory()->createAiToolDetector()->detect($detectionMap);
$tools = array_values($detectionMap);
$tools = $this->getSelectableTools($detectionMap);

if ($detected === null || !$this->isDetectedToolAccepted($detected, $toolRequiringConfirmation)) {
return $this->select('Select your AI tool:', $tools, $tools[0]);
Expand All @@ -84,6 +84,18 @@ protected function resolveToolSelection(array $detectionMap, string $toolRequiri
return $detected;
}

/**
* Several indicator paths can detect the same tool, so each tool is offered once.
*
* @param array<string, string> $detectionMap
*
* @return list<string>
*/
protected function getSelectableTools(array $detectionMap): array
{
return array_values(array_unique($detectionMap));
}

protected function isDetectedToolAccepted(string $detected, string $toolRequiringConfirmation): bool
{
if ($detected === $toolRequiringConfirmation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdkTest\Zed\AiDev\Communication\Console;

use Codeception\Test\Unit;
use ReflectionClass;
use SprykerSdk\Zed\AiDev\AiDevConfig;
use SprykerSdk\Zed\AiDev\Communication\Console\AiToolSetupConsole;

/**
* @group AiDev
* @group Communication
* @group Console
* @group AiToolSetupConsole
*/
class AiToolSetupConsoleTest extends Unit
{
public function testGetSelectableToolsOffersEachToolOnce(): void
{
// Arrange
$reflection = new ReflectionClass(AiToolSetupConsole::class);
$console = $reflection->newInstanceWithoutConstructor();
$method = $reflection->getMethod('getSelectableTools');
$method->setAccessible(true);
$detectionMap = (new AiDevConfig())->getToolDetectionMap();

// Act
$tools = $method->invoke($console, $detectionMap);

// Assert
$this->assertSame(
['Claude Code', 'Windsurf', 'GitHub Copilot', 'Cursor', 'OpenCode', 'Codex CLI'],
$tools,
);
}
}
Loading