diff --git a/tools/negotiation-section.mjs b/tools/negotiation-section.mjs index 082e9f5..80fdf95 100644 --- a/tools/negotiation-section.mjs +++ b/tools/negotiation-section.mjs @@ -33,3 +33,13 @@ function extractAddressee(body, label) { const mm = String(body || '').match(re); return mm ? mm[1].trim() : ''; } + +/** SP2d: контроллер просит арбитраж на ЛЮБОМ круге — маркер `**Арбитраж:** <причина>` в + * артефакте (раздел «Переговоры»). Возвращает причину (truthy) или '' если маркера нет. + * Карточка арбитража показывается при этом маркере независимо от круга (потолок ≤3 остаётся). */ +export function arbitrationRequested(md) { + const text = typeof md === 'string' ? md : ''; + const m = text.match(/\*\*Арбитраж:\*\*\s*([^\n]*)/i); + if (!m) return ''; + return m[1].trim() || 'арбитраж запрошен контроллером'; +} diff --git a/tools/negotiation-section.test.mjs b/tools/negotiation-section.test.mjs index 0773764..202c58b 100644 --- a/tools/negotiation-section.test.mjs +++ b/tools/negotiation-section.test.mjs @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { parseNegotiationSection } from './negotiation-section.mjs'; +import { parseNegotiationSection, arbitrationRequested } from './negotiation-section.mjs'; const PLAN = `# План ## Цель @@ -41,3 +41,18 @@ describe('parseNegotiationSection', () => { expect(parseNegotiationSection(null)).toEqual([]); }); }); + +describe('arbitrationRequested (SP2d)', () => { + it('нет маркера → пусто', () => { + expect(arbitrationRequested('# План\n## Переговоры\n### Круг 1\n**Судье:** x')).toBe(''); + }); + it('маркер с причиной → причина', () => { + expect(arbitrationRequested('## Переговоры\n**Арбитраж:** тупик по §4')).toBe('тупик по §4'); + }); + it('маркер без причины → truthy (дефолт)', () => { + expect(arbitrationRequested('**Арбитраж:**')).toBeTruthy(); + }); + it('не строка → пусто', () => { + expect(arbitrationRequested(null)).toBe(''); + }); +});