Skip to content

SSA full drift checker (template + staging headers)#16

Open
mcxl wants to merge 2 commits into
claude/brave-mestorf-8f2596from
claude/ssa-drift-full
Open

SSA full drift checker (template + staging headers)#16
mcxl wants to merge 2 commits into
claude/brave-mestorf-8f2596from
claude/ssa-drift-full

Conversation

@mcxl

@mcxl mcxl commented May 14, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #15. Promotes the minimal drift checker (1 check) to a full drift checker (3 checks) by first centralising the SSA report placeholder tokens.

  • Refactor: build_ssa_report_docx's inline {{SITE_ADDRESS}} / {{NARRATIVE_SUMMARY}} / {{AUDIT_DATE}} / {{PREPARED_BY}} literals are now module-level PH_* constants plus an SSA_REPORT_PLACEHOLDERS tuple. Pure refactor — 114 docx-build tests unchanged.
  • New check Claude/pims folder guide efy2 n #1 — template placeholders. Walks the SSA report template .docx's word/*.xml parts, concatenates <w:t> text content (so placeholders split across formatting boundaries are still caught), and asserts each PH_* appears.
  • New check fix(pims): correct column name in observation fetch + drop debug wrapper #2 — staging xlsx widths. Every STAGING_HEADERS entry must have a corresponding _STAGING_COL_WIDTHS key. Subset semantics — _STAGING_COL_WIDTHS legitimately carries forward-defined gap-4/5/6 columns (phase, hrcw, swms_required, etc.) not yet in STAGING_HEADERS.

3 checks total, all green on current branch. 5 drift-checker tests cover the clean path and per-check failure paths.

Test plan

  • python tools/check_ssa_drift.py — exits 0 with 3 [X] marks
  • python -m pytest tests/test_ssa_drift_checker.py — 5 tests pass
  • python -m pytest tests/test_ssa_pipeline.py tests/test_ssa_determinism.py tests/test_ssa_oxml_validator.py — docx-build behaviour unchanged after the placeholder refactor (114 passing)

Notes for reviewer

  • Stacked on top of SSA pipeline quality hardening (Phases 1-6) #15. GitHub will auto-rebase the base when SSA pipeline quality hardening (Phases 1-6) #15 merges.
  • The placeholder check uses a <w:t>...</w:t> regex to extract Word's visible text content rather than substring-searching the raw XML, because Word may split a placeholder across multiple text runs when formatting boundaries land mid-token.
  • The staging-width check is deliberately a subset (not equality) — _STAGING_COL_WIDTHS has 6+ forward-defined gap-4/5/6 entries not yet in STAGING_HEADERS. Asymmetric semantics catch the case that matters (missing widths) without requiring those forward-defined entries to be removed.

🤖 Generated with Claude Code

mcxl and others added 2 commits May 15, 2026 08:33
Lifts the 4 inline placeholder strings ({{SITE_ADDRESS}},
{{NARRATIVE_SUMMARY}}, {{AUDIT_DATE}}, {{PREPARED_BY}}) out of
build_ssa_report_docx into module-level PH_* constants plus a
SSA_REPORT_PLACEHOLDERS tuple. Pure refactor — no behaviour change,
114 tests unchanged.

Prerequisite for the full drift checker, which needs an enumerable
constant surface to walk against the template docx.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds two checks on top of the minimal v1 CSV header check:

  - SSA report template carries every PH_* placeholder. Walks the
    template docx's word/*.xml parts, concatenates <w:t> text content
    (handles placeholders split across formatting boundaries), and
    asserts each token in SSA_REPORT_PLACEHOLDERS appears somewhere.
  - Every STAGING_HEADERS entry has a _STAGING_COL_WIDTHS entry.
    Subset semantics — _STAGING_COL_WIDTHS legitimately carries
    forward-defined gap-4/5/6 columns (phase, hrcw, swms_*, etc.)
    not yet in STAGING_HEADERS.

3 checks total now, all green on current main. 5 tests cover both
the clean path and per-check failure paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d04355855b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/check_ssa_drift.py
Comment on lines +84 to +85
haystack = "".join(parts)
missing = [ph for ph in SSA_REPORT_PLACEHOLDERS if ph not in haystack]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject split placeholders that the builder cannot replace

When Word splits a placeholder across formatting runs, this join makes the drift check pass because {{SITE_ + ADDRESS}} is found in the concatenated haystack, but build_ssa_report_docx still replaces only tokens that appear wholly inside one <w:t> (_replace_tokens_in_part iterates individual text nodes). In that edited-template scenario the checker reports green while the generated report keeps unreplaced placeholder pieces, so the check should either require each placeholder within a single text node or the builder needs matching split-run replacement support.

Useful? React with 👍 / 👎.

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.

1 participant