Skip to content

Commit 5a09545

Browse files
authored
fix: release blockers found by the 1.0.0 test campaign (pangular-inspector#432)
Fixes every blocker the 1.0.0 test campaign found: Angular CLI builds, the Angular 20 and pnpm hub, tool argument checks, secret masking in prose, form fields, form history and NgRx arguments, extension pairing and reloads, and overlay reconnects. An idle tab now sends one small heartbeat instead of resending every report, and NgRx store updates no longer slow down with the store's size. Adds the e2e install, MCP, security, panel and resilience scripts for later releases. Fixes pangular-inspector#424
1 parent c83b928 commit 5a09545

202 files changed

Lines changed: 36756 additions & 21245 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-inspector/SKILL.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Read `docs/contributing/coding-standards.md` ("Reading data from the page") befo
2626
- `serialize.ts`: safe, size-limited serialization.
2727
- `router.ts` `providerOf()`: find a service through the injector resolution path.
2828
- Never write attributes into the app's DOM. Never run app code (validators, guards) on a timer unless the user turned recording on.
29-
- Pushes: send on change, skip unchanged payloads (compare with the last JSON), re-send every few cycles so the server doesn't expire the page, and avoid full DOM scans on a timer (cache, rescan after a `MutationObserver` signal).
29+
- Pushes: send on change, skip unchanged payloads (compare with the last JSON), and let the page heartbeat keep the page alive: re-send an unchanged report only when `keepaliveDue`/`keepaliveAfter` says so (the server lost the page), and avoid full DOM scans on a timer (cache, rescan after a `MutationObserver` signal).
3030
- Every report carries `pageId` from `claimPageId()`. Call `forget-<area>-page` from `leave()`.
3131

3232
## Server side (`devframe.ts`, `rpc/`)
3333

34-
- Keep a `Map<pageId, report>` with `reportedAt`, drop pages older than 15 seconds in the shared expiry interval, and write the combined value into the shared state.
34+
- Keep a `Map<pageId, report>` with `reportedAt`, drop pages older than `ttl(pageId)` (from `visibility.ttl()`, so a page with a current heartbeat never expires) in the shared expiry interval, and write the combined value into the shared state.
3535
- Page actions that the panel triggers (restore, highlight, run) go panel -> `request-<area>-action` -> broadcast `<area>-action` to the page -> `<area>-action-result`, keyed by `requestId`, with a timeout.
3636
- Source scans in `rpc/` enrich or stand in for live data. They must return a `kind` for anything the Dashboard counts.
3737

‎app/src/__tests__/analog-tab-restore.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function fakeClient(analog: boolean): DevframeRpcClient {
2525
sharedState: () => Promise.resolve({ value: () => null, on: () => () => {} }),
2626
};
2727
return {
28+
status: 'connected',
2829
connectionMeta: { configs: {} },
2930
scope: () => ({ rpc }),
3031
events: { on: () => () => {} },

‎app/src/__tests__/angular-native-view.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function fakeClient(initial: Pages) {
3838
),
3939
};
4040
const client = {
41+
status: 'connected',
4142
connectionMeta: { configs: {} },
4243
scope: () => ({ rpc }),
4344
events: { on: () => () => {} },

‎app/src/__tests__/app-shell.test.ts‎

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ const connection = vi.hoisted(() => ({
88
answers: [] as boolean[],
99
/** Sends a `connection:status` event to the last connected client's listeners. */
1010
emitStatus: (_status: string) => {},
11+
/** `emitStatus` for each client, in the order they were made. */
12+
emitters: [] as ((status: string) => void)[],
1113
/** The options each attempt passed to `connectDevframe`. */
1214
options: [] as unknown[],
1315
/** How many clients the panel closed. */
1416
closed: 0,
17+
/** The status each new client starts with. */
18+
initialStatus: 'connected',
19+
/** The one-time code the fake server accepts. */
20+
code: '123456',
1521
}));
1622

1723
function fakeClient(): DevframeRpcClient {
@@ -21,8 +27,31 @@ function fakeClient(): DevframeRpcClient {
2127
sharedState: () => Promise.resolve({ value: () => null, on: () => () => {} }),
2228
};
2329
const listeners: ((status: string) => void)[] = [];
24-
connection.emitStatus = (status) => listeners.forEach((listener) => listener(status));
30+
const client = {
31+
status: connection.initialStatus,
32+
connection: { authToken: undefined as string | undefined },
33+
requestAuthCode: vi.fn(() => Promise.resolve()),
34+
requestTrustWithCode: vi.fn(async (code: string) => {
35+
if (code !== connection.code) return false;
36+
client.connection.authToken = 'token-for-code';
37+
connection.emitStatus('connected');
38+
return true;
39+
}),
40+
};
41+
connection.emitStatus = (status) => {
42+
client.status = status;
43+
listeners.forEach((listener) => listener(status));
44+
};
45+
connection.emitters.push(connection.emitStatus);
2546
return {
47+
get status() {
48+
return client.status;
49+
},
50+
get connection() {
51+
return client.connection;
52+
},
53+
requestAuthCode: client.requestAuthCode,
54+
requestTrustWithCode: client.requestTrustWithCode,
2655
connectionMeta: { configs: {} },
2756
scope: () => ({ rpc }),
2857
events: {
@@ -63,7 +92,9 @@ afterEach(() => {
6392
connection.attempts = 0;
6493
connection.answers = [];
6594
connection.options = [];
95+
connection.emitters = [];
6696
connection.closed = 0;
97+
connection.initialStatus = 'connected';
6798
TestBed.resetTestingModule();
6899
});
69100

@@ -110,6 +141,8 @@ describe('App connection retry', () => {
110141
expect(status(fixture)).toBe('Live');
111142

112143
// The dev server restarted: the old client is closed for good.
144+
const kept = globalThis as Record<string, unknown>;
145+
kept['__DEVFRAME_CONNECTION__'] = { connectionMeta: { websocket: 9777 } };
113146
connection.emitStatus('disconnected');
114147
await settle(fixture);
115148
expect(status(fixture)).toBe('Disconnected');
@@ -118,6 +151,8 @@ describe('App connection retry', () => {
118151
await vi.waitFor(() => expect(connection.attempts).toBe(2), { timeout: 3000 });
119152
await settle(fixture);
120153
expect(status(fixture)).toBe('Live');
154+
// It read the connection file again: the server may listen on another port now.
155+
expect(kept['__DEVFRAME_CONNECTION__']).toBeUndefined();
121156
fixture.destroy();
122157
});
123158

@@ -151,6 +186,82 @@ describe('App connection retry', () => {
151186
});
152187
});
153188

189+
describe('App before the server trusts it', () => {
190+
it('shows Connecting, not Live, until the socket is trusted, and the error when it fails', async () => {
191+
connection.answers = [true, false];
192+
connection.initialStatus = 'connecting';
193+
const fixture = TestBed.createComponent(App);
194+
await settle(fixture);
195+
expect(status(fixture)).toBe('Connecting…');
196+
expect(host(fixture).textContent).toContain('Connecting to the devtools server…');
197+
expect(host(fixture).querySelector('app-dashboard')).toBeNull();
198+
expect(connection.options[0]).toMatchObject({ simpleAuth: false });
199+
200+
// The server is down: the reused connection file resolves, the socket does not open.
201+
connection.emitStatus('error');
202+
await settle(fixture);
203+
expect(status(fixture)).toBe('Disconnected');
204+
expect(host(fixture).querySelector('.connection-error')).not.toBeNull();
205+
fixture.destroy();
206+
});
207+
208+
it('does not start a second client while one still waits for the server', async () => {
209+
connection.answers = [false, true, true];
210+
connection.initialStatus = 'connecting';
211+
const fixture = TestBed.createComponent(App);
212+
document.body.appendChild(host(fixture));
213+
await settle(fixture);
214+
const retry = () => host(fixture).querySelector<HTMLButtonElement>('.connection-error button');
215+
216+
// The first retry finds the connection file; its socket is still opening.
217+
retry()!.click();
218+
await settle(fixture);
219+
expect(connection.attempts).toBe(2);
220+
expect(retry()).not.toBeNull();
221+
222+
retry()!.click();
223+
await settle(fixture);
224+
expect(connection.attempts).toBe(2);
225+
226+
connection.emitters[0]!('connected');
227+
await settle(fixture);
228+
expect(status(fixture)).toBe('Live');
229+
fixture.destroy();
230+
});
231+
232+
it('asks for the one-time code when the server does not trust the panel, then connects', async () => {
233+
connection.answers = [true];
234+
connection.initialStatus = 'connecting';
235+
const fixture = TestBed.createComponent(App);
236+
document.body.appendChild(host(fixture));
237+
await settle(fixture);
238+
connection.emitStatus('unauthorized');
239+
await settle(fixture);
240+
expect(status(fixture)).toBe('Code needed');
241+
const form = host(fixture).querySelector('app-auth-code')!;
242+
expect(form).not.toBeNull();
243+
expect(form.querySelector('h2')?.textContent).toBe('Enter the one-time code');
244+
const input = form.querySelector<HTMLInputElement>('input')!;
245+
expect(document.activeElement).toBe(input);
246+
247+
input.value = '000000';
248+
input.dispatchEvent(new Event('input'));
249+
form.querySelector('form')!.dispatchEvent(new Event('submit', { cancelable: true }));
250+
await settle(fixture);
251+
expect(form.querySelector('[role="alert"]')?.textContent).toContain("didn't match");
252+
expect(status(fixture)).toBe('Code needed');
253+
254+
input.value = ' 123456 ';
255+
input.dispatchEvent(new Event('input'));
256+
form.querySelector('form')!.dispatchEvent(new Event('submit', { cancelable: true }));
257+
await settle(fixture);
258+
expect(host(fixture).querySelector('app-auth-code')).toBeNull();
259+
expect(status(fixture)).toBe('Live');
260+
expect(host(fixture).querySelector('app-dashboard')).not.toBeNull();
261+
fixture.destroy();
262+
});
263+
});
264+
154265
describe('App tab bar', () => {
155266
it('keeps one tab in the Tab order and moves along the bar with arrow keys', async () => {
156267
connection.answers = [true];
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { crossServerOrigin, panelAuth } from '../auth-token';
3+
4+
const DEVFRAME_KEY = '__DEVFRAME_CONNECTION_AUTH_TOKEN__';
5+
const extension = {
6+
href: 'chrome-extension://dcogniffeelebaolkkfbopmjcblhblfk/ui/index.html?baseURL=x',
7+
origin: 'chrome-extension://dcogniffeelebaolkkfbopmjcblhblfk',
8+
};
9+
10+
function memoryStorage(initial: Record<string, string> = {}) {
11+
const data = new Map(Object.entries(initial));
12+
return {
13+
data,
14+
getItem: (key: string) => data.get(key) ?? null,
15+
setItem: (key: string, value: string) => void data.set(key, value),
16+
removeItem: (key: string) => void data.delete(key),
17+
};
18+
}
19+
20+
describe('panel auth tokens', () => {
21+
it('treats a server on the panel origin as its own', () => {
22+
const hub = {
23+
href: 'http://localhost:4000/__devframes/pangular/',
24+
origin: 'http://localhost:4000',
25+
};
26+
expect(crossServerOrigin('/__devframes/pangular/', hub)).toBeNull();
27+
expect(crossServerOrigin(['/__pangular/', './'], hub)).toBeNull();
28+
expect(crossServerOrigin(undefined, hub)).toBeNull();
29+
const storage = memoryStorage({ [DEVFRAME_KEY]: 'own' });
30+
expect(panelAuth('/__devframes/pangular/', hub, storage).token).toBeUndefined();
31+
// devframe keeps managing the token of its own origin.
32+
expect(storage.data.get(DEVFRAME_KEY)).toBe('own');
33+
});
34+
35+
it('keeps one token per server origin in the extension', () => {
36+
const storage = memoryStorage();
37+
const vite = 'http://localhost:5173/__devframes/pangular/';
38+
const hub = 'http://localhost:4000/__devframes/pangular/';
39+
expect(crossServerOrigin(vite, extension)).toBe('http://localhost:5173');
40+
41+
const first = panelAuth(vite, extension, storage);
42+
expect(first.token).toBeUndefined();
43+
first.remember('vite-token');
44+
panelAuth(hub, extension, storage).remember('hub-token');
45+
46+
expect(panelAuth(vite, extension, storage).token).toBe('vite-token');
47+
expect(panelAuth(hub, extension, storage).token).toBe('hub-token');
48+
});
49+
50+
it("never leaves devframe's shared slot for the next server to send", () => {
51+
const storage = memoryStorage({ [DEVFRAME_KEY]: 'token-of-another-server' });
52+
const auth = panelAuth('http://localhost:5173/', extension, storage);
53+
expect(storage.data.has(DEVFRAME_KEY)).toBe(false);
54+
storage.data.set(DEVFRAME_KEY, 'copied-by-devframe');
55+
auth.remember('new-token');
56+
expect(storage.data.has(DEVFRAME_KEY)).toBe(false);
57+
expect(auth.token).toBe('new-token');
58+
});
59+
60+
it('ignores an empty token', () => {
61+
const storage = memoryStorage();
62+
panelAuth('http://localhost:5173/', extension, storage).remember(undefined);
63+
expect(storage.data.size).toBe(0);
64+
});
65+
});
66+
67+
/** Two documents on one origin: a shared storage area and a shared broadcast bus. */
68+
function sharedOrigin() {
69+
const data = new Map<string, string>();
70+
const bus = new Set<{ name: string; onmessage: ((event: { data: unknown }) => void) | null }>();
71+
const panel = () => {
72+
class PanelStorage {
73+
getItem(key: string) {
74+
return data.get(key) ?? null;
75+
}
76+
setItem(key: string, value: string) {
77+
data.set(key, value);
78+
}
79+
removeItem(key: string) {
80+
data.delete(key);
81+
}
82+
}
83+
class PanelChannel {
84+
onmessage: ((event: { data: unknown }) => void) | null = null;
85+
constructor(readonly name: string) {
86+
bus.add(this);
87+
}
88+
postMessage(message: unknown) {
89+
for (const other of bus) {
90+
if (other !== this && other.name === this.name) other.onmessage?.({ data: message });
91+
}
92+
}
93+
close() {
94+
bus.delete(this);
95+
}
96+
}
97+
const scope = {
98+
Storage: PanelStorage as unknown as typeof Storage,
99+
BroadcastChannel: PanelChannel as unknown as typeof BroadcastChannel,
100+
};
101+
return { scope, storage: new PanelStorage() };
102+
};
103+
return { data, panel };
104+
}
105+
106+
/** What devframe's client does with the one-time code token, as in devframe/client. */
107+
function devframeClient(
108+
scope: { BroadcastChannel: typeof BroadcastChannel },
109+
storage: Pick<Storage, 'setItem'>,
110+
sentToServer: string[],
111+
) {
112+
let channel: BroadcastChannel | undefined;
113+
try {
114+
channel = new scope.BroadcastChannel('devframe-auth');
115+
} catch {
116+
// devframe leaves the channel out when it cannot open one.
117+
}
118+
const store = (token: string) => {
119+
try {
120+
storage.setItem(DEVFRAME_KEY, token);
121+
} catch {
122+
// As devframe: storage may be blocked.
123+
}
124+
};
125+
if (channel) {
126+
channel.onmessage = (event: MessageEvent) => {
127+
const data = event.data as { type?: string; authToken?: string };
128+
if (data?.type === 'auth-update' && data.authToken) {
129+
store(data.authToken);
130+
sentToServer.push(data.authToken);
131+
}
132+
};
133+
}
134+
return {
135+
trustWithCode(token: string) {
136+
store(token);
137+
try {
138+
channel?.postMessage({ type: 'auth-update', authToken: token });
139+
} catch {
140+
// As devframe.
141+
}
142+
},
143+
};
144+
}
145+
146+
describe('two extension panels on different servers', () => {
147+
it("never hand one server's token to the other", () => {
148+
const origin = sharedOrigin();
149+
const first = origin.panel();
150+
const second = origin.panel();
151+
const authA = panelAuth('http://localhost:4000/', extension, first.storage, first.scope);
152+
const authB = panelAuth('http://localhost:5173/', extension, second.storage, second.scope);
153+
const sentToA: string[] = [];
154+
const sentToB: string[] = [];
155+
const clientA = devframeClient(first.scope, first.storage, sentToA);
156+
devframeClient(second.scope, second.storage, sentToB);
157+
158+
clientA.trustWithCode('token-of-a');
159+
authA.remember('token-of-a');
160+
161+
expect(sentToB).toEqual([]);
162+
expect(origin.data.has(DEVFRAME_KEY)).toBe(false);
163+
expect(authB.token).toBeUndefined();
164+
expect(panelAuth('http://localhost:5173/', extension, second.storage, second.scope).token).toBe(
165+
undefined,
166+
);
167+
expect(panelAuth('http://localhost:4000/', extension, first.storage, first.scope).token).toBe(
168+
'token-of-a',
169+
);
170+
});
171+
172+
it('leave the channel and the slot to devframe for panels next to their server', () => {
173+
const origin = sharedOrigin();
174+
const hub = {
175+
href: 'http://localhost:4000/__devframes/pangular/',
176+
origin: 'http://localhost:4000',
177+
};
178+
const first = origin.panel();
179+
const second = origin.panel();
180+
panelAuth('/__devframes/pangular/', hub, first.storage, first.scope);
181+
panelAuth('/__devframes/pangular/', hub, second.storage, second.scope);
182+
const sent: string[] = [];
183+
const client = devframeClient(first.scope, first.storage, []);
184+
devframeClient(second.scope, second.storage, sent);
185+
client.trustWithCode('hub-token');
186+
// Same server: devframe shares the token between its tabs, as it should.
187+
expect(sent).toEqual(['hub-token']);
188+
expect(origin.data.get(DEVFRAME_KEY)).toBe('hub-token');
189+
});
190+
191+
it('keep other broadcast channels and storage keys working', () => {
192+
const origin = sharedOrigin();
193+
const panel = origin.panel();
194+
panelAuth('http://localhost:4000/', extension, panel.storage, panel.scope);
195+
expect(() => new panel.scope.BroadcastChannel('other')).not.toThrow();
196+
panel.storage.setItem('pangular-tab', 'routes');
197+
expect(panel.storage.getItem('pangular-tab')).toBe('routes');
198+
});
199+
});

‎app/src/__tests__/capacitor-view.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function fakeClient(initial: Record<string, CapacitorPage> | undefined) {
4141
Promise.resolve(name === 'capacitor' ? capacitor : { value: () => null, on: () => () => {} }),
4242
};
4343
const client = {
44+
status: 'connected',
4445
connectionMeta: { configs: {} },
4546
scope: () => ({ rpc }),
4647
events: { on: () => () => {} },

0 commit comments

Comments
 (0)