// 提示词 / 文本节点的「上游继承文本」(用户报障驱动,2026-11-14)。 // // 用户看到的现象:样式节点连到这两个节点后框里是空的,判断「接收文本 / 二次编辑没做」。 // 实际上数据层一直通(生成时用上游文本),缺的是**节点体不回显**,且一打字就是整段替换。 // 这条 spec 钉的是 DOM 行为(纯函数侧见 tests/inherit-text-test.js): // ① 自己没写字 ⇒ 框里直接显示上游文本,状态条「继承 · 来自 X」; // ② 改一个字 ⇒ 接管,状态条变「已固定」并出现「恢复跟随」; // ③ 点「恢复跟随」⇒ 回到跟随上游; // ④ 未接管时上游改动会跟着变(这是「能接收」的实际含义)。 // // 不带插件:用内置「提示词 → 中继 → 提示词」「提示词 → 文本」两条链,等价于样式节点那条路 //(宿主只看 data.outKind / 节点产出文本,不区分是不是插件)。 // 运行:npm run build && IWB_E2E_SPECS=tests/iwb-inherit-text.spec.js npm run test:e2e const { test, expect } = require('./_pw-coverage') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1440, height: 900 } }) const CFG = { providers: [{ id: 'tuzi', name: '探针', baseUrl: 'https://probe.test/v1', fallbacks: [], genPath: '/images/generations', editPath: '/images/edits', keys: [{ id: 'k1', name: 'k', source: 'literal', value: 'sk-test' }], models: [{ name: 'gpt-image-2', visible: true, default: true }], defaultModel: 'gpt-image-2' }] } const SRC_TEXT = '一只戴墨镜的柴犬,胶片颗粒,冷调高对比' const WS = { workspaces: [{ id: 'ws_i', name: '继承文本', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 140, y: 160, w: 300, h: 200, data: { text: SRC_TEXT } }, { id: 'r1', type: 'relay', x: 520, y: 210, data: {} }, { id: 'p2', type: 'prompt', x: 700, y: 160, w: 300, h: 200, data: {} }, { id: 'p3', type: 'prompt', x: 140, y: 470, w: 300, h: 200, data: { text: '原本文案:夏日海边短片脚本' } }, { id: 't1', type: 'textout', x: 700, y: 470, w: 300, h: 200, data: {} }, ], edges: [ { id: 'e1', from: 'p1', to: 'r1' }, { id: 'e2', from: 'r1', to: 'p2' }, { id: 'e3', from: 'p3', to: 't1' }, ], }], activeId: 'ws_i', rev: 1, } const box = (page, id) => page.locator('[data-node-id="' + id + '"]') // 往受控 textarea 里输入(React 只认原生 setter + input 事件;直接改 value 会被吞) async function typeInto(page, id, text) { await page.evaluate(async (args) => { const el = document.querySelector('[data-node-id="' + args.id + '"] textarea') el.focus() await new Promise((r) => setTimeout(r, 60)) const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set setter.call(el, args.text) el.dispatchEvent(new Event('input', { bubbles: true })) el.blur() }, { id, text }) } test('提示词与文本节点显示上游继承文本,改字即接管、可恢复跟随', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) await page.addInitScript((d) => { if (localStorage.getItem('iwb_inherit_init') === '1') return localStorage.clear() localStorage.setItem('iwb_inherit_init', '1') localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_i') localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) }, { ws: WS, cfg: CFG }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForTimeout(700) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.waitForTimeout(900) // ① 提示词节点(经中继):显示上游文本 + 继承状态条 await expect(box(page, 'p2').locator('textarea'), '提示词节点应显示上游文本,而不是空框').toHaveValue(SRC_TEXT) await expect(box(page, 'p2').locator('.iwb-inherit-tag'), '状态条应标「继承」').toHaveText('继承') await expect(box(page, 'p2').locator('textarea')).toHaveClass(/is-inherited/) // ② 文本节点:同样显示 await expect(box(page, 't1').locator('textarea')).toHaveValue('原本文案:夏日海边短片脚本') await expect(box(page, 't1').locator('.iwb-inherit-tag')).toHaveText('继承') // ③ 未接管时跟随上游:改上游,文本节点跟着变 await typeInto(page, 'p3', '上游改过的文案') await expect(box(page, 't1').locator('textarea'), '未接管时应实时跟随上游').toHaveValue('上游改过的文案') // ④ 在文本节点上改一个字 ⇒ 接管 await typeInto(page, 't1', '上游改过的文案(我加了夜景)') await expect(box(page, 't1').locator('textarea')).toHaveValue('上游改过的文案(我加了夜景)') await expect(box(page, 't1').locator('.iwb-inherit-tag'), '接管后状态条应变「已固定」').toHaveText('已固定') await expect(box(page, 't1').locator('textarea')).not.toHaveClass(/is-inherited/) // ⑤ 接管后再改上游,不再覆盖自己的版本 await typeInto(page, 'p3', '上游又改了一次') await expect(box(page, 't1').locator('textarea'), '已接管的节点不该被上游覆盖').toHaveValue('上游改过的文案(我加了夜景)') // ⑥ 恢复跟随:清空自己的文案,回到上游 await box(page, 't1').locator('.iwb-inherit-reset').click() await expect(box(page, 't1').locator('textarea')).toHaveValue('上游又改了一次') await expect(box(page, 't1').locator('.iwb-inherit-tag')).toHaveText('继承') await expect(box(page, 't1').locator('.iwb-inherit-reset')).toHaveCount(0) expect(errors, '全程不应有页面 JS 异常').toEqual([]) }) // 2026-11-23 用户报障:提示词接了变量节点后,文案没进组合节点(出图却有)。 // 根因是组合侧读 batchSrcText(只看 data.text),继承态提示词 data.text 为空 ⇒ 整路被丢。 // 这里钉 DOM:组合节点要出现这一行,且上游改动要跟着变(组合功能本身不变,只是拿到来源)。 const SRC2 = '组合里应该出现这段文案' const WS2 = { workspaces: [{ id: 'ws_c', name: '继承进组合', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 140, y: 160, w: 300, h: 200, data: { text: SRC2 } }, { id: 'r1', type: 'relay', x: 520, y: 210, data: {} }, { id: 'p2', type: 'prompt', x: 700, y: 160, w: 300, h: 200, data: {} }, { id: 'cb', type: 'combine', x: 1040, y: 160, w: 300, h: 200, data: {} }, ], edges: [ { id: 'c1', from: 'p1', to: 'r1' }, { id: 'c2', from: 'r1', to: 'p2' }, { id: 'c3', from: 'p2', to: 'cb' }, ], }], activeId: 'ws_c', rev: 1, } test('提示词(继承态)的文案会进入组合节点,并跟随上游变化', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) await page.addInitScript((d) => { if (localStorage.getItem('iwb_combine_inherit_init') === '1') return localStorage.clear() localStorage.setItem('iwb_combine_inherit_init', '1') localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_c') localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) }, { ws: WS2, cfg: CFG }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForTimeout(700) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.waitForTimeout(900) // ① 组合节点里应出现继承来的那一行(不是空 + 红字提示) await expect(box(page, 'cb').locator('.iwb-combine-src'), '继承态提示词的文案必须进组合').toHaveCount(1) await expect(box(page, 'cb').locator('.iwb-combine-src')).toContainText(SRC2) await expect(box(page, 'cb').locator('.iwb-err'), '有来源时不应再报「请连接有文本的节点」').toHaveCount(0) // ② 跟随上游:改最上游,组合行同步(提示词未接管) await typeInto(page, 'p1', '上游改过之后的文案') await expect(box(page, 'cb').locator('.iwb-combine-src')).toContainText('上游改过之后的文案') // ③ 提示词接管后,组合用提示词自己的文案 await typeInto(page, 'p2', '提示词自己写的文案') await expect(box(page, 'cb').locator('.iwb-combine-src')).toContainText('提示词自己写的文案') await expect(box(page, 'cb').locator('.iwb-combine-src')).not.toContainText('上游改过之后的文案') expect(errors, '全程不应有页面 JS 异常').toEqual([]) })