-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworktree-disk-budget.php
More file actions
55 lines (44 loc) · 2.31 KB
/
Copy pathworktree-disk-budget.php
File metadata and controls
55 lines (44 loc) · 2.31 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
<?php
declare(strict_types=1);
if ( ! defined('ABSPATH') ) {
define('ABSPATH', __DIR__ . '/fixtures/');
}
require_once dirname(__DIR__) . '/vendor/autoload.php';
use DataMachineCode\Workspace\WorktreeDiskBudget;
function assert_true( bool $condition, string $message ): void {
if ( ! $condition ) {
throw new RuntimeException($message);
}
}
$gib = 1073741824;
try {
$budget = WorktreeDiskBudget::evaluate(
array(
'workspace_path' => '/tmp/dmc-test-workspace',
'free_bytes' => 2 * $gib,
'total_bytes' => 100 * $gib,
'worktree_count' => 12,
),
array(
'warn_free_bytes' => 20 * $gib,
'refuse_free_bytes' => 10 * $gib,
'warn_free_percent' => 15.0,
'refuse_free_percent' => 10.0,
'warn_worktree_count' => 100,
)
);
assert_true('refused' === $budget['status'], 'low free space should refuse worktree creation');
assert_true(8 * $gib === $budget['cleanup_recommendations'][0]['expected_reclaim_bytes'], 'recommendations should include the bytes needed to clear the effective floor');
assert_true(str_contains(WorktreeDiskBudget::format_summary($budget), '2.0 GiB (2.0%) free'), 'summary should include current free GiB and percent');
$commands = array_column($budget['cleanup_recommendations'], 'command');
assert_true(in_array('studio wp datamachine-code workspace worktree cleanup-artifacts --dry-run --sort=size', $commands, true), 'artifact cleanup preview command is missing');
assert_true(in_array('studio wp datamachine-code workspace worktree bounded-cleanup-eligible-apply --dry-run --limit=25', $commands, true), 'bounded cleanup-eligible dry-run command is missing');
assert_true(in_array('studio wp datamachine-code workspace worktree emergency-cleanup --format=json', $commands, true), 'emergency cleanup report command is missing');
$bounded = $budget['cleanup_recommendations'][1];
assert_true('studio wp datamachine-code workspace worktree bounded-cleanup-eligible-apply --dry-run --limit=25' === $bounded['preview_command'], 'bounded cleanup preview command is missing');
assert_true('studio wp datamachine-code workspace worktree bounded-cleanup-eligible-apply --limit=25' === $bounded['apply_command'], 'bounded cleanup apply command is missing');
fwrite(STDOUT, "worktree-disk-budget ok\n");
} catch (Throwable $e) {
fwrite(STDERR, $e->getMessage() . "\n");
exit(1);
}