fix(cli): adopt core records canonical hashes and flags local edits

This commit is contained in:
kj
2026-10-08 08:34:54 -03:00
parent c82e095b75
commit a37d4f89de
2 changed files with 50 additions and 11 deletions
+28
View File
@@ -121,3 +121,31 @@ Harness::it('adopt registra el core existente con sus hashes', function () {
rrmdir($proj);
rrmdir($core);
});
Harness::it('adopt del core registra hash canónico y marca ediciones locales', function () {
$repo = $GLOBALS['g9_repo'];
$core = g7_core('0.1.0');
$proj = tmpdir('proj');
// Copia idéntica de Router.php + config.php customizado (proyecto heredado).
write_file($proj . '/src/Libs/Router.php', (string) file_get_contents($core . '/src/Libs/Router.php'));
write_file($proj . '/config.php', "<?php\n// credenciales del proyecto\n");
(new AdoptCommand(new Console()))->run(['--root=' . $proj, '--toolbox=' . $repo, '--core-dir=' . $core]);
$lock = Lock::load($proj);
$coreHashRouter = $lock->core()['files']['src/Libs/Router.php'];
$coreHashConfig = $lock->core()['files']['config.php'];
$canonicalRouter = (string) file_get_contents($core . '/src/Libs/Router.php');
$canonicalConfig = (string) file_get_contents($core . '/config.php');
eq('sha256:' . hash('sha256', $canonicalRouter), $coreHashRouter, 'hash de Router.php = canónico');
eq('sha256:' . hash('sha256', $canonicalConfig), $coreHashConfig, 'hash de config.php = canónico (aunque el local difiera)');
eq('local', $lock->core()['origin'] ?? null, 'origin = local porque hay ediciones locales');
ok(file_get_contents($proj . '/config.php') !== $canonicalConfig, 'la copia local customizada no se tocó');
rrmdir($proj);
rrmdir($core);
});