Compare commits
6 Commits
claude/qa-
...
claude/ado
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
395fdee0da | ||
|
|
277ab2e9e8 | ||
|
|
8e1405d5a5 | ||
|
|
73cd2df294 | ||
|
|
49934b2c25 | ||
|
|
99b66c6370 |
80
.github/workflows/ci.yml
vendored
80
.github/workflows/ci.yml
vendored
@@ -1,71 +1,27 @@
|
|||||||
|
##
|
||||||
|
# Thin CI caller — peptide-reconstitution-calculator
|
||||||
|
#
|
||||||
|
# Delegates all lint/test/file-size jobs to the estate reusable workflow.
|
||||||
|
# Per estate standard: workflow_call is required so deploy.yml can gate on it.
|
||||||
|
# See: peptiderepo/peptide-e2e/.github/workflows/ci.yml@main for job definitions.
|
||||||
|
##
|
||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
pull_request: {}
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
pull_request:
|
workflow_call: {}
|
||||||
branches: [ main ]
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
|
# Required: calling workflow must declare contents: write so the reusable
|
||||||
|
# phpcs job can commit phpcbf auto-fixes back to the PR branch.
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ── PHP Syntax Check ─────────────────────────────────────────────
|
ci:
|
||||||
lint-php:
|
uses: peptiderepo/peptide-e2e/.github/workflows/ci.yml@main
|
||||||
name: PHP Lint (${{ matrix.php }})
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
php: [ '8.1', '8.2', '8.3' ]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up PHP ${{ matrix.php }}
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
tests: stubs
|
||||||
|
has_js: true
|
||||||
- name: Syntax check all PHP files
|
secrets: inherit
|
||||||
run: find . -name "*.php" -not -path "./vendor/*" | xargs -n 1 php -l
|
|
||||||
|
|
||||||
# ── WordPress Coding Standards (PHP CodeSniffer) ──────────────────
|
|
||||||
lint-phpcs:
|
|
||||||
name: WordPress Coding Standards
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: '8.1'
|
|
||||||
|
|
||||||
- name: Install Composer dependencies
|
|
||||||
run: composer install --no-interaction --prefer-dist --no-progress
|
|
||||||
|
|
||||||
- name: Run PHPCS
|
|
||||||
run: composer run lint
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
# ── 300-line file check ──────────────────────────────────────────
|
|
||||||
file-size:
|
|
||||||
name: 300-line file check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Check no PHP file exceeds 300 lines
|
|
||||||
run: |
|
|
||||||
violations=0
|
|
||||||
while IFS= read -r file; do
|
|
||||||
lines=$(wc -l < "$file")
|
|
||||||
if [ "$lines" -gt 300 ]; then
|
|
||||||
echo "VIOLATION: $file ($lines lines)"
|
|
||||||
violations=$((violations + 1))
|
|
||||||
fi
|
|
||||||
done < <(find . -name "*.php" -not -path "./vendor/*" -not -path "./tests/*")
|
|
||||||
if [ "$violations" -gt 0 ]; then
|
|
||||||
echo "$violations file(s) exceed 300 lines"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "All PHP files are 300 lines or fewer."
|
|
||||||
|
|||||||
258
.github/workflows/cto-review.yml
vendored
258
.github/workflows/cto-review.yml
vendored
@@ -1,20 +1,17 @@
|
|||||||
name: CTO Review
|
name: CTO Review
|
||||||
|
|
||||||
# Automated PR review powered by Claude + DeepSeek + Kimi (via OpenRouter)
|
# Automated PR review powered by Claude Haiku (via OpenRouter).
|
||||||
# plus Neurometric PR-Summarizer (a Qwen3-4B task-specialist SLM).
|
|
||||||
#
|
#
|
||||||
# During the A/B window (until further notice), every PR gets reviewed by FOUR models
|
# A/B panel decision 2026-06-12: panel dropped to Haiku-only.
|
||||||
# in parallel. The PR comment shows each model's verdict side-by-side so we can compare
|
# Evidence: convo/cto/threads/2026-06-qa-ab-review/02-analyst-findings.md
|
||||||
# quality/cost on real PRs before picking a permanent default.
|
# DeepSeek: high false-positive rate (absint()="code exec", PLUGIN_DIR="dir traversal").
|
||||||
|
# Kimi: ~60% model failure rate across 13 PRs sampled.
|
||||||
|
# Neurometric: summarizer only, zero unique-real findings, unreliable heuristic verdict.
|
||||||
|
# Haiku: 0 failures, lowest noise, equivalent real-signal catch rate vs 4-voice panel.
|
||||||
#
|
#
|
||||||
# Neurometric is a "prose voice": it does not support OpenAI tool-calling, so its
|
# Does NOT merge. Posts formal APPROVE/REQUEST_CHANGES/COMMENT reviews.
|
||||||
# contribution is raw markdown + a heuristic verdict. It is never the primary voice.
|
|
||||||
#
|
#
|
||||||
# Does NOT merge. Does NOT post formal APPROVE/REQUEST_CHANGES reviews — always COMMENT
|
# Requires repo secret: OPENROUTER_API_KEY
|
||||||
# (GITHUB_TOKEN can't formally approve PRs without repo-setting toggle).
|
|
||||||
#
|
|
||||||
# Requires repo secrets: OPENROUTER_API_KEY, NEUROMETRIC_API_KEY (optional; the
|
|
||||||
# Neurometric voice self-skips with an inline error note if the key is missing).
|
|
||||||
#
|
#
|
||||||
# Cost cap: tracked in Repository Variables (CTO_REVIEW_SPEND_CENTS, CTO_REVIEW_CAP_CENTS).
|
# Cost cap: tracked in Repository Variables (CTO_REVIEW_SPEND_CENTS, CTO_REVIEW_CAP_CENTS).
|
||||||
# Default cap is 1000 cents ($10/month). Auto-resets on the 1st of each month.
|
# Default cap is 1000 cents ($10/month). Auto-resets on the 1st of each month.
|
||||||
@@ -123,17 +120,18 @@ jobs:
|
|||||||
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=50
|
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=50
|
||||||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
||||||
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
||||||
DIFF=$(git diff --no-color "$BASE_SHA" "$HEAD_SHA" | head -c 400000)
|
# Write the diff to a file, not a step output / env var. Passing a
|
||||||
|
# ~400KB diff through the process env (execve argv+envp) exceeds the
|
||||||
|
# runner ARG_MAX and fails the next step with "Argument list too long".
|
||||||
|
# File transport also sidesteps the ~1MB step-output cap.
|
||||||
|
git diff --no-color "$BASE_SHA" "$HEAD_SHA" | head -c 400000 > /tmp/cto-review-diff.txt
|
||||||
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
|
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
|
||||||
SIZE=$(echo -n "$DIFF" | wc -c)
|
SIZE=$(wc -c < /tmp/cto-review-diff.txt)
|
||||||
{
|
{
|
||||||
echo "size=$SIZE"
|
echo "size=$SIZE"
|
||||||
echo "files<<EOF_FILES"
|
echo "files<<EOF_FILES"
|
||||||
echo "$FILES"
|
echo "$FILES"
|
||||||
echo "EOF_FILES"
|
echo "EOF_FILES"
|
||||||
echo "diff<<EOF_DIFF"
|
|
||||||
echo "$DIFF"
|
|
||||||
echo "EOF_DIFF"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Load repo conventions
|
- name: Load repo conventions
|
||||||
@@ -150,18 +148,17 @@ jobs:
|
|||||||
echo "EOF_CONV"
|
echo "EOF_CONV"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Call 4 models in parallel (OpenRouter + Neurometric)
|
- name: Call Haiku via OpenRouter
|
||||||
if: steps.budget.outputs.skip != 'true'
|
if: steps.budget.outputs.skip != 'true'
|
||||||
id: review
|
id: review
|
||||||
env:
|
env:
|
||||||
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
||||||
NEUROMETRIC_API_KEY: ${{ secrets.NEUROMETRIC_API_KEY }}
|
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
PR_BODY: ${{ github.event.pull_request.body }}
|
PR_BODY: ${{ github.event.pull_request.body }}
|
||||||
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
|
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
REPO_NAME: ${{ github.event.repository.name }}
|
REPO_NAME: ${{ github.event.repository.name }}
|
||||||
DIFF: ${{ steps.diff.outputs.diff }}
|
DIFF_PATH: /tmp/cto-review-diff.txt
|
||||||
DIFF_SIZE: ${{ steps.diff.outputs.size }}
|
DIFF_SIZE: ${{ steps.diff.outputs.size }}
|
||||||
CHANGED_FILES: ${{ steps.diff.outputs.files }}
|
CHANGED_FILES: ${{ steps.diff.outputs.files }}
|
||||||
CONVENTIONS: ${{ steps.conventions.outputs.content }}
|
CONVENTIONS: ${{ steps.conventions.outputs.content }}
|
||||||
@@ -183,24 +180,17 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json, os, sys, urllib.request, concurrent.futures
|
import json, os, sys, urllib.request
|
||||||
|
|
||||||
api_key = os.environ["OPENROUTER_API_KEY"]
|
api_key = os.environ["OPENROUTER_API_KEY"]
|
||||||
|
|
||||||
# A/B harness: four models. Each gets the same prompt.
|
# Haiku-only reviewer. A/B panel dropped 2026-06-12 per QA data:
|
||||||
# Primary model's verdict drives the heading. Others are labeled.
|
# DeepSeek high false-positive rate, Kimi ~60% failure rate,
|
||||||
# Edit this list to change the roster (or drop to 1 after A/B window closes).
|
# Neurometric zero unique-real findings. Haiku retained as sole voice.
|
||||||
#
|
MODEL_SLUG = "anthropic/claude-haiku-4.5"
|
||||||
# provider_type semantics:
|
MODEL_DISPLAY = "Claude Haiku 4.5"
|
||||||
# - "openrouter_tools": OpenAI tool-calling via OpenRouter; structured verdict.
|
INPUT_PER_M_USD = 1.00
|
||||||
# - "neurometric_prose": Neurometric marketplace SLM; prose output + heuristic verdict.
|
OUTPUT_PER_M_USD = 5.00
|
||||||
MODELS = [
|
|
||||||
# (slug, display name, input_per_M_USD, output_per_M_USD, is_primary, provider_type)
|
|
||||||
("anthropic/claude-haiku-4.5", "Claude Haiku 4.5", 1.00, 5.00, True, "openrouter_tools"),
|
|
||||||
("deepseek/deepseek-chat-v3.1", "DeepSeek V3.1", 0.15, 0.75, False, "openrouter_tools"),
|
|
||||||
("moonshotai/kimi-k2-thinking", "Kimi K2 Thinking", 0.60, 2.50, False, "openrouter_tools"),
|
|
||||||
("neurometric/pr-summarizer", "Neurometric PR-Summarizer (Qwen3-4B)", 0.00, 0.00, False, "neurometric_prose"),
|
|
||||||
]
|
|
||||||
|
|
||||||
system = """You are the CTO and lead reviewer for the peptiderepo project. You are reviewing a pull request opened by an autonomous agent or human contributor.
|
system = """You are the CTO and lead reviewer for the peptiderepo project. You are reviewing a pull request opened by an autonomous agent or human contributor.
|
||||||
|
|
||||||
@@ -229,7 +219,9 @@ jobs:
|
|||||||
user_blocks.append(f"**Changed files:**\n```\n{os.environ['CHANGED_FILES']}\n```\n")
|
user_blocks.append(f"**Changed files:**\n```\n{os.environ['CHANGED_FILES']}\n```\n")
|
||||||
if os.environ.get("CONVENTIONS", "").strip():
|
if os.environ.get("CONVENTIONS", "").strip():
|
||||||
user_blocks.append(f"# Repo CONVENTIONS.md\n{os.environ['CONVENTIONS']}\n")
|
user_blocks.append(f"# Repo CONVENTIONS.md\n{os.environ['CONVENTIONS']}\n")
|
||||||
user_blocks.append(f"# Diff\n```diff\n{os.environ['DIFF']}\n```\n")
|
with open(os.environ["DIFF_PATH"], encoding="utf-8", errors="replace") as _df:
|
||||||
|
_diff_text = _df.read()
|
||||||
|
user_blocks.append(f"# Diff\n```diff\n{_diff_text}\n```\n")
|
||||||
user_message = "\n\n".join(user_blocks)
|
user_message = "\n\n".join(user_blocks)
|
||||||
|
|
||||||
tools = [{
|
tools = [{
|
||||||
@@ -261,32 +253,8 @@ jobs:
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
PER_MODEL_TIMEOUT = 60 # seconds; one hung model should not block siblings
|
|
||||||
|
|
||||||
# Heuristic verdict inference for prose-voice models that can't do tool-calling.
|
|
||||||
# Keyword order matters: block markers beat approve markers.
|
|
||||||
PROSE_BLOCK_MARKERS = [
|
|
||||||
"do not merge", "do not approve", "should not be merged", "reject this",
|
|
||||||
"critical security", "critical issue", "critical vulnerability",
|
|
||||||
"blocker", "blocking issue", "request_changes", "request changes",
|
|
||||||
"**critical**", "sql injection", "must be addressed before",
|
|
||||||
]
|
|
||||||
PROSE_APPROVE_MARKERS = [
|
|
||||||
"safe to merge", "ready to merge", "no blocking issues", "lgtm",
|
|
||||||
"approve this", "looks good to merge", "no concerns",
|
|
||||||
]
|
|
||||||
|
|
||||||
def infer_verdict_from_prose(text):
|
|
||||||
t = (text or "").lower()
|
|
||||||
if any(m in t for m in PROSE_BLOCK_MARKERS):
|
|
||||||
return "REQUEST_CHANGES"
|
|
||||||
if any(m in t for m in PROSE_APPROVE_MARKERS):
|
|
||||||
return "APPROVE"
|
|
||||||
return "COMMENT"
|
|
||||||
|
|
||||||
def call_openrouter_tools(slug, display, in_rate, out_rate, is_primary):
|
|
||||||
body = {
|
body = {
|
||||||
"model": slug,
|
"model": MODEL_SLUG,
|
||||||
"max_tokens": 2048,
|
"max_tokens": 2048,
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "system", "content": system},
|
{"role": "system", "content": system},
|
||||||
@@ -302,177 +270,83 @@ jobs:
|
|||||||
"Authorization": f"Bearer {api_key}",
|
"Authorization": f"Bearer {api_key}",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"HTTP-Referer": "https://github.com/peptiderepo",
|
"HTTP-Referer": "https://github.com/peptiderepo",
|
||||||
"X-Title": f"peptiderepo CTO reviewer ({display})"
|
"X-Title": f"peptiderepo CTO reviewer ({MODEL_DISPLAY})"
|
||||||
},
|
},
|
||||||
method="POST"
|
method="POST"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
error = None
|
||||||
|
review = None
|
||||||
|
cost_cents = 0.0
|
||||||
|
ptok = 0
|
||||||
|
ctok = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req, timeout=PER_MODEL_TIMEOUT) as resp:
|
with urllib.request.urlopen(req, timeout=60) as resp:
|
||||||
data = json.loads(resp.read())
|
data = json.loads(resp.read())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
error = str(e)[:300]
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
data = {}
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"error": str(e)[:300],
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if not error:
|
||||||
choice = data.get("choices", [{}])[0].get("message", {})
|
choice = data.get("choices", [{}])[0].get("message", {})
|
||||||
tool_calls = choice.get("tool_calls", [])
|
tool_calls = choice.get("tool_calls", [])
|
||||||
if not tool_calls:
|
if not tool_calls:
|
||||||
return {
|
error = f"No tool_call in response. Raw content: {str(choice)[:300]}"
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
else:
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"error": f"No tool_call in response. Raw content: {str(choice)[:300]}",
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
review = json.loads(tool_calls[0]["function"]["arguments"])
|
review = json.loads(tool_calls[0]["function"]["arguments"])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
error = f"Malformed tool args: {e}"
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"error": f"Malformed tool args: {e}",
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if not error:
|
||||||
usage = data.get("usage", {})
|
usage = data.get("usage", {})
|
||||||
ptok = usage.get("prompt_tokens", 0)
|
ptok = usage.get("prompt_tokens", 0)
|
||||||
ctok = usage.get("completion_tokens", 0)
|
ctok = usage.get("completion_tokens", 0)
|
||||||
cost_usd = (ptok * in_rate / 1_000_000) + (ctok * out_rate / 1_000_000)
|
cost_usd = (ptok * INPUT_PER_M_USD / 1_000_000) + (ctok * OUTPUT_PER_M_USD / 1_000_000)
|
||||||
cost_cents = cost_usd * 100
|
cost_cents = cost_usd * 100
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"review": review, "prompt_tokens": ptok, "completion_tokens": ctok,
|
|
||||||
"cost_cents": cost_cents,
|
|
||||||
}
|
|
||||||
|
|
||||||
def call_neurometric_prose(slug, display, is_primary):
|
|
||||||
nm_key = os.environ.get("NEUROMETRIC_API_KEY", "")
|
|
||||||
if not nm_key:
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"error": "NEUROMETRIC_API_KEY secret not set on this repo",
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
body = {
|
|
||||||
"model": slug,
|
|
||||||
"max_tokens": 2048,
|
|
||||||
"messages": [
|
|
||||||
{"role": "system", "content": system},
|
|
||||||
{"role": "user", "content": user_message},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
req = urllib.request.Request(
|
|
||||||
"https://api.neurometric.ai/v1/chat/completions",
|
|
||||||
data=json.dumps(body).encode(),
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {nm_key}",
|
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
|
||||||
method="POST",
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=PER_MODEL_TIMEOUT) as resp:
|
|
||||||
data = json.loads(resp.read())
|
|
||||||
except Exception as e:
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"error": str(e)[:300],
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
prose = data.get("choices", [{}])[0].get("message", {}).get("content") or ""
|
|
||||||
verdict = infer_verdict_from_prose(prose)
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"review": {"verdict": verdict, "prose": prose},
|
|
||||||
"prompt_tokens": 0, "completion_tokens": 0,
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
def call_model(slug, display, in_rate, out_rate, is_primary, provider_type="openrouter_tools"):
|
|
||||||
if provider_type == "neurometric_prose":
|
|
||||||
return call_neurometric_prose(slug, display, is_primary)
|
|
||||||
return call_openrouter_tools(slug, display, in_rate, out_rate, is_primary)
|
|
||||||
|
|
||||||
results = []
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=len(MODELS)) as pool:
|
|
||||||
futures = [pool.submit(call_model, *m) for m in MODELS]
|
|
||||||
for f in concurrent.futures.as_completed(futures):
|
|
||||||
results.append(f.result())
|
|
||||||
|
|
||||||
# Order: primary first, then alphabetical for stable comparison
|
|
||||||
results.sort(key=lambda r: (not r.get("is_primary"), r["display"]))
|
|
||||||
|
|
||||||
# Build combined comment
|
|
||||||
primary = next((r for r in results if r.get("is_primary") and "review" in r), None)
|
|
||||||
heading_verdict = primary["review"]["verdict"] if primary else "MIXED"
|
|
||||||
|
|
||||||
|
# Build comment
|
||||||
|
if error:
|
||||||
|
heading_verdict = "ERROR"
|
||||||
lines = [f"## CTO Review — {heading_verdict}", ""]
|
lines = [f"## CTO Review — {heading_verdict}", ""]
|
||||||
lines.append(f"_A/B harness active: {len(results)} models reviewing in parallel. Primary verdict drives heading; others are advisory._")
|
lines.append(f"Model failed: `{error}`")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
lines.append(f"_reviewer: {MODEL_DISPLAY}_")
|
||||||
total_cents = 0.0
|
else:
|
||||||
for r in results:
|
heading_verdict = review.get("verdict", "COMMENT")
|
||||||
lines.append(f"---")
|
lines = [f"## CTO Review — {heading_verdict}", ""]
|
||||||
primary_tag = " (primary)" if r.get("is_primary") else ""
|
lines.append(f"**Verdict:** {heading_verdict}")
|
||||||
lines.append(f"### {r['display']}{primary_tag}")
|
|
||||||
if "error" in r:
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(f"⚠️ Model failed: `{r['error']}`")
|
lines.append(review.get("summary") or "_(model returned no summary)_")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
continue
|
if review.get("concerns"):
|
||||||
rev = r["review"]
|
|
||||||
lines.append("")
|
|
||||||
if r.get("provider_type") == "neurometric_prose":
|
|
||||||
lines.append(f"**Verdict:** {rev['verdict']} _(heuristic, inferred from prose)_")
|
|
||||||
lines.append("")
|
|
||||||
# Cap at 6KB to keep PR comments readable; 4B model output is rarely over this
|
|
||||||
prose = rev.get("prose", "")
|
|
||||||
if len(prose) > 6000:
|
|
||||||
prose = prose[:6000] + "\n\n_…output truncated for comment length…_"
|
|
||||||
lines.append(prose)
|
|
||||||
lines.append("")
|
|
||||||
lines.append("_free tier; per-call token usage not tracked_")
|
|
||||||
lines.append("")
|
|
||||||
continue
|
|
||||||
lines.append(f"**Verdict:** {rev.get('verdict', 'COMMENT')}")
|
|
||||||
lines.append("")
|
|
||||||
lines.append(rev.get("summary") or "_(model returned no summary)_")
|
|
||||||
lines.append("")
|
|
||||||
if rev.get("concerns"):
|
|
||||||
lines.append("**Concerns:**")
|
lines.append("**Concerns:**")
|
||||||
for c in rev["concerns"]:
|
for c in review["concerns"]:
|
||||||
sev = c["severity"].upper()
|
sev = c.get("severity", "UNKNOWN").upper()
|
||||||
f = f"`{c['file']}`" if c.get("file") else ""
|
f = f"`{c['file']}`" if c.get("file") else ""
|
||||||
lines.append(f"- **{sev}** {f} — {c['issue']}")
|
lines.append(f"- **{sev}** {f} — {c['issue']}")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
if rev.get("positives"):
|
if review.get("positives"):
|
||||||
lines.append("**Positives:** " + "; ".join(rev["positives"]))
|
lines.append("**Positives:** " + "; ".join(review["positives"]))
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(f"_tokens in/out: {r['prompt_tokens']}/{r['completion_tokens']} · cost: ${r['cost_cents']/100:.4f}_")
|
lines.append(f"_tokens in/out: {ptok}/{ctok} · cost: ${cost_cents/100:.4f}_")
|
||||||
total_cents += r["cost_cents"]
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
lines.append("---")
|
lines.append("---")
|
||||||
lines.append(f"_Total review cost: **${total_cents/100:.4f}**. A/B roster configured in `.github/workflows/cto-review.yml`._")
|
lines.append(f"_Total review cost: **${cost_cents/100:.4f}**. Reviewer: {MODEL_DISPLAY}. Roster configured in `.github/workflows/cto-review.yml`._")
|
||||||
|
|
||||||
with open("/tmp/review-body.md", "w") as f:
|
with open("/tmp/review-body.md", "w") as f:
|
||||||
f.write("\n".join(lines))
|
f.write("\n".join(lines))
|
||||||
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
||||||
f.write(f"added_cents={int(round(total_cents))}\n")
|
f.write(f"added_cents={int(round(cost_cents))}\n")
|
||||||
f.write(f"skipped=0\n")
|
f.write(f"skipped=0\n")
|
||||||
f.write(f"primary_verdict={heading_verdict}\n")
|
f.write(f"primary_verdict={heading_verdict}\n")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
- name: Post PR review (formal APPROVE / REQUEST_CHANGES / COMMENT)
|
- name: Post PR review (formal APPROVE / REQUEST_CHANGES / COMMENT)
|
||||||
# Uses primary model's verdict as the formal event. Falls back to COMMENT
|
# Uses Haiku's verdict as the formal event. Falls back to COMMENT
|
||||||
# if the primary model failed or returned something unexpected.
|
# if the model failed or returned something unexpected.
|
||||||
if: steps.budget.outputs.skip != 'true' && steps.review.outputs.skipped != '1'
|
if: steps.budget.outputs.skip != 'true' && steps.review.outputs.skipped != '1'
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
env:
|
env:
|
||||||
|
|||||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -3,6 +3,32 @@
|
|||||||
All notable changes to Peptide Reconstitution Calculator are documented here.
|
All notable changes to Peptide Reconstitution Calculator are documented here.
|
||||||
Format: [Semantic Versioning](https://semver.org/).
|
Format: [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
|
## [1.2.0] — 2026-06-16
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- PHPUnit test suite (WP stubs, `tests: stubs`) — 40 tests across four classes:
|
||||||
|
- `MathTest`: 25 tests covering all PRC_Math methods — concentration mg/mL,
|
||||||
|
mcg/unit, injection volume, syringe units, doses per vial, and the full
|
||||||
|
`calculate()` orchestrator with named peptide scenarios (BPC-157, TB-500,
|
||||||
|
Semaglutide, MK-677, Ipamorelin) plus edge cases (zero water, zero dose,
|
||||||
|
negative inputs, floor rounding, rounding precision).
|
||||||
|
- `DefaultPresetsTest`: 11 tests — collection count, all 8 expected slugs present,
|
||||||
|
required keys on every preset (via dataProvider), valid dose units, min < max,
|
||||||
|
source='default', and spot-checks on BPC-157 / Semaglutide / MK-677.
|
||||||
|
- `RestControllerTest`: 7 tests — calculate() 200 response + correct values for
|
||||||
|
mcg and mg dose units; get_presets() returns 200; get_preset() 200 for known
|
||||||
|
slug and WP_Error for unknown slug.
|
||||||
|
- `PresetProviderTest`: 4 tests — fallback to defaults without PR Core, all
|
||||||
|
presets have slug, cache invalidation, idempotent invalidation.
|
||||||
|
- `phpunit.xml.dist` + `tests/bootstrap.php` (WP function/class stubs).
|
||||||
|
- `composer test` script (`vendor/bin/phpunit --configuration phpunit.xml.dist`).
|
||||||
|
- `phpunit/phpunit ^9.6` and `yoast/phpunit-polyfills ^2.0` in `require-dev`.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `ci.yml` replaced with thin caller delegating to estate reusable workflow
|
||||||
|
(`peptide-e2e/.github/workflows/ci.yml@main`; `tests: stubs`, `has_js: true`,
|
||||||
|
`permissions: contents: write`, `workflow_call` so `deploy.yml` gate works).
|
||||||
|
|
||||||
## [1.1.0] — 2026-04-26
|
## [1.1.0] — 2026-04-26
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -7,10 +7,12 @@
|
|||||||
"php": ">=8.1"
|
"php": ">=8.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.6",
|
||||||
"squizlabs/php_codesniffer": "^3.13",
|
"squizlabs/php_codesniffer": "^3.13",
|
||||||
"wp-coding-standards/wpcs": "^3.0",
|
"wp-coding-standards/wpcs": "^3.0",
|
||||||
"phpcsstandards/phpcsutils": "^1.0",
|
"phpcsstandards/phpcsutils": "^1.0",
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
|
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
||||||
|
"yoast/phpunit-polyfills": "^2.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"test": "vendor/bin/phpunit --configuration phpunit.xml.dist",
|
||||||
"lint": "phpcs",
|
"lint": "phpcs",
|
||||||
"lint:fix": "phpcbf"
|
"lint:fix": "phpcbf"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
* @see class-prc-preset-provider.php — Data source for presets.
|
* @see class-prc-preset-provider.php — Data source for presets.
|
||||||
* @see class-prc-math.php — Calculation engine.
|
* @see class-prc-math.php — Calculation engine.
|
||||||
* @see class-prc-shortcode.php — Frontend JS consumes these endpoints.
|
* @see class-prc-shortcode.php — Frontend JS consumes these endpoints.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -38,39 +39,39 @@ class PRC_Rest_Controller {
|
|||||||
register_rest_route(
|
register_rest_route(
|
||||||
self::NAMESPACE,
|
self::NAMESPACE,
|
||||||
'/presets',
|
'/presets',
|
||||||
[
|
array(
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'callback' => [ $this, 'get_presets' ],
|
'callback' => array( $this, 'get_presets' ),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
]
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
self::NAMESPACE,
|
self::NAMESPACE,
|
||||||
'/presets/(?P<slug>[a-z0-9-]+)',
|
'/presets/(?P<slug>[a-z0-9-]+)',
|
||||||
[
|
array(
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'callback' => [ $this, 'get_preset' ],
|
'callback' => array( $this, 'get_preset' ),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
'args' => [
|
'args' => array(
|
||||||
'slug' => [
|
'slug' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'sanitize_callback' => 'sanitize_title',
|
'sanitize_callback' => 'sanitize_title',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
],
|
),
|
||||||
],
|
),
|
||||||
]
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
self::NAMESPACE,
|
self::NAMESPACE,
|
||||||
'/calculate',
|
'/calculate',
|
||||||
[
|
array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => [ $this, 'calculate' ],
|
'callback' => array( $this, 'calculate' ),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
'args' => $this->get_calculate_args(),
|
'args' => $this->get_calculate_args(),
|
||||||
]
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ class PRC_Rest_Controller {
|
|||||||
* @param \WP_REST_Request $request Request object.
|
* @param \WP_REST_Request $request Request object.
|
||||||
* @return \WP_REST_Response
|
* @return \WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public function get_presets( \WP_REST_Request $request ): \WP_REST_Response {
|
public function get_presets( \WP_REST_Request $request ): \WP_REST_Response { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||||
$provider = new PRC_Preset_Provider();
|
$provider = new PRC_Preset_Provider();
|
||||||
$presets = $provider->get_all_presets();
|
$presets = $provider->get_all_presets();
|
||||||
|
|
||||||
@@ -107,7 +108,7 @@ class PRC_Rest_Controller {
|
|||||||
return new \WP_Error(
|
return new \WP_Error(
|
||||||
'prc_preset_not_found',
|
'prc_preset_not_found',
|
||||||
__( 'Preset not found.', 'peptide-reconstitution-calculator' ),
|
__( 'Preset not found.', 'peptide-reconstitution-calculator' ),
|
||||||
[ 'status' => 404 ]
|
array( 'status' => 404 )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,31 +138,31 @@ class PRC_Rest_Controller {
|
|||||||
* @return array<string, array<string, mixed>>
|
* @return array<string, array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
private function get_calculate_args(): array {
|
private function get_calculate_args(): array {
|
||||||
return [
|
return array(
|
||||||
'vial_mg' => [
|
'vial_mg' => array(
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'sanitize_callback' => 'floatval',
|
'sanitize_callback' => 'floatval',
|
||||||
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
||||||
],
|
),
|
||||||
'water_ml' => [
|
'water_ml' => array(
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'sanitize_callback' => 'floatval',
|
'sanitize_callback' => 'floatval',
|
||||||
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
||||||
],
|
),
|
||||||
'desired_dose' => [
|
'desired_dose' => array(
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'sanitize_callback' => 'floatval',
|
'sanitize_callback' => 'floatval',
|
||||||
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
'validate_callback' => fn( $v ) => is_numeric( $v ) && (float) $v > 0,
|
||||||
],
|
),
|
||||||
'dose_unit' => [
|
'dose_unit' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
'validate_callback' => fn( $v ) => in_array( $v, [ 'mcg', 'mg' ], true ),
|
'validate_callback' => fn( $v ) => in_array( $v, array( 'mcg', 'mg' ), true ),
|
||||||
],
|
),
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
* What: Runs on plugin activation — flushes rewrite rules.
|
* What: Runs on plugin activation — flushes rewrite rules.
|
||||||
* Who calls it: register_activation_hook in bootstrap.
|
* Who calls it: register_activation_hook in bootstrap.
|
||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
|
*
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
*
|
*
|
||||||
* @see class-pr-core-autoloader.php in Peptide Repo Core — same pattern.
|
* @see class-pr-core-autoloader.php in Peptide Repo Core — same pattern.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -22,7 +23,7 @@ class PRC_Autoloader {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register(): void {
|
public static function register(): void {
|
||||||
spl_autoload_register( [ __CLASS__, 'autoload' ] );
|
spl_autoload_register( array( __CLASS__, 'autoload' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*
|
*
|
||||||
* @see class-prc-preset-provider.php — Cache being invalidated.
|
* @see class-prc-preset-provider.php — Cache being invalidated.
|
||||||
* @see PR_Core_Dosing_Repository — Fires the hooks we listen to.
|
* @see PR_Core_Dosing_Repository — Fires the hooks we listen to.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -27,7 +28,7 @@ class PRC_Cache_Listener {
|
|||||||
* @return void Side effect: registers action hooks.
|
* @return void Side effect: registers action hooks.
|
||||||
*/
|
*/
|
||||||
public static function register(): void {
|
public static function register(): void {
|
||||||
$callback = [ __CLASS__, 'invalidate' ];
|
$callback = array( __CLASS__, 'invalidate' );
|
||||||
|
|
||||||
// Dosing row lifecycle — affects calculator presets.
|
// Dosing row lifecycle — affects calculator presets.
|
||||||
add_action( 'pr_core_after_dosing_row_publish', $callback );
|
add_action( 'pr_core_after_dosing_row_publish', $callback );
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
* @see class-prc-shortcode.php — Frontend calculator widget.
|
* @see class-prc-shortcode.php — Frontend calculator widget.
|
||||||
* @see class-prc-rest-controller.php — REST endpoints for presets.
|
* @see class-prc-rest-controller.php — REST endpoints for presets.
|
||||||
* @see class-prc-preset-provider.php — PR Core integration + fallback defaults.
|
* @see class-prc-preset-provider.php — PR Core integration + fallback defaults.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -29,17 +30,17 @@ class PRC_Calculator {
|
|||||||
public static function boot(): void {
|
public static function boot(): void {
|
||||||
// Frontend shortcode — always available.
|
// Frontend shortcode — always available.
|
||||||
$shortcode = new PRC_Shortcode();
|
$shortcode = new PRC_Shortcode();
|
||||||
add_action( 'init', [ $shortcode, 'register' ] );
|
add_action( 'init', array( $shortcode, 'register' ) );
|
||||||
|
|
||||||
// REST API — serves presets to the JS calculator.
|
// REST API — serves presets to the JS calculator.
|
||||||
add_action( 'rest_api_init', [ new PRC_Rest_Controller(), 'register_routes' ] );
|
add_action( 'rest_api_init', array( new PRC_Rest_Controller(), 'register_routes' ) );
|
||||||
|
|
||||||
// Cache invalidation — keep presets in sync with PR Core dosing data.
|
// Cache invalidation — keep presets in sync with PR Core dosing data.
|
||||||
PRC_Cache_Listener::register();
|
PRC_Cache_Listener::register();
|
||||||
|
|
||||||
// Admin notice when PR Core is absent.
|
// Admin notice when PR Core is absent.
|
||||||
if ( is_admin() && ! self::is_pr_core_active() ) {
|
if ( is_admin() && ! self::is_pr_core_active() ) {
|
||||||
add_action( 'admin_notices', [ __CLASS__, 'render_pr_core_notice' ] );
|
add_action( 'admin_notices', array( __CLASS__, 'render_pr_core_notice' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ class PRC_Calculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only show on plugins page and the calculator's own pages.
|
// Only show on plugins page and the calculator's own pages.
|
||||||
$show_on = [ 'plugins', 'settings_page_prc-settings' ];
|
$show_on = array( 'plugins', 'settings_page_prc-settings' );
|
||||||
if ( ! in_array( $screen->id, $show_on, true ) ) {
|
if ( ! in_array( $screen->id, $show_on, true ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
* What: Runs on plugin deactivation — flushes rewrite rules.
|
* What: Runs on plugin deactivation — flushes rewrite rules.
|
||||||
* Who calls it: register_deactivation_hook in bootstrap.
|
* Who calls it: register_deactivation_hook in bootstrap.
|
||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
|
*
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
*
|
*
|
||||||
* @see class-prc-preset-provider.php — Merges these with live PR Core data.
|
* @see class-prc-preset-provider.php — Merges these with live PR Core data.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -27,11 +28,11 @@ class PRC_Default_Presets {
|
|||||||
* @return array<int, array<string, mixed>>
|
* @return array<int, array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
public static function get_all(): array {
|
public static function get_all(): array {
|
||||||
return [
|
return array(
|
||||||
[
|
array(
|
||||||
'slug' => 'bpc-157',
|
'slug' => 'bpc-157',
|
||||||
'name' => 'BPC-157',
|
'name' => 'BPC-157',
|
||||||
'vial_sizes_mg' => [ 5, 10 ],
|
'vial_sizes_mg' => array( 5, 10 ),
|
||||||
'default_vial_mg' => 5,
|
'default_vial_mg' => 5,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 200,
|
'dose_range_min' => 200,
|
||||||
@@ -41,11 +42,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'observational',
|
'evidence_strength' => 'observational',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'tb-500',
|
'slug' => 'tb-500',
|
||||||
'name' => 'TB-500',
|
'name' => 'TB-500',
|
||||||
'vial_sizes_mg' => [ 2, 5, 10 ],
|
'vial_sizes_mg' => array( 2, 5, 10 ),
|
||||||
'default_vial_mg' => 5,
|
'default_vial_mg' => 5,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 2000,
|
'dose_range_min' => 2000,
|
||||||
@@ -55,11 +56,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'preclinical',
|
'evidence_strength' => 'preclinical',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'semaglutide',
|
'slug' => 'semaglutide',
|
||||||
'name' => 'Semaglutide',
|
'name' => 'Semaglutide',
|
||||||
'vial_sizes_mg' => [ 2, 5, 10 ],
|
'vial_sizes_mg' => array( 2, 5, 10 ),
|
||||||
'default_vial_mg' => 5,
|
'default_vial_mg' => 5,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 0.25,
|
'dose_range_min' => 0.25,
|
||||||
@@ -69,11 +70,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'meta-analysis',
|
'evidence_strength' => 'meta-analysis',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'cjc-1295-dac',
|
'slug' => 'cjc-1295-dac',
|
||||||
'name' => 'CJC-1295 (DAC)',
|
'name' => 'CJC-1295 (DAC)',
|
||||||
'vial_sizes_mg' => [ 2, 5 ],
|
'vial_sizes_mg' => array( 2, 5 ),
|
||||||
'default_vial_mg' => 2,
|
'default_vial_mg' => 2,
|
||||||
'recommended_water_ml' => 1.0,
|
'recommended_water_ml' => 1.0,
|
||||||
'dose_range_min' => 1000,
|
'dose_range_min' => 1000,
|
||||||
@@ -83,11 +84,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'preclinical',
|
'evidence_strength' => 'preclinical',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'ipamorelin',
|
'slug' => 'ipamorelin',
|
||||||
'name' => 'Ipamorelin',
|
'name' => 'Ipamorelin',
|
||||||
'vial_sizes_mg' => [ 2, 5 ],
|
'vial_sizes_mg' => array( 2, 5 ),
|
||||||
'default_vial_mg' => 5,
|
'default_vial_mg' => 5,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 100,
|
'dose_range_min' => 100,
|
||||||
@@ -97,11 +98,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'preclinical',
|
'evidence_strength' => 'preclinical',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'pt-141',
|
'slug' => 'pt-141',
|
||||||
'name' => 'PT-141 (Bremelanotide)',
|
'name' => 'PT-141 (Bremelanotide)',
|
||||||
'vial_sizes_mg' => [ 2, 10 ],
|
'vial_sizes_mg' => array( 2, 10 ),
|
||||||
'default_vial_mg' => 10,
|
'default_vial_mg' => 10,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 500,
|
'dose_range_min' => 500,
|
||||||
@@ -111,11 +112,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'rct-large',
|
'evidence_strength' => 'rct-large',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'mk-677',
|
'slug' => 'mk-677',
|
||||||
'name' => 'MK-677 (Ibutamoren)',
|
'name' => 'MK-677 (Ibutamoren)',
|
||||||
'vial_sizes_mg' => [ 15, 30 ],
|
'vial_sizes_mg' => array( 15, 30 ),
|
||||||
'default_vial_mg' => 30,
|
'default_vial_mg' => 30,
|
||||||
'recommended_water_ml' => 3.0,
|
'recommended_water_ml' => 3.0,
|
||||||
'dose_range_min' => 10,
|
'dose_range_min' => 10,
|
||||||
@@ -125,11 +126,11 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'rct-small',
|
'evidence_strength' => 'rct-small',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
[
|
array(
|
||||||
'slug' => 'ghrp-6',
|
'slug' => 'ghrp-6',
|
||||||
'name' => 'GHRP-6',
|
'name' => 'GHRP-6',
|
||||||
'vial_sizes_mg' => [ 5, 10 ],
|
'vial_sizes_mg' => array( 5, 10 ),
|
||||||
'default_vial_mg' => 5,
|
'default_vial_mg' => 5,
|
||||||
'recommended_water_ml' => 2.0,
|
'recommended_water_ml' => 2.0,
|
||||||
'dose_range_min' => 100,
|
'dose_range_min' => 100,
|
||||||
@@ -139,7 +140,7 @@ class PRC_Default_Presets {
|
|||||||
'evidence_strength' => 'preclinical',
|
'evidence_strength' => 'preclinical',
|
||||||
'dosing_row_count' => 0,
|
'dosing_row_count' => 0,
|
||||||
'source' => 'default',
|
'source' => 'default',
|
||||||
],
|
),
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
*
|
*
|
||||||
* @see assets/js/calculator.js — Client-side mirror of this math.
|
* @see assets/js/calculator.js — Client-side mirror of this math.
|
||||||
* @see api/class-prc-rest-controller.php — Server-side consumer.
|
* @see api/class-prc-rest-controller.php — Server-side consumer.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -58,7 +59,7 @@ class PRC_Math {
|
|||||||
$syringe_units = self::syringe_units( $injection_ml );
|
$syringe_units = self::syringe_units( $injection_ml );
|
||||||
$doses_per_vial = self::doses_per_vial( $vial_mg, $dose_mg );
|
$doses_per_vial = self::doses_per_vial( $vial_mg, $dose_mg );
|
||||||
|
|
||||||
return [
|
return array(
|
||||||
'concentration_mg_per_ml' => round( $concentration_mg_per_ml, 4 ),
|
'concentration_mg_per_ml' => round( $concentration_mg_per_ml, 4 ),
|
||||||
'concentration_mcg_per_unit' => round( $concentration_mcg_per_unit, 2 ),
|
'concentration_mcg_per_unit' => round( $concentration_mcg_per_unit, 2 ),
|
||||||
'injection_volume_ml' => round( $injection_ml, 4 ),
|
'injection_volume_ml' => round( $injection_ml, 4 ),
|
||||||
@@ -69,7 +70,7 @@ class PRC_Math {
|
|||||||
'desired_dose_mg' => round( $dose_mg, 4 ),
|
'desired_dose_mg' => round( $dose_mg, 4 ),
|
||||||
'desired_dose_display' => $desired_dose,
|
'desired_dose_display' => $desired_dose,
|
||||||
'dose_unit' => $dose_unit,
|
'dose_unit' => $dose_unit,
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
* @see class-prc-default-presets.php — Hardcoded fallback presets.
|
* @see class-prc-default-presets.php — Hardcoded fallback presets.
|
||||||
* @see PR_Core_Peptide_Repository (PR Core) — Peptide list source.
|
* @see PR_Core_Peptide_Repository (PR Core) — Peptide list source.
|
||||||
* @see PR_Core_Dosing_Repository (PR Core) — Dosing data source.
|
* @see PR_Core_Dosing_Repository (PR Core) — Dosing data source.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -89,19 +90,19 @@ class PRC_Preset_Provider {
|
|||||||
// could fail to autoload (e.g. fatal error in PR Core bootstrap).
|
// could fail to autoload (e.g. fatal error in PR Core bootstrap).
|
||||||
// Fall back to empty array so the caller merges in defaults gracefully.
|
// Fall back to empty array so the caller merges in defaults gracefully.
|
||||||
if ( ! class_exists( 'PR_Core_Peptide_Repository' ) || ! class_exists( 'PR_Core_Dosing_Repository' ) ) {
|
if ( ! class_exists( 'PR_Core_Peptide_Repository' ) || ! class_exists( 'PR_Core_Dosing_Repository' ) ) {
|
||||||
return [];
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$peptide_repo = new PR_Core_Peptide_Repository();
|
$peptide_repo = new PR_Core_Peptide_Repository();
|
||||||
$dosing_repo = new PR_Core_Dosing_Repository();
|
$dosing_repo = new PR_Core_Dosing_Repository();
|
||||||
|
|
||||||
$peptides = $peptide_repo->find_all( [ 'posts_per_page' => 100 ] );
|
$peptides = $peptide_repo->find_all( array( 'posts_per_page' => 100 ) );
|
||||||
$presets = [];
|
$presets = array();
|
||||||
|
|
||||||
foreach ( $peptides as $peptide ) {
|
foreach ( $peptides as $peptide ) {
|
||||||
$rows = $dosing_repo->find_by_peptide(
|
$rows = $dosing_repo->find_by_peptide(
|
||||||
$peptide->id,
|
$peptide->id,
|
||||||
[ 'route' => 'subcutaneous' ]
|
array( 'route' => 'subcutaneous' )
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( empty( $rows ) ) {
|
if ( empty( $rows ) ) {
|
||||||
@@ -133,7 +134,7 @@ class PRC_Preset_Provider {
|
|||||||
// Extract dose range across all rows.
|
// Extract dose range across all rows.
|
||||||
$dose_mins = array_filter( array_map( fn( $r ) => $r->dose_min, $rows ) );
|
$dose_mins = array_filter( array_map( fn( $r ) => $r->dose_min, $rows ) );
|
||||||
$dose_maxs = array_filter( array_map( fn( $r ) => $r->dose_max, $rows ) );
|
$dose_maxs = array_filter( array_map( fn( $r ) => $r->dose_max, $rows ) );
|
||||||
$dose_unit = $rows[0]->dose_unit ?: 'mcg';
|
$dose_unit = ! empty( $rows[0]->dose_unit ) ? $rows[0]->dose_unit : 'mcg';
|
||||||
|
|
||||||
// Derive typical vial sizes from dose range.
|
// Derive typical vial sizes from dose range.
|
||||||
// Why: Most peptides are sold in standard vial sizes (2mg, 5mg, 10mg, 15mg, 30mg).
|
// Why: Most peptides are sold in standard vial sizes (2mg, 5mg, 10mg, 15mg, 30mg).
|
||||||
@@ -147,9 +148,9 @@ class PRC_Preset_Provider {
|
|||||||
$display_name = $peptide->title ?? '';
|
$display_name = $peptide->title ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return array(
|
||||||
'slug' => $peptide->slug,
|
'slug' => $peptide->slug,
|
||||||
'name' => $display_name ?: $peptide->title,
|
'name' => ! empty( $display_name ) ? $display_name : $peptide->title,
|
||||||
'vial_sizes_mg' => $vial_sizes,
|
'vial_sizes_mg' => $vial_sizes,
|
||||||
'default_vial_mg' => $vial_sizes[0] ?? 5,
|
'default_vial_mg' => $vial_sizes[0] ?? 5,
|
||||||
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
|
'recommended_water_ml' => $this->recommend_water_ml( $vial_sizes[0] ?? 5 ),
|
||||||
@@ -160,7 +161,7 @@ class PRC_Preset_Provider {
|
|||||||
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
|
'evidence_strength' => $peptide->evidence_strength ?? 'preclinical',
|
||||||
'dosing_row_count' => count( $rows ),
|
'dosing_row_count' => count( $rows ),
|
||||||
'source' => 'pr_core',
|
'source' => 'pr_core',
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,10 +177,10 @@ class PRC_Preset_Provider {
|
|||||||
* @return float[] Standard vial sizes in mg.
|
* @return float[] Standard vial sizes in mg.
|
||||||
*/
|
*/
|
||||||
private function infer_vial_sizes( array $dose_mins, array $dose_maxs, string $dose_unit ): array {
|
private function infer_vial_sizes( array $dose_mins, array $dose_maxs, string $dose_unit ): array {
|
||||||
$standard_sizes = [ 2, 5, 10, 15, 30 ];
|
$standard_sizes = array( 2, 5, 10, 15, 30 );
|
||||||
|
|
||||||
if ( empty( $dose_mins ) && empty( $dose_maxs ) ) {
|
if ( empty( $dose_mins ) && empty( $dose_maxs ) ) {
|
||||||
return [ 5, 10 ];
|
return array( 5, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert everything to mg for comparison.
|
// Convert everything to mg for comparison.
|
||||||
@@ -192,7 +193,7 @@ class PRC_Preset_Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pick vials that hold at least 10 doses at the max dose level.
|
// Pick vials that hold at least 10 doses at the max dose level.
|
||||||
$viable = [];
|
$viable = array();
|
||||||
foreach ( $standard_sizes as $size ) {
|
foreach ( $standard_sizes as $size ) {
|
||||||
if ( $max_dose_mg > 0 && ( $size / $max_dose_mg ) >= 5 ) {
|
if ( $max_dose_mg > 0 && ( $size / $max_dose_mg ) >= 5 ) {
|
||||||
$viable[] = $size;
|
$viable[] = $size;
|
||||||
@@ -200,7 +201,7 @@ class PRC_Preset_Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: return two middle sizes if heuristic found nothing.
|
// Fallback: return two middle sizes if heuristic found nothing.
|
||||||
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : [ 5, 10 ];
|
return ! empty( $viable ) ? array_slice( $viable, 0, 3 ) : array( 5, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
* @see assets/js/calculator.js — Client-side calculator logic.
|
* @see assets/js/calculator.js — Client-side calculator logic.
|
||||||
* @see assets/css/calculator.css — Calculator styles.
|
* @see assets/css/calculator.css — Calculator styles.
|
||||||
* @see class-prc-calculator.php — Boot orchestrator.
|
* @see class-prc-calculator.php — Boot orchestrator.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -34,7 +35,7 @@ class PRC_Shortcode {
|
|||||||
* @return void Side effect: registers shortcode.
|
* @return void Side effect: registers shortcode.
|
||||||
*/
|
*/
|
||||||
public function register(): void {
|
public function register(): void {
|
||||||
add_shortcode( 'prc_calculator', [ $this, 'render' ] );
|
add_shortcode( 'prc_calculator', array( $this, 'render' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,11 +48,11 @@ class PRC_Shortcode {
|
|||||||
* @param array<string, string>|string $atts Shortcode attributes.
|
* @param array<string, string>|string $atts Shortcode attributes.
|
||||||
* @return string HTML output.
|
* @return string HTML output.
|
||||||
*/
|
*/
|
||||||
public function render( $atts = [] ): string {
|
public function render( $atts = array() ): string {
|
||||||
$atts = shortcode_atts(
|
$atts = shortcode_atts(
|
||||||
[
|
array(
|
||||||
'peptide' => '', // Pre-select a peptide by slug.
|
'peptide' => '', // Pre-select a peptide by slug.
|
||||||
],
|
),
|
||||||
$atts,
|
$atts,
|
||||||
'prc_calculator'
|
'prc_calculator'
|
||||||
);
|
);
|
||||||
@@ -81,14 +82,14 @@ class PRC_Shortcode {
|
|||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'prc-calculator',
|
'prc-calculator',
|
||||||
PRC_PLUGIN_URL . 'assets/css/calculator.css',
|
PRC_PLUGIN_URL . 'assets/css/calculator.css',
|
||||||
[],
|
array(),
|
||||||
PRC_VERSION
|
PRC_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'prc-calculator',
|
'prc-calculator',
|
||||||
PRC_PLUGIN_URL . 'assets/js/calculator.js',
|
PRC_PLUGIN_URL . 'assets/js/calculator.js',
|
||||||
[],
|
array(),
|
||||||
PRC_VERSION,
|
PRC_VERSION,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -96,11 +97,14 @@ class PRC_Shortcode {
|
|||||||
// Pass presets and config to JS — all REST endpoints are public-read,
|
// Pass presets and config to JS — all REST endpoints are public-read,
|
||||||
// so no nonce is needed. The restUrl is provided for future use.
|
// so no nonce is needed. The restUrl is provided for future use.
|
||||||
$provider = new PRC_Preset_Provider();
|
$provider = new PRC_Preset_Provider();
|
||||||
wp_localize_script( 'prc-calculator', 'prcConfig', [
|
wp_localize_script(
|
||||||
|
'prc-calculator',
|
||||||
|
'prcConfig',
|
||||||
|
array(
|
||||||
'presets' => $provider->get_all_presets(),
|
'presets' => $provider->get_all_presets(),
|
||||||
'restUrl' => esc_url_raw( rest_url( 'prc/v1' ) ),
|
'restUrl' => esc_url_raw( rest_url( 'prc/v1' ) ),
|
||||||
'syringeUnits' => 100, // Must match PRC_Math::SYRINGE_UNITS_PER_ML and calculator.js SYRINGE_UNITS_PER_ML.
|
'syringeUnits' => 100, // Must match PRC_Math::SYRINGE_UNITS_PER_ML and calculator.js SYRINGE_UNITS_PER_ML.
|
||||||
'i18n' => [
|
'i18n' => array(
|
||||||
'selectPeptide' => __( 'Select a peptide…', 'peptide-reconstitution-calculator' ),
|
'selectPeptide' => __( 'Select a peptide…', 'peptide-reconstitution-calculator' ),
|
||||||
'customEntry' => __( 'Custom / Manual Entry', 'peptide-reconstitution-calculator' ),
|
'customEntry' => __( 'Custom / Manual Entry', 'peptide-reconstitution-calculator' ),
|
||||||
'calculate' => __( 'Calculate', 'peptide-reconstitution-calculator' ),
|
'calculate' => __( 'Calculate', 'peptide-reconstitution-calculator' ),
|
||||||
@@ -111,8 +115,9 @@ class PRC_Shortcode {
|
|||||||
'dosesPerVial' => __( 'Doses Per Vial', 'peptide-reconstitution-calculator' ),
|
'dosesPerVial' => __( 'Doses Per Vial', 'peptide-reconstitution-calculator' ),
|
||||||
'perUnit' => __( 'per unit', 'peptide-reconstitution-calculator' ),
|
'perUnit' => __( 'per unit', 'peptide-reconstitution-calculator' ),
|
||||||
'disclaimer' => __( 'For informational purposes only. Not medical advice. Always consult a qualified healthcare professional.', 'peptide-reconstitution-calculator' ),
|
'disclaimer' => __( 'For informational purposes only. Not medical advice. Always consult a qualified healthcare professional.', 'peptide-reconstitution-calculator' ),
|
||||||
],
|
),
|
||||||
] );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->assets_enqueued = true;
|
$this->assets_enqueued = true;
|
||||||
}
|
}
|
||||||
|
|||||||
13
package-lock.json
generated
Normal file
13
package-lock.json
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "peptide-reconstitution-calculator",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "peptide-reconstitution-calculator",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"license": "GPL-2.0-or-later"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
package.json
Normal file
9
package.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "peptide-reconstitution-calculator",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"description": "Reconstitution calculator WordPress plugin — JS asset package config.",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"lint": "node --check assets/js/calculator.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: Peptide Reconstitution Calculator
|
* Plugin Name: Peptide Reconstitution Calculator
|
||||||
* Plugin URI: https://peptiderepo.com/tools/reconstitution-calculator
|
* Plugin URI: https://peptiderepo.com/tools/reconstitution-calculator
|
||||||
* Description: Interactive reconstitution calculator with peptide-specific presets from Peptide Repo Core. Computes concentration, injection volume, syringe units, and doses per vial.
|
* Description: Interactive reconstitution calculator with peptide-specific presets from Peptide Repo Core. Computes concentration, injection volume, syringe units, and doses per vial.
|
||||||
* Version: 1.0.0
|
* Version: 1.2.0
|
||||||
* Author: peptiderepo
|
* Author: peptiderepo
|
||||||
* Author URI: https://peptiderepo.com
|
* Author URI: https://peptiderepo.com
|
||||||
* License: GPL-2.0-or-later
|
* License: GPL-2.0-or-later
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
*
|
*
|
||||||
* Depends on: Peptide Repo Core (optional — provides peptide-specific presets).
|
* Depends on: Peptide Repo Core (optional — provides peptide-specific presets).
|
||||||
* Without PR Core, the calculator still works with manual entry and built-in defaults.
|
* Without PR Core, the calculator still works with manual entry and built-in defaults.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -25,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|
|
||||||
/* ── Constants ────────────────────────────────────────────────────────── */
|
/* ── Constants ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
define( 'PRC_VERSION', '1.0.0' );
|
define( 'PRC_VERSION', '1.2.0' );
|
||||||
define( 'PRC_PLUGIN_FILE', __FILE__ );
|
define( 'PRC_PLUGIN_FILE', __FILE__ );
|
||||||
define( 'PRC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
define( 'PRC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'PRC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'PRC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
@@ -37,9 +38,9 @@ PRC_Autoloader::register();
|
|||||||
|
|
||||||
/* ── Activation / Deactivation ────────────────────────────────────────── */
|
/* ── Activation / Deactivation ────────────────────────────────────────── */
|
||||||
|
|
||||||
register_activation_hook( __FILE__, [ 'PRC_Activator', 'activate' ] );
|
register_activation_hook( __FILE__, array( 'PRC_Activator', 'activate' ) );
|
||||||
register_deactivation_hook( __FILE__, [ 'PRC_Deactivator', 'deactivate' ] );
|
register_deactivation_hook( __FILE__, array( 'PRC_Deactivator', 'deactivate' ) );
|
||||||
|
|
||||||
/* ── Boot ─────────────────────────────────────────────────────────────── */
|
/* ── Boot ─────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
add_action( 'plugins_loaded', [ 'PRC_Calculator', 'boot' ] );
|
add_action( 'plugins_loaded', array( 'PRC_Calculator', 'boot' ) );
|
||||||
|
|||||||
20
phpunit.xml.dist
Executable file
20
phpunit.xml.dist
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<phpunit
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
|
||||||
|
bootstrap="tests/bootstrap.php"
|
||||||
|
backupGlobals="false"
|
||||||
|
colors="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit">
|
||||||
|
<directory suffix="Test.php">./tests/unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<coverage processUncoveredFiles="true">
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">./includes</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
|
</phpunit>
|
||||||
331
tests/bootstrap.php
Executable file
331
tests/bootstrap.php
Executable file
@@ -0,0 +1,331 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPUnit bootstrap for Peptide Reconstitution Calculator tests.
|
||||||
|
*
|
||||||
|
* Loads WordPress stubs so unit tests can reference WP functions and classes
|
||||||
|
* without requiring a full WordPress installation. All stubs are minimal
|
||||||
|
* no-ops sufficient for the tested surface area.
|
||||||
|
*
|
||||||
|
* @package PRC\Tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Composer autoloader.
|
||||||
|
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
// ── WordPress constant stubs ──────────────────────────────────────────
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
define( 'ABSPATH', '/tmp/wordpress/' );
|
||||||
|
}
|
||||||
|
if ( ! defined( 'WPINC' ) ) {
|
||||||
|
define( 'WPINC', 'wp-includes' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin constants normally defined in the main bootstrap file.
|
||||||
|
if ( ! defined( 'PRC_VERSION' ) ) {
|
||||||
|
define( 'PRC_VERSION', '1.2.0-test' );
|
||||||
|
}
|
||||||
|
if ( ! defined( 'PRC_PLUGIN_FILE' ) ) {
|
||||||
|
define( 'PRC_PLUGIN_FILE', dirname( __DIR__ ) . '/peptide-reconstitution-calculator.php' );
|
||||||
|
}
|
||||||
|
if ( ! defined( 'PRC_PLUGIN_DIR' ) ) {
|
||||||
|
define( 'PRC_PLUGIN_DIR', dirname( __DIR__ ) . '/' );
|
||||||
|
}
|
||||||
|
if ( ! defined( 'PRC_PLUGIN_URL' ) ) {
|
||||||
|
define( 'PRC_PLUGIN_URL', 'https://example.com/wp-content/plugins/peptide-reconstitution-calculator/' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── WordPress function stubs ──────────────────────────────────────────
|
||||||
|
|
||||||
|
if ( ! function_exists( 'plugin_dir_path' ) ) {
|
||||||
|
function plugin_dir_path( $file ) {
|
||||||
|
return trailingslashit( dirname( $file ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'plugin_dir_url' ) ) {
|
||||||
|
function plugin_dir_url( $file ) {
|
||||||
|
return 'https://example.com/wp-content/plugins/' . basename( dirname( $file ) ) . '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'plugin_basename' ) ) {
|
||||||
|
function plugin_basename( $file ) {
|
||||||
|
return basename( dirname( $file ) ) . '/' . basename( $file );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'trailingslashit' ) ) {
|
||||||
|
function trailingslashit( $string ) {
|
||||||
|
return rtrim( $string, '/\\' ) . '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'sanitize_text_field' ) ) {
|
||||||
|
function sanitize_text_field( $str ) {
|
||||||
|
return trim( strip_tags( $str ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'sanitize_title' ) ) {
|
||||||
|
function sanitize_title( $title, $fallback_title = '', $context = 'save' ) {
|
||||||
|
$title = strip_tags( $title );
|
||||||
|
$title = strtolower( $title );
|
||||||
|
$title = preg_replace( '/[^a-z0-9\-]/', '-', $title );
|
||||||
|
$title = preg_replace( '/-+/', '-', $title );
|
||||||
|
return trim( $title, '-' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'absint' ) ) {
|
||||||
|
function absint( $val ) {
|
||||||
|
return abs( (int) $val );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'add_action' ) ) {
|
||||||
|
function add_action( $tag, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'add_filter' ) ) {
|
||||||
|
function add_filter( $tag, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'add_shortcode' ) ) {
|
||||||
|
function add_shortcode( $tag, $callback ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'shortcode_atts' ) ) {
|
||||||
|
function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
|
||||||
|
$atts = (array) $atts;
|
||||||
|
$out = array();
|
||||||
|
foreach ( $pairs as $name => $default ) {
|
||||||
|
$out[ $name ] = array_key_exists( $name, $atts ) ? $atts[ $name ] : $default;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'register_rest_route' ) ) {
|
||||||
|
function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'rest_url' ) ) {
|
||||||
|
function rest_url( $path = '' ) {
|
||||||
|
return 'https://example.com/wp-json/' . ltrim( $path, '/' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'esc_url_raw' ) ) {
|
||||||
|
function esc_url_raw( $url, $protocols = null ) {
|
||||||
|
return filter_var( $url, FILTER_SANITIZE_URL ) ?: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'esc_attr' ) ) {
|
||||||
|
function esc_attr( $text ) {
|
||||||
|
return htmlspecialchars( $text, ENT_QUOTES, 'UTF-8' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'esc_html' ) ) {
|
||||||
|
function esc_html( $text ) {
|
||||||
|
return htmlspecialchars( $text, ENT_QUOTES, 'UTF-8' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'esc_html__' ) ) {
|
||||||
|
function esc_html__( $text, $domain = 'default' ) {
|
||||||
|
return htmlspecialchars( $text, ENT_QUOTES, 'UTF-8' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'esc_html_e' ) ) {
|
||||||
|
function esc_html_e( $text, $domain = 'default' ) {
|
||||||
|
echo htmlspecialchars( $text, ENT_QUOTES, 'UTF-8' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( '__' ) ) {
|
||||||
|
function __( $text, $domain = 'default' ) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'is_admin' ) ) {
|
||||||
|
function is_admin() {
|
||||||
|
global $_test_is_admin;
|
||||||
|
return ! empty( $_test_is_admin );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'wp_enqueue_style' ) ) {
|
||||||
|
function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'wp_enqueue_script' ) ) {
|
||||||
|
function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $args = array() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'wp_localize_script' ) ) {
|
||||||
|
function wp_localize_script( $handle, $object_name, $l10n ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'get_transient' ) ) {
|
||||||
|
function get_transient( $transient ) {
|
||||||
|
global $_test_transients;
|
||||||
|
return isset( $_test_transients[ $transient ] ) ? $_test_transients[ $transient ] : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'set_transient' ) ) {
|
||||||
|
function set_transient( $transient, $value, $expiration = 0 ) {
|
||||||
|
global $_test_transients;
|
||||||
|
$_test_transients[ $transient ] = $value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'delete_transient' ) ) {
|
||||||
|
function delete_transient( $transient ) {
|
||||||
|
global $_test_transients;
|
||||||
|
unset( $_test_transients[ $transient ] );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'register_activation_hook' ) ) {
|
||||||
|
function register_activation_hook( $file, $callback ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'register_deactivation_hook' ) ) {
|
||||||
|
function register_deactivation_hook( $file, $callback ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'delete_option' ) ) {
|
||||||
|
function delete_option( $option ) {
|
||||||
|
global $_test_options;
|
||||||
|
unset( $_test_options[ $option ] );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'wp_cache_flush' ) ) {
|
||||||
|
function wp_cache_flush() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'get_option' ) ) {
|
||||||
|
function get_option( $option, $default = false ) {
|
||||||
|
global $_test_options;
|
||||||
|
return isset( $_test_options[ $option ] ) ? $_test_options[ $option ] : $default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'do_action' ) ) {
|
||||||
|
function do_action( $tag, ...$args ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WP_REST_Request stub used by REST controller tests.
|
||||||
|
if ( ! class_exists( 'WP_REST_Request' ) ) {
|
||||||
|
class WP_REST_Request {
|
||||||
|
/** @var array<string, mixed> */
|
||||||
|
private array $params = array();
|
||||||
|
private string $method;
|
||||||
|
|
||||||
|
public function __construct( string $method = 'GET', string $route = '' ) {
|
||||||
|
$this->method = $method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function set_param( string $key, $value ): void {
|
||||||
|
$this->params[ $key ] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get_param( string $key ) {
|
||||||
|
return $this->params[ $key ] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function get_params(): array {
|
||||||
|
return $this->params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WP_REST_Response stub.
|
||||||
|
if ( ! class_exists( 'WP_REST_Response' ) ) {
|
||||||
|
class WP_REST_Response {
|
||||||
|
/** @var mixed */
|
||||||
|
public $data;
|
||||||
|
public int $status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $data
|
||||||
|
*/
|
||||||
|
public function __construct( $data = null, int $status = 200 ) {
|
||||||
|
$this->data = $data;
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return mixed */
|
||||||
|
public function get_data() {
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_status(): int {
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WP_Error stub.
|
||||||
|
if ( ! class_exists( 'WP_Error' ) ) {
|
||||||
|
class WP_Error {
|
||||||
|
/** @var array<string, string[]> */
|
||||||
|
public array $errors = array();
|
||||||
|
/** @var array<string, mixed> */
|
||||||
|
public array $error_data = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $data
|
||||||
|
*/
|
||||||
|
public function __construct( string $code = '', string $message = '', $data = '' ) {
|
||||||
|
if ( $code ) {
|
||||||
|
$this->errors[ $code ][] = $message;
|
||||||
|
if ( $data ) {
|
||||||
|
$this->error_data[ $code ] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_error_code(): string {
|
||||||
|
$codes = array_keys( $this->errors );
|
||||||
|
return $codes ? $codes[0] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_error_message( string $code = '' ): string {
|
||||||
|
if ( ! $code ) {
|
||||||
|
$code = $this->get_error_code();
|
||||||
|
}
|
||||||
|
return isset( $this->errors[ $code ] ) ? $this->errors[ $code ][0] : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'is_wp_error' ) ) {
|
||||||
|
function is_wp_error( $thing ): bool {
|
||||||
|
return ( $thing instanceof WP_Error );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Load plugin classes for testing ──────────────────────────────────
|
||||||
|
|
||||||
|
// The autoloader resolves PRC_ classes from includes/ — register it now.
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/class-prc-autoloader.php';
|
||||||
|
PRC_Autoloader::register();
|
||||||
|
|
||||||
|
// Load pure classes explicitly (no WP hooks fire at require time).
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/class-prc-math.php';
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/class-prc-default-presets.php';
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/class-prc-calculator.php';
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/class-prc-preset-provider.php';
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/api/class-prc-rest-controller.php';
|
||||||
|
require_once PRC_PLUGIN_DIR . 'includes/frontend/class-prc-shortcode.php';
|
||||||
265
tests/unit/DefaultPresetsTest.php
Executable file
265
tests/unit/DefaultPresetsTest.php
Executable file
@@ -0,0 +1,265 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for PRC_Default_Presets.
|
||||||
|
*
|
||||||
|
* Verifies that the hardcoded fallback preset list is well-formed:
|
||||||
|
* expected slugs are present, required keys exist, numeric ranges
|
||||||
|
* are sensible, and no data has been accidentally corrupted.
|
||||||
|
*
|
||||||
|
* @package PRC\Tests\Unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for PRC_Default_Presets::get_all().
|
||||||
|
*/
|
||||||
|
class DefaultPresetsTest extends TestCase {
|
||||||
|
|
||||||
|
/** @var array<int, array<string, mixed>> */
|
||||||
|
private array $presets;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->presets = PRC_Default_Presets::get_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Collection shape ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_all() returns an array with at least one entry.
|
||||||
|
*/
|
||||||
|
public function test_get_all_returns_array(): void {
|
||||||
|
$this->assertIsArray( $this->presets );
|
||||||
|
$this->assertGreaterThanOrEqual( 1, count( $this->presets ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exactly 8 built-in presets are defined.
|
||||||
|
*/
|
||||||
|
public function test_get_all_contains_eight_presets(): void {
|
||||||
|
$this->assertCount( 8, $this->presets );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 8 expected slugs are all present.
|
||||||
|
*/
|
||||||
|
public function test_expected_slugs_present(): void {
|
||||||
|
$slugs = array_column( $this->presets, 'slug' );
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'bpc-157',
|
||||||
|
'tb-500',
|
||||||
|
'semaglutide',
|
||||||
|
'cjc-1295-dac',
|
||||||
|
'ipamorelin',
|
||||||
|
'pt-141',
|
||||||
|
'mk-677',
|
||||||
|
'ghrp-6',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ( $expected as $slug ) {
|
||||||
|
$this->assertContains( $slug, $slugs, "Missing expected slug: $slug" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Per-preset required fields ────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every preset has all required keys.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_has_required_keys( array $preset ): void {
|
||||||
|
$required = [
|
||||||
|
'slug',
|
||||||
|
'name',
|
||||||
|
'vial_sizes_mg',
|
||||||
|
'default_vial_mg',
|
||||||
|
'recommended_water_ml',
|
||||||
|
'dose_range_min',
|
||||||
|
'dose_range_max',
|
||||||
|
'dose_unit',
|
||||||
|
'typical_frequency',
|
||||||
|
'evidence_strength',
|
||||||
|
'source',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ( $required as $key ) {
|
||||||
|
$this->assertArrayHasKey( $key, $preset, "Missing key '$key' in preset '{$preset['slug']}'" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every preset's slug is a non-empty string.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_slug_is_non_empty_string( array $preset ): void {
|
||||||
|
$this->assertIsString( $preset['slug'] );
|
||||||
|
$this->assertNotEmpty( $preset['slug'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every preset's name is a non-empty string.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_name_is_non_empty_string( array $preset ): void {
|
||||||
|
$this->assertIsString( $preset['name'] );
|
||||||
|
$this->assertNotEmpty( $preset['name'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vial_sizes_mg is a non-empty array of positive floats.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_vial_sizes_are_positive( array $preset ): void {
|
||||||
|
$this->assertIsArray( $preset['vial_sizes_mg'] );
|
||||||
|
$this->assertNotEmpty( $preset['vial_sizes_mg'] );
|
||||||
|
|
||||||
|
foreach ( $preset['vial_sizes_mg'] as $size ) {
|
||||||
|
$this->assertIsNumeric( $size );
|
||||||
|
$this->assertGreaterThan( 0, $size, "Non-positive vial size in preset '{$preset['slug']}'" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default_vial_mg is one of the values in vial_sizes_mg.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_default_vial_is_in_sizes( array $preset ): void {
|
||||||
|
$this->assertContains(
|
||||||
|
$preset['default_vial_mg'],
|
||||||
|
$preset['vial_sizes_mg'],
|
||||||
|
"default_vial_mg not in vial_sizes_mg for preset '{$preset['slug']}'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* recommended_water_ml is positive.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_recommended_water_is_positive( array $preset ): void {
|
||||||
|
$this->assertGreaterThan( 0, $preset['recommended_water_ml'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dose_unit is either 'mcg' or 'mg'.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_dose_unit_is_valid( array $preset ): void {
|
||||||
|
$this->assertContains( $preset['dose_unit'], [ 'mcg', 'mg' ], "Invalid dose_unit in preset '{$preset['slug']}'" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dose_range_min < dose_range_max when both are non-null.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_dose_range_min_less_than_max( array $preset ): void {
|
||||||
|
if ( null === $preset['dose_range_min'] || null === $preset['dose_range_max'] ) {
|
||||||
|
$this->addToAssertionCount( 1 ); // Null ranges are acceptable.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertLessThan(
|
||||||
|
$preset['dose_range_max'],
|
||||||
|
$preset['dose_range_min'],
|
||||||
|
"dose_range_min >= dose_range_max in preset '{$preset['slug']}'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* source field is 'default' for every built-in preset.
|
||||||
|
*
|
||||||
|
* @dataProvider preset_provider
|
||||||
|
* @param array<string, mixed> $preset
|
||||||
|
*/
|
||||||
|
public function test_preset_source_is_default( array $preset ): void {
|
||||||
|
$this->assertSame( 'default', $preset['source'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Spot-check specific known values ──────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPC-157: 5 mg default vial, 2 mL water, 500 mcg max dose.
|
||||||
|
*/
|
||||||
|
public function test_bpc157_specific_values(): void {
|
||||||
|
$preset = $this->find_preset( 'bpc-157' );
|
||||||
|
|
||||||
|
$this->assertNotNull( $preset );
|
||||||
|
$this->assertSame( 5.0, (float) $preset['default_vial_mg'] );
|
||||||
|
$this->assertSame( 2.0, (float) $preset['recommended_water_ml'] );
|
||||||
|
$this->assertSame( 500.0, (float) $preset['dose_range_max'] );
|
||||||
|
$this->assertSame( 'mcg', $preset['dose_unit'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semaglutide: dose_unit is mg (not mcg), max dose 2.4 mg.
|
||||||
|
*/
|
||||||
|
public function test_semaglutide_mg_dose_unit(): void {
|
||||||
|
$preset = $this->find_preset( 'semaglutide' );
|
||||||
|
|
||||||
|
$this->assertNotNull( $preset );
|
||||||
|
$this->assertSame( 'mg', $preset['dose_unit'] );
|
||||||
|
$this->assertEqualsWithDelta( 2.4, (float) $preset['dose_range_max'], 0.01 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MK-677: 30 mg default vial, 3 mL water (large-vial path in recommend_water_ml).
|
||||||
|
*/
|
||||||
|
public function test_mk677_large_vial_water_recommendation(): void {
|
||||||
|
$preset = $this->find_preset( 'mk-677' );
|
||||||
|
|
||||||
|
$this->assertNotNull( $preset );
|
||||||
|
$this->assertSame( 30.0, (float) $preset['default_vial_mg'] );
|
||||||
|
$this->assertSame( 3.0, (float) $preset['recommended_water_ml'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── DataProvider ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides each preset individually.
|
||||||
|
*
|
||||||
|
* @return array<string, array{array<string, mixed>}>
|
||||||
|
*/
|
||||||
|
public function preset_provider(): array {
|
||||||
|
$presets = PRC_Default_Presets::get_all();
|
||||||
|
$cases = [];
|
||||||
|
foreach ( $presets as $preset ) {
|
||||||
|
$cases[ $preset['slug'] ] = [ $preset ];
|
||||||
|
}
|
||||||
|
return $cases;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Helpers ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a preset by slug.
|
||||||
|
*
|
||||||
|
* @param string $slug
|
||||||
|
* @return array<string, mixed>|null
|
||||||
|
*/
|
||||||
|
private function find_preset( string $slug ): ?array {
|
||||||
|
foreach ( $this->presets as $preset ) {
|
||||||
|
if ( $preset['slug'] === $slug ) {
|
||||||
|
return $preset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
444
tests/unit/MathTest.php
Executable file
444
tests/unit/MathTest.php
Executable file
@@ -0,0 +1,444 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for PRC_Math — the pure reconstitution calculation engine.
|
||||||
|
*
|
||||||
|
* Covers the full public API of PRC_Math: concentration, injection volume,
|
||||||
|
* syringe units, doses per vial, and the top-level calculate() orchestrator.
|
||||||
|
* All expected values were computed manually from the formulas in class-prc-math.php.
|
||||||
|
*
|
||||||
|
* Math reference:
|
||||||
|
* concentration_mg_per_ml = vial_mg / water_ml
|
||||||
|
* concentration_mcg_per_unit = (vial_mg * 1000) / (water_ml * 100)
|
||||||
|
* injection_volume_ml = dose_mg / concentration_mg_per_ml
|
||||||
|
* syringe_units = injection_volume_ml * 100
|
||||||
|
* doses_per_vial = vial_mg / dose_mg (floor in calculate())
|
||||||
|
*
|
||||||
|
* @package PRC\Tests\Unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for PRC_Math static methods.
|
||||||
|
*/
|
||||||
|
class MathTest extends TestCase {
|
||||||
|
|
||||||
|
// ── concentration_mg_per_ml ───────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard BPC-157 vial: 5 mg peptide in 2 mL water → 2.5 mg/mL.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_standard(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 5.0, 2.0 );
|
||||||
|
$this->assertEqualsWithDelta( 2.5, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 10 mg peptide in 2 mL water → 5.0 mg/mL.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_high_dose(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 10.0, 2.0 );
|
||||||
|
$this->assertEqualsWithDelta( 5.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2 mg peptide in 1 mL water → 2.0 mg/mL.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_small_vial(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 2.0, 1.0 );
|
||||||
|
$this->assertEqualsWithDelta( 2.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 30 mg peptide in 3 mL water → 10.0 mg/mL.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_large_vial(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 30.0, 3.0 );
|
||||||
|
$this->assertEqualsWithDelta( 10.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero water volume → returns 0 (division guard).
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_zero_water_returns_zero(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 5.0, 0.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative water volume is treated as zero (guard condition uses <=).
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_negative_water_returns_zero(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 5.0, -1.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero vial mg with valid water → 0 mg/mL.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mg_per_ml_zero_peptide(): void {
|
||||||
|
$result = PRC_Math::concentration_mg_per_ml( 0.0, 2.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── concentration_mcg_per_unit ────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5 mg / 2 mL: (5 * 1000) / (2 * 100) = 5000 / 200 = 25.0 mcg/unit.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mcg_per_unit_standard(): void {
|
||||||
|
$result = PRC_Math::concentration_mcg_per_unit( 5.0, 2.0 );
|
||||||
|
$this->assertEqualsWithDelta( 25.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 10 mg / 2 mL: (10 * 1000) / (2 * 100) = 10000 / 200 = 50.0 mcg/unit.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mcg_per_unit_10mg_2ml(): void {
|
||||||
|
$result = PRC_Math::concentration_mcg_per_unit( 10.0, 2.0 );
|
||||||
|
$this->assertEqualsWithDelta( 50.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2 mg / 1 mL: (2 * 1000) / (1 * 100) = 2000 / 100 = 20.0 mcg/unit.
|
||||||
|
*/
|
||||||
|
public function test_concentration_mcg_per_unit_2mg_1ml(): void {
|
||||||
|
$result = PRC_Math::concentration_mcg_per_unit( 2.0, 1.0 );
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero water → returns 0 (guard).
|
||||||
|
*/
|
||||||
|
public function test_concentration_mcg_per_unit_zero_water_returns_zero(): void {
|
||||||
|
$result = PRC_Math::concentration_mcg_per_unit( 5.0, 0.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── injection_volume_ml ───────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 250 mcg dose at 2.5 mg/mL: dose_mg = 0.25 → 0.25 / 2.5 = 0.1 mL.
|
||||||
|
*/
|
||||||
|
public function test_injection_volume_ml_standard(): void {
|
||||||
|
$result = PRC_Math::injection_volume_ml( 0.25, 2.5 );
|
||||||
|
$this->assertEqualsWithDelta( 0.1, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 500 mcg dose at 2.5 mg/mL: 0.5 / 2.5 = 0.2 mL.
|
||||||
|
*/
|
||||||
|
public function test_injection_volume_ml_higher_dose(): void {
|
||||||
|
$result = PRC_Math::injection_volume_ml( 0.5, 2.5 );
|
||||||
|
$this->assertEqualsWithDelta( 0.2, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1 mg dose at 5 mg/mL: 1.0 / 5.0 = 0.2 mL.
|
||||||
|
*/
|
||||||
|
public function test_injection_volume_ml_mg_dose(): void {
|
||||||
|
$result = PRC_Math::injection_volume_ml( 1.0, 5.0 );
|
||||||
|
$this->assertEqualsWithDelta( 0.2, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero concentration → returns 0 (division guard).
|
||||||
|
*/
|
||||||
|
public function test_injection_volume_ml_zero_concentration_returns_zero(): void {
|
||||||
|
$result = PRC_Math::injection_volume_ml( 0.25, 0.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative concentration → returns 0 (guard condition uses <=).
|
||||||
|
*/
|
||||||
|
public function test_injection_volume_ml_negative_concentration_returns_zero(): void {
|
||||||
|
$result = PRC_Math::injection_volume_ml( 0.25, -1.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── syringe_units ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0.1 mL × 100 = 10 units.
|
||||||
|
*/
|
||||||
|
public function test_syringe_units_0_1_ml(): void {
|
||||||
|
$result = PRC_Math::syringe_units( 0.1 );
|
||||||
|
$this->assertEqualsWithDelta( 10.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0.2 mL × 100 = 20 units.
|
||||||
|
*/
|
||||||
|
public function test_syringe_units_0_2_ml(): void {
|
||||||
|
$result = PRC_Math::syringe_units( 0.2 );
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1 mL × 100 = 100 units (full syringe).
|
||||||
|
*/
|
||||||
|
public function test_syringe_units_full_ml(): void {
|
||||||
|
$result = PRC_Math::syringe_units( 1.0 );
|
||||||
|
$this->assertEqualsWithDelta( 100.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0 mL → 0 units.
|
||||||
|
*/
|
||||||
|
public function test_syringe_units_zero(): void {
|
||||||
|
$result = PRC_Math::syringe_units( 0.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fractional: 0.05 mL × 100 = 5.0 units.
|
||||||
|
*/
|
||||||
|
public function test_syringe_units_fractional(): void {
|
||||||
|
$result = PRC_Math::syringe_units( 0.05 );
|
||||||
|
$this->assertEqualsWithDelta( 5.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── doses_per_vial ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5 mg vial at 0.25 mg dose → 20 doses.
|
||||||
|
*/
|
||||||
|
public function test_doses_per_vial_standard(): void {
|
||||||
|
$result = PRC_Math::doses_per_vial( 5.0, 0.25 );
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 10 mg vial at 0.5 mg dose → 20 doses.
|
||||||
|
*/
|
||||||
|
public function test_doses_per_vial_large_vial(): void {
|
||||||
|
$result = PRC_Math::doses_per_vial( 10.0, 0.5 );
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $result, 0.0001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5 mg vial at 0.3 mg dose → 16.666... (floor returns 16 in calculate()).
|
||||||
|
*/
|
||||||
|
public function test_doses_per_vial_non_integer(): void {
|
||||||
|
$result = PRC_Math::doses_per_vial( 5.0, 0.3 );
|
||||||
|
// Raw float — floor applied in calculate().
|
||||||
|
$this->assertGreaterThan( 16.0, $result );
|
||||||
|
$this->assertLessThan( 17.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero dose → returns 0 (guard against division by zero).
|
||||||
|
*/
|
||||||
|
public function test_doses_per_vial_zero_dose_returns_zero(): void {
|
||||||
|
$result = PRC_Math::doses_per_vial( 5.0, 0.0 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative dose → returns 0 (guard condition uses <=).
|
||||||
|
*/
|
||||||
|
public function test_doses_per_vial_negative_dose_returns_zero(): void {
|
||||||
|
$result = PRC_Math::doses_per_vial( 5.0, -0.25 );
|
||||||
|
$this->assertSame( 0.0, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── calculate() — full orchestrator ──────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPC-157 typical scenario: 5 mg vial, 2 mL BAC water, 250 mcg dose.
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* concentration_mg_per_ml = 5 / 2 = 2.5
|
||||||
|
* concentration_mcg_per_unit = (5000) / (200) = 25.0
|
||||||
|
* injection_volume_ml = 0.25 / 2.5 = 0.1
|
||||||
|
* syringe_units = 0.1 * 100 = 10
|
||||||
|
* doses_per_vial = floor(5 / 0.25) = 20
|
||||||
|
*/
|
||||||
|
public function test_calculate_bpc157_250mcg_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 250.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertIsArray( $result );
|
||||||
|
$this->assertEqualsWithDelta( 2.5, $result['concentration_mg_per_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 25.0, $result['concentration_mcg_per_unit'], 0.01 );
|
||||||
|
$this->assertEqualsWithDelta( 0.1, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 10.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 20.0, $result['doses_per_vial'] );
|
||||||
|
$this->assertSame( 5.0, $result['total_peptide_mg'] );
|
||||||
|
$this->assertSame( 2.0, $result['water_ml'] );
|
||||||
|
$this->assertEqualsWithDelta( 0.25, $result['desired_dose_mg'], 0.0001 );
|
||||||
|
$this->assertSame( 250.0, $result['desired_dose_display'] );
|
||||||
|
$this->assertSame( 'mcg', $result['dose_unit'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semaglutide scenario: 5 mg vial, 2 mL BAC water, 0.5 mg dose (mg unit).
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* concentration_mg_per_ml = 5 / 2 = 2.5
|
||||||
|
* concentration_mcg_per_unit = 25.0
|
||||||
|
* injection_volume_ml = 0.5 / 2.5 = 0.2
|
||||||
|
* syringe_units = 0.2 * 100 = 20
|
||||||
|
* doses_per_vial = floor(5 / 0.5) = 10
|
||||||
|
*/
|
||||||
|
public function test_calculate_semaglutide_0_5mg_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 0.5, 'mg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 2.5, $result['concentration_mg_per_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 25.0, $result['concentration_mcg_per_unit'], 0.01 );
|
||||||
|
$this->assertEqualsWithDelta( 0.2, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 10.0, $result['doses_per_vial'] );
|
||||||
|
$this->assertSame( 'mg', $result['dose_unit'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TB-500 high-dose scenario: 10 mg vial, 2 mL water, 2000 mcg dose.
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* concentration_mg_per_ml = 10 / 2 = 5.0
|
||||||
|
* concentration_mcg_per_unit = (10000) / (200) = 50.0
|
||||||
|
* injection_volume_ml = 2.0 / 5.0 = 0.4
|
||||||
|
* syringe_units = 0.4 * 100 = 40
|
||||||
|
* doses_per_vial = floor(10 / 2) = 5
|
||||||
|
*/
|
||||||
|
public function test_calculate_tb500_2000mcg_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 10.0, 2.0, 2000.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 5.0, $result['concentration_mg_per_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 50.0, $result['concentration_mcg_per_unit'], 0.01 );
|
||||||
|
$this->assertEqualsWithDelta( 0.4, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 40.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 5.0, $result['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MK-677 mg-dose scenario: 30 mg vial, 3 mL water, 25 mg dose.
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* concentration_mg_per_ml = 30 / 3 = 10.0
|
||||||
|
* concentration_mcg_per_unit = (30000) / (300) = 100.0
|
||||||
|
* injection_volume_ml = 25 / 10 = 2.5
|
||||||
|
* syringe_units = 2.5 * 100 = 250
|
||||||
|
* doses_per_vial = floor(30 / 25) = 1
|
||||||
|
*/
|
||||||
|
public function test_calculate_mk677_25mg_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 30.0, 3.0, 25.0, 'mg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 10.0, $result['concentration_mg_per_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 100.0, $result['concentration_mcg_per_unit'], 0.01 );
|
||||||
|
$this->assertEqualsWithDelta( 2.5, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 250.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 1.0, $result['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum BPC-157 dose: 200 mcg from a 5 mg / 2 mL vial.
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* injection_volume_ml = 0.2 / 2.5 = 0.08
|
||||||
|
* syringe_units = 0.08 * 100 = 8.0
|
||||||
|
* doses_per_vial = floor(5 / 0.2) = 25
|
||||||
|
*/
|
||||||
|
public function test_calculate_bpc157_200mcg_minimum_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 200.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 0.08, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 8.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 25.0, $result['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Very small dose: 100 mcg from 5 mg / 2 mL.
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* injection_volume_ml = 0.1 / 2.5 = 0.04
|
||||||
|
* syringe_units = 4.0
|
||||||
|
* doses_per_vial = floor(5 / 0.1) = 50
|
||||||
|
*/
|
||||||
|
public function test_calculate_ipamorelin_100mcg_dose(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 100.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 0.04, $result['injection_volume_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 4.0, $result['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 50.0, $result['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-integer doses-per-vial: 5 mg vial, 300 mcg dose → 16.666 → floor → 16.
|
||||||
|
*/
|
||||||
|
public function test_calculate_doses_per_vial_is_floored(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 300.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertSame( 16.0, $result['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mcg/unit output is rounded to 2 decimal places.
|
||||||
|
*/
|
||||||
|
public function test_calculate_concentration_mcg_per_unit_rounded_to_two_decimals(): void {
|
||||||
|
// 3 mg / 2 mL: mcg_per_unit = 3000 / 200 = 15.0 — exact, check rounding still works.
|
||||||
|
$result = PRC_Math::calculate( 3.0, 2.0, 150.0, 'mcg' );
|
||||||
|
// 15.0 rounded to 2 dp = 15.0.
|
||||||
|
$this->assertEqualsWithDelta( 15.0, $result['concentration_mcg_per_unit'], 0.005 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* concentration_mg_per_ml output is rounded to 4 decimal places.
|
||||||
|
*
|
||||||
|
* 7 mg / 3 mL = 2.333... → rounded to 4 dp = 2.3333.
|
||||||
|
*/
|
||||||
|
public function test_calculate_concentration_rounded_to_four_decimals(): void {
|
||||||
|
$result = PRC_Math::calculate( 7.0, 3.0, 100.0, 'mcg' );
|
||||||
|
$this->assertEqualsWithDelta( 2.3333, $result['concentration_mg_per_ml'], 0.00005 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result array has the expected keys.
|
||||||
|
*/
|
||||||
|
public function test_calculate_returns_expected_keys(): void {
|
||||||
|
$result = PRC_Math::calculate( 5.0, 2.0, 250.0, 'mcg' );
|
||||||
|
|
||||||
|
$expected_keys = [
|
||||||
|
'concentration_mg_per_ml',
|
||||||
|
'concentration_mcg_per_unit',
|
||||||
|
'injection_volume_ml',
|
||||||
|
'syringe_units',
|
||||||
|
'doses_per_vial',
|
||||||
|
'total_peptide_mg',
|
||||||
|
'water_ml',
|
||||||
|
'desired_dose_mg',
|
||||||
|
'desired_dose_display',
|
||||||
|
'dose_unit',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ( $expected_keys as $key ) {
|
||||||
|
$this->assertArrayHasKey( $key, $result, "Missing key: $key" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mcg unit: desired_dose_mg is divided by 1000.
|
||||||
|
* 500 mcg → 0.5 mg stored as desired_dose_mg.
|
||||||
|
*/
|
||||||
|
public function test_calculate_mcg_dose_unit_conversion(): void {
|
||||||
|
$result = PRC_Math::calculate( 10.0, 2.0, 500.0, 'mcg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 0.5, $result['desired_dose_mg'], 0.0001 );
|
||||||
|
$this->assertSame( 500.0, $result['desired_dose_display'] );
|
||||||
|
$this->assertSame( 'mcg', $result['dose_unit'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mg unit: desired_dose_mg equals the raw input value.
|
||||||
|
*/
|
||||||
|
public function test_calculate_mg_dose_unit_no_conversion(): void {
|
||||||
|
$result = PRC_Math::calculate( 10.0, 2.0, 1.5, 'mg' );
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 1.5, $result['desired_dose_mg'], 0.0001 );
|
||||||
|
$this->assertSame( 1.5, $result['desired_dose_display'] );
|
||||||
|
$this->assertSame( 'mg', $result['dose_unit'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
96
tests/unit/PresetProviderTest.php
Executable file
96
tests/unit/PresetProviderTest.php
Executable file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for PRC_Preset_Provider (standalone/no-PR-Core path).
|
||||||
|
*
|
||||||
|
* Tests the provider in the state where PR Core is NOT active (no
|
||||||
|
* PR_CORE_VERSION constant), exercising the default-preset fallback,
|
||||||
|
* cache read/write, and cache invalidation.
|
||||||
|
*
|
||||||
|
* @package PRC\Tests\Unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for PRC_Preset_Provider without PR Core.
|
||||||
|
*/
|
||||||
|
class PresetProviderTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
// Ensure PR_CORE_VERSION is not defined (test environment default).
|
||||||
|
// The provider checks PRC_Calculator::is_pr_core_active() which checks
|
||||||
|
// defined('PR_CORE_VERSION'). We cannot un-define, so tests assume
|
||||||
|
// the constant is absent (which it is in a clean test run).
|
||||||
|
global $_test_transients;
|
||||||
|
$_test_transients = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Fallback behavior (no PR Core) ───────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_all_presets() returns a non-empty array when PR Core is absent.
|
||||||
|
*/
|
||||||
|
public function test_get_all_presets_returns_defaults_without_pr_core(): void {
|
||||||
|
$provider = new PRC_Preset_Provider();
|
||||||
|
$presets = $provider->get_all_presets();
|
||||||
|
|
||||||
|
$this->assertIsArray( $presets );
|
||||||
|
$this->assertGreaterThan( 0, count( $presets ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_all_presets() matches PRC_Default_Presets::get_all() when PR Core absent.
|
||||||
|
*/
|
||||||
|
public function test_get_all_presets_matches_defaults(): void {
|
||||||
|
$provider = new PRC_Preset_Provider();
|
||||||
|
$actual = $provider->get_all_presets();
|
||||||
|
$expected = PRC_Default_Presets::get_all();
|
||||||
|
|
||||||
|
$this->assertEquals( $expected, $actual );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All returned presets have a slug key.
|
||||||
|
*/
|
||||||
|
public function test_all_presets_have_slug(): void {
|
||||||
|
$provider = new PRC_Preset_Provider();
|
||||||
|
$presets = $provider->get_all_presets();
|
||||||
|
|
||||||
|
foreach ( $presets as $preset ) {
|
||||||
|
$this->assertArrayHasKey( 'slug', $preset );
|
||||||
|
$this->assertNotEmpty( $preset['slug'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Cache invalidation ────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* invalidate_cache() removes the 'prc_presets_all' transient.
|
||||||
|
*/
|
||||||
|
public function test_invalidate_cache_removes_transient(): void {
|
||||||
|
global $_test_transients;
|
||||||
|
|
||||||
|
// Seed the transient manually.
|
||||||
|
$_test_transients['prc_presets_all'] = [ 'cached-data' ];
|
||||||
|
|
||||||
|
$provider = new PRC_Preset_Provider();
|
||||||
|
$provider->invalidate_cache();
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey( 'prc_presets_all', $_test_transients );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiple invalidate_cache() calls are safe (idempotent).
|
||||||
|
*/
|
||||||
|
public function test_invalidate_cache_is_idempotent(): void {
|
||||||
|
$provider = new PRC_Preset_Provider();
|
||||||
|
|
||||||
|
// Should not throw, even if transient was never set.
|
||||||
|
$provider->invalidate_cache();
|
||||||
|
$provider->invalidate_cache();
|
||||||
|
|
||||||
|
$this->addToAssertionCount( 1 ); // If we got here, no exception.
|
||||||
|
}
|
||||||
|
}
|
||||||
150
tests/unit/RestControllerTest.php
Executable file
150
tests/unit/RestControllerTest.php
Executable file
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for PRC_Rest_Controller.
|
||||||
|
*
|
||||||
|
* Tests the calculate() method callback using the WP_REST_Request stub.
|
||||||
|
* The get_presets() / get_preset() methods are thin wrappers over
|
||||||
|
* PRC_Preset_Provider, which is covered by PresetProviderTest.
|
||||||
|
*
|
||||||
|
* @package PRC\Tests\Unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for PRC_Rest_Controller REST callback methods.
|
||||||
|
*/
|
||||||
|
class RestControllerTest extends TestCase {
|
||||||
|
|
||||||
|
private PRC_Rest_Controller $controller;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$this->controller = new PRC_Rest_Controller();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── /calculate callback ───────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate() returns a WP_REST_Response with status 200.
|
||||||
|
*/
|
||||||
|
public function test_calculate_returns_200_response(): void {
|
||||||
|
$request = new WP_REST_Request( 'POST' );
|
||||||
|
$request->set_param( 'vial_mg', '5' );
|
||||||
|
$request->set_param( 'water_ml', '2' );
|
||||||
|
$request->set_param( 'desired_dose', '250' );
|
||||||
|
$request->set_param( 'dose_unit', 'mcg' );
|
||||||
|
|
||||||
|
$response = $this->controller->calculate( $request );
|
||||||
|
|
||||||
|
$this->assertInstanceOf( WP_REST_Response::class, $response );
|
||||||
|
$this->assertSame( 200, $response->get_status() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate() returns the correct BPC-157 math results.
|
||||||
|
*
|
||||||
|
* 5 mg / 2 mL / 250 mcg → concentration 2.5, syringe units 10.
|
||||||
|
*/
|
||||||
|
public function test_calculate_bpc157_correct_values(): void {
|
||||||
|
$request = new WP_REST_Request( 'POST' );
|
||||||
|
$request->set_param( 'vial_mg', '5' );
|
||||||
|
$request->set_param( 'water_ml', '2' );
|
||||||
|
$request->set_param( 'desired_dose', '250' );
|
||||||
|
$request->set_param( 'dose_unit', 'mcg' );
|
||||||
|
|
||||||
|
$response = $this->controller->calculate( $request );
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertIsArray( $data );
|
||||||
|
$this->assertEqualsWithDelta( 2.5, $data['concentration_mg_per_ml'], 0.0001 );
|
||||||
|
$this->assertEqualsWithDelta( 10.0, $data['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 20.0, $data['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate() accepts mg dose unit correctly.
|
||||||
|
*
|
||||||
|
* 5 mg / 2 mL / 0.5 mg → syringe units 20.
|
||||||
|
*/
|
||||||
|
public function test_calculate_mg_dose_unit(): void {
|
||||||
|
$request = new WP_REST_Request( 'POST' );
|
||||||
|
$request->set_param( 'vial_mg', '5' );
|
||||||
|
$request->set_param( 'water_ml', '2' );
|
||||||
|
$request->set_param( 'desired_dose', '0.5' );
|
||||||
|
$request->set_param( 'dose_unit', 'mg' );
|
||||||
|
|
||||||
|
$response = $this->controller->calculate( $request );
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta( 20.0, $data['syringe_units'], 0.1 );
|
||||||
|
$this->assertSame( 10.0, $data['doses_per_vial'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate() returns all expected keys in the response data.
|
||||||
|
*/
|
||||||
|
public function test_calculate_response_has_expected_keys(): void {
|
||||||
|
$request = new WP_REST_Request( 'POST' );
|
||||||
|
$request->set_param( 'vial_mg', '5' );
|
||||||
|
$request->set_param( 'water_ml', '2' );
|
||||||
|
$request->set_param( 'desired_dose', '250' );
|
||||||
|
$request->set_param( 'dose_unit', 'mcg' );
|
||||||
|
|
||||||
|
$data = $this->controller->calculate( $request )->get_data();
|
||||||
|
|
||||||
|
$expected_keys = [
|
||||||
|
'concentration_mg_per_ml',
|
||||||
|
'concentration_mcg_per_unit',
|
||||||
|
'injection_volume_ml',
|
||||||
|
'syringe_units',
|
||||||
|
'doses_per_vial',
|
||||||
|
'dose_unit',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ( $expected_keys as $key ) {
|
||||||
|
$this->assertArrayHasKey( $key, $data, "Missing key: $key" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_presets() returns a 200 response with an array.
|
||||||
|
*/
|
||||||
|
public function test_get_presets_returns_200_with_array(): void {
|
||||||
|
$request = new WP_REST_Request( 'GET' );
|
||||||
|
$response = $this->controller->get_presets( $request );
|
||||||
|
|
||||||
|
$this->assertSame( 200, $response->get_status() );
|
||||||
|
$this->assertIsArray( $response->get_data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_preset() returns a WP_Error for an unknown slug.
|
||||||
|
*/
|
||||||
|
public function test_get_preset_unknown_slug_returns_wp_error(): void {
|
||||||
|
$request = new WP_REST_Request( 'GET' );
|
||||||
|
$request->set_param( 'slug', 'nonexistent-peptide-xyz' );
|
||||||
|
|
||||||
|
$result = $this->controller->get_preset( $request );
|
||||||
|
|
||||||
|
$this->assertInstanceOf( WP_Error::class, $result );
|
||||||
|
$this->assertSame( 'prc_preset_not_found', $result->get_error_code() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_preset() returns a 200 response for a known slug.
|
||||||
|
*/
|
||||||
|
public function test_get_preset_known_slug_returns_200(): void {
|
||||||
|
$request = new WP_REST_Request( 'GET' );
|
||||||
|
$request->set_param( 'slug', 'bpc-157' );
|
||||||
|
|
||||||
|
$result = $this->controller->get_preset( $request );
|
||||||
|
|
||||||
|
$this->assertInstanceOf( WP_REST_Response::class, $result );
|
||||||
|
$this->assertSame( 200, $result->get_status() );
|
||||||
|
|
||||||
|
$data = $result->get_data();
|
||||||
|
$this->assertSame( 'bpc-157', $data['slug'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
* Dependencies: None (standalone, no autoloader).
|
* Dependencies: None (standalone, no autoloader).
|
||||||
*
|
*
|
||||||
* @see ARCHITECTURE.md — Teardown section.
|
* @see ARCHITECTURE.md — Teardown section.
|
||||||
|
* @package PeptideReconstitutionCalculator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -18,7 +19,7 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// Delete all prc_ prefixed options.
|
// Delete all prc_ prefixed options.
|
||||||
$wpdb->query(
|
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||||
$wpdb->esc_like( 'prc_' ) . '%'
|
$wpdb->esc_like( 'prc_' ) . '%'
|
||||||
@@ -26,7 +27,7 @@ $wpdb->query(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Delete all prc_ prefixed transients.
|
// Delete all prc_ prefixed transients.
|
||||||
$wpdb->query(
|
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
|
||||||
$wpdb->esc_like( '_transient_prc_' ) . '%',
|
$wpdb->esc_like( '_transient_prc_' ) . '%',
|
||||||
|
|||||||
Reference in New Issue
Block a user