Fill added documents completely on creation #68

Merged
parkerhdavis merged 2 commits from fix-add-document-incomplete-fill into main 2026-06-16 14:00:22 -06:00
parkerhdavis commented 2026-06-16 14:00:16 -06:00 (Migrated from github.com)

Problem

After filling a client's questionnaire and creating a new document, the generated .docx was not fully populated on disk — variables/conditionals showed raw template placeholder text (the bare display name) when opened in an external editor. Opening the document once in Lily silently corrected the file, even with no edits.

Root cause

addMultipleDocuments (the only "Add New Document" path) passed the raw client variable pool to replace_variables_v2. Any variable or conditional absent from that pool — a template-only placeholder, an untouched questionnaire field, or a conditional with no controlling value — was left in raw template form, because update_sdt_v2 leaves an SDT untouched when its variable is missing from the map. openDocument builds a complete per-variable map (defaulting absent entries to "" / "false"), which is why opening the doc in the editor fixed it.

Fix

  • addMultipleDocuments now builds a complete per-document value map (matching the open/save paths), defaulting absent variables to "" / "false" plus schema defaults, via a shared buildVariableValues helper. So every variable resolves on disk at creation time.
  • update_sdt_v2 hardening (defense-in-depth): a simple variable absent from the map now blanks to a bookmark, and a schema-backed conditional with an absent controlling variable takes its false branch, instead of leaving the SDT in raw template form. A conditional with no schema entry (branches unknown) is still left untouched. Adds a regression test.
  • Removes the dead selectTemplate store action. It was the original single-document creation action, orphaned when the TemplatePicker moved to multi-select. It was also the path that already had the correct complete-map logic — keeping a never-exercised reference path is what let the live path silently diverge into this bug.

Verification

make test (96 pass, incl. new regression test), make typecheck, and make lint all clean.

## Problem After filling a client's questionnaire and creating a new document, the generated `.docx` was not fully populated on disk — variables/conditionals showed raw template placeholder text (the bare display name) when opened in an external editor. Opening the document once in Lily silently corrected the file, even with no edits. ## Root cause `addMultipleDocuments` (the only "Add New Document" path) passed the **raw client variable pool** to `replace_variables_v2`. Any variable or conditional absent from that pool — a template-only placeholder, an untouched questionnaire field, or a conditional with no controlling value — was left in raw template form, because `update_sdt_v2` leaves an SDT untouched when its variable is missing from the map. `openDocument` builds a *complete* per-variable map (defaulting absent entries to `""` / `"false"`), which is why opening the doc in the editor fixed it. ## Fix - **`addMultipleDocuments`** now builds a complete per-document value map (matching the open/save paths), defaulting absent variables to `""` / `"false"` plus schema defaults, via a shared `buildVariableValues` helper. So every variable resolves on disk at creation time. - **`update_sdt_v2` hardening (defense-in-depth):** a simple variable absent from the map now blanks to a bookmark, and a schema-backed conditional with an absent controlling variable takes its false branch, instead of leaving the SDT in raw template form. A conditional with no schema entry (branches unknown) is still left untouched. Adds a regression test. - **Removes the dead `selectTemplate` store action.** It was the original single-document creation action, orphaned when the TemplatePicker moved to multi-select. It was also the path that already had the correct complete-map logic — keeping a never-exercised reference path is what let the live path silently diverge into this bug. ## Verification `make test` (96 pass, incl. new regression test), `make typecheck`, and `make lint` all clean.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
parker/lily!68
No description provided.