diff --git a/scripts/agents/planner.agent.js b/scripts/agents/planner.agent.js index fa47abb9..41d83474 100644 --- a/scripts/agents/planner.agent.js +++ b/scripts/agents/planner.agent.js @@ -257,12 +257,19 @@ function generatePlan(context) { **Confidence:** ${context.projectAssignment.confidence} **Reason:** ${context.projectAssignment.reason} `; - return plan.replace( - /---\r?\n\*\*Generated by Planner Agent\*\*.*/, - `${projectSection.trimStart()} ---- -**Generated by Planner Agent** `, - ); + const marker = ""; + const markerIndex = plan.indexOf(marker); + if (markerIndex !== -1) { + const footerIndex = plan.lastIndexOf("---", markerIndex); + if (footerIndex !== -1) { + return ( + plan.slice(0, footerIndex) + + projectSection.trimStart() + + "\n" + + plan.slice(footerIndex) + ); + } + } } return plan; diff --git a/tests/jest.setup.localstorage.js b/tests/jest.setup.localstorage.js index 8c07bf7b..4f41e7e8 100644 --- a/tests/jest.setup.localstorage.js +++ b/tests/jest.setup.localstorage.js @@ -1,10 +1,10 @@ /** - * Jest Setup: localStorage polyfill - * Provides localStorage mock for jsdom test environment + * Jest Setup: Node.js built-ins polyfill + * Provides polyfills for Node.js built-ins in jsdom test environment * - * @fileoverview localStorage polyfill for jest/jsdom tests + * @fileoverview Built-ins polyfills for jest/jsdom tests * @author LightSpeedWP Team - * @version 1.0.0 + * @version 1.1.0 */ // Polyfill TextDecoder and TextEncoder for test environments that don't have them @@ -24,3 +24,17 @@ if (typeof global.localStorage === "undefined") { }; global.localStorage = localStorageMock; } + +// Polyfill TextDecoder and TextEncoder for ESM modules using @actions/core +if ( + typeof global.TextDecoder === "undefined" || + typeof global.TextEncoder === "undefined" +) { + const { TextDecoder, TextEncoder } = require("util"); + if (typeof global.TextDecoder === "undefined") { + global.TextDecoder = TextDecoder; + } + if (typeof global.TextEncoder === "undefined") { + global.TextEncoder = TextEncoder; + } +}