Skip to content

Commit cd5c91e

Browse files
authored
feat: refetch, rule presets, redaction counts, device pick, router types and Firefox build (#491)
Refs #373, #368, #369, #371, #342
1 parent 905701d commit cd5c91e

116 files changed

Lines changed: 3893 additions & 1127 deletions

File tree

Some content is hidden

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

‎.claude/skills/devtools-commit/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The rules are in `docs/contributing/commit-message-guidelines.md`. Summary:
2222
## Pull requests
2323

2424
- Pull requests are squash merged; the title becomes the commit on `main`, so it must follow the header format.
25-
- A `commit-msg` hook (`scripts/commit-message.mjs`, enabled by `pnpm install`) warns about a bad message as you commit; CI checks the title and every commit in the pull request: a bad title fails the check, and problems in the commits show as warnings. Run `pnpm commit:check` before pushing, and fix flagged messages with `git commit --amend` or a reword rebase.
25+
- A `commit-msg` hook (`scripts/commit-message.mjs`, enabled by `pnpm install`) warns about a bad message as you commit; CI checks the title and every commit in the pull request: a bad title or a bad commit message fails the check. Run `pnpm commit:check` before pushing, and fix flagged messages with `git commit --amend` or a reword rebase.
2626
- Address review feedback with fixup commits (`docs/contributing/using-fixup-commits.md`).
2727
- One feature per pull request, with its tests (including agent tool tests when tools change).
2828
- Rebuild and commit `extension/ui` when `app/` changed.

‎.github/workflows/commit-message.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
env:
3535
BASE: ${{ github.event.pull_request.base.sha }}
3636
HEAD: ${{ github.event.pull_request.head.sha }}
37-
run: node scripts/commit-message.mjs --range "$BASE..$HEAD" --warn
37+
run: node scripts/commit-message.mjs --range "$BASE..$HEAD"

‎app/src/__tests__/live-route-apps.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function routerPage(extra: Partial<RouterPage> = {}): RouterPage {
1010
return {
1111
pageId: 'p1',
1212
reportedAt: 1,
13+
changedAt: 1,
1314
snapshot: { url: '/home', queryParams: {}, fragment: null, root },
1415
navigations: [
1516
{

‎app/src/__tests__/live-route-pinned.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function routerPage(pageId: string): RouterPage {
99
return {
1010
pageId,
1111
reportedAt: 1,
12+
changedAt: 1,
1213
snapshot: {
1314
url: `/${pageId}`,
1415
queryParams: {},

‎app/src/__tests__/native-controls.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ describe('browser-only controls', () => {
100100
});
101101

102102
it.each(['angular-native', 'nativescript'])(
103-
'hides the picker and the live views for a %s page, and keeps recording and the tree',
103+
'offers the device picker, hides the live views for a %s page, and keeps recording and the tree',
104104
async (platform) => {
105105
const fixture = await render(platform);
106106
const host = fixture.nativeElement as HTMLElement;
107107
expect(buttons(fixture)).not.toContain('Pick component on page');
108+
expect(buttons(fixture)).toContain('Pick component on device');
108109
expect(buttons(fixture)).toContain('Record');
109110
expect(host.querySelector('#cd-heading')).not.toBeNull();
110111
expect(buttons(fixture)).not.toContain('Flash checks');
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { TestBed, type ComponentFixture } from '@angular/core/testing';
2+
import type { DevframeRpcClient } from 'devframe/client';
3+
import { afterEach, describe, expect, it, vi } from 'vitest';
4+
5+
const calls: [string, unknown][] = [];
6+
let answer: unknown = { ok: true, found: true, entries: 2, status: 200 };
7+
8+
vi.mock('../rpc', () => ({
9+
rpcCall: async (_rpc: unknown, name: string, arg?: unknown) => {
10+
calls.push([name, arg]);
11+
return answer;
12+
},
13+
}));
14+
15+
const { NetworkInspector } = await import('../pages/network-inspector');
16+
17+
const page = {
18+
pageId: 'p1',
19+
url: 'http://localhost:4000/trips',
20+
initialUrl: 'http://localhost:4000/trips',
21+
title: 'Trips',
22+
hydration: null,
23+
calls: [],
24+
reportedAt: 1,
25+
};
26+
27+
function client(
28+
actions: Record<string, boolean> = {},
29+
payload: Record<string, unknown> = { found: true, size: 7, entries: [] },
30+
): DevframeRpcClient {
31+
const values: Record<string, unknown> = {
32+
http: { serverCalls: [], pages: [page], rules: [], ssrOverrides: [] },
33+
'http-payloads': { pages: { p1: payload } },
34+
};
35+
const rpc = {
36+
sharedState: (name: string) =>
37+
Promise.resolve({ value: () => values[name], on: () => () => {} }),
38+
};
39+
return {
40+
connectionMeta: { configs: { pangular: { actions } } },
41+
scope: () => ({ rpc }),
42+
} as unknown as DevframeRpcClient;
43+
}
44+
45+
let fixture: ComponentFixture<InstanceType<typeof NetworkInspector>>;
46+
47+
async function render(rpc: DevframeRpcClient) {
48+
fixture = TestBed.createComponent(NetworkInspector);
49+
fixture.componentRef.setInput('rpc', rpc);
50+
await fixture.whenStable();
51+
await new Promise((resolve) => setTimeout(resolve));
52+
await fixture.whenStable();
53+
return fixture.nativeElement as HTMLElement;
54+
}
55+
56+
const button = (host: HTMLElement) =>
57+
host.querySelector<HTMLButtonElement>('button[data-refetch-payload]')!;
58+
59+
describe('NetworkInspector payload refetch', () => {
60+
afterEach(() => {
61+
fixture?.destroy();
62+
TestBed.resetTestingModule();
63+
calls.length = 0;
64+
answer = { ok: true, found: true, entries: 2, status: 200 };
65+
});
66+
67+
it('asks the server to refetch the selected page and announces the result', async () => {
68+
const host = await render(client());
69+
const refetch = button(host);
70+
expect(refetch.textContent!.trim()).toBe('Refetch');
71+
expect(refetch.getAttribute('aria-describedby')).toBe('refetch-hint');
72+
refetch.click();
73+
await fixture.whenStable();
74+
expect(calls).toContainEqual(['request-http-payload-refetch', { pageId: 'p1' }]);
75+
expect(host.querySelector('.toolbar [role="status"]')!.textContent).toBe(
76+
'Refetched: 2 entries.',
77+
);
78+
});
79+
80+
it('reads out the reason when the refetch does nothing', async () => {
81+
answer = { error: 'The page did not answer within 15s. Is the tab still open?' };
82+
const host = await render(client());
83+
button(host).click();
84+
await fixture.whenStable();
85+
expect(host.querySelector('.toolbar [role="status"]')!.textContent).toBe(
86+
'The page did not answer within 15s. Is the tab still open?',
87+
);
88+
});
89+
90+
it('is off when HTTP actions are off, and says why', async () => {
91+
const host = await render(client({ http: false }));
92+
const refetch = button(host);
93+
expect(refetch.disabled).toBe(true);
94+
expect(refetch.getAttribute('aria-describedby')).toBe('http-writes-off refetch-hint');
95+
expect(host.querySelector('#http-writes-off')).not.toBeNull();
96+
});
97+
98+
it('marks a payload that came from a refetch', async () => {
99+
const host = await render(client({}, { found: true, size: 7, entries: [], refetchedAt: 5 }));
100+
expect(host.querySelector('[data-refetched]')!.textContent).toBe('Refetched');
101+
});
102+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Type } from '@angular/core';
2+
import { TestBed } from '@angular/core/testing';
3+
import { afterEach, describe, expect, it } from 'vitest';
4+
import { RedactionCount } from '../ui/redaction-count';
5+
import { StoreStateTree } from '../pages/store-state-tree';
6+
7+
function render<T>(type: Type<T>, inputs: Record<string, unknown>) {
8+
const fixture = TestBed.createComponent(type);
9+
for (const [name, value] of Object.entries(inputs)) fixture.componentRef.setInput(name, value);
10+
fixture.detectChanges();
11+
return fixture;
12+
}
13+
14+
describe('RedactionCount', () => {
15+
afterEach(() => TestBed.resetTestingModule());
16+
17+
it('says how many values the redaction masked', () => {
18+
const fixture = render(RedactionCount, {
19+
value: { token: '[redacted]', user: { email: '[email]', name: 'Ada' } },
20+
});
21+
const line = (fixture.nativeElement as HTMLElement).querySelector('[data-redaction-count]')!;
22+
expect(line.textContent!.replace(/\s+/g, ' ').trim()).toBe(
23+
'2 values masked by redaction (secret names, tokens and emails).',
24+
);
25+
});
26+
27+
it('shows nothing when nothing was masked', () => {
28+
const fixture = render(RedactionCount, { value: { name: 'Ada' } });
29+
expect(
30+
(fixture.nativeElement as HTMLElement).querySelector('[data-redaction-count]'),
31+
).toBeNull();
32+
});
33+
34+
it('marks a count past the budget as a lower bound', () => {
35+
const fixture = render(RedactionCount, {
36+
value: Array.from({ length: 30_000 }, () => '[redacted]'),
37+
});
38+
const line = (fixture.nativeElement as HTMLElement).querySelector('[data-redaction-count]')!;
39+
expect(line.textContent).toContain('At least 20000 values masked');
40+
});
41+
42+
it('shows the count above the store state tree', () => {
43+
const fixture = render(StoreStateTree, { value: { auth: { token: '[redacted]' } } });
44+
const line = (fixture.nativeElement as HTMLElement).querySelector('[data-redaction-count]')!;
45+
expect(line.textContent).toContain('1 value masked');
46+
});
47+
});

‎app/src/__tests__/route-diff.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function nav(id: number, extra: Partial<NavigationRecord> = {}): NavigationRecor
2424
}
2525

2626
function page(navigations: NavigationRecord[]): RouterPage {
27-
return { pageId: 'p1', reportedAt: 1, snapshot: null, navigations };
27+
return { pageId: 'p1', reportedAt: 1, changedAt: 1, snapshot: null, navigations };
2828
}
2929

3030
async function settle(fixture: ComponentFixture<unknown>) {

‎app/src/__tests__/route-preview.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function settle(fixture: ComponentFixture<unknown>) {
2121
const page: RouterPage = {
2222
pageId: 'p1',
2323
reportedAt: 1,
24+
changedAt: 1,
2425
snapshot: null,
2526
navigations: [],
2627
config: [{ id: '0', path: 'account', fullPath: '/account', kind: 'component', component: 'A' }],

‎app/src/__tests__/route-timeline-clear.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function nav(id: number, url: string, extra: Partial<NavigationRecord> = {}): Na
2424
}
2525

2626
function page(extra: Partial<RouterPage> = {}): RouterPage {
27-
return { pageId: 'p1', reportedAt: 1, snapshot: null, navigations: [], ...extra };
27+
return { pageId: 'p1', reportedAt: 1, changedAt: 1, snapshot: null, navigations: [], ...extra };
2828
}
2929

3030
async function settle(fixture: ComponentFixture<unknown>) {

0 commit comments

Comments
 (0)