fix: validate memory get ranges · openclaw/openclaw@3617539
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -74,8 +74,8 @@ const MemoryGetSchema = {
|
74 | 74 | type: "object", |
75 | 75 | properties: { |
76 | 76 | path: { type: "string" }, |
77 | | -from: { type: "number" }, |
78 | | -lines: { type: "number" }, |
| 77 | +from: { type: "integer", minimum: 1 }, |
| 78 | +lines: { type: "integer", minimum: 1 }, |
79 | 79 | corpus: { type: "string", enum: ["memory", "wiki", "all"] }, |
80 | 80 | }, |
81 | 81 | required: ["path"], |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -207,6 +207,21 @@ describe("memory tools", () => {
|
207 | 207 | expect(getMemorySearchManagerMockCalls()).toBe(0); |
208 | 208 | }); |
209 | 209 | |
| 210 | +it("rejects fractional memory_get ranges before reading files", async () => { |
| 211 | +setMemoryBackend("builtin"); |
| 212 | +const tool = createMemoryGetToolOrThrow(); |
| 213 | + |
| 214 | +await expect( |
| 215 | +tool.execute("call_fractional_range", { |
| 216 | +path: "memory/2026-02-19.md", |
| 217 | +from: 1.5, |
| 218 | +lines: 2, |
| 219 | +}), |
| 220 | +).rejects.toThrow("from must be a positive integer"); |
| 221 | +expect(getReadAgentMemoryFileMockCalls()).toBe(0); |
| 222 | +expect(getMemorySearchManagerMockCalls()).toBe(0); |
| 223 | +}); |
| 224 | + |
210 | 225 | it("returns truncation metadata and a continuation notice for partial memory_get results", async () => { |
211 | 226 | setMemoryBackend("builtin"); |
212 | 227 | setMemoryReadFileImpl(async (params: MemoryReadParams) => ({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,8 @@ export const MemorySearchSchema = Type.Object({
|
37 | 37 | |
38 | 38 | export const MemoryGetSchema = Type.Object({ |
39 | 39 | path: Type.String(), |
40 | | -from: Type.Optional(Type.Number()), |
41 | | -lines: Type.Optional(Type.Number()), |
| 40 | +from: Type.Optional(Type.Integer()), |
| 41 | +lines: Type.Optional(Type.Integer()), |
42 | 42 | corpus: Type.Optional(stringEnum(["memory", "wiki", "all"])), |
43 | 43 | }); |
44 | 44 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import {
|
4 | 4 | asToolParamsRecord, |
5 | 5 | jsonResult, |
6 | 6 | readNumberParam, |
| 7 | +readPositiveIntegerParam, |
7 | 8 | readStringParam, |
8 | 9 | type MemoryCorpusSearchResult, |
9 | 10 | type OpenClawConfig, |
@@ -443,8 +444,8 @@ export function createMemoryGetTool(options: {
|
443 | 444 | async (_toolCallId, params) => { |
444 | 445 | const rawParams = asToolParamsRecord(params); |
445 | 446 | const relPath = readStringParam(rawParams, "path", { required: true }); |
446 | | -const from = readNumberParam(rawParams, "from", { integer: true }); |
447 | | -const lines = readNumberParam(rawParams, "lines", { integer: true }); |
| 447 | +const from = readPositiveIntegerParam(rawParams, "from"); |
| 448 | +const lines = readPositiveIntegerParam(rawParams, "lines"); |
448 | 449 | const requestedCorpus = readStringParam(rawParams, "corpus") as |
449 | 450 | | "memory" |
450 | 451 | | "wiki" |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ export {
|
8 | 8 | asToolParamsRecord, |
9 | 9 | jsonResult, |
10 | 10 | readNumberParam, |
| 11 | +readPositiveIntegerParam, |
11 | 12 | readStringParam, |
12 | 13 | type AnyAgentTool, |
13 | 14 | } from "../agents/tools/common.js"; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。