// Tests for WAF/LAF/LEK format detection (KAR-920/P5.3). Synthetic
// sheet-name/header-text fixtures only — no real BMW file content (see // allow-customer-string
// module header for the server-only real-file smoke check, not committed).
//
// KAR-920 adversarial-review fix (10.07.2026, F1 BLOCKING + F2): the original
// version of this file tested a row-BLOB substring match (join every
// header-region cell / every sheet name into one string, then substring
// search). The reviewer's PoC showed that design rejects a genuine QAF
// (F1: a Prämissen free-text sentence merely MENTIONING a signature phrase)
// and lets two unrelated sheet names assemble a signature across their join
// boundary (F2). The fix (see foreign-form-detection.ts module header) is
// cell-bound matching + a ≥2-independent-cell-hit requirement for the
// header-region path. Tests below are updated accordingly: several
// single-occurrence fixtures now need 2 occurrences to still detect (a real
// form title repeats — verified on the real WAF_de.xlsm sample), and the
// former "split-across-cells detects" test is INVERTED into a
// false-positive-guard test — join-assembled signatures must never detect
// (that was itself the F1/F2 bug pattern, not a real-file shape).

import { describe, expect, it } from 'vitest'
import ExcelJS from 'exceljs'
import {
  detectForeignForm,
  foreignFormWorkbookFromExcelJs,
  HEADER_SCAN_ROWS,
  type ForeignFormWorkbook,
} from '../foreign-form-detection'

/** Build a synthetic ForeignFormWorkbook from a plain { sheetName: headerRow
 * text[] } map — mirrors g60/parser.ts's workbookFromSheets test helper. */
function workbookFromHeaders(sheets: Record<string, readonly string[]>): ForeignFormWorkbook {
  return {
    sheetNames: Object.keys(sheets),
    headerRegionText: (name) => sheets[name] ?? [],
  }
}

describe('detectForeignForm — LEK signatures', () => {
  it('detects LEK via the "LEK COST BREAK-DOWN" header-region title repeated across 2 cells (teil3.md:201 [78])', () => {
    // Real form titles repeat across merged-cell segments (verified on the
    // real WAF_de.xlsm sample) — a single occurrence is deliberately NOT
    // enough post-fix (see MIN_HEADER_CELL_HITS in foreign-form-detection.ts).
    const wb = workbookFromHeaders({
      'Cost Break-Down': ['LEK COST BREAK-DOWN', 'LEK COST BREAK-DOWN', 'Seite 2 von 4'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('LEK')
    expect(hit?.matchedLabel).toBe('LEK COST BREAK-DOWN')
    expect(hit?.source).toContain('teil3.md:201')
  })

  it('detects LEK via the "Zahlungsplan LEK Allgemein" header-region title repeated across 2 cells (teil3.md:171 [76])', () => {
    const wb = workbookFromHeaders({
      Zahlungsplan: ['Zahlungsplan LEK Allgemein', 'Zahlungsplan LEK Allgemein', 'Vergabeumfang'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('LEK')
    expect(hit?.matchedLabel).toBe('Zahlungsplan LEK Allgemein')
  })

  it('does NOT detect a signature that only exists by joining unrelated adjacent cells (KAR-920 F1/F2 adversarial-review fix: this WAS a false positive pre-fix)', () => {
    // 'LEK' | 'COST' | 'BREAK-DOWN' as 3 SEPARATE cells: none of them
    // individually contains the full "LEK COST BREAK DOWN" pattern — the
    // pre-fix row-blob join used to assemble it across cell boundaries.
    const wb = workbookFromHeaders({ Sheet1: ['LEK', 'COST', 'BREAK-DOWN'] })
    expect(detectForeignForm(wb)).toBeNull()
  })
})

describe('detectForeignForm — LAF signatures', () => {
  it('detects LAF via "Logistikkosten Analyse Formular" repeated across 2 cells (teil3.md:13 [67])', () => {
    // Rider fix (PR #293 Sev 30): isCloseCellMatch is now exact-after-
    // normalization — the title cell contains exactly the phrase, the
    // surrounding "LAF (...)"/version text sits in SEPARATE, non-matching
    // cells (real form layouts split a compound header across adjacent
    // cells; only the phrase-only cell needs to match).
    const wb = workbookFromHeaders({
      Packaging: ['LAF', 'Logistikkosten Analyse Formular', 'Logistikkosten Analyse Formular', 'Version LAF 6.2_06_01'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('LAF')
    expect(hit?.matchedLabel).toBe('Logistikkosten Analyse Formular')
    expect(hit?.source).toContain('teil3.md:13')
  })

  it('detects LAF via "Lieferantenvorverpackung - LVP" repeated across 2 cells (teil3.md:127 [73])', () => {
    const wb = workbookFromHeaders({
      LVP: ['Lieferantenvorverpackung - LVP', 'Lieferantenvorverpackung - LVP', 'LAF, Seite 3 von 4'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('LAF')
    expect(hit?.matchedLabel).toBe('Lieferantenvorverpackung - LVP')
  })
})

describe('detectForeignForm — WAF signatures', () => {
  it('detects WAF via "Werkzeug Analyse Formular" repeated across 2 cells (teil3.md:254 [80])', () => {
    const wb = workbookFromHeaders({
      Analyse: ['BMW Group', 'Werkzeug Analyse Formular', 'Werkzeug Analyse Formular', 'Sprache'], // allow-customer-string
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('WAF')
    expect(hit?.matchedLabel).toBe('Werkzeug Analyse Formular')
    expect(hit?.source).toContain('teil3.md:254')
  })

  it('detects WAF via the repeated-title real-file shape (WAF_de.xlsm smoke check: "Werkzeug Analyse Formular" repeated across 12 adjacent title cells)', () => {
    const repeated = Array.from({ length: 12 }, () => 'Werkzeug Analyse Formular')
    const wb = workbookFromHeaders({ Analyse: repeated })
    expect(detectForeignForm(wb)?.kind).toBe('WAF')
  })

  it('detects WAF via the compound-word variant "Werkzeuganalyseformular" repeated across 2 cells (teil3.md:334 [84])', () => {
    // Rider fix (PR #293 Sev 30): exact-match cell — "Das " sits in a
    // separate title-prefix cell, not prepended to the matching cell itself.
    const wb = workbookFromHeaders({ Sheet1: ['Das', 'Werkzeuganalyseformular', 'Werkzeuganalyseformular'] })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('WAF')
    expect(hit?.matchedLabel).toBe('Werkzeuganalyseformular')
  })
})

describe('detectForeignForm — MIN_HEADER_CELL_HITS boundary (KAR-920 F1 fix)', () => {
  it('does NOT detect with exactly 1 qualifying header-region cell hit', () => {
    const wb = workbookFromHeaders({ Analyse: ['Werkzeug Analyse Formular'] })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('detects with exactly 2 qualifying header-region cell hits (the minimum)', () => {
    const wb = workbookFromHeaders({ Analyse: ['Werkzeug Analyse Formular', 'Werkzeug Analyse Formular'] })
    expect(detectForeignForm(wb)?.kind).toBe('WAF')
  })
})

describe('detectForeignForm — matches via sheet (tab) name too, not just header text', () => {
  it('detects a signature that appears as the worksheet tab name itself (single hit is sufficient for the sheet-name path)', () => {
    const wb = workbookFromHeaders({ 'LEK COST BREAK-DOWN': [] })
    expect(detectForeignForm(wb)?.kind).toBe('LEK')
  })

  it('exact form-title tab name is still detected after the F1 fix (PR #295 review) — the sheet-name path must not regress', () => {
    const wb = workbookFromHeaders({ 'Werkzeug Analyse Formular': [] })
    expect(detectForeignForm(wb)?.kind).toBe('WAF')
  })

  it('PR #295 review F1 (Sev ~45): a short cross-reference-shaped tab name ("s. Werkzeug Analyse Formular", within Excel\'s 31-char tab limit) must NOT detect on a single sheet-name hit', () => {
    // Reviewer-reproduced PoC: this tab name satisfies the widened
    // word-boundary+slack check that KAR-923 introduced for header-region
    // cells, and the sheet-name path is single-hit (no MIN_HEADER_CELL_HITS
    // net) — so if the sheet-name path reused that widened check, this
    // otherwise-harmless workbook would be rejected outright. The fix
    // (isExactSignatureMatch) restores exact-match-only for sheet names.
    const tabName = 's. Werkzeug Analyse Formular'
    expect(tabName.length).toBeLessThanOrEqual(31)
    const wb = workbookFromHeaders({ [tabName]: [] })
    expect(detectForeignForm(wb)).toBeNull()
  })
})

describe('detectForeignForm — bilingual message', () => {
  it('produces the exact required DE/EN error text per format', () => {
    const laf = detectForeignForm(
      workbookFromHeaders({ S: ['Logistikkosten Analyse Formular', 'Logistikkosten Analyse Formular'] }),
    )
    expect(laf?.reasonDe).toBe('Diese Datei ist ein LAF-Formular, kein QAF — wird aktuell nicht unterstützt.')
    expect(laf?.reasonEn).toBe('This file is a LAF form, not a QAF — currently unsupported.')

    const lek = detectForeignForm(workbookFromHeaders({ S: ['LEK COST BREAK-DOWN', 'LEK COST BREAK-DOWN'] }))
    expect(lek?.reasonDe).toBe('Diese Datei ist ein LEK-Formular, kein QAF — wird aktuell nicht unterstützt.')
    expect(lek?.reasonEn).toBe('This file is a LEK form, not a QAF — currently unsupported.')

    const waf = detectForeignForm(workbookFromHeaders({ S: ['Werkzeug Analyse Formular', 'Werkzeug Analyse Formular'] }))
    expect(waf?.reasonDe).toBe('Diese Datei ist ein WAF-Formular, kein QAF — wird aktuell nicht unterstützt.')
    expect(waf?.reasonEn).toBe('This file is a WAF form, not a QAF — currently unsupported.')
  })
})

describe('detectForeignForm — false-positive guard (a real QAF must NEVER be rejected)', () => {
  it('KAR-920 adversarial-review F1 PoC: a Prämissen free-text sentence merely MENTIONING a signature phrase must not reject a real QAF', () => {
    // Reviewer-verified PoC, reproduced verbatim: real QAF Prämissen sheets
    // legitimately carry multi-column free text down to row 16-20
    // (structurally verified across the 20-file real sample) — a plausible
    // cross-reference note that happens to CONTAIN "Werkzeug Analyse
    // Formular" as a substring of a much longer sentence must not trigger.
    const wb = workbookFromHeaders({
      Praemissen: [
        'Angebotsdatum:',
        'Anbieter/Lieferant:',
        'Sonderwerkzeuge werden separat über das Werkzeug Analyse Formular kalkuliert und sind hier nicht enthalten.',
      ],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('KAR-920 adversarial-review F2 PoC: a signature must not assemble across the boundary between two unrelated sheet names', () => {
    const wb = workbookFromHeaders({ 'Kosten Werkzeug': [], 'Analyse Formular X': [] })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('returns null for typical Summary-QAF sheet names + header text', () => {
    const wb = workbookFromHeaders({
      SUMMARY: ['SUMMARY', 'Angebotsdatum:', 'Anbieter/Lieferant:', 'BMW Sachnummer:', 'Teilebenennung:'], // allow-customer-string
      Fertigungskosten: ['Fertigungskosten', 'Positionsnummer', 'Prozessbezeichnung', 'Maschine'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('returns null for a typical MATERIAL/SBM/RMR/LOGISTICS/LC-CN/CO2e QAF sheet set', () => {
    const wb = workbookFromHeaders({
      MATERIAL: ['MATERIAL', 'Positionsnummer', 'Benennung Rohmaterial'],
      'SBM-DEVICES-FWZ': ['SBM-DEVICES-FWZ', 'Verrechnungsform', 'Werkzeugart'],
      'RAW MATERIAL RISKS': ['RAW MATERIAL RISKS', 'Rohstoffbezeichnung'],
      'LOGISTICS&CUSTOM': ['LOGISTICS&CUSTOM', 'Transportkosten', 'Zoll'],
      'LC-CN': ['LC-CN', 'Local Content Quotation Analyse'],
      CO2e: ['CO2e', 'Carbon Footprint'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('returns null for a typical G60 detail-QAF sheet set (INPUT + numbered cost tabs)', () => {
    const wb = workbookFromHeaders({
      INPUT: ['Zykluszeit', 'Lohnkosten', 'Maschinenstundensatz'],
      '1_2': ['Positionsnummer', 'Prozessbezeichnung', 'Zykluszeit'],
      '2_2': ['Positionsnummer', 'Prozessbezeichnung', 'Zykluszeit'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('does NOT trigger on the individual generic words alone (Analyse, Formular, Werkzeug) without the full phrase', () => {
    const wb = workbookFromHeaders({
      Analyse: ['Risikoanalyse', 'Analyse der Rohstoffpreise'],
      Werkzeuge: ['Werkzeugart', 'Werkzeugkonzept'],
      Formulare: ['Bemerkungsformular', 'Freitextformular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('does NOT trigger on a near-miss with the words present but out of order', () => {
    const wb = workbookFromHeaders({ S: ['Formular Analyse Werkzeug', 'Down Break Cost LEK'] })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('does NOT trigger when only two of three signature words are present', () => {
    const wb = workbookFromHeaders({ S: ['Werkzeug Formular', 'Logistikkosten Formular', 'LEK Break-Down'] })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('returns null for an empty workbook', () => {
    expect(detectForeignForm(workbookFromHeaders({}))).toBeNull()
  })

  it('Re-Review rider (PR #293 Sev 30): a short cross-reference pointer repeated 2× must NOT detect — only an exact phrase-only cell may', () => {
    // "siehe Werkzeug Analyse Formular" is short enough (~1.2× the pattern
    // length) to have slipped through the old CELL_LENGTH_SLACK=1.5 guard
    // while also satisfying MIN_HEADER_CELL_HITS=2 (a legitimate short
    // pointer note can plausibly repeat, e.g. once per relevant Prämissen
    // row) — the exact-match fix closes this gap: the cell must equal the
    // phrase, not merely be close to its length.
    const wb = workbookFromHeaders({
      Praemissen: ['siehe Werkzeug Analyse Formular', 'siehe Werkzeug Analyse Formular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })
})

describe('detectForeignForm — KAR-923 compound-title robustness (word-boundary + reference-marker exclusion)', () => {
  // PR #294 review finding: PR #293's exact-match-only isCloseCellMatch is
  // real-file-verified only for WAF-Signature-1 (WAF_de.xlsm's title cells
  // contain exactly "Werkzeug Analyse Formular" and nothing else). LAF and
  // WAF-Signature-2 have no real sample; the Leitfaden wording itself
  // ("LAF (Logistikkosten Analyse Formular), Version LAF 6.2_06_01",
  // teil3.md:13 [67]; "Das Werkzeuganalyseformular", teil3.md:334 [84])
  // shows the printed title is plausibly ONE compound cell, not a
  // phrase-only cell — which the PR #293 exact-match would silently miss
  // (false negative → falls through into the QAF parser, the exact failure
  // class P5.3 exists to prevent). These tests cover the KAR-923 fix.

  it('detects LAF via a single compound-title cell ("LAF (Logistikkosten Analyse Formular), Version LAF 6.2_06_01", teil3.md:13 [67]) repeated 2×', () => {
    const wb = workbookFromHeaders({
      Packaging: [
        'LAF (Logistikkosten Analyse Formular), Version LAF 6.2_06_01',
        'LAF (Logistikkosten Analyse Formular), Version LAF 6.2_06_01',
      ],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('LAF')
    expect(hit?.matchedLabel).toBe('Logistikkosten Analyse Formular')
  })

  it('detects WAF via the single compound-title cell "Das Werkzeuganalyseformular" (teil3.md:334 [84]) repeated 2×, not split across cells', () => {
    const wb = workbookFromHeaders({
      Sheet1: ['Das Werkzeuganalyseformular', 'Das Werkzeuganalyseformular'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('WAF')
    expect(hit?.matchedLabel).toBe('Werkzeuganalyseformular')
  })

  it('detects WAF via a numbered compound title "3. Werkzeug Analyse Formular" repeated 2×', () => {
    const wb = workbookFromHeaders({
      Sheet1: ['3. Werkzeug Analyse Formular', '3. Werkzeug Analyse Formular'],
    })
    const hit = detectForeignForm(wb)
    expect(hit?.kind).toBe('WAF')
  })

  it('KAR-920 F1 PoC still returns null under the relaxed word-boundary heuristic (the free-text sentence is far longer than pattern + slack)', () => {
    // Same reviewer-verified PoC as the F1 test above — re-asserted here to
    // make explicit that the KAR-923 relaxation does not reopen it. The
    // sentence is ~106 normalized chars vs. the WAF pattern's 25 + the
    // CLOSE_MATCH_MAX_EXTRA_CHARS slack (40) = 65, so it still fails the
    // length check even though it now also contains the phrase at a word
    // boundary.
    const wb = workbookFromHeaders({
      Praemissen: [
        'Angebotsdatum:',
        'Anbieter/Lieferant:',
        'Sonderwerkzeuge werden separat über das Werkzeug Analyse Formular kalkuliert und sind hier nicht enthalten.',
      ],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('a short cross-reference "siehe Werkzeug Analyse Formular" repeated 2× still returns null — explicit reference-marker exclusion, not just length slack', () => {
    // Deliberate trade-off decision (KAR-923 task): "siehe"/"vgl."/"see" are
    // explicitly excluded as reference-marker words so a short pointer
    // cell — which IS within the compound-title length slack on its own —
    // does not re-open the PR #293 Re-Review rider gap (Sev 30).
    const wb = workbookFromHeaders({
      Praemissen: ['siehe Werkzeug Analyse Formular', 'siehe Werkzeug Analyse Formular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('a short cross-reference "vgl. Werkzeug Analyse Formular" repeated 2× returns null (vgl. marker)', () => {
    const wb = workbookFromHeaders({
      Praemissen: ['vgl. Werkzeug Analyse Formular', 'vgl. Werkzeug Analyse Formular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('a short cross-reference "see Werkzeug Analyse Formular" repeated 2× returns null (see marker)', () => {
    const wb = workbookFromHeaders({
      Praemissen: ['see Werkzeug Analyse Formular', 'see Werkzeug Analyse Formular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('a compound cell that exceeds the length slack (real title + a long trailing sentence) still returns null', () => {
    const wb = workbookFromHeaders({
      Praemissen: [
        'Werkzeug Analyse Formular für Sonderwerkzeuge, die separat kalkuliert und in einem eigenen Dokument abgerechnet werden',
        'Werkzeug Analyse Formular für Sonderwerkzeuge, die separat kalkuliert und in einem eigenen Dokument abgerechnet werden',
      ],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('PR #295 review F2 (Sev ~20-25): a single "gemäß Werkzeug Analyse Formular Anlage 3" cell returns null (1 hit, below MIN_HEADER_CELL_HITS anyway — belt)', () => {
    const wb = workbookFromHeaders({
      Praemissen: ['gemäß Werkzeug Analyse Formular Anlage 3'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('PR #295 review F2: "gemäß Werkzeug Analyse Formular Anlage 3" repeated 2× still returns null — reference-marker exclusion (GEM), not just MIN_HEADER_CELL_HITS (suspenders)', () => {
    // Reviewer PoC: "gemäß" normalizes to "GEM SS" (Ä stripped as a
    // separator, ß→SS survives as [A-Z0-9]) — the "GEM" token is what fires
    // REFERENCE_MARKER_WORDS. Without this, 2× repetition would satisfy
    // MIN_HEADER_CELL_HITS and misdetect.
    const wb = workbookFromHeaders({
      Praemissen: ['gemäß Werkzeug Analyse Formular Anlage 3', 'gemäß Werkzeug Analyse Formular Anlage 3'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('PR #295 review F2: "laut Werkzeug Analyse Formular kalkuliert" repeated 2× returns null (LAUT marker)', () => {
    const wb = workbookFromHeaders({
      Praemissen: ['laut Werkzeug Analyse Formular kalkuliert', 'laut Werkzeug Analyse Formular kalkuliert'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })

  it('PR #295 review F2: the abbreviated pointer "s. Werkzeug Analyse Formular" repeated 2× (as HEADER-CELL text, not a sheet name) returns null (S marker)', () => {
    const wb = workbookFromHeaders({
      Praemissen: ['s. Werkzeug Analyse Formular', 's. Werkzeug Analyse Formular'],
    })
    expect(detectForeignForm(wb)).toBeNull()
  })
})

describe('foreignFormWorkbookFromExcelJs — ExcelJS bridge', () => {
  it('exposes sheet names and header-region text from a real ExcelJS worksheet', () => {
    const wb = new ExcelJS.Workbook()
    const ws = wb.addWorksheet('Analyse')
    ws.getCell('C1').value = 'Werkzeug Analyse Formular'
    ws.getCell('D1').value = 'Werkzeug Analyse Formular'
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(bridged.sheetNames).toEqual(['Analyse'])
    expect(bridged.headerRegionText('Analyse')).toEqual(['Werkzeug Analyse Formular', 'Werkzeug Analyse Formular'])
    expect(detectForeignForm(bridged)?.kind).toBe('WAF')
  })

  it('never reads beyond HEADER_SCAN_ROWS — a signature placed further down is not seen', () => {
    const wb = new ExcelJS.Workbook()
    const ws = wb.addWorksheet('Deep')
    ws.getCell(`A${HEADER_SCAN_ROWS + 5}`).value = 'Werkzeug Analyse Formular'
    ws.getCell(`B${HEADER_SCAN_ROWS + 5}`).value = 'Werkzeug Analyse Formular'
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(bridged.headerRegionText('Deep')).toEqual([])
    expect(detectForeignForm(bridged)).toBeNull()
  })

  it('still detects a signature repeated across 2 cells within the scanned header region', () => {
    const wb = new ExcelJS.Workbook()
    const ws = wb.addWorksheet('Shallow')
    ws.getCell(`A${HEADER_SCAN_ROWS}`).value = 'Werkzeug Analyse Formular'
    ws.getCell(`B${HEADER_SCAN_ROWS}`).value = 'Werkzeug Analyse Formular'
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(detectForeignForm(bridged)?.kind).toBe('WAF')
  })

  it('returns an empty array for a sheet name that does not exist', () => {
    const wb = new ExcelJS.Workbook()
    wb.addWorksheet('Only')
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(bridged.headerRegionText('Nonexistent')).toEqual([])
  })

  it('returns null for a real Summary-QAF-shaped workbook (regression: no false positive through the real bridge)', () => {
    const wb = new ExcelJS.Workbook()
    const ws = wb.addWorksheet('SUMMARY')
    ws.getCell('B5').value = 'Angebotsdatum:'
    ws.getCell('F5').value = 'Anbieter/Lieferant:'
    ws.getCell('F8').value = 'BMW Sachnummer:' // allow-customer-string
    wb.addWorksheet('Fertigungskosten')
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(detectForeignForm(bridged)).toBeNull()
  })

  it('KAR-920 adversarial-review F1 PoC through the real ExcelJS bridge: a Prämissen free-text sentence must not reject a real QAF', () => {
    const wb = new ExcelJS.Workbook()
    const ws = wb.addWorksheet('Praemissen')
    ws.getCell('B5').value = 'Angebotsdatum:'
    ws.getCell('B16').value =
      'Sonderwerkzeuge werden separat über das Werkzeug Analyse Formular kalkuliert und sind hier nicht enthalten.'
    const bridged = foreignFormWorkbookFromExcelJs(wb)
    expect(detectForeignForm(bridged)).toBeNull()
  })
})
