fix(cli): honor --dry-run when updating and removing core files

This commit is contained in:
kj
2026-10-08 08:34:54 -03:00
parent 8168865f3a
commit c82e095b75
2 changed files with 53 additions and 0 deletions
@@ -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;
+42
View File
@@ -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', "<?php\n// customizado\n");
(new UpdateCommand(new Console()))->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();