fix(codex-supervisor): centralize session limit parsing · openclaw/openclaw@3416edf
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
File tree
extensions/codex-supervisor/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -123,6 +123,18 @@ describe("createCodexSupervisorTools", () => {
|
123 | 123 | max_stored_sessions: 1001, |
124 | 124 | }), |
125 | 125 | ).rejects.toThrow("max_stored_sessions must be between 1 and 1000"); |
| 126 | +await expect( |
| 127 | +toolByName(tools, "codex_sessions_list").execute("call-2", { |
| 128 | +include_stored: true, |
| 129 | +max_stored_sessions: null, |
| 130 | +}), |
| 131 | +).rejects.toThrow("max_stored_sessions must be an integer"); |
| 132 | +await expect( |
| 133 | +toolByName(tools, "codex_sessions_list").execute("call-3", { |
| 134 | +include_stored: true, |
| 135 | +max_stored_sessions: Number.MAX_SAFE_INTEGER + 1, |
| 136 | +}), |
| 137 | +).rejects.toThrow("max_stored_sessions must be between 1 and 1000"); |
126 | 138 | }); |
127 | 139 | |
128 | 140 | it("allows trusted read and write tools when policy enables them", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { jsonResult, readStringParam, type AnyAgentTool } from "openclaw/plugin-sdk/core"; |
| 2 | +import { asSafeIntegerInRange } from "openclaw/plugin-sdk/number-runtime"; |
2 | 3 | import { Type } from "typebox"; |
3 | 4 | import { |
4 | 5 | redactCodexSupervisorEndpoint, |
@@ -73,13 +74,14 @@ function readIntegerParam(params: Record<string, unknown>, key: string): number
|
73 | 74 | if (value === undefined) { |
74 | 75 | return undefined; |
75 | 76 | } |
76 | | -if (typeof value !== "number" || !Number.isInteger(value)) { |
| 77 | +const integer = asSafeIntegerInRange(value, { min: 1, max: 1000 }); |
| 78 | +if (integer === undefined) { |
| 79 | +if (typeof value === "number" && Number.isInteger(value)) { |
| 80 | +throw new Error(`${key} must be between 1 and 1000`); |
| 81 | +} |
77 | 82 | throw new Error(`${key} must be an integer`); |
78 | 83 | } |
79 | | -if (value < 1 || value > 1000) { |
80 | | -throw new Error(`${key} must be between 1 and 1000`); |
81 | | -} |
82 | | -return value; |
| 84 | +return integer; |
83 | 85 | } |
84 | 86 | |
85 | 87 | function readModeParam(params: Record<string, unknown>): CodexSupervisorTurnMode | undefined { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@
|
2 | 2 | |
3 | 3 | export { |
4 | 4 | asFiniteNumberInRange, |
| 5 | +asSafeIntegerInRange, |
5 | 6 | parseFiniteNumber, |
6 | 7 | clampTimerTimeoutMs, |
7 | 8 | resolveTimerTimeoutMs, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。