Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ in the DevTools Elements panel (if any).
- **id** (number) **(required)**: The ID for the class, obtained from details.
- **filterName** (enum: "objectsRetainedByDetachedDomNodes", "objectsRetainedByConsole", "objectsRetainedByEventHandlers", "objectsRetainedByContexts", "sharedNativeContext", "noNativeContext", "attributedToSpecificNativeContext") _(optional)_: An optional filter to apply to the nodes.
- **objectId** (number) _(optional)_: The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.
- **pageIdx** (number) _(optional)_: The page index for pagination.
- **pageSize** (number) _(optional)_: The page size for pagination.
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
- **pageSize** (integer) _(optional)_: Maximum number of items to return. When omitted, returns all items.

---

Expand All @@ -501,8 +501,8 @@ in the DevTools Elements panel (if any).
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
- **filterName** (enum: "objectsRetainedByDetachedDomNodes", "objectsRetainedByConsole", "objectsRetainedByEventHandlers", "objectsRetainedByContexts", "sharedNativeContext", "noNativeContext", "attributedToSpecificNativeContext") _(optional)_: An optional filter to apply to the aggregates.
- **objectId** (number) _(optional)_: The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.
- **pageIdx** (number) _(optional)_: The page index for pagination of aggregates.
- **pageSize** (number) _(optional)_: The page size for pagination of aggregates.
- **pageIdx** (integer) _(optional)_: Page number of aggregates to return (0-based). When omitted, returns the first page.
- **pageSize** (integer) _(optional)_: Maximum number of aggregates to return. When omitted, returns all aggregates.

---

Expand All @@ -524,8 +524,8 @@ in the DevTools Elements panel (if any).
**Parameters:**

- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
- **pageIdx** (number) _(optional)_: The page index for pagination.
- **pageSize** (number) _(optional)_: The page size for pagination.
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
- **pageSize** (integer) _(optional)_: Maximum number of items to return. When omitted, returns all items.

---

Expand All @@ -537,8 +537,8 @@ in the DevTools Elements panel (if any).

- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
- **nodeId** (number) **(required)**: The node ID to get outgoing edges for.
- **pageIdx** (number) _(optional)_: The page index for pagination.
- **pageSize** (number) _(optional)_: The page size for pagination.
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
- **pageSize** (integer) _(optional)_: Maximum number of items to return. When omitted, returns all items.

---

Expand All @@ -561,8 +561,8 @@ in the DevTools Elements panel (if any).

- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
- **nodeId** (number) **(required)**: The node ID to get retainers for.
- **pageIdx** (number) _(optional)_: The page index for pagination.
- **pageSize** (number) _(optional)_: The page size for pagination.
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
- **pageSize** (integer) _(optional)_: Maximum number of items to return. When omitted, returns all items.

---

Expand Down
50 changes: 30 additions & 20 deletions src/bin/chrome-devtools-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,16 @@ export const commands: Commands = {
},
pageIdx: {
name: 'pageIdx',
type: 'number',
description: 'The page index for pagination.',
type: 'integer',
description:
'Page number to return (0-based). When omitted, returns the first page.',
required: false,
},
pageSize: {
name: 'pageSize',
type: 'number',
description: 'The page size for pagination.',
type: 'integer',
description:
'Maximum number of items to return. When omitted, returns all items.',
required: false,
},
},
Expand Down Expand Up @@ -420,14 +422,16 @@ export const commands: Commands = {
},
pageIdx: {
name: 'pageIdx',
type: 'number',
description: 'The page index for pagination of aggregates.',
type: 'integer',
description:
'Page number of aggregates to return (0-based). When omitted, returns the first page.',
required: false,
},
pageSize: {
name: 'pageSize',
type: 'number',
description: 'The page size for pagination of aggregates.',
type: 'integer',
description:
'Maximum number of aggregates to return. When omitted, returns all aggregates.',
required: false,
},
},
Expand Down Expand Up @@ -464,14 +468,16 @@ export const commands: Commands = {
},
pageIdx: {
name: 'pageIdx',
type: 'number',
description: 'The page index for pagination.',
type: 'integer',
description:
'Page number to return (0-based). When omitted, returns the first page.',
required: false,
},
pageSize: {
name: 'pageSize',
type: 'number',
description: 'The page size for pagination.',
type: 'integer',
description:
'Maximum number of items to return. When omitted, returns all items.',
required: false,
},
},
Expand All @@ -495,14 +501,16 @@ export const commands: Commands = {
},
pageIdx: {
name: 'pageIdx',
type: 'number',
description: 'The page index for pagination.',
type: 'integer',
description:
'Page number to return (0-based). When omitted, returns the first page.',
required: false,
},
pageSize: {
name: 'pageSize',
type: 'number',
description: 'The page size for pagination.',
type: 'integer',
description:
'Maximum number of items to return. When omitted, returns all items.',
required: false,
},
},
Expand Down Expand Up @@ -545,14 +553,16 @@ export const commands: Commands = {
},
pageIdx: {
name: 'pageIdx',
type: 'number',
description: 'The page index for pagination.',
type: 'integer',
description:
'Page number to return (0-based). When omitted, returns the first page.',
required: false,
},
pageSize: {
name: 'pageSize',
type: 'number',
description: 'The page size for pagination.',
type: 'integer',
description:
'Maximum number of items to return. When omitted, returns all items.',
required: false,
},
},
Expand Down
84 changes: 74 additions & 10 deletions src/tools/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ export const getHeapSnapshotDetails = defineTool({
),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe('The page index for pagination of aggregates.'),
.describe(
'Page number of aggregates to return (0-based). When omitted, returns the first page.',
),
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe('The page size for pagination of aggregates.'),
.describe(
'Maximum number of aggregates to return. When omitted, returns all aggregates.',
),
},
blockedByDialog: false,
verifyFilesSchema: ['filePath'],
Expand Down Expand Up @@ -143,8 +151,22 @@ export const getHeapSnapshotClassNodes = defineTool({
.describe(
'The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.',
),
pageIdx: zod.number().optional().describe('The page index for pagination.'),
pageSize: zod.number().optional().describe('The page size for pagination.'),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe(
'Page number to return (0-based). When omitted, returns the first page.',
),
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe(
'Maximum number of items to return. When omitted, returns all items.',
),
},
blockedByDialog: false,
verifyFilesSchema: ['filePath'],
Expand Down Expand Up @@ -177,8 +199,22 @@ export const getHeapSnapshotRetainers = defineTool({
schema: {
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
nodeId: zod.number().describe('The node ID to get retainers for.'),
pageIdx: zod.number().optional().describe('The page index for pagination.'),
pageSize: zod.number().optional().describe('The page size for pagination.'),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe(
'Page number to return (0-based). When omitted, returns the first page.',
),
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe(
'Maximum number of items to return. When omitted, returns all items.',
),
},
handler: async (request, response, context) => {
const retainers = await context.getHeapSnapshotRetainers(
Expand Down Expand Up @@ -276,8 +312,22 @@ export const getHeapSnapshotEdges = defineTool({
schema: {
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
nodeId: zod.number().describe('The node ID to get outgoing edges for.'),
pageIdx: zod.number().optional().describe('The page index for pagination.'),
pageSize: zod.number().optional().describe('The page size for pagination.'),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe(
'Page number to return (0-based). When omitted, returns the first page.',
),
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe(
'Maximum number of items to return. When omitted, returns all items.',
),
},
handler: async (request, response, context) => {
const edges = await context.getHeapSnapshotEdges(
Expand Down Expand Up @@ -375,8 +425,22 @@ export const getHeapSnapshotDuplicateStrings = defineTool({
verifyFilesSchema: ['filePath'],
schema: {
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
pageIdx: zod.number().optional().describe('The page index for pagination.'),
pageSize: zod.number().optional().describe('The page size for pagination.'),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe(
'Page number to return (0-based). When omitted, returns the first page.',
),
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe(
'Maximum number of items to return. When omitted, returns all items.',
),
},
handler: async (request, response, context) => {
const duplicateStrings = await context.getHeapSnapshotDuplicateStrings(
Expand Down
44 changes: 44 additions & 0 deletions tests/tools/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,48 @@ describe('memory', () => {
});
});
});

describe('pagination schemas', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test technically tests the zod, so we can remove it.

const paginatedTools = [
getHeapSnapshotDetails,
getHeapSnapshotClassNodes,
getHeapSnapshotRetainers,
getHeapSnapshotEdges,
getHeapSnapshotDuplicateStrings,
];

it('rejects a non-positive pageSize', () => {
for (const tool of paginatedTools) {
for (const pageSize of [0, -1, 1.5]) {
assert.strictEqual(
tool.schema.pageSize.safeParse(pageSize).success,
false,
`${tool.name} should reject pageSize ${pageSize}`,
);
}
assert.strictEqual(tool.schema.pageSize.safeParse(1).success, true);
assert.strictEqual(
tool.schema.pageSize.safeParse(undefined).success,
true,
);
}
});

it('rejects a negative or non-integer pageIdx', () => {
for (const tool of paginatedTools) {
for (const pageIdx of [-1, 0.5]) {
assert.strictEqual(
tool.schema.pageIdx.safeParse(pageIdx).success,
false,
`${tool.name} should reject pageIdx ${pageIdx}`,
);
}
assert.strictEqual(tool.schema.pageIdx.safeParse(0).success, true);
assert.strictEqual(
tool.schema.pageIdx.safeParse(undefined).success,
true,
);
}
});
});
});
Loading