Skip to content
Closed
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
49 changes: 48 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,22 @@
✓ addOutput → it uses singular form for single test file
✓ addOutput → it returns original exit code when shard is not set

PASS Tests\Unit\Plugins\Tia\ChangedFiles
✓ it resolves the project prefix inside the repository
✓ it reports working tree changes relative to the project, dropping siblings
✓ it reports committed changes relative to the project, dropping siblings
✓ it drops a file whose content came back to its baseline across the prefix boundary
✓ it honours a gitignore inside the project
✓ it leaves a project at the repository root untouched
✓ it reports the changes it left outside the project
✓ it reports nothing outside the project for a project at the repository root
✓ it ties a fingerprint to the project location inside the repository
✓ it sees a committed non-ascii path that git would otherwise quote
✓ it sees a committed non-ascii path at the repository root too
✓ it keeps a tracked outside change and drops an untracked ignored one
✓ it keeps a tracked project change that the ignore rules match
✓ it reads committed paths from the repository root even when git is told to be relative

PASS Tests\Unit\Plugins\Tia\ContentHash
✓ of() → it returns false when file does not exist
✓ of() → it hashes an existing file
Expand Down Expand Up @@ -1949,6 +1965,36 @@
✓ it detects an added or removed non-platform dependency
✓ it is independent of package ordering

PASS Tests\Unit\Plugins\Tia\MonorepoBaselines
✓ it detects the baseline repository from a project subdirectory with ('github.com')
✓ it detects the baseline repository from a project subdirectory with ('gitlab.com')
✓ it uses the nearest repository for baseline detection with ('github.com')
✓ it uses the nearest repository for baseline detection with ('gitlab.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "relative gitdir and commondir" / ('github.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "relative gitdir and commondir" / ('gitlab.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "relative gitdir and absolute commondir" / ('github.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "relative gitdir and absolute commondir" / ('gitlab.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "absolute gitdir and relative commondir" / ('github.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "absolute gitdir and relative commondir" / ('gitlab.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "absolute gitdir and commondir" / ('github.com')
✓ it detects worktree baselines through relative and absolute git pointers with dataset "absolute gitdir and commondir" / ('gitlab.com')
✓ it uses the submodule baseline repository instead of its parent remote with dataset "relative gitdir" / ('github.com')
✓ it uses the submodule baseline repository instead of its parent remote with dataset "relative gitdir" / ('gitlab.com')
✓ it uses the submodule baseline repository instead of its parent remote with dataset "absolute gitdir" / ('github.com')
✓ it uses the submodule baseline repository instead of its parent remote with dataset "absolute gitdir" / ('gitlab.com')
✓ it does not use the parent baseline remote when a nested git file is malformed with ('github.com')
✓ it does not use the parent baseline remote when a nested git file is malformed with ('gitlab.com')
✓ it keeps caches separate for sibling projects with the same name
✓ it shares a nested project cache and fingerprint across worktrees

PASS Tests\Unit\Plugins\Tia\MonorepoChangedFiles
✓ it detects committed Unicode filenames with git path quoting enabled with dataset "repository root"
✓ it detects committed Unicode filenames with git path quoting enabled with dataset "nested project"
✓ it reports the old path when a file moves outside the project with dataset "staged move"
✓ it reports the old path when a file moves outside the project with dataset "committed move"
✓ it ignores cosmetic changes when reading a nested project baseline
✓ it includes untracked files inside the project

PASS Tests\Unit\Plugins\Tia\Recorder
✓ activateLinkTracking() → it tracks tables without a coverage driver
✓ activateLinkTracking() → it tracks inertia components without a coverage driver
Expand All @@ -1963,6 +2009,7 @@
PASS Tests\Unit\Plugins\Tia\Storage
✓ it uses a project-relative configured directory
✓ it uses an absolute configured directory
✓ it keeps the state directory of a project at the repository root

PASS Tests\Unit\Plugins\Tia\TableExtractor
✓ fromSql() → it extracts tables from plain DML
Expand Down Expand Up @@ -2259,4 +2306,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1600 passed (3489 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1641 passed (3541 assertions)
121 changes: 121 additions & 0 deletions tests/Unit/Plugins/Tia/MonorepoBaselines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

use Pest\Plugins\Tia\Baselines\GitHubRemote;
use Pest\Plugins\Tia\Baselines\GitLabRemote;
use Pest\Plugins\Tia\Fingerprint;
use Pest\Plugins\Tia\Storage;
use Pest\Plugins\Tia\WatchPatterns;
use Symfony\Component\Process\Process;
use Tests\Fixtures\Tia\GitRepo;

beforeEach(function (): void {
$this->root = sys_get_temp_dir().'/pest-tia-monorepo-baselines-'.bin2hex(random_bytes(8));
mkdir($this->root.'/apps/api', 0755, true);
file_put_contents($this->root.'/apps/api/composer.json', '{}');

$this->repo = new GitRepo($this->root);
$this->repo->init();
$this->repo->addOrigin('git@github.com:acme/mono.git');
});

afterEach(function (): void {
Storage::useDirectory(null);
new Process(['rm', '-rf', $this->root])->mustRun();
});

it('detects the baseline repository from a project subdirectory', function (string $host): void {
$this->repo->setOriginUrl('git@'.$host.':acme/mono.git');

$remote = $host === 'github.com'
? new GitHubRemote(new WatchPatterns)
: new GitLabRemote(new WatchPatterns);

expect($remote->detect($this->root.'/apps/api'))->toBe('acme/mono');
})->with(['github.com', 'gitlab.com'])->skipOnWindows();

it('uses the nearest repository for baseline detection', function (string $host): void {
$this->repo->setOriginUrl('git@'.$host.':acme/mono.git');
$nested = new GitRepo($this->root.'/apps/api');
$nested->init();
$nested->addOrigin('git@'.$host.':acme/nested.git');

$remote = $host === 'github.com'
? new GitHubRemote(new WatchPatterns)
: new GitLabRemote(new WatchPatterns);

expect($remote->detect($nested->path))->toBe('acme/nested');
})->with(['github.com', 'gitlab.com'])->skipOnWindows();

it('detects worktree baselines through relative and absolute git pointers', function (bool $absoluteGitDir, bool $absoluteCommonDir, string $host): void {
$this->repo->setOriginUrl('git@'.$host.':acme/mono.git');
$worktree = $this->repo->worktree($this->root.'/worktree', 'feature');
$gitDir = $this->root.'/.git/worktrees/worktree';

file_put_contents($worktree.'/.git', 'gitdir: '.($absoluteGitDir ? $gitDir : '../.git/worktrees/worktree')."\n");
file_put_contents($gitDir.'/commondir', ($absoluteCommonDir ? $this->root.'/.git' : '../..')."\n");
file_put_contents($gitDir.'/config', "[remote \"origin\"]\n\turl = git@".$host.":acme/wrong.git\n");

$remote = $host === 'github.com'
? new GitHubRemote(new WatchPatterns)
: new GitLabRemote(new WatchPatterns);

expect($remote->detect($worktree.'/apps/api'))->toBe('acme/mono');
})->with([
'relative gitdir and commondir' => [false, false],
'relative gitdir and absolute commondir' => [false, true],
'absolute gitdir and relative commondir' => [true, false],
'absolute gitdir and commondir' => [true, true],
])->with(['github.com', 'gitlab.com'])->skipOnWindows();

it('uses the submodule baseline repository instead of its parent remote', function (bool $absoluteGitDir, string $host): void {
$this->repo->setOriginUrl('git@'.$host.':acme/mono.git');
mkdir($this->root.'/source/apps/api', 0755, true);
file_put_contents($this->root.'/source/apps/api/composer.json', '{}');
$source = new GitRepo($this->root.'/source');
$source->init();

$this->repo->run(['-c', 'protocol.file.allow=always', 'submodule', 'add', $source->path, 'packages/module']);
$submodule = new GitRepo($this->root.'/packages/module');
$submodule->setOriginUrl('git@'.$host.':acme/module.git');
$gitDir = $submodule->output(['rev-parse', '--absolute-git-dir']);

file_put_contents($submodule->path.'/.git', 'gitdir: '.($absoluteGitDir ? $gitDir : '../../.git/modules/packages/module')."\n");

$remote = $host === 'github.com'
? new GitHubRemote(new WatchPatterns)
: new GitLabRemote(new WatchPatterns);

expect($remote->detect($submodule->path.'/apps/api'))->toBe('acme/module');
})->with([
'relative gitdir' => false,
'absolute gitdir' => true,
])->with(['github.com', 'gitlab.com'])->skipOnWindows();

it('does not use the parent baseline remote when a nested git file is malformed', function (string $host): void {
$this->repo->setOriginUrl('git@'.$host.':acme/mono.git');
file_put_contents($this->root.'/apps/api/.git', "not a gitdir\n");

$remote = $host === 'github.com'
? new GitHubRemote(new WatchPatterns)
: new GitLabRemote(new WatchPatterns);

expect($remote->detect($this->root.'/apps/api'))->toBeNull();
})->with(['github.com', 'gitlab.com'])->skipOnWindows();

it('keeps caches separate for sibling projects with the same name', function (): void {
mkdir($this->root.'/services/api', 0755, true);

expect(Storage::tempDir($this->root.'/apps/api'))
->not->toBe(Storage::tempDir($this->root.'/services/api'));
})->skipOnWindows();

it('shares a nested project cache and fingerprint across worktrees', function (): void {
$worktree = $this->repo->worktree($this->root.'/worktree', 'feature');

expect(Storage::tempDir($this->root.'/apps/api'))
->toBe(Storage::tempDir($worktree.'/apps/api'))
->and(Fingerprint::compute($this->root.'/apps/api'))
->toBe(Fingerprint::compute($worktree.'/apps/api'));
})->skipOnWindows();
65 changes: 65 additions & 0 deletions tests/Unit/Plugins/Tia/MonorepoChangedFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

use Pest\Plugins\Tia\ChangedFiles;
use Symfony\Component\Process\Process;
use Tests\Fixtures\Tia\GitRepo;

beforeEach(function (): void {
$this->root = sys_get_temp_dir().'/pest-tia-monorepo-changes-'.bin2hex(random_bytes(8));
mkdir($this->root.'/apps/api/app', 0755, true);
mkdir($this->root.'/apps/web', 0755, true);
file_put_contents($this->root.'/apps/api/app/Service.php', "<?php\n\$service = 1;\n");

$this->repo = new GitRepo($this->root);
$this->repo->init();
$this->sha = $this->repo->sha();
});

afterEach(function (): void {
new Process(['rm', '-rf', $this->root])->mustRun();
});

it('detects committed Unicode filenames with git path quoting enabled', function (string $directory): void {
$this->repo->config('core.quotePath', 'true');
$project = $this->root.$directory;
file_put_contents($project.'/Ærlig.php', "<?php\n\$value = 1;\n");
$this->repo->commit('Add a Unicode filename');
$sha = $this->repo->sha();

file_put_contents($project.'/Ærlig.php', "<?php\n\$value = 2;\n");
$this->repo->commit('Change the Unicode file');

expect(new ChangedFiles($project)->since($sha))->toBe(['Ærlig.php']);
})->with([
'repository root' => '',
'nested project' => '/apps/api',
])->skipOnWindows();

it('reports the old path when a file moves outside the project', function (bool $committed): void {
$this->repo->run(['mv', 'apps/api/app/Service.php', 'apps/web/Service.php']);

if ($committed) {
$this->repo->commit('Move the service into a sibling project');
}

expect(new ChangedFiles($this->root.'/apps/api')->since($this->sha))->toBe(['app/Service.php']);
})->with([
'staged move' => false,
'committed move' => true,
])->skipOnWindows();

it('ignores cosmetic changes when reading a nested project baseline', function (): void {
file_put_contents($this->root.'/apps/api/app/Service.php', "<?php\n\$service = 1;\n");
$this->repo->commit('Change whitespace');

expect(new ChangedFiles($this->root.'/apps/api')->since($this->sha))->toBe([]);
})->skipOnWindows();

it('includes untracked files inside the project', function (): void {
file_put_contents($this->root.'/apps/api/app/Fresh.php', "<?php\n");
file_put_contents($this->root.'/apps/web/Other.php', "<?php\n");

expect(new ChangedFiles($this->root.'/apps/api')->since($this->sha))->toBe(['app/Fresh.php']);
})->skipOnWindows();
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$output = $run('--exclude-group=integration');
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));

$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1581 passed (3431 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1622 passed (3483 assertions)';

expect($output)
->toContain("Tests: {$expected}")
Expand Down