make(Kernel::class)->bootstrap(); try { $db = DB::connection(); if (! preg_match('/^sgf_sourcing_test_[a-f0-9]{12}$/D', $db->getDatabaseName())) { throw new RuntimeException('Copy only'); } $fixture = json_decode(file_get_contents($work.'/fixture.json'), true); $command = $argv[1]; if (in_array($command, ['revoke-evaluate', 'restore-evaluate', 'revoke-propose', 'restore-propose', 'revoke-view', 'restore-view'])) { $right = str_contains($command, 'evaluate') ? 'purchasing_sourcing.evaluate' : (str_contains($command, 'propose') ? 'purchasing_sourcing.propose' : 'purchasing_requisitions.view'); $id = str_contains($command, 'evaluate') ? $fixture['user_id'] : (str_contains($command, 'propose') ? 2 : 3); $scope = ['user_id' => $id, 'tenant_id' => 1, 'company_id' => 1, 'unit_id' => 1, 'permission' => $right]; if (str_starts_with($command, 'revoke')) { $db->table('permission_grants')->where($scope)->delete(); } else { $db->table('permission_grants')->insertOrIgnore($scope + ['created_at' => now(), 'updated_at' => now()]); } } elseif ($command === 'fail-on') { file_put_contents($host.'/storage/framework/sourcing-failure.fixture', 'isolated failure injection'); } elseif ($command === 'fail-off') { unlink($host.'/storage/framework/sourcing-failure.fixture'); } else { throw new RuntimeException('Unsupported fixture control'); } echo json_encode(['ok' => true]); } catch (Throwable $e) { fwrite(STDERR, $e->getMessage()); exit(1); }