From c82e095b75859be5be66073d44004702748dd3b0 Mon Sep 17 00:00:00 2001 From: kj Date: Thu, 8 Oct 2026 08:34:54 -0300 Subject: [PATCH] fix(cli): honor --dry-run when updating and removing core files --- packages/commands/src/Toolbox/Installer.php | 11 ++++++ tests/group7_commands_test.php | 42 +++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/packages/commands/src/Toolbox/Installer.php b/packages/commands/src/Toolbox/Installer.php index ad62895..e7a6fbe 100644 --- a/packages/commands/src/Toolbox/Installer.php +++ b/packages/commands/src/Toolbox/Installer.php @@ -284,6 +284,13 @@ final class Installer } $absolute = $this->root . '/' . $relative; + + if ($options['dryRun'] ?? false) { + $actions[$relative] = 'planned'; + $installed[$relative] = 'sha256:' . hash('sha256', $provider->read($relative)); + continue; + } + $action = $this->sync->write($absolute, $provider->read($relative), $expected[$relative] ?? null, $options); $actions[$relative] = $action; @@ -300,6 +307,10 @@ final class Installer if (isset($installed[$relative]) || isset($protected[$relative]) || in_array($relative, $files, true)) { continue; } + if ($options['dryRun'] ?? false) { + $actions[$relative] = 'remove-planned'; + continue; + } $action = $this->sync->remove($this->root . '/' . $relative, $hash, $options); if ($action === FileSync::ABORTED) { $aborted[] = $relative; diff --git a/tests/group7_commands_test.php b/tests/group7_commands_test.php index 4d496d8..976de01 100644 --- a/tests/group7_commands_test.php +++ b/tests/group7_commands_test.php @@ -194,6 +194,48 @@ Harness::it('--dry-run no escribe archivos ni lock', function () { rrmdir($tool); }); +Harness::it('update core --dry-run no escribe archivos', function () { + $proj = tmpdir('proj'); + $tool = g7_toolbox(); + $core = g7_core('1.0.0', 'router-v1'); + $core2 = g7_core('2.0.0', 'router-v2'); + + (new InstallCommand(new Console()))->run([$proj, '--toolbox=' . $tool, '--core-dir=' . $core, '--yes']); + + $routerBefore = (string) file_get_contents($proj . '/src/Libs/Router.php'); + (new UpdateCommand(new Console()))->run(['core', '--root=' . $proj, '--toolbox=' . $tool, '--core-dir=' . $core2, '--yes', '--dry-run']); + + ok(str_contains($routerBefore, 'router-v1'), 'estado inicial correcto'); + ok(str_contains((string) file_get_contents($proj . '/src/Libs/Router.php'), 'router-v1'), 'dry-run no escribe el fichero'); + eq('1.0.0', Lock::load($proj)->core()['version'], 'dry-run no actualiza la version en el lock'); + + rrmdir($proj); + rrmdir($tool); + rrmdir($core); + rrmdir($core2); +}); + +Harness::it('update core --dry-run aborta por drift sin escribir', function () { + $proj = tmpdir('proj'); + $tool = g7_toolbox(); + $core = g7_core('1.0.0', 'router-v1'); + $core2 = g7_core('2.0.0', 'router-v2'); + + (new InstallCommand(new Console()))->run([$proj, '--toolbox=' . $tool, '--core-dir=' . $core, '--yes']); + write_file($proj . '/config.php', "run(['core', '--root=' . $proj, '--toolbox=' . $tool, '--core-dir=' . $core2, '--yes', '--dry-run']); + + ok(!is_file($proj . '/config.php.bak'), 'dry-run no crea backups'); + ok(str_contains((string) file_get_contents($proj . '/config.php'), 'customizado'), 'dry-run conserva la edicion local'); + ok(str_contains((string) file_get_contents($proj . '/src/Libs/Router.php'), 'router-v1'), 'dry-run no toca ficheros sin drift'); + + rrmdir($proj); + rrmdir($tool); + rrmdir($core); + rrmdir($core2); +}); + Harness::it('core sin tags: versión desconocida y commit pineado', function () { $proj = tmpdir('proj'); $tool = g7_toolbox();