feat: PRAB article JSON-LD emitter + meta reader (v0.8.0)

- PR_Core_Jsonld_Article: meta-triggered emitter for PRAutoBlogger posts
  (trigger: _prab_schema_version=1 on post type). Yoast path retypes page
  node to MedicalWebPage (wpseo_schema_webpage_type priority 10) and enriches
  Article piece with citation[], about[]→Drug @id, lastReviewed, honest
  reviewedBy (wpseo_schema_graph priority 13). No-Yoast fallback emits
  standalone @graph. Posts without trigger meta are byte-unchanged.

- PR_Core_Prab_Meta_Reader: sanitises all _prab_* contract-v1 meta at read
  time. URLs validated (http/https), DOIs normalised to https://doi.org/ URI,
  JSON arrays per-element validated, WP user ID resolved. Malformed values
  degrade gracefully. Honest reviewedBy: Person ONLY when mode=human + valid
  user ID; else Organization. Never a fabricated person.

- Unit tests: JsonldArticleTest.php — 22 assertions covering is_triggered,
  review_mode, reviewed_by Person/Org decision tree, citation sanitization,
  DOI normalisation, about linkage, retype passthrough, enrich, no-new-nodes,
  editorial-system-never-person.

- bootstrap.php: WP_User stub + get_userdata reads pr_test_userdata global.
- ARCHITECTURE.md: updated JSON-LD class tree + PRAB emission section.
- CONVENTIONS.md: PRAB contract v2 extension guide added.
- CHANGELOG.md + version bump to v0.8.0.

Ratified contract: convo/prcore/decisions/2026-06-11-jsonld-contract-v1.md
File sizes: article.php=235L, meta-reader.php=265L (both < 300-line gate).
No duplicate Article/WebPage nodes. uninstall.php unaffected (_prab_* unowned).

Agent-Session: prcore-jsonld-article-20260622
This commit is contained in:
peptiderepo
2026-06-23 04:23:21 +00:00
parent a7a2bb2f6d
commit 1ce471981b
9 changed files with 950 additions and 4 deletions

View File

@@ -63,6 +63,26 @@ v0.6.0 uses four focused classes (see ARCHITECTURE.md §#6). To add a new field
4. To add a new schema piece (not Drug), create a new `PR_Core_Jsonld_<Piece>` class in `frontend/` and inject it from `PR_Core_Jsonld::inject_graph_pieces()`.
5. The `pr_core_jsonld_peptide` filter on the Drug node array is preserved for consumer plugins.
## How To: Add Fields to the PRAB Article JSON-LD (contract v2+)
The `_prab_*` meta contract is versioned (`_prab_schema_version`). The contract is frozen at v1
until prcore and PRAB coordinate a version bump. To add new fields:
1. Propose the new field in `convo/prcore/decisions/` (CTO ratifies; PRAB and prcore must agree).
2. Bump `_prab_schema_version` to 2 in PRAB's meta write code — do NOT bump before prcore ships support.
3. Add the new field to `PR_Core_Prab_Meta_Reader` (sanitize at read time, degrade gracefully).
4. Add emission logic to `PR_Core_Jsonld_Article` — emit only when field is non-empty.
5. Add unit tests for the new field in `tests/unit/JsonldArticleTest.php`.
6. Bump `SUPPORTED_VERSION` in `PR_Core_Prab_Meta_Reader::SUPPORTED_VERSION` to 2.
7. Update the contract decision doc and CHANGELOG.
Key rules:
- prcore **reads** `_prab_*` meta only. PRAB **writes** only. The namespace boundary is hard.
- `uninstall.php` must NOT touch `_prab_*` keys — they belong to PRAB's namespace.
- `quality_score` and similar audit fields must never be emitted (no schema.org mapping).
- The `reviewedBy` Person guard is non-negotiable: Person only with human mode + valid user ID.
## Error Handling
- Repository methods return `null` or `0` on failure, never throw.