fix(harness): bound empty hook prompts · openclaw/openclaw@692c7e7
vincentkoc
·
2026-06-21
·
via Recent Commits to openclaw:main
File tree
extensions/codex/src/app-server
| Original file line number | Diff line number | Diff line change |
|---|
@@ -295,6 +295,18 @@ describe("projectContextEngineAssemblyForCodex", () => {
|
295 | 295 | expect(fitted).not.toContain("hook context"); |
296 | 296 | }); |
297 | 297 | |
| 298 | +it("bounds hook output for an empty original input", () => { |
| 299 | +const maxChars = 420; |
| 300 | +const fitted = fitCodexProjectedContextForTurnStart({ |
| 301 | +promptText: `hook context ${"h".repeat(800)} hook tail`, |
| 302 | +preservedRange: { start: 0, end: 0 }, |
| 303 | + maxChars, |
| 304 | +}); |
| 305 | + |
| 306 | +expect(fitted.length).toBeLessThanOrEqual(maxChars); |
| 307 | +expect(fitted).toContain("hook tail"); |
| 308 | +}); |
| 309 | + |
298 | 310 | it("bounds output for a large request under the default Codex turn limit", () => { |
299 | 311 | const maxChars = CODEX_TURN_START_TEXT_INPUT_MAX_CHARS; |
300 | 312 | // A large assembled header prefix already over the cap forces the |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -142,6 +142,9 @@ export function fitCodexProjectedContextForTurnStart(params: {
|
142 | 142 | return params.promptText; |
143 | 143 | } |
144 | 144 | const preservedText = params.promptText.slice(preservedRange.start, preservedRange.end); |
| 145 | +if (!preservedText) { |
| 146 | +return truncateOlderContext(params.promptText, maxChars); |
| 147 | +} |
145 | 148 | if (preservedText.length >= maxChars) { |
146 | 149 | return truncateOlderContext(preservedText, maxChars); |
147 | 150 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -567,6 +567,34 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
|
567 | 567 | await run; |
568 | 568 | }); |
569 | 569 | |
| 570 | +it("bounds hook-appended output for an empty prompt without an active context engine", async () => { |
| 571 | +initializeGlobalHookRunner( |
| 572 | +createMockPluginRegistry([ |
| 573 | +{ |
| 574 | +hookName: "before_prompt_build", |
| 575 | +handler: async () => ({ |
| 576 | +appendContext: `hook context ${"h".repeat(1_100_000)} hook tail`, |
| 577 | +}), |
| 578 | +}, |
| 579 | +]), |
| 580 | +); |
| 581 | +const sessionFile = path.join(tempDir, "session.jsonl"); |
| 582 | +const workspaceDir = path.join(tempDir, "workspace"); |
| 583 | +const harness = createStartedThreadHarness(); |
| 584 | +const params = createParams(sessionFile, workspaceDir); |
| 585 | +params.prompt = ""; |
| 586 | + |
| 587 | +const run = runCodexAppServerAttempt(params); |
| 588 | +await harness.waitForMethod("turn/start"); |
| 589 | + |
| 590 | +const inputText = getRequestInputText(harness); |
| 591 | +expect(inputText.length).toBeLessThanOrEqual(CODEX_TURN_START_TEXT_INPUT_MAX_CHARS); |
| 592 | +expect(inputText).toContain("hook tail"); |
| 593 | + |
| 594 | +await harness.completeTurn(); |
| 595 | +await run; |
| 596 | +}); |
| 597 | + |
570 | 598 | it("uses configured compaction reserve when sizing Codex context-engine projections", async () => { |
571 | 599 | const sessionFile = path.join(tempDir, "session.jsonl"); |
572 | 600 | const workspaceDir = path.join(tempDir, "workspace"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -99,14 +99,10 @@ export async function resolveAgentHarnessBeforePromptBuildResult(params: {
|
99 | 99 | wrapPluginSystemContextSection(promptBuildResult?.appendSystemContext), |
100 | 100 | wrapPluginSystemContextSection(beforeAgentStartResult?.appendSystemContext), |
101 | 101 | ]) ?? systemPrompt, |
102 | | - ...(params.prompt |
103 | | - ? { |
104 | | -promptInputRange: { |
105 | | -start: promptInputStart, |
106 | | -end: promptInputStart + params.prompt.length, |
107 | | -}, |
108 | | -} |
109 | | - : {}), |
| 102 | +promptInputRange: { |
| 103 | +start: promptInputStart, |
| 104 | +end: promptInputStart + params.prompt.length, |
| 105 | +}, |
110 | 106 | }; |
111 | 107 | } |
112 | 108 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。