Files
oci-deal-accelerator/tests/test_oci_pptx_render.py
root b30a4f0d32 Diagram generation: ref-arch-driven procedure + spec validator + KB enrichment
The diagram path now follows a documented standard procedure (lookup
the closest Oracle Architecture Center reference → confirm components
→ author absolute_layout → spec validator → render → visually verify)
and ships persistent guardrails so layout regressions can't recur.

Persistent procedure changes (apply to all users, all sessions):
- tools/diagram_spec_validator.py — geometry checks (CONTAINER_TOO_THIN,
  CONTAINER_PADDING_VIOLATION, LABEL_OVERFLOW_PARENT) run BEFORE either
  renderer (drawio + PPTX). Catches the subnet-collapse / label-overflow
  bugs that the post-render drawio validator missed.
- tools/oci_diagram_gen.py + tools/oci_pptx_diagram_gen.py — call the
  spec validator before emitting any output. Adds mysql / mysql_heatwave
  type aliases.
- tools/archcenter_pattern_lookup.py — scores against cached page
  descriptions (not just the 1-line summary), supports --queries for
  multi-fragment composition, and applies synonym expansion via
  kb/architecture-center/synonyms.yaml so "LB HA cross AD" matches
  "load balancer high availability availability domain".
- kb/architecture-center/synonyms.yaml — canonical synonym table
  (load balancer, autonomous database, data guard, …) used by the
  lookup scorer.

KB enrichment:
- tools/archcenter_description_fetcher.py + 121 cached _description.md
  under kb/diagram/assets/archcenter-refs/<slug>/. Removes the runtime
  dependency on docs.oracle.com when authoring specs and feeds the
  pattern-lookup scorer.
- 110+ cached .drawio / .svg / .png references for offline reuse,
  plus the OCI Toolkit v24.2 import (kb/diagram/assets/oci-toolkit-drawio).

Documentation:
- docs/skill/output-formats.md — new "Standard diagram-generation
  procedure (MANDATORY)" + geometry rules + the new validator entry.
- SKILL.md option 2 — references the mandatory procedure.
- README.md — describes the spec validator, archcenter_pattern_lookup
  and description fetcher, and updates the KB-health table.

Tooling that backs the procedure (cumulative across recent sessions):
tools/archcenter_case_runner.py, archcenter_batch_driver.py,
archcenter_zip_downloader.py, drawio_visual_validator.py,
drawio_fidelity_eval.py, harvest_drawio_icon.py, import_oci_library.py,
oci_pptx_diagram_gen.py, oci_pptx_render.py, refresh_pptx_icon_index.py.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 21:15:21 -03:00

91 lines
3.6 KiB
Python

import sys
from pathlib import Path
from PIL import Image
PROJECT_ROOT = Path(__file__).resolve().parent.parent
TOOLS_DIR = PROJECT_ROOT / "tools"
if str(TOOLS_DIR) not in sys.path:
sys.path.insert(0, str(TOOLS_DIR))
from oci_deck_gen import OCIDeckGenerator
from oci_pptx_render import render_pptx_to_png
def test_render_pptx_to_png_detects_native_architecture_slide(tmp_path):
spec = {
"metadata": {
"customer": "TestCo",
"project": "Native Diagram",
"subtitle": "Render test",
},
"summary": {
"why": "Test native rendering",
"current_state": ["Legacy DB"],
"target_state": "OCI target",
"timeline": "Q2",
},
"architecture": {
"description": "Absolute layout render test",
"visual": {
"render_mode": "native_pptx",
"absolute_layout": {
"canvas": {"width": 900, "height": 520},
"containers": [
{"id": "region", "type": "region", "label": "OCI Region", "x": 160, "y": 30, "w": 640, "h": 430},
{"id": "vcn", "type": "vcn", "label": "VCN 10.0.0.0/16", "x": 210, "y": 110, "w": 500, "h": 270},
],
"services": [
{"id": "api", "type": "api_gateway", "label": "", "x": 290, "y": 170, "w": 90, "h": 84},
{"id": "oke", "type": "oke", "label": "", "x": 420, "y": 165, "w": 96, "h": 88},
{"id": "notify", "type": "notifications", "label": "", "x": 560, "y": 170, "w": 90, "h": 84},
],
"labels": [
{"id": "lbl1", "text": "Coordinate-faithful reconstruction from the official Architecture Center diagram.", "x": 80, "y": 470, "w": 740, "h": 26},
],
"connections": [],
},
},
},
"output": {"render_standard_sections": False},
"custom_slides": [{
"type": "diagram",
"title": "Render Test",
"description": "Coordinate-faithful reconstruction from the official Architecture Center diagram.",
"visual": {
"render_mode": "native_pptx",
"absolute_layout": {
"canvas": {"width": 900, "height": 520},
"containers": [
{"id": "region", "type": "region", "label": "OCI Region", "x": 160, "y": 30, "w": 640, "h": 430},
],
"services": [
{"id": "api", "type": "api_gateway", "label": "", "x": 320, "y": 170, "w": 90, "h": 84},
{"id": "notify", "type": "notifications", "label": "", "x": 480, "y": 170, "w": 90, "h": 84},
],
"labels": [
{"id": "lbl1", "text": "Coordinate-faithful reconstruction from the official Architecture Center diagram.", "x": 90, "y": 470, "w": 720, "h": 26},
],
"connections": [],
},
},
}],
}
pptx_path = tmp_path / "render-test.pptx"
png_path = tmp_path / "render-test.png"
gen = OCIDeckGenerator.from_spec(spec)
gen.save(str(pptx_path))
meta = render_pptx_to_png(pptx_path, png_path, width=1200)
assert png_path.is_file()
assert meta["display_number"] >= 1
assert meta["shape_counts"]["grpSp"] >= 2
with Image.open(png_path) as image:
assert image.size[0] == 1200
assert image.getbbox() is not None