Skip to content

Commit f1f4765

Browse files
authored
fix: audit findings for components, injectors, signals, pipes and HTTP (#361)
Fixes confirmed audit findings from #344, #345, #346, #350 and #351. The issues stay open for the items that need a product decision or a larger change.
1 parent a5052da commit f1f4765

73 files changed

Lines changed: 2349 additions & 393 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎app/src/__tests__/component-tree-defer.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,37 @@ describe('defer blocks', () => {
5353
expect(badge.classList.contains('defer-state')).toBe(true);
5454
expect(badge.classList.contains('defer-state-complete')).toBe(true);
5555
});
56+
57+
it('keeps a row without an owner focusable, marked aria-disabled', async () => {
58+
const fixture = TestBed.createComponent(ComponentTree);
59+
const page = {
60+
pageId: 'p1',
61+
roots: [{ id: 'c1', name: 'App', tag: 'app-root', children: [] }],
62+
count: 1,
63+
detail: null,
64+
reportedAt: 1000,
65+
deferBlocks: [
66+
{
67+
id: 'd1',
68+
state: 'placeholder',
69+
hydration: 'not-configured',
70+
triggers: [],
71+
rootIds: [],
72+
},
73+
],
74+
};
75+
fixture.componentRef.setInput('rpc', client({ p1: page }));
76+
for (let i = 0; i < 3; i++) {
77+
await new Promise((resolve) => setTimeout(resolve));
78+
await fixture.whenStable();
79+
}
80+
const row = (fixture.nativeElement as HTMLElement).querySelector<HTMLButtonElement>(
81+
'.defer-row',
82+
)!;
83+
expect(row.disabled).toBe(false);
84+
expect(row.getAttribute('aria-disabled')).toBe('true');
85+
row.click();
86+
await fixture.whenStable();
87+
expect(row.textContent).toContain('Unknown component');
88+
});
5689
});

‎app/src/__tests__/di-inspector-pages.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,66 @@ describe('injector tree page picker', () => {
503503
expect(el.textContent).not.toContain('This injector is no longer on the page');
504504
});
505505
});
506+
507+
describe('injector tree search and zone', () => {
508+
afterEach(() => {
509+
scopeToPage(null);
510+
document.body.innerHTML = '';
511+
});
512+
513+
const providing = (count: number) =>
514+
Array.from({ length: count }, (_, i) => ({
515+
injector: {
516+
id: `e${i}`,
517+
type: 'element',
518+
name: `app-${i}`,
519+
providerCount: 1,
520+
component: 'C',
521+
},
522+
providers: [{ token: 'Store', type: 'class', isViewProvider: false }],
523+
children: [],
524+
}));
525+
526+
it('shows the change detection mode the page reported', async () => {
527+
const fixture = await render({ roots: providing(1), environment: [], zone: 'zone-unused' });
528+
expect((fixture.nativeElement as HTMLElement).textContent).toContain(
529+
'Change detection: Zoneless, zone.js loaded',
530+
);
531+
});
532+
533+
it('says how many more injectors provide the token past the shown chips', async () => {
534+
const fixture = await render({ roots: providing(15), environment: [] });
535+
fixture.componentInstance.query.set('store');
536+
await fixture.whenStable();
537+
const where = (fixture.nativeElement as HTMLElement).querySelector('.where')!;
538+
expect(where.querySelectorAll('.chip')).toHaveLength(12);
539+
expect(where.textContent).toContain('+3 more');
540+
expect(where.getAttribute('role')).toBeNull();
541+
});
542+
543+
it('announces one search summary once typing pauses', async () => {
544+
const fixture = await render({ roots: providing(2), environment: [] });
545+
vi.useFakeTimers();
546+
try {
547+
const status = () =>
548+
(fixture.nativeElement as HTMLElement).querySelector('[role="status"].sr-only')!
549+
.textContent;
550+
for (const query of ['s', 'st', 'sto', 'store']) {
551+
fixture.componentInstance.query.set(query);
552+
fixture.detectChanges();
553+
await vi.advanceTimersByTimeAsync(100);
554+
}
555+
expect(status()).toBe('');
556+
await vi.advanceTimersByTimeAsync(600);
557+
fixture.detectChanges();
558+
expect(status()).toBe('2 injectors provide “store”.');
559+
fixture.componentInstance.query.set('zzz');
560+
fixture.detectChanges();
561+
await vi.advanceTimersByTimeAsync(600);
562+
fixture.detectChanges();
563+
expect(status()).toBe('Nothing here matches “zzz”.');
564+
} finally {
565+
vi.useRealTimers();
566+
}
567+
});
568+
});

‎app/src/__tests__/pipes-record-page.test.ts‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,109 @@ describe('pipes filter box', () => {
105105
expect(document.activeElement).toBe(host.querySelector('input[type="search"]'));
106106
});
107107
});
108+
109+
describe('pipes live data per page', () => {
110+
afterEach(() => {
111+
scopeToPage(null);
112+
document.body.innerHTML = '';
113+
});
114+
115+
const live = (count: number) => ({
116+
name: 'price',
117+
className: 'PricePipe',
118+
isPure: true,
119+
instanceCount: count,
120+
components: [{ name: 'Cart', count }],
121+
});
122+
123+
function withPages(snapshot: unknown) {
124+
const rpc = {
125+
call: (name: string) =>
126+
Promise.resolve(
127+
name === 'get-pipes'
128+
? [
129+
{
130+
name: 'price',
131+
className: 'PricePipe',
132+
file: 'src/price.pipe.ts',
133+
line: 4,
134+
isStandalone: true,
135+
isPure: true,
136+
builtin: false,
137+
usageCount: 2,
138+
usages: [
139+
{ file: 'src/cart.html', line: 3 },
140+
{ file: 'src/total.html', line: 7 },
141+
],
142+
},
143+
]
144+
: [],
145+
),
146+
callEvent: () => Promise.resolve(),
147+
sharedState: () => Promise.resolve({ value: () => snapshot, on: () => () => {} }),
148+
};
149+
return { connectionMeta: {}, scope: () => ({ rpc }) } as unknown as DevframeRpcClient;
150+
}
151+
152+
it('shows only the page the panel belongs to when several pages report', async () => {
153+
scopeToPage('B');
154+
const fixture = await render(
155+
withPages({
156+
pipes: [live(5)],
157+
async: [],
158+
reportedAt: 0,
159+
instrumented: [],
160+
pages: [
161+
{ pageId: 'A', pipes: [live(3)], async: [] },
162+
{ pageId: 'B', pipes: [live(2)], async: [] },
163+
],
164+
}),
165+
);
166+
expect(fixture.componentInstance.liveFor('price')?.instanceCount).toBe(2);
167+
});
168+
169+
it('lists the template usages of a custom pipe', async () => {
170+
const fixture = await render(
171+
withPages({ pipes: [], async: [], reportedAt: 0, instrumented: [] }),
172+
);
173+
const component = fixture.componentInstance;
174+
component.selected.set(component.pipes()[0]);
175+
await fixture.whenStable();
176+
const host = fixture.nativeElement as HTMLElement;
177+
expect(host.textContent).toContain('Used in templates');
178+
expect(host.textContent).toContain('src/total.html:7');
179+
expect(host.textContent).toContain('2 uses');
180+
});
181+
182+
it('names the component and caller of each called instance', async () => {
183+
const fixture = await render(
184+
withPages({
185+
pipes: [
186+
{
187+
...live(2),
188+
call: {
189+
callCount: 3,
190+
totalMs: 1.5,
191+
maxMs: 1,
192+
lastMs: 0.5,
193+
instances: [
194+
{ component: 'Cart', callCount: 2, lastCaller: 'Cart.total (cart.ts:4)' },
195+
{ component: 'Summary', callCount: 1, target: { pageId: 'A', id: 's1' } },
196+
],
197+
},
198+
},
199+
],
200+
async: [],
201+
reportedAt: 0,
202+
instrumented: [],
203+
}),
204+
);
205+
const component = fixture.componentInstance;
206+
component.selected.set(component.pipes()[0]);
207+
await fixture.whenStable();
208+
const host = fixture.nativeElement as HTMLElement;
209+
expect(host.textContent).toContain('Cart.total (cart.ts:4)');
210+
expect(host.textContent).toContain('1.50 ms total');
211+
expect(host.querySelector('button[aria-label="Highlight Summary on the page"]')).not.toBeNull();
212+
});
213+
});

‎app/src/__tests__/signal-inspector.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,54 @@ describe('SignalInspector', () => {
395395
expect(box.value).toBe('');
396396
});
397397
});
398+
399+
describe('relations, filters and write hints', () => {
400+
const linked = {
401+
...graph,
402+
nodes: [
403+
{ id: '1', kind: 'signal', epoch: 2, value: 1 },
404+
{ id: '2', kind: 'computed', label: 'double', epoch: 1, value: 2 },
405+
{ id: '3', kind: 'signal', label: 'query', epoch: 3, value: 'x' },
406+
],
407+
edges: [{ consumer: 1, producer: 0 }],
408+
history: {
409+
'3': [
410+
{ epoch: 1, value: 'a', at: 1, source: 'initial' },
411+
{ epoch: 3, value: 'x', at: 2, source: 'sample', missed: 1 },
412+
],
413+
},
414+
resources: [{ id: 'resource:9', name: 'trips', named: true, epoch: 1, nodeIds: [] }],
415+
};
416+
417+
it('lists producers and consumers from the edges', async () => {
418+
const fixture = await render(linked);
419+
const page = fixture.componentInstance;
420+
const [unnamed, double] = linked.nodes as never[];
421+
expect(page.getDependencies(double).map((n: { id: string }) => n.id)).toEqual(['1']);
422+
expect(page.getConsumers(unnamed).map((n: { id: string }) => n.id)).toEqual(['2']);
423+
expect(page.getDependencies(unnamed)).toEqual([]);
424+
});
425+
426+
it('matches resources by kind only on a prefix of three letters or more', async () => {
427+
const fixture = await render(linked);
428+
const page = fixture.componentInstance;
429+
page.filter.set('e');
430+
expect(page.filteredResources()).toEqual([]);
431+
page.filter.set('res');
432+
expect(page.filteredResources().map((r) => r.id)).toEqual(['resource:9']);
433+
page.filter.set('trip');
434+
expect(page.filteredResources().map((r) => r.id)).toEqual(['resource:9']);
435+
});
436+
437+
it('explains why an unnamed signal or a sampled-only history has no set entries', async () => {
438+
const fixture = await render(linked);
439+
const page = fixture.componentInstance;
440+
page.selectedId.set('1');
441+
expect(page.writeHint()).toMatch(/has no name.*debugName/);
442+
page.selectedId.set('3');
443+
expect(page.writeHint()).toMatch(/Every change here was sampled/);
444+
page.selectedId.set('2');
445+
expect(page.writeHint()).toBe('');
446+
});
447+
});
398448
});

‎app/src/pages/cd-recording.ts‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
import { Component, computed, input, signal } from '@angular/core';
2+
import type { CdReport } from '@pangular-inspector/devtools/config';
23
import type { DevframeRpcClient } from 'devframe/client';
34
import { panelConfig } from '../devtools-config';
45
import { time } from '../format';
56
import { rpcCall as call } from '../rpc';
67
import { LimitNote } from '../ui/limit-note';
78

8-
export interface CdCheck {
9-
name: string;
10-
checks: number;
11-
ms: number;
12-
}
13-
14-
export interface CdCycle {
15-
id: number;
16-
at: number;
17-
ms: number;
18-
passes: number;
19-
trigger?: string;
20-
checks: number;
21-
components: CdCheck[];
22-
}
23-
24-
export interface CdComponentStat extends CdCheck {
25-
maxMs: number;
26-
cycles: number;
27-
}
28-
29-
export interface CdPage {
30-
pageId: string;
31-
supported: boolean;
32-
recording: boolean;
33-
startedAt: number | null;
34-
dropped: number;
35-
cycles: CdCycle[];
36-
components: CdComponentStat[];
37-
hosts: Record<string, number>;
38-
}
9+
export type { CdCheck, CdComponentStat, CdCycle } from '@pangular-inspector/devtools/config';
10+
/** One page's recording, as the page reports it. */
11+
export type CdPage = CdReport;
3912

4013
const SHOWN = 10;
4114
const SHOWN_CYCLES = 30;

‎app/src/pages/component-tree.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ function bare(name: string): string {
521521
<button
522522
type="button"
523523
class="defer-row"
524-
[disabled]="!block.owner"
524+
[attr.aria-disabled]="block.owner ? null : 'true'"
525525
(click)="showOwner(block)"
526526
(focus)="highlightBlock(block)"
527527
(blur)="highlight(null)"
@@ -864,7 +864,7 @@ function bare(name: string): string {
864864
border-color: var(--border);
865865
text-align: left;
866866
}
867-
.defer-row:disabled {
867+
.defer-row[aria-disabled='true'] {
868868
cursor: default;
869869
}
870870
.defer-state {

0 commit comments

Comments
 (0)