Files
michaelschiemer/debug_make_console.php
Michael Schiemer 9b74ade5b0 feat: Fix discovery system critical issues
Resolved multiple critical discovery system issues:

## Discovery System Fixes
- Fixed console commands not being discovered on first run
- Implemented fallback discovery for empty caches
- Added context-aware caching with separate cache keys
- Fixed object serialization preventing __PHP_Incomplete_Class

## Cache System Improvements
- Smart caching that only caches meaningful results
- Separate caches for different execution contexts (console, web, test)
- Proper array serialization/deserialization for cache compatibility
- Cache hit logging for debugging and monitoring

## Object Serialization Fixes
- Fixed DiscoveredAttribute serialization with proper string conversion
- Sanitized additional data to prevent object reference issues
- Added fallback for corrupted cache entries

## Performance & Reliability
- All 69 console commands properly discovered and cached
- 534 total discovery items successfully cached and restored
- No more __PHP_Incomplete_Class cache corruption
- Improved error handling and graceful fallbacks

## Testing & Quality
- Fixed code style issues across discovery components
- Enhanced logging for better debugging capabilities
- Improved cache validation and error recovery

Ready for production deployment with stable discovery system.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 12:04:17 +02:00

99 lines
4.1 KiB
PHP

#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use App\Framework\Core\AppBootstrapper;
use App\Framework\Performance\EnhancedPerformanceCollector;
use App\Framework\DateTime\SystemClock;
use App\Framework\DateTime\SystemHighResolutionClock;
use App\Framework\Performance\MemoryMonitor;
use App\Framework\Discovery\Results\DiscoveryRegistry;
use App\Framework\Console\ConsoleCommand;
use App\Framework\Context\ExecutionContext;
echo "=== Debug: Make Console Issue ===" . PHP_EOL;
echo "Current environment:" . PHP_EOL;
echo " TERM: " . ($_SERVER['TERM'] ?? 'not set') . PHP_EOL;
echo " STDIN: " . (stream_isatty(STDIN) ? 'TTY' : 'not TTY') . PHP_EOL;
echo " STDOUT: " . (stream_isatty(STDOUT) ? 'TTY' : 'not TTY') . PHP_EOL;
echo " argv[0]: " . ($_SERVER['argv'][0] ?? 'not set') . PHP_EOL;
echo " Command line: " . implode(' ', $_SERVER['argv'] ?? []) . PHP_EOL;
try {
echo "1. Creating components..." . PHP_EOL;
$clock = new SystemClock();
$highResClock = new SystemHighResolutionClock();
$memoryMonitor = new MemoryMonitor();
$collector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, enabled: false);
$bootstrapper = new AppBootstrapper(__DIR__, $collector, $memoryMonitor);
echo "2. Detecting execution context..." . PHP_EOL;
$context = ExecutionContext::detect();
echo " Context type: " . $context->getType()->value . PHP_EOL;
echo "3. Bootstrapping console..." . PHP_EOL;
$consoleApp = $bootstrapper->bootstrapConsole();
echo "4. Getting container..." . PHP_EOL;
$reflection = new ReflectionClass($consoleApp);
$containerProperty = $reflection->getProperty('container');
$containerProperty->setAccessible(true);
$container = $containerProperty->getValue($consoleApp);
echo "5. Checking DiscoveryRegistry..." . PHP_EOL;
if ($container->has(DiscoveryRegistry::class)) {
$discoveryRegistry = $container->get(DiscoveryRegistry::class);
$commands = $discoveryRegistry->attributes->get(ConsoleCommand::class);
echo " ConsoleCommand attributes: " . count($commands) . PHP_EOL;
if (count($commands) > 0) {
echo " First 3 commands:" . PHP_EOL;
foreach (array_slice($commands, 0, 3) as $discovered) {
$command = $discovered->createAttributeInstance();
echo " - " . $command->name . PHP_EOL;
}
}
} else {
echo " DiscoveryRegistry NOT found!" . PHP_EOL;
}
echo "6. Checking CommandRegistry..." . PHP_EOL;
$registryProperty = $reflection->getProperty('commandRegistry');
$registryProperty->setAccessible(true);
$commandRegistry = $registryProperty->getValue($consoleApp);
if ($commandRegistry) {
$commandRegistryReflection = new ReflectionClass($commandRegistry);
$commandListProperty = $commandRegistryReflection->getProperty('commandList');
$commandListProperty->setAccessible(true);
$commandList = $commandListProperty->getValue($commandRegistry);
if ($commandList) {
echo " CommandList count: " . $commandList->count() . PHP_EOL;
} else {
echo " CommandList is NULL!" . PHP_EOL;
}
} else {
echo " CommandRegistry is NULL!" . PHP_EOL;
}
echo "7. Cache key analysis..." . PHP_EOL;
$pathProvider = $container->get(\App\Framework\Core\PathProvider::class);
$currentContext = ExecutionContext::detect();
$contextString = $currentContext->getType()->value;
$defaultPaths = [$pathProvider->getSourcePath()];
echo " Context: " . $contextString . PHP_EOL;
echo " Paths: " . implode(', ', $defaultPaths) . PHP_EOL;
// Generate cache key as it would be done in DiscoveryServiceBootstrapper
$pathsHash = md5(implode('|', $defaultPaths));
$cacheKey = "discovery:full_{$pathsHash}_{$contextString}";
echo " Expected cache key: " . $cacheKey . PHP_EOL;
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . PHP_EOL;
echo "Stack trace: " . $e->getTraceAsString() . PHP_EOL;
}