feat(compat): declare core independence with core:"none" (INDEPENDENT status, block inheritance, no warning)
This commit is contained in:
@@ -9,9 +9,9 @@ $GLOBALS['g11_repo'] = dirname(__DIR__);
|
||||
/**
|
||||
* Contratos:
|
||||
* - levels.json debe cubrir exactamente los componentes del catalogo.
|
||||
* - si tests/compat/report.json existe, todo 'tested' declarado debe estar
|
||||
* respaldado por un 'ok' del reporte, y los niveles 'none' no deben
|
||||
* declarar tested.
|
||||
* - si tests/compat/report.json existe: todo 'tested' declarado debe estar
|
||||
* respaldado por un 'ok' del reporte, y el nivel 'none' de evidencia debe
|
||||
* coincidir con la declaracion 'core: none' del manifiesto (bidireccional).
|
||||
* Sin reporte (entorno offline sin haber corrido el barrido) solo se exige el
|
||||
* primer contrato.
|
||||
*/
|
||||
@@ -51,19 +51,25 @@ Harness::it('los stamps tested estan respaldados por el reporte del barrido', fu
|
||||
$report = json_decode((string) file_get_contents($reportPath), true);
|
||||
ok(is_array($report) && isset($report['components']), 'report.json valido');
|
||||
|
||||
$levels = json_decode((string) file_get_contents($repo . '/tests/compat/levels.json'), true);
|
||||
$catalog = Catalog::fromRoot($repo);
|
||||
$levels = json_decode((string) file_get_contents($repo . '/tests/compat/levels.json'), true);
|
||||
$catalog = Catalog::fromRoot($repo);
|
||||
|
||||
foreach ($catalog->packages() as $manifest) {
|
||||
foreach (array_keys($manifest->components()) as $component) {
|
||||
$id = $manifest->name . ':' . $component;
|
||||
$level = $levels[$manifest->name][$component] ?? null;
|
||||
$level = is_array($level) ? $level['level'] : $level;
|
||||
$status = $report['components'][$id]['status'] ?? 'missing';
|
||||
$tested = $manifest->testedCore($component);
|
||||
$id = $manifest->name . ':' . $component;
|
||||
$level = $levels[$manifest->name][$component] ?? null;
|
||||
$level = is_array($level) ? $level['level'] : $level;
|
||||
$status = $report['components'][$id]['status'] ?? 'missing';
|
||||
$tested = $manifest->testedCore($component);
|
||||
$independ = $manifest->coreIndependent($component);
|
||||
|
||||
if ($level === 'none') {
|
||||
eq(null, $tested, "$id esta deliberadamente sin datos y no debe declarar tested");
|
||||
ok($independ, "$id esta sin evidencia de barrido y debe declarar core none");
|
||||
}
|
||||
|
||||
if ($independ) {
|
||||
eq('none', $level, "$id se declara independiente y su nivel debe ser none");
|
||||
eq(null, $tested, "$id independiente no puede declarar tested");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,3 +146,36 @@ Harness::it('la descripcion del componente prevalece y hereda del paquete', func
|
||||
'components' => ['c' => ['files' => ['c.php'], 'description' => 7]],
|
||||
]), 'description no-string es inválida');
|
||||
});
|
||||
|
||||
Harness::it('core admite "none" como bloque con herencia completa', function () {
|
||||
$m = Manifest::fromArray([
|
||||
'name' => 'pkg',
|
||||
'version' => '1.0.0',
|
||||
'core' => 'none',
|
||||
'components' => [
|
||||
'a' => ['files' => ['src/A.php']],
|
||||
'b' => ['files' => ['src/B.php'], 'core' => ['requires' => '>=0.2', 'tested' => '0.2']],
|
||||
],
|
||||
]);
|
||||
|
||||
ok($m->coreIndependent('a'), 'a hereda la independencia del paquete');
|
||||
ok(!$m->coreIndependent('b'), 'b sobreescribe el bloque con su rango');
|
||||
eq('>=0.2', $m->coreRequirement('b'));
|
||||
eq('0.2', $m->testedCore('b'));
|
||||
eq(null, $m->coreRequirement('a'), 'independiente no arrastra rangos');
|
||||
|
||||
$m2 = Manifest::fromArray([
|
||||
'name' => 'pkg2',
|
||||
'version' => '1.0.0',
|
||||
'core' => ['requires' => '>=0.1'],
|
||||
'components' => ['c' => ['files' => ['src/C.php'], 'core' => 'none']],
|
||||
]);
|
||||
ok($m2->coreIndependent('c'), 'componente declara none sobre rango de paquete');
|
||||
eq(null, $m2->coreRequirement('c'), 'el rango del paquete no se filtra al bloque declarado none');
|
||||
eq('>=0.1', $m2->coreRequirement());
|
||||
|
||||
throws(fn () => Manifest::fromArray([
|
||||
'name' => 'bad', 'version' => '1.0.0', 'core' => 'otro',
|
||||
'components' => ['x' => ['files' => ['x.php']]],
|
||||
]), 'core string distinto de none es inválido');
|
||||
});
|
||||
|
||||
@@ -66,3 +66,67 @@ Harness::it('doctor no modifica lock ni archivos', function () {
|
||||
rrmdir($root);
|
||||
rrmdir($tool);
|
||||
});
|
||||
|
||||
Harness::it('core independiente: sin aviso en add incluso sin core conocido', function () {
|
||||
$root = tmpdir('proj');
|
||||
$tool = tmpdir('tool');
|
||||
write_file($tool . '/packages/http/duckbrain.json', json_encode([
|
||||
'name' => 'http', 'version' => '1.0.0', 'description' => 'HTTP',
|
||||
'core' => 'none',
|
||||
'components' => ['aria2' => ['files' => ['src/Libs/Aria2.php']]],
|
||||
]));
|
||||
write_file($tool . '/packages/http/src/Libs/Aria2.php', "<?php\n");
|
||||
write_file($root . '/src/Libs/Router.php', "<?php\n");
|
||||
|
||||
$lock = Lock::load($root);
|
||||
$lock->setCore(['version' => null, 'commit' => 'x', 'files' => []]);
|
||||
$lock->save($root);
|
||||
|
||||
$out = fopen('php://memory', 'rw');
|
||||
$inst = new Toolbox\Installer($root, $tool, new Console($out));
|
||||
$res = $inst->add(['http:aria2'], []);
|
||||
rewind($out);
|
||||
$text = (string) stream_get_contents($out);
|
||||
|
||||
eq([], $res['warnings'], 'independiente no produce aviso');
|
||||
eq([], $res['aborted'], 'nada se aborta');
|
||||
ok(str_contains(implode(',', $res['installed']), 'http:aria2'), 'instala normal');
|
||||
ok(!str_contains($text, 'sin datos'), 'sin ruido en consola');
|
||||
|
||||
// control: mismo fixture sin declaración sí avisa
|
||||
write_file($tool . '/packages/http/duckbrain.json', json_encode([
|
||||
'name' => 'http', 'version' => '1.0.1', 'description' => 'HTTP',
|
||||
'components' => ['aria2' => ['files' => ['src/Libs/Aria2.php']]],
|
||||
]));
|
||||
$out2 = fopen('php://memory', 'rw');
|
||||
$res2 = (new Toolbox\Installer($root, $tool, new Console($out2)))->add(['http:aria2'], ['yes' => true]);
|
||||
ok($res2['warnings'] !== [], 'sin declaración sigue avisando');
|
||||
|
||||
rrmdir($root);
|
||||
rrmdir($tool);
|
||||
});
|
||||
|
||||
Harness::it('doctor muestra independiente sin rangos y sin fallo', function () {
|
||||
$root = tmpdir('proj');
|
||||
$tool = tmpdir('tool');
|
||||
write_file($tool . '/packages/db/duckbrain.json', json_encode([
|
||||
'name' => 'db', 'version' => '1.0.0', 'description' => 'DB',
|
||||
'components' => ['sql' => ['files' => ['src/Libs/Sql.php'], 'core' => 'none']],
|
||||
]));
|
||||
write_file($tool . '/packages/db/src/Libs/Sql.php', "<?php\n");
|
||||
|
||||
$lock = Lock::load($root);
|
||||
$lock->setCore(['version' => '1.5.0', 'commit' => 'c', 'files' => []]);
|
||||
$lock->setComponent('db:sql', ['package' => 'db', 'version' => '1.0.0', 'mode' => 'copy', 'files' => []]);
|
||||
$lock->save($root);
|
||||
|
||||
$out = fopen('php://memory', 'rw');
|
||||
$code = (new DoctorCommand(new Console($out)))->run(['--root=' . $root, '--toolbox=' . $tool]);
|
||||
rewind($out);
|
||||
$text = (string) stream_get_contents($out);
|
||||
|
||||
eq(0, $code);
|
||||
ok(str_contains($text, 'INDEPENDIENTE'), 'estado independiente visible');
|
||||
rrmdir($root);
|
||||
rrmdir($tool);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user