Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/vcs/src/VCS/Adapter/Git/Bitbucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,8 @@ public function getRepositoryPresignedUrl(string $owner, string $repositoryName,

public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
{
if (\in_array($rootDirectory, ['', '0', '/'], true)) {
$rootDirectory = $this->normalizeRepositoryPath($rootDirectory);
if ($rootDirectory === '') {
$rootDirectory = '*';
}

Expand Down
3 changes: 2 additions & 1 deletion packages/vcs/src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ public function updateCheckRun(
*/
public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
{
if ($rootDirectory === '' || $rootDirectory === '0') {
$rootDirectory = $this->normalizeRepositoryPath($rootDirectory);
if ($rootDirectory === '') {
$rootDirectory = '*';
}

Expand Down
3 changes: 2 additions & 1 deletion packages/vcs/src/VCS/Adapter/Git/GitLab.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,8 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s

public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
{
if (\in_array($rootDirectory, ['', '0', '/'], true)) {
$rootDirectory = $this->normalizeRepositoryPath($rootDirectory);
if ($rootDirectory === '') {
$rootDirectory = '*';
}

Expand Down
3 changes: 2 additions & 1 deletion packages/vcs/src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,8 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
*/
public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
{
if ($rootDirectory === '' || $rootDirectory === '0') {
$rootDirectory = $this->normalizeRepositoryPath($rootDirectory);
if ($rootDirectory === '') {
$rootDirectory = '*';
}
$cloneUrl = "{$this->giteaUrl}/{$owner}/{$repositoryName}";
Expand Down
3 changes: 2 additions & 1 deletion packages/vcs/src/VCS/Adapter/Git/Origin.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ public function updateComment(string $owner, string $repositoryName, string $com
*/
public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
{
if ($rootDirectory === '' || $rootDirectory === '0') {
$rootDirectory = $this->normalizeRepositoryPath($rootDirectory);
if ($rootDirectory === '') {
$rootDirectory = '*';
}

Expand Down
33 changes: 31 additions & 2 deletions packages/vcs/tests/Unit/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace Utopia\Tests\Unit;

use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Utopia\VCS\Adapter\Git;

/**
* The half of the adapter contract that needs no provider: reading a webhook
* delivery and verifying its signature. Every provider answers it from a
* payload the subclass builds, so the suite runs on a bare host.
* delivery and verifying its signature, and building a clone command. Every
* provider answers it from a payload the subclass builds, so the suite runs on
* a bare host.
*/
abstract class Base extends TestCase
{
Expand Down Expand Up @@ -221,4 +223,31 @@ public function testGetEventUnsupportedEvent(): void

$this->assertEmpty($result);
}

#[DataProvider('rootDirectories')]
public function testGenerateCloneCommandSelectsTheRootDirectory(string $rootDirectory, string $pattern): void
{
$command = $this->vcsAdapter->generateCloneCommand('owner', 'repo', 'main', Git::CLONE_TYPE_BRANCH, '/tmp/clone', $rootDirectory);

$this->assertStringContainsString(escapeshellarg($pattern), $command);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test Mirrors Command Text

This test checks only that the shell-escaped pattern occurs somewhere in the generated command. It can therefore pass if the pattern is written to the wrong file, duplicated, or later overridden, and it never verifies the checkout tree that this regression actually broke. This violates the repository directive to test observable behavior instead of mirroring source or configuration. The requirement must be satisfied before merging by exercising the command against a local Git fixture and asserting the resulting files.

Context Used: Call out and harshly judge implementation-coupled ... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/vcs/tests/Unit/Base.php
Line: 232

Comment:
**Test Mirrors Command Text**

This test checks only that the shell-escaped pattern occurs somewhere in the generated command. It can therefore pass if the pattern is written to the wrong file, duplicated, or later overridden, and it never verifies the checkout tree that this regression actually broke. This violates the repository directive to test observable behavior instead of mirroring source or configuration. The requirement must be satisfied before merging by exercising the command against a local Git fixture and asserting the resulting files.

**Context Used:** Call out and harshly judge implementation-coupled ... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

}

/**
* Git matches a sparse-checkout pattern gitignore-style, so a './' prefix
* looks for a directory literally named '.' and checks out nothing.
*/
public static function rootDirectories(): \Iterator
{
yield 'repository root' => ['', '*'];
yield 'dot' => ['.', '*'];
yield 'dot slash' => ['./', '*'];
yield 'slash' => ['/', '*'];
yield 'bare' => ['docs', 'docs'];
yield 'trailing slash' => ['docs/', 'docs'];
yield 'dot slash prefix' => ['./docs', 'docs'];
yield 'dot slash prefix and trailing slash' => ['./docs/', 'docs'];
yield 'nested' => ['./astro/starter', 'astro/starter'];
// A directory named '0' is a real path, not a root sentinel.
yield 'zero' => ['0', '0'];
}
}
5 changes: 4 additions & 1 deletion packages/vcs/tests/Unit/ForgejoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class ForgejoTest extends GiteaBase

protected function createAdapter(): Forgejo
{
return new Forgejo(new Cache(new None()));
$adapter = new Forgejo(new Cache(new None()));
$adapter->setEndpoint('http://gitea:3000');

return $adapter;
}
}
5 changes: 4 additions & 1 deletion packages/vcs/tests/Unit/GiteaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class GiteaTest extends GiteaBase

protected function createAdapter(): Gitea
{
return new Gitea(new Cache(new None()));
$adapter = new Gitea(new Cache(new None()));
$adapter->setEndpoint('http://gitea:3000');

return $adapter;
}
}
5 changes: 4 additions & 1 deletion packages/vcs/tests/Unit/GogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ final class GogsTest extends GiteaBase

protected function createAdapter(): Gogs
{
return new Gogs(new Cache(new None()));
$adapter = new Gogs(new Cache(new None()));
$adapter->setEndpoint('http://gitea:3000');

return $adapter;
}
}
Loading