test(app): 補齊 isSafeRepoPath/extractBalancedJSON/normalizeText/repairJSONArrayWithAI/格式化函式測試
為可測性 export 三個內部函式(isSafeRepoPath、extractBalancedJSON/extractJSONText、normalizeText)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
fc10ab7266
commit
775cc575ae
+2
-2
@@ -165,7 +165,7 @@ function stripOuterFence(text) {
|
||||
* @param {number} startIndex - 起始掃描索引,應指向 `{` 或 `[`。
|
||||
* @returns {string|null} 配對完整的 JSON 子字串;找不到配對時回傳 `null`。
|
||||
*/
|
||||
function extractBalancedJSON(text, startIndex) {
|
||||
export function extractBalancedJSON(text, startIndex) {
|
||||
const source = String(text);
|
||||
const open = source[startIndex];
|
||||
const close = open === '{' ? '}' : ']';
|
||||
@@ -208,7 +208,7 @@ function extractBalancedJSON(text, startIndex) {
|
||||
* @param {*} text - 可能含有 JSON 的原始內容(會被轉為字串)。
|
||||
* @returns {string} 最可能為合法 JSON 的字串片段,或去 fence 後的原文。
|
||||
*/
|
||||
function extractJSONText(text) {
|
||||
export function extractJSONText(text) {
|
||||
const stripped = stripOuterFence(text);
|
||||
try {
|
||||
JSON.parse(stripped);
|
||||
|
||||
Reference in New Issue
Block a user