feat(cli): lock captures effective description; list shows it; new commands surface view with origin and collision reporting
This commit is contained in:
@@ -130,3 +130,80 @@ Harness::it('bin nuevo sin el motor: los aliases del motor son comando desconoci
|
||||
rrmdir($proj);
|
||||
rrmdir($core);
|
||||
});
|
||||
|
||||
Harness::it('list muestra la descripción del lock por componente, con — si falta', function () {
|
||||
$root = tmpdir('proj');
|
||||
$tool = tmpdir('tool');
|
||||
write_file($tool . '/packages/mix/duckbrain.json', json_encode([
|
||||
'name' => 'mix',
|
||||
'version' => '1.0.0',
|
||||
'description' => 'Descripción del paquete',
|
||||
'components' => [
|
||||
'own' => ['files' => ['src/Libs/Own.php'], 'description' => 'Descripción propia'],
|
||||
'inh' => ['files' => ['src/Libs/Inh.php']],
|
||||
'old' => ['files' => ['src/Libs/Old.php']],
|
||||
],
|
||||
'default' => ['own', 'inh', 'old'],
|
||||
]));
|
||||
foreach (['Own', 'Inh', 'Old'] as $c) {
|
||||
write_file($tool . "/packages/mix/src/Libs/{$c}.php", "<?php\n");
|
||||
}
|
||||
|
||||
(new Toolbox\Installer($root, $tool, new Console()))->add(['mix'], ['yes' => true]);
|
||||
|
||||
// simular lock viejo: quitar la descripción de `old`
|
||||
$raw = json_decode((string) file_get_contents($root . '/.duckbrain/lock.json'), true);
|
||||
unset($raw['components']['mix:old']['description']);
|
||||
file_put_contents($root . '/.duckbrain/lock.json', json_encode($raw));
|
||||
|
||||
$out = fopen('php://memory', 'rw');
|
||||
$code = (new Toolbox\Commands\ListCommand(new Console($out)))->run(['--root=' . $root, '--toolbox=' . $tool]);
|
||||
rewind($out);
|
||||
$text = (string) stream_get_contents($out);
|
||||
|
||||
eq(0, $code);
|
||||
ok((bool) preg_match('/mix:own.*Descripción propia/', $text), 'fila propia con su descripción');
|
||||
ok((bool) preg_match('/mix:inh.*Descripción del paquete/', $text), 'fila heredada con la del paquete');
|
||||
ok((bool) preg_match('/mix:old.*—/', $text), 'lock viejo sin campo muestra —');
|
||||
|
||||
rrmdir($root);
|
||||
rrmdir($tool);
|
||||
});
|
||||
|
||||
Harness::it('commands lista la superficie con origen y reporta colisiones', function () {
|
||||
$repo = $GLOBALS['g8_repo'];
|
||||
$core = g7_core('0.1.0');
|
||||
$proj = tmpdir('proj');
|
||||
|
||||
(new InstallCommand(new Console()))->run([$proj, '--toolbox=' . $repo, '--core-dir=' . $core, '--yes']);
|
||||
(new AddCommand(new Console()))->run(['commands', 'commands:toolbox', '--root=' . $proj, '--toolbox=' . $repo, '--yes']);
|
||||
|
||||
$eco = "<?php\n\nnamespace Commands;\n\nclass Eco implements \\Interfaces\\CommandInterface\n{\n public static function describe(): string { return 'eco local'; }\n public static function aliases(): array { return ['hola']; }\n public function run(): void {}\n}\n";
|
||||
write_file($proj . '/src/Commands/Eco.php', $eco);
|
||||
|
||||
// sin colisión: funciona desde el bin del proyecto
|
||||
$o = []; exec('cd ' . escapeshellarg($proj) . ' && php duckbrain commands 2>&1', $o, $code);
|
||||
eq(0, $code, 'bin del proyecto sirve commands');
|
||||
$text = implode("\n", $o);
|
||||
ok(str_contains($text, 'eco') && str_contains($text, 'hola'), 'comando propio con su alias');
|
||||
ok(str_contains($text, 'proyecto'), 'origen proyecto');
|
||||
ok(str_contains($text, 'commands:migration@'), 'origen componente@versión desde el lock');
|
||||
|
||||
// con colisión (roba el nombre de clase migration): el motor REPORTA, el bin aborta
|
||||
write_file($proj . '/src/Commands/Eco.php', str_replace("['hola']", "['migration']", $eco));
|
||||
|
||||
$out = fopen('php://memory', 'rw');
|
||||
$code = (new Toolbox\Commands\CommandsCommand(new Console($out, $out)))->run(['--root=' . $proj]);
|
||||
rewind($out);
|
||||
$text = (string) stream_get_contents($out);
|
||||
|
||||
eq(0, $code, 'la vista no aborta ante colisiones');
|
||||
ok(str_contains($text, 'migration!'), 'fila marcada con !');
|
||||
ok(str_contains($text, "WARN: alias 'migration'"), 'warn con los dueños');
|
||||
|
||||
$o = []; exec('cd ' . escapeshellarg($proj) . ' && php duckbrain list 2>&1', $o, $c2);
|
||||
eq(1, $c2, 'el despachador sí aborta ante colisión (guard del bin)');
|
||||
|
||||
rrmdir($proj);
|
||||
rrmdir($core);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user