Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(desktop): 修 composer 胶囊间距用例的脆弱正则 (#867)

Dash05330547ffe6
diff --git a/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx b/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
index 47809c8b40..c4e1e0e821 100644
--- a/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
@@ -80,8 +80,10 @@ function ComposerHarness({ onEditor }: { onEditor?: (editor: Editor) => void })
describe('composer atomic chip presentation', () => {
it('aligns selected-text quotes and every other atom to the same text baseline', () => {
+ // 规则体用 [^}] 界定,不假设 `}` 前面正好是换行:CSS 声明里不会出现 `}`,
+ // 所以缩进或换行风格调整不会再让这条断言失配(同下面那条间距用例)。
const alignmentRule = globalsSource.match(
- /\.ProseMirror :is\(\[data-mention-chip\], \[data-pasted-text-chip\], \[data-composer-quote\]\) \{([\s\S]*?)\n\}/,
+ /\.ProseMirror :is\(\[data-mention-chip\], \[data-pasted-text-chip\], \[data-composer-quote\]\)\s*\{([^}]*)\}/,
)?.[1];
expect(alignmentRule).toContain('position: relative');
@@ -89,10 +91,28 @@ describe('composer atomic chip presentation', () => {
});
it('keeps the caret and prose 4px away from every composer pill', () => {
- const gapRule = globalsSource.match(
- /\.ProseMirror :is\(\s*\[data-mention-chip\],\s*\[data-pasted-text-chip\],\s*\[data-composer-quote\],\s*\.ghost-cmd-pill,\s*\.slash-cmd-pill\s*\) \{([\s\S]*?)\n\}/,
- )?.[1];
-
+ // 按「规则体设了 margin-inline」定位这条共用外间距规则,而不是把整份选择器
+ // 列表写死:这条 :is() 是所有 composer 胶囊共用的,新增胶囊时会往列表里加成员
+ // (如 #599 的 .quick-start-pill)。写死完整列表会让那类改动把断言变成
+ // gapRule === undefined,报出与本意无关的 "undefined and string" 断言错误。
+ const gapRuleMatch = [
+ ...globalsSource.matchAll(/\.ProseMirror :is\(([^)]*)\)\s*\{([^}]*)\}/g),
+ ].find(([, , body]) => body.includes('margin-inline'));
+ const [, gapSelectors, gapRule] = gapRuleMatch ?? [];
+
+ // 已知胶囊必须都在共用列表里(防的是「某个胶囊被漏掉」,而不是列表长度)。
+ // 新增胶囊时把它加进这份清单,用例才真的覆盖「每一个 composer 胶囊」。
+ expect(gapSelectors).toBeDefined();
+ for (const pill of [
+ '[data-mention-chip]',
+ '[data-pasted-text-chip]',
+ '[data-composer-quote]',
+ '.ghost-cmd-pill',
+ '.slash-cmd-pill',
+ '.quick-start-pill',
+ ]) {
+ expect(gapSelectors).toContain(pill);
+ }
expect(gapRule).toContain('margin-inline: 4px');
});