Skip to content

Commit 842c1e2

Browse files
Naorayclaude
andauthored
fix(templates): un-nest stack trace details in comment template (#47)
Closes #31 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 544b1a7 commit 842c1e2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

resources/views/comment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
```shell
2121
{simplified_stack_trace}
2222
```
23+
</details>
2324

2425
<details>
2526
<summary>📋 View Complete Stack Trace</summary>
@@ -29,6 +30,7 @@
2930
```
3031

3132
</details>
33+
<!-- stacktrace:end -->
3234

3335
<!-- prev-stacktrace:start -->
3436
<details>
@@ -38,8 +40,6 @@
3840

3941
</details>
4042
<!-- prev-stacktrace:end -->
41-
</details>
42-
<!-- stacktrace:end -->
4343

4444
<!-- queries:start -->
4545
<details>

tests/Issues/TemplateRendererTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@
8181
->toContain('View Previous Exceptions');
8282
});
8383

84+
test('comment template has stack trace details as siblings not nested', function () {
85+
$template = $this->stubLoader->load('comment');
86+
87+
// Verify in the raw template that the stacktrace section contains exactly 2 sibling
88+
// <details> blocks (Stack Trace + View Complete Stack Trace), not nested ones.
89+
$stackTraceStart = strpos($template, '<!-- stacktrace:start -->');
90+
$stackTraceEnd = strpos($template, '<!-- stacktrace:end -->');
91+
92+
expect($stackTraceStart)->not->toBeFalse();
93+
expect($stackTraceEnd)->not->toBeFalse();
94+
95+
$stackTraceSection = substr($template, $stackTraceStart, $stackTraceEnd - $stackTraceStart + strlen('<!-- stacktrace:end -->'));
96+
97+
// Count details tags in the stacktrace section - should be 2 sibling blocks
98+
preg_match_all('/<details>/', $stackTraceSection, $openTags);
99+
preg_match_all('/<\/details>/', $stackTraceSection, $closeTags);
100+
101+
expect(count($openTags[0]))->toBe(2)
102+
->and(count($closeTags[0]))->toBe(2);
103+
104+
// The first </details> should appear BEFORE the second <details>,
105+
// proving they are siblings, not nested.
106+
$firstClose = strpos($stackTraceSection, '</details>');
107+
$secondOpen = strpos($stackTraceSection, '<details>', strpos($stackTraceSection, '<details>') + 1);
108+
expect($firstClose)->toBeLessThan($secondOpen);
109+
110+
// Verify previous exceptions section is outside the stacktrace markers
111+
$prevStart = strpos($template, '<!-- prev-stacktrace:start -->');
112+
expect($prevStart)->toBeGreaterThan($stackTraceEnd);
113+
});
114+
84115
test('it cleans all empty sections', function () {
85116
$record = createLogRecord('');
86117

0 commit comments

Comments
 (0)