From e5ec442500bfeeb2abb3a26ff39300eafe7d7238 Mon Sep 17 00:00:00 2001 From: zoujing Date: Thu, 4 Jun 2026 10:57:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E9=80=A0=E4=BA=86=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=B8=B2=E6=9F=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/test-ParsedValueView-strict.mjs | 43 ++++ scripts/test-longTextCard.mjs | 54 ++++ .../ChatLongAnswer/ParsedValueView.vue | 237 +++++++++--------- .../ChatModule/AnswerComponent/index.vue | 3 +- src/utils/longTextCard.js | 149 ++++------- 5 files changed, 267 insertions(+), 219 deletions(-) create mode 100644 scripts/test-ParsedValueView-strict.mjs create mode 100644 scripts/test-longTextCard.mjs diff --git a/scripts/test-ParsedValueView-strict.mjs b/scripts/test-ParsedValueView-strict.mjs new file mode 100644 index 0000000..32c6c14 --- /dev/null +++ b/scripts/test-ParsedValueView-strict.mjs @@ -0,0 +1,43 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import { resolve } from "node:path"; + +const source = await readFile( + resolve("src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue"), + "utf8" +); + +const forbiddenCompatibilitySnippets = [ + "valueObj.image_url", + "valueObj.image,", + "valueObj.image_id", + "valueObj.content_image", + "valueObj.sopt_name", + "valueObj.name", + "valueObj.title", + "valueObj.sopt_description", + "valueObj.description", + "valueObj.desc", + "valueObj.sopt_longitude", + "valueObj.longitude", + "valueObj.lng", + "valueObj.sopt_latitude", + "valueObj.latitude", + "valueObj.lat", + "valueObj.sopt_tag", + "valueObj.tag", + "valueObj.type", + "value?.questions", + "value?.items", + "value?.list", +]; + +for (const snippet of forbiddenCompatibilitySnippets) { + assert.equal( + source.includes(snippet), + false, + `ParsedValueView should not guess compatibility field: ${snippet}` + ); +} + +console.log("ParsedValueView strict field checks passed"); diff --git a/scripts/test-longTextCard.mjs b/scripts/test-longTextCard.mjs new file mode 100644 index 0000000..9972902 --- /dev/null +++ b/scripts/test-longTextCard.mjs @@ -0,0 +1,54 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import { resolve } from "node:path"; + +const source = await readFile(resolve("src/utils/longTextCard.js"), "utf8"); +const moduleUrl = `data:text/javascript;base64,${Buffer.from(source).toString("base64")}`; +const longTextCard = await import(moduleUrl); + +const { + parseLongTextDisplayValue, + sanitizeLongTextDisplayValue, + hasLongTextDisplayValue, + formatLongTextDisplayValue, +} = longTextCard; + +assert.deepEqual( + parseLongTextDisplayValue('[ "see bridge", "hear water" ]'), + ["see bridge", "hear water"], + "serialized arrays should be parsed for display" +); + +assert.deepEqual( + parseLongTextDisplayValue('{"spot_name":"bridge","spot_longitude:":107.712345}'), + { spot_name: "bridge", "spot_longitude:": 107.712345 }, + "serialized objects should be parsed for display" +); + +assert.deepEqual( + sanitizeLongTextDisplayValue( + { + content: "hidden", + components: ["hidden"], + view_section_items: '[ "check piers", "count arches" ]', + nested: { + title: "keep", + }, + }, + ["content", "components"] + ), + { + view_section_items: ["check piers", "count arches"], + nested: { + title: "keep", + }, + }, + "sanitizing should parse JSON-like strings and ignore configured keys" +); + +assert.equal(hasLongTextDisplayValue('["follow up"]'), true); +assert.equal(hasLongTextDisplayValue({ a: "", b: [" ", null] }), false); +assert.equal(formatLongTextDisplayValue(true), "\u662f"); +assert.equal(formatLongTextDisplayValue({ title: "bridge" }), '{"title":"bridge"}'); + +console.log("longTextCard display helpers passed"); diff --git a/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue b/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue index 7a76361..aa0f706 100644 --- a/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue +++ b/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue @@ -1,52 +1,53 @@