Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4ea5407
feat(store): add Store DevTools history tools, ngrx.trace and action …
erkamyaman Nov 7, 2026
ceb1d95
feat(store): add a state tree, Store DevTools controls, call sites an…
erkamyaman Nov 7, 2026
e19a501
docs(store): document the Store DevTools history, ngrx.trace and expl…
erkamyaman Nov 7, 2026
13002ea
fix(store): drop the collector's own frames from bundled call sites
erkamyaman Nov 7, 2026
1e3603b
fix(store): keep the colon on the key and name the frequency table once
erkamyaman Nov 7, 2026
2e964df
docs(mcp): count one hundred agent tools on the tools page
erkamyaman Nov 7, 2026
c5d01ae
build(extension): rebuild the panel bundle
erkamyaman Nov 7, 2026
56e3171
ci(store): add MCP e2e cases for ngrx-store-devtools and ngrx-explain…
erkamyaman Nov 7, 2026
ed9966d
Merge remote-tracking branch 'origin/main' into feat/ngrx-tools
erkamyaman Nov 7, 2026
6b59d05
fix(store): mark ngrx-store-devtools as a destructive tool
erkamyaman Nov 7, 2026
3345405
ci(store): assert the ngrx-explain-change answer and the store-devtoo…
erkamyaman Nov 7, 2026
28db6fb
Merge remote-tracking branch 'origin/main' into feat/ngrx-tools
erkamyaman Nov 7, 2026
7a63ee2
fix(store): refuse a Store DevTools jump to a signal store entry
erkamyaman Nov 7, 2026
4b36826
docs(store): say that a jump by seq logs Restore #N
erkamyaman Nov 7, 2026
efcd05d
ci(store): give the ngrx-explain-change read plan cases a path and ch…
erkamyaman Nov 7, 2026
eb82992
Merge remote-tracking branch 'origin/main' into feat/ngrx-tools
erkamyaman Nov 7, 2026
067ae97
Merge remote-tracking branch 'origin/main' into feat/ngrx-tools
erkamyaman Nov 7, 2026
0021aa3
build(extension): rebuild extension/ui after the main merges
erkamyaman Nov 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions app/src/__tests__/store-devtools-history.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import { TestBed, type ComponentFixture } from '@angular/core/testing';
import type { DevframeRpcClient } from 'devframe/client';
import { afterEach, describe, expect, it } from 'vitest';
import { StoreInspector } from '../pages/store-inspector';
import { traceFrame, type NgrxLogEntry, type NgrxPage } from '../pages/store-types';

type Call = (name: string, arg?: Record<string, unknown>) => Promise<unknown>;

function fakeClient(call: Call, page: NgrxPage): DevframeRpcClient {
const rpc = {
call,
callEvent: () => Promise.resolve(),
sharedState: () => Promise.resolve({ value: () => ({ pages: [page] }), on: () => () => {} }),
};
return { connectionMeta: {}, scope: () => ({ rpc }) } as unknown as DevframeRpcClient;
}

function entry(seq: number, extra: Partial<NgrxLogEntry> = {}): NgrxLogEntry {
return {
seq,
source: 'store',
storeId: 'store',
type: '[Cart] Add Item',
action: { type: '[Cart] Add Item', id: seq },
origin: 'dispatch',
timestamp: 0,
diff: [{ path: 'cart.items[0]', op: 'add', after: seq }],
restorable: true,
...extra,
};
}

async function settle(fixture: ComponentFixture<unknown>) {
for (let i = 0; i < 3; i++) {
await new Promise((resolve) => setTimeout(resolve));
await fixture.whenStable();
}
}

const root = (fixture: ComponentFixture<unknown>) => fixture.nativeElement as HTMLElement;

function button(fixture: ComponentFixture<unknown>, name: string) {
return Array.from(root(fixture).querySelectorAll<HTMLButtonElement>('button')).find(
(b) => (b.textContent ?? '').trim() === name,
);
}

async function mount(page: Partial<NgrxPage>) {
const calls: { name: string; arg?: Record<string, unknown> }[] = [];
const fixture = TestBed.createComponent(StoreInspector);
fixture.componentRef.setInput(
'rpc',
fakeClient(
(name, arg) => {
if (name === 'get-ngrx-store') return Promise.resolve([]);
calls.push({ name, arg });
return Promise.resolve({ ok: true, message: 'Done on the page.' });
},
{
pageId: 'p1',
url: '/',
title: 'App',
stores: [],
classic: { state: { cart: { items: [1, 2] } }, devtools: true, scope: 'root' },
log: [],
reportedAt: 0,
...page,
},
),
);
await settle(fixture);
return { fixture, calls };
}

const devtoolsCalls = (calls: { name: string; arg?: Record<string, unknown> }[]) =>
calls.filter((c) => c.name === 'request-ngrx-action').map((c) => c.arg?.['request']);

afterEach(() => {
document.body.innerHTML = '';
});

describe('Store DevTools history controls', () => {
it('pauses recording, jumps to the committed state and commits', async () => {
const { fixture, calls } = await mount({ log: [entry(1)] });
button(fixture, 'Pause recording')!.click();
await settle(fixture);
button(fixture, 'Jump to committed state')!.click();
await settle(fixture);
button(fixture, 'Commit')!.click();
await settle(fixture);
expect(devtoolsCalls(calls)).toEqual([
{ type: 'devtools', op: 'pause', paused: true },
{ type: 'devtools', op: 'jump', index: 0 },
{ type: 'devtools', op: 'commit' },
]);
expect(root(fixture).querySelector('.message')?.textContent).toContain('Done on the page.');
});

it('asks before a reset, and Cancel goes back to the Reset button', async () => {
const { fixture, calls } = await mount({ log: [entry(1)] });
button(fixture, 'Reset…')!.click();
await settle(fixture);
expect(document.activeElement?.textContent?.trim()).toBe('Cancel');
button(fixture, 'Cancel')!.click();
await settle(fixture);
expect(document.activeElement?.textContent?.trim()).toBe('Reset…');
button(fixture, 'Reset…')!.click();
await settle(fixture);
button(fixture, 'Reset history')!.click();
await settle(fixture);
expect(devtoolsCalls(calls)).toEqual([{ type: 'devtools', op: 'reset' }]);
});

it('shows paused recording and skipped actions, and toggles the selected one', async () => {
const { fixture, calls } = await mount({
log: [entry(1), entry(2)],
classic: {
state: {},
devtools: true,
scope: 'root',
recordingPaused: true,
skipped: [1],
},
});
const text = root(fixture).textContent ?? '';
expect(text).toContain('Recording is paused');
expect(text).toContain('1 skipped action is left out of the state.');
expect(button(fixture, 'Resume recording')).toBeDefined();
const items = Array.from(root(fixture).querySelectorAll<HTMLButtonElement>('.log-item'));
const first = items.find((b) => b.textContent?.includes('#1'))!;
expect(first.textContent).toContain('skipped');
first.click();
await settle(fixture);
button(fixture, 'Include this action')!.click();
await settle(fixture);
expect(devtoolsCalls(calls)).toEqual([{ type: 'devtools', op: 'toggle', seq: 1 }]);
});
});

describe('call sites and action frequency', () => {
it('splits a trace frame into its function, file and line', () => {
expect(traceFrame('addItem (src/app/cart.ts:12:5)')).toEqual({
name: 'addItem',
file: 'src/app/cart.ts',
line: 12,
});
expect(traceFrame('src/main.ts:3:1')).toEqual({ name: '', file: 'src/main.ts', line: 3 });
expect(traceFrame('native')).toEqual({ name: 'native' });
});

it('lists where the selected entry came from', async () => {
const { fixture } = await mount({
log: [entry(1, { trace: ['addItem (src/app/cart.ts:12:5)', 'onClick (src/app/x.ts:4:2)'] })],
});
root(fixture).querySelector<HTMLButtonElement>('.log-item')!.click();
await settle(fixture);
const frames = Array.from(root(fixture).querySelectorAll('.trace li')).map((li) =>
li.textContent?.trim(),
);
expect(frames).toEqual(['addItem (src/app/cart.ts:12)', 'onClick (src/app/x.ts:4)']);
});

it('shows how often each action ran and flags an effect loop', async () => {
const { fixture } = await mount({
log: [entry(1)],
stats: [
{
source: 'store',
storeId: 'store',
type: '[Poll] Tick',
count: 40,
effects: 40,
lastAt: 1,
burst: 25,
loop: true,
},
{
source: 'store',
storeId: 'store',
type: '[Cart] Add Item',
count: 1,
lastAt: 1,
burst: 1,
},
{ source: 'signal-store', storeId: 'ngrx-1', type: 'load', count: 3, lastAt: 1, burst: 1 },
],
});
const rows = Array.from(root(fixture).querySelectorAll('.stats tbody tr')).map((tr) =>
Array.from(tr.children).map((c) => c.textContent?.trim()),
);
expect(rows).toEqual([
['[Poll] Tick Possible effect loop', '40', 'n/a', 'n/a', '25'],
['[Cart] Add Item', '1', 'n/a', 'n/a', '1'],
]);
expect(root(fixture).textContent).toContain('dispatched 20 or more times within one second');
});

it('marks the paths the newest change wrote in the state tree', async () => {
const { fixture } = await mount({ log: [entry(1)] });
const changed = Array.from(root(fixture).querySelectorAll('app-state-tree .row.changed')).map(
(row) => row.querySelector('.key')?.textContent,
);
expect(changed).toEqual(['0:']);
expect(root(fixture).querySelector('app-state-tree .row .mark')?.textContent).toBe('changed');
});
});
2 changes: 1 addition & 1 deletion app/src/__tests__/store-inspector-focus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('StoreInspector restore focus', () => {
it('focuses the state when restoring the newest action does not pause the store', async () => {
const host = await restoreNewest({ ok: true, paused: false, message: 'Jumped.' });
expect(host.querySelector('.paused')).toBeNull();
expect(document.activeElement).toBe(host.querySelector('pre.tree'));
expect(document.activeElement).toBe(host.querySelector('app-state-tree .tree'));
});

it('focuses "Back to latest" when the restore pauses the store', async () => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/__tests__/store-inspector-redux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('other stores in the store inspector', () => {
await settle(fixture);
const root = fixture.nativeElement as HTMLElement;
expect(root.querySelector('.detail-head h3')?.textContent).toBe('NGXS');
expect(root.querySelector('pre.tree')?.textContent).toContain('booked');
expect(root.querySelector('app-state-tree .tree')?.textContent).toContain('booked');
expect(text(fixture)).toContain('Action log');
// No Store as global, Restore or Dispatch again for a store the panel only reads.
expect(root.querySelector('app-store-global')).toBeNull();
Expand Down
5 changes: 2 additions & 3 deletions app/src/__tests__/store-inspector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ describe('StoreInspector copy', () => {

it('copies the formatted state shown in the panel', async () => {
const { fixture } = await mount([]);
const shown = root(fixture).querySelector('pre.tree')!.textContent;
expect(root(fixture).querySelector('app-state-tree .tree')!.textContent).toContain('items');
copyButton(fixture, 'Copy state')!.click();
await settle(fixture);
expect(copied).toEqual([shown]);
expect(copied[0]).toBe('{\n items: []\n}');
expect(copied).toEqual(['{\n items: []\n}']);
expect(message(fixture)).toBe('Copied.');
});

Expand Down
81 changes: 81 additions & 0 deletions app/src/__tests__/store-state-tree.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { TestBed } from '@angular/core/testing';
import { afterEach, describe, expect, it } from 'vitest';
import { StoreStateTree, childPath, stateRows } from '../pages/store-state-tree';

const state = {
cart: { items: [{ id: 1, name: 'rome' }], total: 3 },
user: { name: 'ada', 'first name': 'Ada' },
when: { '@type': 'Date', value: '2026-01-01T00:00:00.000Z' },
};

afterEach(() => {
document.body.innerHTML = '';
});

describe('stateRows', () => {
it('writes paths the way the change log does', () => {
expect(childPath('', 'cart')).toBe('cart');
expect(childPath('cart', 'items')).toBe('cart.items');
expect(childPath('cart.items', 0)).toBe('cart.items[0]');
expect(childPath('user', 'first name')).toBe('user["first name"]');
});

it('opens the first level, nodes holding a change, and what the user opened', () => {
const plain = stateRows(state).rows.map((r) => r.path);
expect(plain).toEqual([
'cart',
'cart.items',
'cart.total',
'user',
'user.name',
'user["first name"]',
'when',
]);
const changed = stateRows(state, { changed: ['cart.items[0].name'] }).rows;
expect(changed.map((r) => r.path)).toContain('cart.items[0].name');
expect(changed.find((r) => r.path === 'cart.items[0].name')!.changed).toBe(true);
expect(changed.find((r) => r.path === 'cart')!.holdsChange).toBe(true);
const closed = stateRows(state, { closed: new Set(['cart']) }).rows.map((r) => r.path);
expect(closed).not.toContain('cart.items');
// A tagged value is one leaf.
expect(stateRows(state).rows.find((r) => r.path === 'when')).toMatchObject({ node: false });
});

it('narrows to matching keys and values and their parents', () => {
const { rows, matches } = stateRows(state, { query: 'rome' });
expect(rows.map((r) => r.path)).toEqual([
'cart',
'cart.items',
'cart.items[0]',
'cart.items[0].name',
]);
expect(matches).toBe(1);
expect(stateRows(state, { query: 'nothing here' }).rows).toEqual([]);
});
});

describe('StoreStateTree', () => {
it('opens a node, searches and emits the path to copy', async () => {
const fixture = TestBed.createComponent(StoreStateTree);
fixture.componentRef.setInput('value', state);
const copied: string[] = [];
fixture.componentInstance.copied.subscribe((path) => copied.push(path));
await fixture.whenStable();
const el = fixture.nativeElement as HTMLElement;
const items = Array.from(el.querySelectorAll<HTMLButtonElement>('.toggle')).find((b) =>
b.textContent?.includes('items'),
)!;
expect(items.getAttribute('aria-expanded')).toBe('false');
items.click();
await fixture.whenStable();
expect(items.getAttribute('aria-expanded')).toBe('true');
expect(el.querySelector('[aria-label="Copy path cart.items[0]"]')).not.toBeNull();
el.querySelector<HTMLButtonElement>('[aria-label="Copy path cart.total"]')!.click();
expect(copied).toEqual(['cart.total']);
const search = el.querySelector<HTMLInputElement>('input[type="search"]')!;
search.value = 'ada';
search.dispatchEvent(new Event('input'));
await fixture.whenStable();
expect(el.querySelector('.count')?.textContent?.trim()).toBe('2 matches');
});
});
Loading
Loading