-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmoke-worktree-prune-no-git.php
More file actions
112 lines (92 loc) · 3.35 KB
/
Copy pathsmoke-worktree-prune-no-git.php
File metadata and controls
112 lines (92 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Pure-PHP smoke for worktree prune when the workspace is visible but git is unavailable.
*
* Run: php tests/smoke-worktree-prune-no-git.php
*/
declare( strict_types=1 );
namespace DataMachine\Core\FilesRepository {
class FilesystemHelper
{
public static function get(): ?self
{
return null;
}
}
}
namespace {
$tmp = sys_get_temp_dir() . '/dmc-worktree-prune-no-git-' . getmypid();
if (! defined('ABSPATH') ) {
define('ABSPATH', $tmp . '/wp/');
}
if (! defined('DATAMACHINE_WORKSPACE_PATH') ) {
define('DATAMACHINE_WORKSPACE_PATH', $tmp . '/workspace');
}
if (! class_exists('WP_Error') ) {
class WP_Error
{
public function __construct( private string $code, private string $message, private array $data = array() )
{
}
public function get_error_code(): string
{
return $this->code;
}
public function get_error_message(): string
{
return $this->message;
}
public function get_error_data(): array
{
return $this->data;
}
}
}
if (! function_exists('is_wp_error') ) {
function is_wp_error( $value ): bool
{
return $value instanceof WP_Error;
}
}
$failures = array();
$total = 0;
$assert = function ( string $label, bool $condition ) use ( &$failures, &$total ): void {
++$total;
if ($condition ) {
echo " ok {$label}\n";
return;
}
$failures[] = $label;
echo " fail {$label}\n";
};
$old_path = getenv('PATH');
putenv('PATH=/nonexistent-dmc-no-git');
mkdir(DATAMACHINE_WORKSPACE_PATH . '/demo/.git', 0777, true);
require __DIR__ . '/../inc/Support/RuntimeCapabilities.php';
require __DIR__ . '/../inc/Support/ProcessRunner.php';
require __DIR__ . '/../inc/Support/GitRunner.php';
require __DIR__ . '/../inc/Support/PathSecurity.php';
require __DIR__ . '/../inc/Workspace/WorktreeContextInjector.php';
require __DIR__ . '/../inc/Workspace/WorkspaceMutationLock.php';
require __DIR__ . '/../inc/Workspace/Workspace.php';
echo "Worktree prune without git - smoke\n";
$workspace = new DataMachineCode\Workspace\Workspace();
$result = $workspace->worktree_prune();
$assert('prune returns success instead of git-unavailable error', ! is_wp_error($result) && true === ( $result['success'] ?? false ));
$assert('prune records skipped primary', ! is_wp_error($result) && 'demo' === ( $result['skipped'][0]['repo'] ?? '' ));
$assert('prune returns host git command', ! is_wp_error($result) && str_contains((string) ( $result['next_commands'][0] ?? '' ), 'git -C'));
$assert('inventory refresh still runs', ! is_wp_error($result) && isset($result['inventory']['summary']));
putenv(false === $old_path ? 'PATH' : 'PATH=' . $old_path);
if (is_dir($tmp) ) {
exec('rm -rf ' . escapeshellarg($tmp));
}
if (! empty($failures) ) {
echo "\nFAIL: " . count($failures) . " assertion(s) failed out of {$total}\n";
foreach ( $failures as $failure ) {
echo " - {$failure}\n";
}
exit(1);
}
echo "\nOK ({$total} assertions)\n";
exit(0);
}