_duplex_map translates before rendering: LongEdge->TwoSidedLongEdge, ShortEdge->TwoSidedShortEdge
WOW64 guard comment avoids 'pnputil.exe' text to preserve ordering assertion in test
duration
completed_date
tasks_completed
files_created
files_modified
tests_added
tests_passing
~2 min
2026-04-10
1
3
0
7
68
Phase 4 Plan 01: Script Generator (Install) Summary
One-liner: Jinja2-based install.ps1 generator with WOW64 guard, UAC elevation, pnputil two-step, and duplex mapping
What Was Built
A TDD-developed module imptune/generators/script_generator.py with a single public function render_install() that renders the install.ps1.j2 Jinja2 template into a complete, production-ready PowerShell printer install script.
render_install() function
Takes plain string arguments (no ORM dependency) for easy unit testing
Translates duplex_mode via _duplex_map before passing to template
Converts Python booleans to lowercase strings ("true"/"false") for PowerShell $true/$false rendering
install.ps1.j2 template structure (in order)
Header comment with printer name and required Intune install command
WOW64 guard ($env:PROCESSOR_ARCHITECTURE + SysNative relaunch) — FIRST executable block
SYSTEM vs admin detection ([WindowsIdentity]::GetCurrent(), IsSystem, IsInRole(Administrator)) + UAC self-elevation via Start-Process -Verb Runas
pnputil two-step: /add-driver to stage INF, then Add-PrinterDriver to register
Idempotent port creation: Get-PrinterPort check before Add-PrinterPort
Idempotent printer creation: Get-Printer check before Add-Printer
Set-PrintConfiguration with translated duplex, color, paper size, collate
One auto-fix required during GREEN: template comment contained "pnputil.exe" before the WOW64 PROCESSOR_ARCHITECTURE check text, causing the ordering assertion in test_render_install_wow64_guard to fail. Fixed by removing .exe from the comment text. Not a logic error — purely a textual ordering issue in the rendered output.
GREEN phase — script_generator.py + install.ps1.j2
Deviations from Plan
Auto-fixed Issues
1. [Rule 1 - Bug] Template comment contained 'pnputil.exe' before WOW64 guard text
Found during: GREEN phase test run
Issue: Comment in the WOW64 guard block header said "pnputil.exe is 64-bit only", so the string "pnputil.exe" appeared in the rendered output before "PROCESSOR_ARCHITECTURE", breaking the ordering assertion in test_render_install_wow64_guard
Fix: Changed "pnputil.exe is 64-bit only" to "pnputil is 64-bit only" in the template comment