|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Worktree admission must not block on a workspace-wide allocation walk. |
| 4 | + */ |
| 5 | + |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace DataMachineCode\Workspace { |
| 9 | + final class WorktreeContextInjector { |
| 10 | + public static function bootstrap_capacity_reservations(): array { |
| 11 | + return array( 'bytes' => 0, 'inodes' => 0 ); |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + final class WorktreeDiskBudget { |
| 16 | + public static array $options = array(); |
| 17 | + |
| 18 | + public static function thresholds( string $repo, string $branch ): array { |
| 19 | + return array(); |
| 20 | + } |
| 21 | + |
| 22 | + public static function inspect( string $workspace, array $thresholds, bool $force, array $options, array $demand ): array { |
| 23 | + self::$options = $options; |
| 24 | + return array( 'status' => 'ok', 'creation_allowed' => true ); |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +namespace { |
| 30 | + if ( ! defined('ABSPATH') ) { |
| 31 | + define('ABSPATH', __DIR__ . '/fixtures/'); |
| 32 | + } |
| 33 | + |
| 34 | + require_once dirname(__DIR__) . '/inc/Workspace/WorkspaceWorktreeLifecycle.php'; |
| 35 | + |
| 36 | + use DataMachineCode\Workspace\WorkspaceWorktreeLifecycle; |
| 37 | + use DataMachineCode\Workspace\WorktreeDiskBudget; |
| 38 | + |
| 39 | + final class WorktreePlanCapacityHotPathHarness { |
| 40 | + use WorkspaceWorktreeLifecycle { inspect_worktree_capacity as public inspectCapacity; } |
| 41 | + |
| 42 | + private string $workspace_path = '/workspace'; |
| 43 | + } |
| 44 | + |
| 45 | + $result = ( new WorktreePlanCapacityHotPathHarness() )->inspectCapacity( |
| 46 | + 'repo', |
| 47 | + 'branch', |
| 48 | + false, |
| 49 | + array( 'bytes' => 1, 'inodes' => 1 ) |
| 50 | + ); |
| 51 | + |
| 52 | + if ( true !== ( $result['creation_allowed'] ?? false ) ) { |
| 53 | + throw new RuntimeException('Capacity admission result was not preserved.'); |
| 54 | + } |
| 55 | + if ( false !== ( WorktreeDiskBudget::$options['include_workspace_usage'] ?? null ) ) { |
| 56 | + throw new RuntimeException('Worktree planning enabled the synchronous workspace allocation walk.'); |
| 57 | + } |
| 58 | + |
| 59 | + echo "worktree-plan-capacity-hot-path: ok\n"; |
| 60 | +} |
0 commit comments