Skip to content

Add document-level tests for the Word export - #1271

Open
jasonleenaylor wants to merge 1 commit into
mainfrom
word-export-document-tests
Open

jasonleenaylor wants to merge 1 commit into
mainfrom
word-export-document-tests

Conversation

@jasonleenaylor

@jasonleenaylor jasonleenaylor commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Start here: Src/xWorks/xWorksTests/LcmWordGeneratorDocumentTests.cs, the eight tests at the bottom of the file. Each test name says which document it saves and what it checks.

What it does

Adds eight tests that call LcmWordGenerator.SavePublishedDocx, open the saved .docx, and assert on its XML parts with XPath. They cover a left-to-right dictionary, a right-to-left vernacular, a right-to-left analysis language in a left-to-right dictionary, and a reversal index. This is item 0.O-0 of the plan in #1259.

Why it is needed

No test reached SavePublishedDocx in a normal run. The two that call it are skipped unless FW_RUN_MANUAL_DOCX_EXPORT_TESTS=1. The plan reworks the style resolver, the image reader and the writer's static state. These tests are how those changes are shown not to alter the saved document.

Where to look

  • One production change. LcmWordGenerator.IsBidi gets an internal setter so the fixture's Setup can reset it. Without the reset, the right-to-left test left it true for every later test in the process.
  • Right-to-left marks. The writer adds w:rtl to a run only when the entry style is right-to-left (LcmWordGenerator.cs:2841). SavePublishedDocx_RightToLeftAnalysisInLeftToRightDictionary_HasNoRightToLeftMarks records that Arabic glosses in a left-to-right dictionary get no mark. @mark-sil, is that intended?
  • Element layout. Style assertions select attributes (w:ind/@w:left), so they hold whether the writer emits one w:ind element or three.
  • Run order. The fixture is [NonParallelizable], because the writer keeps the document it is building in static fields.

Not here

  • Schema validation. The exported documents fail Open XML validation in 13 ways. That is LT-22927. This PR has no validator code.
  • Paragraph borders. The Word export writes none, and a test records that.
  • Rendering. No exported document was opened in Word.

Verification

  • Build: 0 warnings, 0 errors. Comment hygiene and token hygiene clean.
  • LcmWordGeneratorTests: 40 total, 38 passed, 2 skipped (the manual .docx tests).
  • Four of the document tests run alone: each passed.
  • Full xWorksTests: 2,026 total, 2,024 passed, 2 skipped.
  • The branch is 4 commits behind main. None of them touch these files, and the tests were not rerun on top of them.

Next: approve, or say that the right-to-left behaviour above is a defect and I will file it.


Reading this a year from now -- start here

These tests were written before the Word writer moved to liblcm. They pin what the writer saved at that time, including behaviour nobody had decided was correct. A test here that fails after a deliberate change to Word output is expected to be updated, not worked around.

What each test pins
Test Pins
Body Paragraph style order of the whole body, letter headings, run text per style, four sections with 1, 2, 1, 2 columns, no w:rtl
Styles part Entry, sense and subsense paragraph properties; headword and gloss run properties; every style the body uses is defined once
Numbering The first sense of each entry restarts at 1, a second sense continues, both subsenses share one bulleted list
Picture The image part and its relationship, the frame size, the picture size
Headers and settings Both page headers, the compatibility settings, the list of parts in the file
Right-to-left vernacular w:bidi on every section and on the entry style only, w:rtl on the Hebrew runs and no others, complex-script font properties
Right-to-left analysis Arabic glosses in a left-to-right dictionary get no w:rtl or w:bidi
Reversal index Letter headings from the reversal forms, guideword page headers, no numbering part

Assertions that depend on thread timing (numbering ids, style order) hold in any order.

Paths not taken
  • A list of known validator errors in the tests. The first version ran OpenXmlValidator on each document and allowed 13 known kinds of error. "This document has exactly these defects" is not a property anyone intends, and the check could not tell a fixed error from a present one. The errors are in LT-22927. The assertion to add once they are fixed is that the validator reports none.
  • Comparing style properties as strings. The first version turned each style property into a string such as ind left=720 and compared arrays. That pinned the number of w:ind elements and hid attribute ordering in a helper.
  • The Open XML SDK's typed objects. The writer emits up to three w:ind elements per style, and the typed Indentation property returns only the first. Reading the file with the library that wrote it also makes the tests less independent.
Preflight review details

Code Review Summary

Branch: word-export-document-tests
Base: main (merge base 19f02c1)
Date: 2026-12-01
Review model: Claude Fable 5 (Claude Code)
Files changed: 3

Overview

The branch adds eight document-level tests for the Word export. Each test
calls LcmWordGenerator.SavePublishedDocx, opens the saved .docx, and asserts
on its XML parts with XPath. This is item 0.O-0 of the plan to move dictionary
configuration to liblcm (PR #1259). The tests exist so that the Word writer
rework in later items (0.L, 0.O-1, 0.O-2) can be shown not to change output.

The review found no failing assertion. It found five Important and four Minor
points about how robust the tests were. Six led to changes during the review,
two were left by decision, and one was dropped on evidence. The validator
check was taken out of the branch and filed as LT-22927.

Contract/API Changes

  • LcmWordGenerator.IsBidi: the setter changed from private to internal
    so the test fixture can reset it. No behaviour change. xWorksTests already
    has InternalsVisibleTo.

No other production code changed.

Findings

Critical - Must address before merge

None.

Important - Should address before merge

  • SaveAndReadDocx used a fixed temp folder name, shared by every
    test run on the machine, so two worktrees could delete each other's files.
    (fixed during review: Path.GetRandomFileName(), as other xWorks tests
    do)
  • The tests set process-wide static state in the Word writer.
    SavePublishedDocx assigns MasterFragment, s_styleCollection and
    IsBidi. IsBidi stayed true after the right-to-left test, and the
    fixture could not run in parallel with itself. (fixed during review:
    Setup resets IsBidi next to ClearStyleCollection(); the fixture is
    [NonParallelizable]; the setter is internal)
  • StyleProperties reduced style XML to strings such as
    "ind left=720" and compared arrays of them at 14 call sites. It pinned
    the writer's element layout and hid attribute ordering in the helper.
    (fixed during review: removed; five XPath assertion helpers plus
    AssertPropertyCount replace it)
  • The validator baseline was string matching on a snapshot of
    defects.
    It was checked one way, used one list for four documents, and
    matched the SDK's description text. (fixed during review: all validator
    code removed from the branch; the 13 kinds of error are filed as LT-22927)
  • The right-to-left analysis test asserts that Arabic glosses in a
    left-to-right dictionary get no w:rtl mark, which may be a writer
    defect.
    (Author: keep the test as a record of current behaviour and ask
    Mark on the PR whether it is intended.)

Minor - Consider

  • The Hebrew writing system was created inside whichever document test
    ran first
    , so a left-to-right document could differ by run order. (fixed
    during review: created with WritingSystemManager.GetOrSet, which does not
    add it to the project's vernacular list)
  • Seven comments were wrapped with one-word lines. (fixed during
    review: rewrapped by hand)
  • The new helpers overlap the manual-docx helpers, and "EvenPages",
    "OddPages" and "Letter Heading" repeat WordStylesGenerator
    constants.
    (Author: leave. A test of saved output compares against
    literal text, and merging helpers means editing existing tests.)
  • Five tests regenerate the same left-to-right document. (Dropped on
    evidence: each repeated save takes about 30 ms.)

Required Validation / Evidence

Run on 2026-12-01 after the last in-review change, with -CommentHygiene -TokenHygiene:

  • ./build.ps1 -BuildTests -SkipNative: succeeded, 0 warnings, 0 errors.
  • comment-hygiene and token-hygiene: clean.
  • ./test.ps1 -TestProject Src/xWorks/xWorksTests -TestFilter FullyQualifiedName~LcmWordGeneratorTests: 40 total, 38 passed, 2 skipped
    (the manual .docx tests), 0 failed.
  • Four document tests each run alone (styles, right-to-left vernacular,
    right-to-left analysis, reversal index): each 1 of 1 passed. This checks
    that they do not depend on run order.
  • Full xWorksTests: 2,026 total, 2,024 passed, 2 skipped, 0 failed.

Not done:

  • No exported document was opened in Word.
  • The branch is 4 commits behind origin/main. None of those commits touch
    the three changed files. The tests were not rerun on top of them.

Jira: developer-only test change, no ticket needed for the branch itself.
LT-22927 covers the validation errors the tests exposed.

Positive Observations

  • Every assertion reads the saved file, so the tests do not depend on how the
    writer is built and can move to liblcm with it.
  • Assertions that depend on thread timing (numbering ids, style order) hold
    in any order.
  • The right-to-left tests restore the writing-system state they change in a
    finally block.
  • Scope is small: one new test file, one visibility change, and a few lines
    in the existing fixture.

Interview Notes

  • Static state: the author asked whether the branch introduced statics. It
    adds no static state (one static readonly array, since removed, and
    stateless helpers). It does make the fixture depend on the writer's
    existing statics; the author chose the reset-in-Setup repair.
  • StyleProperties: the author objected to reducing XML to strings and chose
    XPath assertions.
  • Validator: the author asked for the motivation. It came from the plan
    review (run the validator on today's output early). The author decided the
    branch carries no validator code and that the errors go to Jira. Office
    2007 is the intended schema, for cross-platform support.
  • Right-to-left analysis test: written in this branch; it records what the
    writer does today. Kept, with a question to Mark.
  • Nothing else to flag.

In-Review Quality Check

The validation above was run with every in-review change applied.

Suggested Review Focus

  • Is "no w:rtl on right-to-left text in a left-to-right dictionary"
    intended? (LcmWordGenerator.cs:2841, test at
    LcmWordGeneratorDocumentTests.cs:695)
  • Do the XPath helpers pin the right properties for the plan's later
    items (0.L, 0.O-1, 0.O-2)?
  • Is internal set on IsBidi acceptable until 0.O-2 removes the
    static?

🤖 Generated with Claude Code


This change is Reviewable

Add eight tests that call LcmWordGenerator.SavePublishedDocx and
assert with XPath on the parts of the saved .docx file: the body,
sections, page headers, styles, numbering, the embedded picture,
and settings. They cover a left-to-right dictionary, a
right-to-left vernacular, a right-to-left analysis language in a
left-to-right dictionary, and a reversal index.

The only existing tests that reach SavePublishedDocx are skipped
unless FW_RUN_MANUAL_DOCX_EXPORT_TESTS is set.

SavePublishedDocx sets the static LcmWordGenerator.IsBidi, and
nothing reset it between tests. Its setter becomes internal so
the fixture's Setup can reset it, and the fixture is marked
NonParallelizable. LcmWordGeneratorTests becomes a partial class
so the new tests share its fixture.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

NUnit Tests

    1 files  ±0      1 suites  ±0   12m 18s ⏱️ +48s
7 438 tests +8  7 358 ✅ +7  79 💤 ±0  1 ❌ +1 
7 447 runs  +8  7 367 ✅ +7  79 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 60072b1. ± Comparison against base commit c5da1ae.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.14%. Comparing base (19f02c1) to head (60072b1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1271      +/-   ##
==========================================
+ Coverage   40.60%   41.14%   +0.54%     
==========================================
  Files        1601     1603       +2     
  Lines      360728   360816      +88     
  Branches    42239    42246       +7     
==========================================
+ Hits       146474   148467    +1993     
+ Misses     184615   182933    -1682     
+ Partials    29639    29416     -223     
Files with missing lines Coverage Δ
Src/xWorks/LcmWordGenerator.cs 73.28% <ø> (+31.81%) ⬆️

... and 49 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants