Skip to content

Commit 6afb644

Browse files
fulloclaude
andcommitted
TrendReporter: add response_code column to Recent History table
Reporter alignment: TrendReporter now shows HTTP status codes in the Recent History section. CLI entries show '—' instead of 0. New columns: Timestamp, Method, Status, Script, Time, SCI, Memory Tests: testTrendReporterShowsResponseCode, testTrendReporterCliShowsDashForStatus 113 tests, 556 assertions, PHPStan clean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 28bab15 commit 6afb644

2 files changed

Lines changed: 60 additions & 4 deletions

File tree

src/Reporter/TrendReporter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,26 @@ private function buildReport(array $entries, Config $config): string
198198
$lines[] = ' ── Recent History (last 20) ──';
199199
$lines[] = '';
200200
$lines[] = sprintf(
201-
' %-20s %-6s %-25s %8s %10s %8s',
201+
' %-20s %-6s %6s %-25s %8s %10s %8s',
202202
'Timestamp',
203203
'Method',
204+
'Status',
204205
'Script',
205206
'Time(ms)',
206207
'SCI(mgCO2)',
207208
'Mem(MB)',
208209
);
209-
$lines[] = ' ' . str_repeat('', 82);
210+
$lines[] = ' ' . str_repeat('', 90);
210211

211212
$recent = array_slice($entries, -20);
212213
$prevSci = null;
213214

214215
foreach ($recent as $entry) {
215216
$sci = (float) ($entry['sci.sci_mgco2eq'] ?? 0);
216217
$mem = $entry['memory.memory_peak_mb'] ?? '?';
218+
$method = $entry['request.method'] ?? 'CLI';
219+
$status = (int) ($entry['request.response_code'] ?? 0);
220+
$statusStr = ($method !== 'CLI' && $status > 0) ? (string) $status : '';
217221
$delta = '';
218222

219223
if ($prevSci !== null && $prevSci > 0) {
@@ -230,9 +234,10 @@ private function buildReport(array $entries, Config $config): string
230234
?? 'unknown';
231235

232236
$lines[] = sprintf(
233-
' %-20s %-6s %-25s %8.2f %8.4f%s %8s',
237+
' %-20s %-6s %6s %-25s %8.2f %8.4f%s %8s',
234238
substr($entry['timestamp'] ?? '', 0, 19),
235-
$entry['request.method'] ?? 'CLI',
239+
$method,
240+
$statusStr,
236241
$this->shortenPath($script, 25),
237242
$entry['time.wall_time_ms'] ?? 0,
238243
$sci,

tests/ReporterTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,55 @@ public function testTrendReporterShowsEmptyMessageWithNoEntries(): void
395395
$content = (string) file_get_contents($this->outputDir . '/sci-trend.txt');
396396
$this->assertStringContainsString('No profiling data collected yet', $content);
397397
}
398+
399+
public function testTrendReporterShowsResponseCode(): void
400+
{
401+
$config = new Config(outputDir: $this->outputDir);
402+
$jsonReporter = new JsonReporter();
403+
$trendReporter = new TrendReporter();
404+
405+
// Write HTTP entries with status codes
406+
$jsonReporter->report(
407+
$this->createResult(uri: '/api/users', responseCode: 200, sciScore: 0.3),
408+
$config,
409+
);
410+
$jsonReporter->report(
411+
$this->createResult(uri: '/api/users', responseCode: 404, sciScore: 0.5),
412+
$config,
413+
);
414+
415+
$trendReporter->report($this->createResult(), $config);
416+
417+
$content = (string) file_get_contents($this->outputDir . '/sci-trend.txt');
418+
// Status column should show HTTP codes
419+
$this->assertStringContainsString('Status', $content);
420+
$this->assertStringContainsString('200', $content);
421+
$this->assertStringContainsString('404', $content);
422+
}
423+
424+
public function testTrendReporterCliShowsDashForStatus(): void
425+
{
426+
$config = new Config(outputDir: $this->outputDir);
427+
$jsonReporter = new JsonReporter();
428+
$trendReporter = new TrendReporter();
429+
430+
// Write CLI entries (response_code = 0)
431+
$cliResult = new ProfileResult(
432+
collectorMetrics: [
433+
'time' => ['wall_time_ms' => 50.0, 'wall_time_sec' => 0.05],
434+
'memory' => ['memory_peak_mb' => 4.0],
435+
'request' => ['method' => 'CLI', 'uri' => '/usr/bin/artisan', 'script_filename' => '/usr/bin/artisan', 'response_code' => 0],
436+
'config' => ['device_power_watts' => 18.0, 'grid_carbon_intensity' => 332.0, 'embodied_carbon' => 211000.0, 'device_lifetime_hours' => 11680.0, 'machine_description' => 'Test'],
437+
],
438+
sciMetrics: ['sci_mgco2eq' => 0.5],
439+
timestamp: '2026-01-01T00:00:00+00:00',
440+
profileId: 'cli1',
441+
);
442+
$jsonReporter->report($cliResult, $config);
443+
$jsonReporter->report($cliResult, $config);
444+
$trendReporter->report($cliResult, $config);
445+
446+
$content = (string) file_get_contents($this->outputDir . '/sci-trend.txt');
447+
$this->assertStringContainsString('', $content); // dash for CLI status
448+
}
398449
}

0 commit comments

Comments
 (0)