Compare commits
14 Commits
claude/fix
...
claude/m4-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d194e2109f | ||
|
|
7fa91ec975 | ||
|
|
65c5de61cb | ||
|
|
d590dc9dee | ||
|
|
a05d90405d | ||
|
|
52a05f994c | ||
|
|
1562d30584 | ||
|
|
3c29588824 | ||
|
|
a09d210895 | ||
|
|
3ed4b10ecd | ||
|
|
655843e42b | ||
|
|
afb43e7a41 | ||
|
|
852f7b01a3 | ||
|
|
e183e26926 |
131
.github/workflows/deploy-app.yml
vendored
Normal file
131
.github/workflows/deploy-app.yml
vendored
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
name: Reusable Deploy (staging → smoke → production)
|
||||||
|
|
||||||
|
# Single shared deploy pipeline for every peptiderepo plugin and the theme.
|
||||||
|
# Callers pass `target_path` + `secrets: inherit`; deploy logic lives HERE so a
|
||||||
|
# fix lands once instead of in six copy-pasted deploy.yml files.
|
||||||
|
#
|
||||||
|
# Hardened against the documented Hostinger behaviour of rate-limiting concurrent
|
||||||
|
# GitHub-runner IPs (connection timeouts, exit 255): the rsync is retried with
|
||||||
|
# backoff, and the plugin-inventory guard is best-effort so a throttled count
|
||||||
|
# check never fails an otherwise-good deploy.
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
target_path:
|
||||||
|
description: "wp-content subpath, e.g. wp-content/plugins/prautoblogger"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
run_smoke:
|
||||||
|
description: "Run the staging smoke suite (informational; never gates prod)"
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
|
type: boolean
|
||||||
|
secrets:
|
||||||
|
SSH_PRIVATE_KEY: {required: true}
|
||||||
|
SSH_HOST: {required: true}
|
||||||
|
SSH_PORT: {required: true}
|
||||||
|
SSH_USERNAME: {required: true}
|
||||||
|
STAGING_WP_ADMIN_USER: {required: false}
|
||||||
|
STAGING_WP_ADMIN_PASSWORD: {required: false}
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-staging:
|
||||||
|
name: Deploy to Staging
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: staging
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Deploy via rsync → staging (retry-on-throttle)
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan -p "${{ secrets.SSH_PORT }}" "${{ secrets.SSH_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
|
BASE="/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html"
|
||||||
|
SSHOPT="-i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=accept-new -o ConnectTimeout=30 -o BatchMode=yes"
|
||||||
|
n=0
|
||||||
|
until [ "$n" -ge 4 ]; do
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude '.git' --exclude '.github' --exclude 'tests' --exclude 'node_modules' \
|
||||||
|
--exclude 'vendor' --exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
|
--exclude 'phpunit.xml' --exclude 'phpunit.xml.dist' --exclude 'phpcs.xml.dist' \
|
||||||
|
--exclude '.phpcs.xml.dist' --exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' \
|
||||||
|
--exclude 'CHANGELOG.md' --exclude 'qa-reviews' \
|
||||||
|
-e "ssh $SSHOPT" \
|
||||||
|
./ "${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:$BASE/staging/${{ inputs.target_path }}/" && break
|
||||||
|
n=$((n+1)); echo "staging rsync failed (attempt $n/4) — Hostinger may be throttling runner IPs; retrying in 25s..."; sleep 25
|
||||||
|
done
|
||||||
|
[ "$n" -lt 4 ] || { echo "::error::staging rsync failed after 4 attempts"; exit 1; }
|
||||||
|
- name: Staging health check
|
||||||
|
run: |
|
||||||
|
sleep 5
|
||||||
|
echo "Staging responded: HTTP $(curl -s -o /dev/null -w '%{http_code}' https://staging.peptiderepo.com/ || echo 000)"
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
|
||||||
|
smoke:
|
||||||
|
name: Smoke tests (staging)
|
||||||
|
needs: deploy-staging
|
||||||
|
if: ${{ inputs.run_smoke }}
|
||||||
|
uses: peptiderepo/peptide-e2e/.github/workflows/smoke.yml@main
|
||||||
|
secrets:
|
||||||
|
STAGING_WP_ADMIN_USER: ${{ secrets.STAGING_WP_ADMIN_USER }}
|
||||||
|
STAGING_WP_ADMIN_PASSWORD: ${{ secrets.STAGING_WP_ADMIN_PASSWORD }}
|
||||||
|
|
||||||
|
deploy-production:
|
||||||
|
name: Deploy to Production
|
||||||
|
# Smoke is now a GATE: a smoke FAILURE blocks production. A deliberately
|
||||||
|
# skipped smoke (run_smoke: false) still allows prod via the if-condition.
|
||||||
|
needs: [deploy-staging, smoke]
|
||||||
|
if: ${{ !cancelled() && needs.deploy-staging.result == 'success' && needs.smoke.result != 'failure' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Deploy via rsync → production (retry + inventory guard)
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan -p "${{ secrets.SSH_PORT }}" "${{ secrets.SSH_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
|
BASE="/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html"
|
||||||
|
SSHOPT="-i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=accept-new -o ConnectTimeout=30 -o BatchMode=yes"
|
||||||
|
PRE=$(ssh $SSHOPT "${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}" "wp --path=$BASE plugin list --status=active --field=name 2>/dev/null | wc -l" 2>/dev/null || echo 0)
|
||||||
|
echo "Pre-deploy active plugins (best-effort): $PRE"
|
||||||
|
n=0
|
||||||
|
until [ "$n" -ge 4 ]; do
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude '.git' --exclude '.github' --exclude 'tests' --exclude 'node_modules' \
|
||||||
|
--exclude 'vendor' --exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
|
--exclude 'phpunit.xml' --exclude 'phpunit.xml.dist' --exclude 'phpcs.xml.dist' \
|
||||||
|
--exclude '.phpcs.xml.dist' --exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' \
|
||||||
|
--exclude 'CHANGELOG.md' --exclude 'qa-reviews' \
|
||||||
|
-e "ssh $SSHOPT" \
|
||||||
|
./ "${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:$BASE/${{ inputs.target_path }}/" && break
|
||||||
|
n=$((n+1)); echo "prod rsync failed (attempt $n/4) — retrying in 25s..."; sleep 25
|
||||||
|
done
|
||||||
|
[ "$n" -lt 4 ] || { echo "::error::production rsync failed after 4 attempts"; exit 1; }
|
||||||
|
POST=$(ssh $SSHOPT "${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}" "wp --path=$BASE plugin list --status=active --field=name 2>/dev/null | wc -l; find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null || true" 2>/dev/null | head -1 || echo 0)
|
||||||
|
echo "Post-deploy active plugins (best-effort): $POST"
|
||||||
|
if [ "${PRE:-0}" -gt 0 ] && [ "${POST:-0}" -gt 0 ] && [ "${POST:-0}" -lt "${PRE:-0}" ]; then
|
||||||
|
echo "::error::active plugin count dropped ${PRE} -> ${POST} after deploy"; exit 1
|
||||||
|
fi
|
||||||
|
- name: Production health check
|
||||||
|
run: |
|
||||||
|
sleep 5
|
||||||
|
S=$(curl -s -o /dev/null -w '%{http_code}' https://peptiderepo.com)
|
||||||
|
if [ "$S" != "200" ] && [ "$S" != "403" ]; then echo "::error::site returned HTTP $S"; exit 1; fi
|
||||||
|
echo "Production healthy (HTTP $S)"
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
- name: Deploy summary
|
||||||
|
run: |
|
||||||
|
echo "## Deployment complete" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "- **Target:** ${{ inputs.target_path }}" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> "$GITHUB_STEP_SUMMARY"
|
||||||
86
.github/workflows/deploy-health.yml
vendored
Normal file
86
.github/workflows/deploy-health.yml
vendored
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
name: Deploy Health Monitor
|
||||||
|
|
||||||
|
# Daily drift + deploy-failure check across all peptiderepo app repos.
|
||||||
|
# Runs on GitHub's scheduler (independent of the local board cron that died).
|
||||||
|
# Opens ONE de-duplicated 'deploy-health' issue here when something is off.
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 13 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: write
|
||||||
|
actions: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check prod-vs-main drift + last deploy status
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const owner = 'peptiderepo';
|
||||||
|
const repos = [
|
||||||
|
'prautoblogger','peptide-repo-core','peptide-search-ai',
|
||||||
|
'peptide-news-plugin','peptide-reconstitution-calculator','peptide-starter-theme'
|
||||||
|
];
|
||||||
|
const short = s => s ? String(s).substring(0,7) : '—';
|
||||||
|
const problems = [];
|
||||||
|
for (const repo of repos) {
|
||||||
|
try {
|
||||||
|
const main = (await github.rest.repos.getBranch({owner, repo, branch:'main'})).data.commit.sha;
|
||||||
|
let runConc = 'none', runSha = '';
|
||||||
|
try {
|
||||||
|
const runs = (await github.rest.actions.listWorkflowRuns({owner, repo, workflow_id:'deploy.yml', per_page:1})).data.workflow_runs;
|
||||||
|
if (runs.length) { runConc = runs[0].conclusion || runs[0].status; runSha = runs[0].head_sha; }
|
||||||
|
} catch (e) { runConc = 'no-deploy-workflow'; }
|
||||||
|
let prodSha = null, prodState = 'none';
|
||||||
|
const deps = (await github.rest.repos.listDeployments({owner, repo, environment:'production', per_page:1})).data;
|
||||||
|
if (deps.length) {
|
||||||
|
prodSha = deps[0].sha;
|
||||||
|
const sts = (await github.rest.repos.listDeploymentStatuses({owner, repo, deployment_id: deps[0].id, per_page:1})).data;
|
||||||
|
if (sts.length) prodState = sts[0].state;
|
||||||
|
}
|
||||||
|
if (runConc === 'failure') problems.push(`**${repo}**: latest deploy run failed (\`${short(runSha)}\`)`);
|
||||||
|
if (prodSha && prodSha !== main) {
|
||||||
|
// Only real drift if undeployed commits touch DEPLOYABLE files
|
||||||
|
// (ignore .github/, tests/, and docs/build files the deploy excludes).
|
||||||
|
try {
|
||||||
|
const cmp = (await github.rest.repos.compareCommits({owner, repo, base: prodSha, head: main})).data;
|
||||||
|
const deployable = (cmp.files || []).some(f => {
|
||||||
|
const x = f.filename;
|
||||||
|
if (x.startsWith('.github/') || x.startsWith('tests/')) return false;
|
||||||
|
if (/^(ARCHITECTURE|CONVENTIONS|CHANGELOG|README)\.md$/.test(x)) return false;
|
||||||
|
if (/^(composer\.(json|lock)|phpunit\.xml(\.dist)?|\.?phpcs\.xml\.dist)$/.test(x)) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (deployable) problems.push(`**${repo}**: prod behind main — prod=\`${short(prodSha)}\` vs main=\`${short(main)}\` (undeployed code changes)`);
|
||||||
|
} catch (e) {
|
||||||
|
problems.push(`**${repo}**: prod sha != main sha (could not diff: ${e.message})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (prodSha && prodState !== 'success') problems.push(`**${repo}**: last production deployment state is \`${prodState}\``);
|
||||||
|
core.info(`${repo}: main=${short(main)} lastRun=${runConc} prodDeploy=${short(prodSha)}/${prodState}`);
|
||||||
|
} catch (e) {
|
||||||
|
problems.push(`**${repo}**: monitor error — ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const summary = problems.length
|
||||||
|
? `### ⚠️ Deploy health: ${problems.length} issue(s)\n\n` + problems.map(p=>`- ${p}`).join('\n')
|
||||||
|
: `### ✅ All app repos current; last deploy healthy`;
|
||||||
|
await core.summary.addRaw(summary).write();
|
||||||
|
if (problems.length) {
|
||||||
|
const existing = (await github.rest.issues.listForRepo({owner, repo: context.repo.repo, labels:'deploy-health', state:'open'})).data;
|
||||||
|
if (existing.length === 0) {
|
||||||
|
await github.rest.issues.create({ owner, repo: context.repo.repo,
|
||||||
|
title: `Deploy health: ${problems.length} issue(s) detected`,
|
||||||
|
body: summary + `\n\n_Opened by deploy-health.yml. Close once resolved; the monitor won't reopen while this stays open._`,
|
||||||
|
labels: ['deploy-health'] });
|
||||||
|
core.warning(`Opened deploy-health issue (${problems.length} problems)`);
|
||||||
|
} else {
|
||||||
|
core.warning(`${problems.length} problems; deploy-health issue already open (#${existing[0].number})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
79
CHANGELOG.md
Normal file
79
CHANGELOG.md
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to the peptide-e2e smoke suite will be documented here.
|
||||||
|
|
||||||
|
## [1.5.0] - 2026-06-14
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Board Generate Now smoke (M4, skip-if-absent)** (`06-board-generate-now.spec.ts`).
|
||||||
|
Asserts the PRAutoBlogger board page loads, `#prab-generate-now` button is present
|
||||||
|
and carries a nonce, and the kick-off AJAX action returns valid JSON (no PHP fatal).
|
||||||
|
READ-ONLY: never waits for generation to complete; `kick_off()` is idempotent.
|
||||||
|
SKIPS with a loud annotation when `#prab-board` or `#prab-generate-now` is absent
|
||||||
|
(v0.21.0 M4 not yet deployed) so the e2e PR can merge before prautoblogger PR #166
|
||||||
|
per the M2/M3 merge-order binding. 27 tests total (was 25), delta = 2.
|
||||||
|
|
||||||
|
## [1.4.0] - 2026-06-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Dossier edit + re-run smoke (M3, skip-if-absent)** (`05-dossier-edit.spec.ts`).
|
||||||
|
Opens a discovered post's dossier and exercises the v0.20.0 edit surface READ-ONLY:
|
||||||
|
opens/closes the first edit panel (asserts textareas, Save/Re-run buttons, the
|
||||||
|
fork-preserved + queued-execution copy), asserts every disabled edit affordance
|
||||||
|
carries a visible reason, and checks the M3 sidebar cards (Run Spend, Models &
|
||||||
|
Prompts). NEVER clicks Save or any Re-run button (those fork inputs / queue paid
|
||||||
|
LLM jobs). SKIPS with a loud annotation when `.prab-stage-rerun-footer` is absent
|
||||||
|
(plugin v0.20.0 not yet deployed) so this PR can merge before prautoblogger PR #161
|
||||||
|
per the M3 merge-order binding. 25 tests total (was 24), delta = 1.
|
||||||
|
|
||||||
|
## [1.3.0] - 2026-06-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **Auth setup survives `ERR_ABORTED` on wp-login.php** (`global.setup.ts`).
|
||||||
|
When Hostinger's LiteSpeed throttles a GitHub runner IP, `page.goto` can
|
||||||
|
throw `net::ERR_ABORTED` rather than a `TimeoutError`. Playwright marks the
|
||||||
|
browser context closed internally on abort, so the existing
|
||||||
|
`context.close()` call in the catch block threw
|
||||||
|
`"browserContext.close: Target page, context or browser has been closed"`,
|
||||||
|
which propagated out of catch and killed setup before the remaining retries
|
||||||
|
ran. Two production deploys were blocked by this flake on 2026-06-12.
|
||||||
|
|
||||||
|
Fix: introduced `safeClose()` helper that swallows the already-closed
|
||||||
|
error, so an aborted context never terminates the retry loop. Max attempts
|
||||||
|
raised from 3 → 5; backoff is now exponential (5 s / 10 s / 20 s / 40 s)
|
||||||
|
instead of a flat 15 s, giving the throttle window more time to clear.
|
||||||
|
Worst-case timing: 5 × 90 s navigation + 75 s backoff = ~525 s, well under
|
||||||
|
the 900 s (15 min) job timeout. Final-failure message explicitly names the
|
||||||
|
LiteSpeed throttle hypothesis so future CI logs self-diagnose.
|
||||||
|
|
||||||
|
## [1.2.0] - 2026-06-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Dossier page smoke test** (`03-admin-plugins.spec.ts` — `WP Admin — PRAutoBlogger Article Dossier`).
|
||||||
|
Navigates to `/wp-admin/admin.php?page=prautoblogger-dossier&post_id=<N>`, asserts HTTP 200,
|
||||||
|
`#prab-dossier` container visible, body does NOT contain "Invalid plugin page" or "Fatal error".
|
||||||
|
Guards against: menu-ordering regression (wrong hookname → wp_die 404), PHP fatals on dossier
|
||||||
|
load, missing dossier container, and stage-section regression.
|
||||||
|
|
||||||
|
Defensive strategy: tries canonical staging post IDs 925/930 first, then falls back to the
|
||||||
|
most recent REST post, then falls back to post_id=0 (graceful empty state). Stage-section
|
||||||
|
assertions are conditional on a run record existing. Loud test.info() annotations on fallback
|
||||||
|
paths. New in PRAutoBlogger v0.19.2 / v0.19.3.
|
||||||
|
|
||||||
|
## [1.1.0] - 2026-06-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Board page smoke test** (`03-admin-plugins.spec.ts` — `WP Admin — PRAutoBlogger board page`).
|
||||||
|
Navigates to `/wp-admin/admin.php?page=prautoblogger-board`, asserts HTTP 200,
|
||||||
|
`#prab-board` container visible, and body does NOT contain "Invalid plugin page".
|
||||||
|
Guards against the v0.19.1 regression class: Board submenu registered before parent
|
||||||
|
menu existed (both at admin_menu priority 10) → WordPress fallback hookname →
|
||||||
|
wp_die 404. Now in the deploy-gate smoke suite so this failure class is un-shippable.
|
||||||
|
|
||||||
|
Note: cannot be validated against prod until v0.19.1 of PRAutoBlogger deploys.
|
||||||
|
Spec compiles and lists cleanly under `npx playwright test --list`.
|
||||||
|
|
||||||
|
## [1.0.0] - 2026-06-11
|
||||||
|
|
||||||
|
Initial release. 21 tests across 5 specs: homepage, reconstitution calculator,
|
||||||
|
peptide search, admin plugins, REST API.
|
||||||
129
global.setup.ts
129
global.setup.ts
@@ -7,6 +7,26 @@
|
|||||||
*
|
*
|
||||||
* The saved auth state (playwright/.auth/admin.json) is reused by the
|
* The saved auth state (playwright/.auth/admin.json) is reused by the
|
||||||
* "chromium" project so individual tests don't each incur a login round-trip.
|
* "chromium" project so individual tests don't each incur a login round-trip.
|
||||||
|
*
|
||||||
|
* Retry hardening (2026-06-12 v1): Hostinger rate-limits GitHub runner IPs on
|
||||||
|
* wp-login.php, causing TimeoutError on page.goto. The login attempt is now
|
||||||
|
* retried up to MAX_ATTEMPTS times with a fresh browser context per attempt
|
||||||
|
* and BACKOFF_MS delay between attempts so transient throttle windows clear.
|
||||||
|
*
|
||||||
|
* Retry hardening (2026-06-12 v2 — ERR_ABORTED fix): When Hostinger aborts
|
||||||
|
* the connection (net::ERR_ABORTED), Playwright marks the context as closed
|
||||||
|
* internally. A subsequent context.close() call throws
|
||||||
|
* "browserContext.close: Target page, context or browser has been closed",
|
||||||
|
* which propagated out of the catch block and crashed setup without consuming
|
||||||
|
* remaining retries. Fix: context.close() is now guarded in its own
|
||||||
|
* try/catch so an already-closed context never aborts the retry loop.
|
||||||
|
* MAX_ATTEMPTS raised to 5; backoff doubled each time (5s/10s/20s/40s) so the
|
||||||
|
* LiteSpeed throttle window has time to clear before each retry.
|
||||||
|
*
|
||||||
|
* Timing math (job timeout-minutes: 15 = 900 s):
|
||||||
|
* 5 attempts × NAV_TIMEOUT (90 s) = 450 s navigation ceiling
|
||||||
|
* 4 inter-attempt waits (5+10+20+40 s) = 75 s backoff ceiling
|
||||||
|
* Total worst-case: ~525 s — well under the 900 s job timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { test as setup, expect } from '@playwright/test';
|
import { test as setup, expect } from '@playwright/test';
|
||||||
@@ -15,9 +35,27 @@ import * as fs from 'fs';
|
|||||||
|
|
||||||
const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json');
|
const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json');
|
||||||
|
|
||||||
setup('authenticate as WP admin', async ({ page }) => {
|
const MAX_ATTEMPTS = 5;
|
||||||
|
const NAV_TIMEOUT = 90_000; // 90 s per navigation attempt
|
||||||
|
|
||||||
|
/** Exponential backoff delays (ms) between attempts: 5 s, 10 s, 20 s, 40 s */
|
||||||
|
function backoffMs(attempt: number): number {
|
||||||
|
return 5_000 * Math.pow(2, attempt - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Safely close a context that Playwright may have already closed internally. */
|
||||||
|
async function safeClose(context: import('@playwright/test').BrowserContext): Promise<void> {
|
||||||
|
try {
|
||||||
|
await context.close();
|
||||||
|
} catch {
|
||||||
|
// Ignored: context was already closed (e.g. after ERR_ABORTED or crash).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setup('authenticate as WP admin', async ({ browser }) => {
|
||||||
const user = process.env.WP_ADMIN_USER;
|
const user = process.env.WP_ADMIN_USER;
|
||||||
const password = process.env.WP_ADMIN_PASSWORD;
|
const password = process.env.WP_ADMIN_PASSWORD;
|
||||||
|
const baseURL = process.env.BASE_URL ?? 'https://staging.peptiderepo.com';
|
||||||
|
|
||||||
if (!user || !password) {
|
if (!user || !password) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -25,28 +63,79 @@ setup('authenticate as WP admin', async ({ page }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure directory exists
|
// Ensure auth directory exists
|
||||||
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
|
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
|
||||||
|
|
||||||
await page.goto('/wp-login.php');
|
let lastError: unknown;
|
||||||
await page.fill('#user_login', user);
|
|
||||||
await page.fill('#user_pass', password);
|
|
||||||
await page.click('#wp-submit');
|
|
||||||
|
|
||||||
// Wait for any post-login navigation. The site may redirect successful logins
|
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||||
// to the homepage (via a login_redirect filter) rather than to wp-admin —
|
console.log(
|
||||||
// staging does this. So we don't assert the post-submit URL; instead, we
|
`[setup] Login attempt ${attempt}/${MAX_ATTEMPTS} — navigating to wp-login.php ...`
|
||||||
// verify we're no longer ON wp-login.php (which would indicate a credential
|
);
|
||||||
// rejection or 2FA prompt) and then navigate explicitly to wp-admin.
|
|
||||||
await page.waitForURL((url) => !url.pathname.includes('/wp-login.php'), {
|
|
||||||
timeout: 20_000,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Navigate explicitly into wp-admin to capture the authenticated admin session.
|
// Fresh context per attempt so stale cookies / throttle state don't carry over.
|
||||||
await page.goto('/wp-admin/');
|
const context = await browser.newContext({ baseURL });
|
||||||
await expect(page).toHaveURL(/\/wp-admin\//, { timeout: 20_000 });
|
const page = await context.newPage();
|
||||||
await expect(page.locator('#wpadminbar')).toBeVisible();
|
|
||||||
|
|
||||||
// Persist session cookies + localStorage to disk
|
try {
|
||||||
await page.context().storageState({ path: AUTH_FILE });
|
await page.goto('/wp-login.php', { timeout: NAV_TIMEOUT });
|
||||||
|
await page.fill('#user_login', user);
|
||||||
|
await page.fill('#user_pass', password);
|
||||||
|
await page.click('#wp-submit');
|
||||||
|
|
||||||
|
// Wait for any post-login navigation. The site may redirect successful
|
||||||
|
// logins to the homepage (via a login_redirect filter) rather than to
|
||||||
|
// wp-admin — staging does this. So we don't assert the post-submit URL;
|
||||||
|
// instead, we verify we're no longer ON wp-login.php (which would
|
||||||
|
// indicate a credential rejection or 2FA prompt) and then navigate
|
||||||
|
// explicitly to wp-admin.
|
||||||
|
await page.waitForURL(
|
||||||
|
(url) => !url.pathname.includes('/wp-login.php'),
|
||||||
|
{ timeout: NAV_TIMEOUT }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Navigate explicitly into wp-admin to capture the authenticated admin session.
|
||||||
|
await page.goto('/wp-admin/', { timeout: NAV_TIMEOUT });
|
||||||
|
await expect(page).toHaveURL(/\/wp-admin\//, { timeout: 20_000 });
|
||||||
|
await expect(page.locator('#wpadminbar')).toBeVisible({ timeout: 20_000 });
|
||||||
|
|
||||||
|
// Persist session cookies + localStorage to disk
|
||||||
|
await page.context().storageState({ path: AUTH_FILE });
|
||||||
|
|
||||||
|
console.log(`[setup] Login succeeded on attempt ${attempt}/${MAX_ATTEMPTS}`);
|
||||||
|
await safeClose(context);
|
||||||
|
return; // success — exit setup
|
||||||
|
} catch (err) {
|
||||||
|
lastError = err;
|
||||||
|
const message = err instanceof Error ? err.message : String(err);
|
||||||
|
console.error(
|
||||||
|
`[setup] Login attempt ${attempt}/${MAX_ATTEMPTS} FAILED: ${message}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// IMPORTANT: use safeClose — if Playwright received ERR_ABORTED it marks
|
||||||
|
// the context closed internally, so a plain context.close() throws
|
||||||
|
// "Target page, context or browser has been closed". Without this guard
|
||||||
|
// that secondary throw propagated out of catch and killed setup before
|
||||||
|
// the remaining retries ran.
|
||||||
|
await safeClose(context);
|
||||||
|
|
||||||
|
if (attempt < MAX_ATTEMPTS) {
|
||||||
|
const wait = backoffMs(attempt);
|
||||||
|
console.log(
|
||||||
|
`[setup] Waiting ${wait / 1000}s before retry ` +
|
||||||
|
`(LiteSpeed throttle cool-down — attempt ${attempt + 1}/${MAX_ATTEMPTS}) ...`
|
||||||
|
);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, wait));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All attempts exhausted — surface the last error with a clear diagnostic.
|
||||||
|
throw new Error(
|
||||||
|
`[setup] All ${MAX_ATTEMPTS} login attempts failed. ` +
|
||||||
|
`Last error: ${lastError instanceof Error ? lastError.message : String(lastError)}\n` +
|
||||||
|
`Hypothesis: Hostinger LiteSpeed is throttling GitHub runner IPs on wp-login.php — ` +
|
||||||
|
`connections abort (ERR_ABORTED) or time out in bursts. ` +
|
||||||
|
`Re-run the workflow once the throttle window clears, or increase MAX_ATTEMPTS / backoffMs().`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
44
package-lock.json
generated
44
package-lock.json
generated
@@ -1,25 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "peptide-e2e",
|
"name": "peptide-e2e",
|
||||||
"version": "1.0.0",
|
"version": "1.4.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "peptide-e2e",
|
"name": "peptide-e2e",
|
||||||
"version": "1.0.0",
|
"version": "1.4.0",
|
||||||
|
"dependencies": {
|
||||||
|
"typescript": "^6.0.3"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.43.0",
|
"@playwright/test": "^1.60.0",
|
||||||
"dotenv": "^16.4.5"
|
"dotenv": "^16.4.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@playwright/test": {
|
"node_modules/@playwright/test": {
|
||||||
"version": "1.59.1",
|
"version": "1.60.0",
|
||||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.60.0.tgz",
|
||||||
"integrity": "sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==",
|
"integrity": "sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"playwright": "1.59.1"
|
"playwright": "1.60.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright": "cli.js"
|
"playwright": "cli.js"
|
||||||
@@ -57,13 +60,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright": {
|
"node_modules/playwright": {
|
||||||
"version": "1.59.1",
|
"version": "1.60.0",
|
||||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.59.1.tgz",
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz",
|
||||||
"integrity": "sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==",
|
"integrity": "sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"playwright-core": "1.59.1"
|
"playwright-core": "1.60.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright": "cli.js"
|
"playwright": "cli.js"
|
||||||
@@ -76,9 +79,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright-core": {
|
"node_modules/playwright-core": {
|
||||||
"version": "1.59.1",
|
"version": "1.60.0",
|
||||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.59.1.tgz",
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz",
|
||||||
"integrity": "sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==",
|
"integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -87,6 +90,19 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "6.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
|
||||||
|
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.17"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peptide-e2e",
|
"name": "peptide-e2e",
|
||||||
"version": "1.0.0",
|
"version": "1.5.0",
|
||||||
"description": "Playwright smoke tests for peptiderepo.com (staging + production)",
|
"description": "Playwright smoke tests for peptiderepo.com (staging + production)",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -11,7 +11,10 @@
|
|||||||
"report": "playwright show-report"
|
"report": "playwright show-report"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.43.0",
|
"@playwright/test": "^1.60.0",
|
||||||
"dotenv": "^16.4.5"
|
"dotenv": "^16.4.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"typescript": "^6.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,31 +39,14 @@ test.describe('Reconstitution Calculator', () => {
|
|||||||
expect(options).toBeGreaterThan(1); // >1 means at least one peptide beyond placeholder
|
expect(options).toBeGreaterThan(1); // >1 means at least one peptide beyond placeholder
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fills inputs and gets a numeric result', async ({ page }) => {
|
test('fills inputs and gets a numeric result', async ({ page }) => {
|
||||||
// Select BPC-157 or the first non-placeholder option
|
const calc = page.locator('.prc-calculator');
|
||||||
const select = page.locator('select').first();
|
// The calculator auto-computes once a peptide preset is chosen (the preset
|
||||||
const firstPeptide = select.locator('option').nth(1);
|
// supplies vial size, recommended water volume and a default dose).
|
||||||
const firstValue = await firstPeptide.getAttribute('value');
|
await calc.locator('#prc-peptide-select').selectOption({ index: 1 });
|
||||||
await select.selectOption(firstValue ?? '');
|
// Results panel unhides and renders numeric result cards.
|
||||||
|
const results = page.locator('#prc-results');
|
||||||
// Fill reconstitution volume (mL) — use a known valid value
|
await expect(results).toBeVisible({ timeout: 10_000 });
|
||||||
const volInput = page.locator('input[name*="recon"], input[placeholder*="mL"], input[type="number"]').first();
|
await expect(page.locator('.prc-result-card__value').first()).toHaveText(/\d/, { timeout: 5_000 });
|
||||||
await volInput.fill('2');
|
});
|
||||||
|
|
||||||
// Fill desired dose
|
|
||||||
const doseInput = page.locator('input[name*="dose"], input[placeholder*="dose"], input[type="number"]').nth(1);
|
|
||||||
await doseInput.fill('250');
|
|
||||||
|
|
||||||
// Trigger calculation (button or auto-calculate on input)
|
|
||||||
const calcButton = page.locator('button[type="submit"], button:has-text("Calculate")');
|
|
||||||
if (await calcButton.count() > 0) {
|
|
||||||
await calcButton.first().click();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Results container should show a non-zero concentration or injection volume
|
|
||||||
const results = page.locator('.prc-results, .calculator-results, [data-prc-result]').first();
|
|
||||||
await expect(results).toBeVisible({ timeout: 5_000 });
|
|
||||||
const resultText = await results.textContent();
|
|
||||||
expect(resultText).toMatch(/\d+(\.\d+)?/); // contains at least one number
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ test.describe('Peptide Search AI', () => {
|
|||||||
test('search input widget is present on page', async ({ page }) => {
|
test('search input widget is present on page', async ({ page }) => {
|
||||||
// PSA renders a form with class .psa-search-form or input with data-psa attr
|
// PSA renders a form with class .psa-search-form or input with data-psa attr
|
||||||
const searchInput = page.locator(
|
const searchInput = page.locator(
|
||||||
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
|
'.hero-search .psa-search-input'
|
||||||
).first();
|
).first();
|
||||||
await expect(searchInput).toBeVisible({ timeout: 10_000 });
|
await expect(searchInput).toBeVisible({ timeout: 10_000 });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('searching for a known peptide returns results', async ({ page }) => {
|
test('searching for a known peptide returns results', async ({ page }) => {
|
||||||
const searchInput = page.locator(
|
const searchInput = page.locator(
|
||||||
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
|
'.hero-search .psa-search-input'
|
||||||
).first();
|
).first();
|
||||||
await expect(searchInput).toBeVisible();
|
await expect(searchInput).toBeVisible();
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ test.describe('Peptide Search AI', () => {
|
|||||||
await searchInput.press('Enter');
|
await searchInput.press('Enter');
|
||||||
|
|
||||||
// Results container should appear and contain something
|
// Results container should appear and contain something
|
||||||
const results = page.locator('.psa-results, .psa-search-results, [data-psa-results]').first();
|
const results = page.locator('.hero-search .psa-search-results').first();
|
||||||
await expect(results).toBeVisible({ timeout: 15_000 });
|
await expect(results).toBeVisible({ timeout: 15_000 });
|
||||||
const text = await results.textContent();
|
const text = await results.textContent();
|
||||||
expect((text ?? '').trim().length).toBeGreaterThan(0);
|
expect((text ?? '').trim().length).toBeGreaterThan(0);
|
||||||
@@ -57,7 +57,7 @@ test.describe('Peptide Search AI', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const searchInput = page.locator(
|
const searchInput = page.locator(
|
||||||
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
|
'.hero-search .psa-search-input'
|
||||||
).first();
|
).first();
|
||||||
await searchInput.fill('TB-500');
|
await searchInput.fill('TB-500');
|
||||||
await searchInput.press('Enter');
|
await searchInput.press('Enter');
|
||||||
|
|||||||
@@ -94,13 +94,52 @@ test.describe('WP Admin — PRAutoBlogger settings page', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.describe('WP Admin — PRAutoBlogger board page', () => {
|
||||||
|
/**
|
||||||
|
* Smoke test: Board submenu page must load without 404 or "Invalid plugin page".
|
||||||
|
*
|
||||||
|
* This test guards against the v0.19.1 regression class: Board submenu was
|
||||||
|
* registered before the parent top-level menu page existed (both at admin_menu
|
||||||
|
* priority 10), causing WordPress to fall back to the `admin_page_*` hookname.
|
||||||
|
* At request time WP recomputed the hookname, found nothing, and called
|
||||||
|
* wp_die("Invalid plugin page"). The fix (v0.19.1) moves the board hook to
|
||||||
|
* priority 11 so the parent menu slot is populated first.
|
||||||
|
*
|
||||||
|
* Selector sourced from templates/admin/board-page.php: `<div id="prab-board" ...>`.
|
||||||
|
*
|
||||||
|
* NOTE: This test cannot be validated against prod until v0.19.1 is deployed.
|
||||||
|
* It is included in the deploy-gate smoke suite so the bug class becomes
|
||||||
|
* un-shippable in future. The spec compiles and lists cleanly; the test will
|
||||||
|
* run correctly once the fix is live.
|
||||||
|
*/
|
||||||
|
test('board page loads and board container is present', async ({ page }) => {
|
||||||
|
// Navigate to the Board submenu page.
|
||||||
|
const res = await page.goto(`${ADMIN}/admin.php?page=prautoblogger-board`);
|
||||||
|
|
||||||
|
// Must be HTTP 200 — not wp_die 404.
|
||||||
|
expect(res?.status()).toBe(200);
|
||||||
|
|
||||||
|
// wp-admin chrome must render (confirms we're authenticated and in admin).
|
||||||
|
await expect(page.locator('#wpbody')).toBeVisible();
|
||||||
|
|
||||||
|
// Body must NOT contain the wp_die "Invalid plugin page" error string.
|
||||||
|
const body = await page.textContent('body');
|
||||||
|
expect(body).not.toContain('Invalid plugin page');
|
||||||
|
|
||||||
|
// Board container div must be present (from templates/admin/board-page.php).
|
||||||
|
// selector: <div id="prab-board" class="prab-board" ...>
|
||||||
|
await expect(page.locator('#prab-board')).toBeVisible({ timeout: 10_000 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test.describe('WP Admin — Peptide Repo Core admin', () => {
|
test.describe('WP Admin — Peptide Repo Core admin', () => {
|
||||||
test('PR Core menu item exists in wp-admin', async ({ page }) => {
|
test('PR Core menu item exists in wp-admin', async ({ page }) => {
|
||||||
await page.goto(`${ADMIN}/`);
|
await page.goto(`${ADMIN}/`);
|
||||||
// PR Core registers the peptide CPT which creates a "Peptides" menu item const nav = page.locator('#adminmenu');
|
// PR Core registers the peptide CPT which creates a "Peptides" menu item
|
||||||
|
const nav = page.locator('#adminmenu');
|
||||||
await expect(nav).toBeVisible();
|
await expect(nav).toBeVisible();
|
||||||
// "Peptides" top-level menu item is registered by the peptide CPT
|
// PR Core registers the peptide CPT, which adds a post_type=peptide admin menu/submenu (label-agnostic).
|
||||||
await expect(nav.locator('text=Peptides')).toBeVisible({ timeout: 10_000 });
|
await expect(nav.locator('a[href*="post_type=peptide"]').first()).toBeAttached({ timeout: 10_000 });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('PR Core Settings page loads', async ({ page }) => {
|
test('PR Core Settings page loads', async ({ page }) => {
|
||||||
@@ -115,3 +154,116 @@ test.describe('WP Admin — Peptide Repo Core admin', () => {
|
|||||||
await expect(page.locator('form')).toBeVisible();
|
await expect(page.locator('form')).toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.describe('WP Admin — PRAutoBlogger Article Dossier', () => {
|
||||||
|
/**
|
||||||
|
* Smoke test: Article Dossier page must load without "Invalid plugin page" error.
|
||||||
|
*
|
||||||
|
* The dossier is a hidden-submenu page registered at admin_menu priority 12
|
||||||
|
* (after board p11, after parent p10). It is link-accessed via
|
||||||
|
* admin.php?page=prautoblogger-dossier&post_id=<int>.
|
||||||
|
*
|
||||||
|
* This test guards against:
|
||||||
|
* 1. Menu-ordering regression (wrong hookname → wp_die 404).
|
||||||
|
* 2. PHP fatal errors on dossier load (missing require, fatal in assembler).
|
||||||
|
* 3. Missing dossier container div (template regression).
|
||||||
|
* 4. Stage-section regression (stage markup absent when run data exists).
|
||||||
|
*
|
||||||
|
* Defensive strategy: the test first queries the WP REST API for a post
|
||||||
|
* published by PRAutoBlogger (_prautoblogger_generated=1). If a post is found,
|
||||||
|
* it opens its dossier and asserts the full set. If no matching post exists
|
||||||
|
* on this environment (staging/prod may differ), the test opens the dossier
|
||||||
|
* with post_id=0 and asserts the graceful "no run record" empty state — which
|
||||||
|
* still validates page load, no fatal, no "Invalid plugin page".
|
||||||
|
*
|
||||||
|
* Selector sourced from templates/admin/dossier-page.php:
|
||||||
|
* <div id="prab-dossier" class="prab-dossier-wrap" ...>
|
||||||
|
*
|
||||||
|
* Posts 925/930 are the canonical staging test posts (v0.18.3 generation run).
|
||||||
|
* They are tried first; REST fallback handles environments where they don't exist.
|
||||||
|
*/
|
||||||
|
test('dossier page loads and dossier container is present', async ({ page, request }) => {
|
||||||
|
const ADMIN = '/wp-admin';
|
||||||
|
const CANDIDATE_POST_IDS = [925, 930]; // staging canonical posts from v0.18.3
|
||||||
|
|
||||||
|
// Strategy 1: try known staging post IDs
|
||||||
|
let targetPostId: number | null = null;
|
||||||
|
|
||||||
|
for (const pid of CANDIDATE_POST_IDS) {
|
||||||
|
const apiRes = await request.get(`/wp-json/wp/v2/posts/${pid}`);
|
||||||
|
if (apiRes.ok()) {
|
||||||
|
targetPostId = pid;
|
||||||
|
console.log(`[dossier smoke] Found candidate post id=${pid} via REST API`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strategy 2: query for any PRAutoBlogger-generated post via REST
|
||||||
|
if (targetPostId === null) {
|
||||||
|
const listRes = await request.get('/wp-json/wp/v2/posts?per_page=5&orderby=date&order=desc');
|
||||||
|
if (listRes.ok()) {
|
||||||
|
const posts: Array<{ id: number; meta?: Record<string, unknown> }> = await listRes.json();
|
||||||
|
if (posts.length > 0) {
|
||||||
|
targetPostId = posts[0].id;
|
||||||
|
console.log(`[dossier smoke] Fallback: using most recent post id=${targetPostId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Navigate to dossier — use targetPostId if found, else post_id=0 for graceful empty state
|
||||||
|
const postIdParam = targetPostId !== null ? targetPostId : 0;
|
||||||
|
const dossierUrl = `${ADMIN}/admin.php?page=prautoblogger-dossier&post_id=${postIdParam}`;
|
||||||
|
|
||||||
|
if (targetPostId === null) {
|
||||||
|
// Loud annotation — the dossier will render empty state, not full dossier
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'warning',
|
||||||
|
description:
|
||||||
|
'[dossier smoke] No PRAutoBlogger post found on this environment. ' +
|
||||||
|
'Asserting graceful empty state (post_id=0). ' +
|
||||||
|
'Full dossier assertions (stage sections) require a post with a run record.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await page.goto(dossierUrl);
|
||||||
|
|
||||||
|
// Must be HTTP 200 — not wp_die 404 (menu-ordering regression guard).
|
||||||
|
expect(res?.status()).toBe(200);
|
||||||
|
|
||||||
|
// wp-admin chrome must render (confirms auth session is valid).
|
||||||
|
await expect(page.locator('#wpbody')).toBeVisible();
|
||||||
|
|
||||||
|
// Body must NOT contain the wp_die "Invalid plugin page" error string.
|
||||||
|
const body = await page.textContent('body');
|
||||||
|
expect(body).not.toContain('Invalid plugin page');
|
||||||
|
expect(body).not.toContain('Fatal error');
|
||||||
|
|
||||||
|
// Dossier container div must be present in all cases (full run OR empty state).
|
||||||
|
// Selector from templates/admin/dossier-page.php: <div id="prab-dossier" ...>
|
||||||
|
await expect(page.locator('#prab-dossier')).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
// Stage sections — only assert if we have a post with (likely) a run record.
|
||||||
|
if (targetPostId !== null) {
|
||||||
|
// At least one stage section must be present IF the post has a run record.
|
||||||
|
// The dossier may still show empty state if this post pre-dates the substrate.
|
||||||
|
// We assert conditionally: if any stage section exists, it has the right class.
|
||||||
|
const stageSections = page.locator('.prab-stage-section');
|
||||||
|
const stageCount = await stageSections.count();
|
||||||
|
|
||||||
|
if (stageCount > 0) {
|
||||||
|
// Dossier has stage data — verify stage sections render without error
|
||||||
|
console.log(`[dossier smoke] Found ${stageCount} stage sections on post id=${targetPostId}`);
|
||||||
|
await expect(stageSections.first()).toBeVisible();
|
||||||
|
} else {
|
||||||
|
// Post exists but has no run stages — graceful empty state (pre-substrate post)
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'info',
|
||||||
|
description:
|
||||||
|
`[dossier smoke] Post id=${targetPostId} exists but has no stage sections. ` +
|
||||||
|
'This is the expected graceful state for posts published before v0.18.0.',
|
||||||
|
});
|
||||||
|
// The dossier container is already verified above; this is not a failure.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ test.describe('REST API — Peptide Search AI', () => {
|
|||||||
expect([200, 404]).toContain(res.status());
|
expect([200, 404]).toContain(res.status());
|
||||||
if (res.status() === 200) {
|
if (res.status() === 200) {
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
expect(body).toHaveProperty('status');
|
|
||||||
expect(body).toHaveProperty('results');
|
expect(body).toHaveProperty('results');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
136
tests/05-dossier-edit.spec.ts
Normal file
136
tests/05-dossier-edit.spec.ts
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/**
|
||||||
|
* 05-dossier-edit.spec.ts
|
||||||
|
*
|
||||||
|
* What: Smoke for the PRAutoBlogger dossier EDIT + RE-RUN surface
|
||||||
|
* (plugin v0.20.0, Phase 2 admin M3). Read-only: opens/closes the
|
||||||
|
* edit panel and asserts structure — it NEVER clicks Save or any
|
||||||
|
* Re-run button (those fork inputs / queue paid LLM jobs).
|
||||||
|
* Who triggers it: Playwright chromium project (post-auth setup).
|
||||||
|
* Dependencies: wp-admin authenticated session (from global.setup.ts).
|
||||||
|
*
|
||||||
|
* SKIP-IF-ABSENT (M3 binding): this spec targets a surface that may not
|
||||||
|
* be deployed yet. When the M3 markup (.prab-stage-rerun-footer) is
|
||||||
|
* absent from the dossier, the test SKIPS with a loud annotation so this
|
||||||
|
* PR can merge before the plugin PR ships. Once v0.20.0 is live, the
|
||||||
|
* skip path goes dead and the assertions gate as usual.
|
||||||
|
*
|
||||||
|
* Selectors sourced from prautoblogger v0.20.0:
|
||||||
|
* templates/admin/dossier-stage-section.php (.prab-stage-rerun-footer,
|
||||||
|
* .prab-edit-toggle, .prab-edit-unavailable, .prab-rerun-from)
|
||||||
|
* templates/admin/dossier-edit-panel.php (.prab-edit-panel,
|
||||||
|
* .prab-edit-textarea, .prab-edit-save, .prab-edit-rerun)
|
||||||
|
* templates/admin/dossier-sidebar-cards.php (.prab-run-spend,
|
||||||
|
* .prab-models-card)
|
||||||
|
*
|
||||||
|
* @see prautoblogger PR #161 (v0.20.0) — the surface under test.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
const ADMIN = '/wp-admin';
|
||||||
|
const CANDIDATE_POST_IDS = [925, 930]; // canonical staging posts
|
||||||
|
|
||||||
|
test.describe('WP Admin — PRAutoBlogger dossier edit + re-run (M3)', () => {
|
||||||
|
test('edit affordances render structurally (no mutations)', async ({ page, request }) => {
|
||||||
|
// ── Post discovery (same defensive strategy as the dossier smoke) ──
|
||||||
|
let targetPostId: number | null = null;
|
||||||
|
for (const pid of CANDIDATE_POST_IDS) {
|
||||||
|
const apiRes = await request.get(`/wp-json/wp/v2/posts/${pid}`);
|
||||||
|
if (apiRes.ok()) {
|
||||||
|
targetPostId = pid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetPostId === null) {
|
||||||
|
const listRes = await request.get('/wp-json/wp/v2/posts?per_page=5&orderby=date&order=desc');
|
||||||
|
if (listRes.ok()) {
|
||||||
|
const posts: Array<{ id: number }> = await listRes.json();
|
||||||
|
if (posts.length > 0) {
|
||||||
|
targetPostId = posts[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetPostId === null) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'warning',
|
||||||
|
description:
|
||||||
|
'[dossier-edit smoke] No post found on this environment — ' +
|
||||||
|
'cannot exercise the edit surface. Skipping.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await page.goto(`${ADMIN}/admin.php?page=prautoblogger-dossier&post_id=${targetPostId}`);
|
||||||
|
expect(res?.status()).toBe(200);
|
||||||
|
await expect(page.locator('#wpbody')).toBeVisible();
|
||||||
|
const body = await page.textContent('body');
|
||||||
|
expect(body).not.toContain('Fatal error');
|
||||||
|
expect(body).not.toContain('Invalid plugin page');
|
||||||
|
|
||||||
|
// ── SKIP-IF-ABSENT gate: M3 markup not deployed yet ────────────────
|
||||||
|
const footers = page.locator('.prab-stage-rerun-footer');
|
||||||
|
const footerCount = await footers.count();
|
||||||
|
if (footerCount === 0) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'warning',
|
||||||
|
description:
|
||||||
|
'[dossier-edit smoke] .prab-stage-rerun-footer absent — the M3 ' +
|
||||||
|
'edit+rerun surface (plugin v0.20.0) is not deployed on this ' +
|
||||||
|
'environment, or this post has no stage sections. Skipping per ' +
|
||||||
|
'the merge-early binding.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[dossier-edit smoke] Found ${footerCount} stage rerun footers on post id=${targetPostId}`);
|
||||||
|
|
||||||
|
// ── Disabled affordances must explain themselves ───────────────────
|
||||||
|
const unavailable = page.locator('.prab-edit-unavailable');
|
||||||
|
const unavailableCount = await unavailable.count();
|
||||||
|
for (let i = 0; i < unavailableCount; i++) {
|
||||||
|
const reason = (await unavailable.nth(i).textContent())?.trim() ?? '';
|
||||||
|
expect(reason.length, 'disabled edit affordances must carry a visible reason').toBeGreaterThan(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Edit panel open/close (read-only — NEVER click save/rerun) ─────
|
||||||
|
const toggles = page.locator('.prab-edit-toggle');
|
||||||
|
const toggleCount = await toggles.count();
|
||||||
|
if (toggleCount === 0) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'info',
|
||||||
|
description:
|
||||||
|
'[dossier-edit smoke] No editable stage on this post (no recorded ' +
|
||||||
|
'request_json yet, or post is published/frozen). Disabled-state ' +
|
||||||
|
'reasons were asserted; panel interaction not exercisable.',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstToggle = toggles.first();
|
||||||
|
const panelId = await firstToggle.getAttribute('aria-controls');
|
||||||
|
expect(panelId).toBeTruthy();
|
||||||
|
const panel = page.locator(`#${panelId}`);
|
||||||
|
|
||||||
|
await firstToggle.click();
|
||||||
|
await expect(panel).toBeVisible();
|
||||||
|
await expect(firstToggle).toHaveAttribute('aria-expanded', 'true');
|
||||||
|
|
||||||
|
// Panel structure: textareas + save + rerun buttons + fork/queue copy.
|
||||||
|
expect(await panel.locator('.prab-edit-textarea').count()).toBeGreaterThan(0);
|
||||||
|
await expect(panel.locator('.prab-edit-save')).toBeVisible();
|
||||||
|
await expect(panel.locator('.prab-edit-rerun')).toBeVisible();
|
||||||
|
const copy = (await panel.textContent()) ?? '';
|
||||||
|
expect(copy).toContain('original is preserved'); // fork copy (guardrail 1)
|
||||||
|
expect(copy.toLowerCase()).toContain('queued'); // chained-cron copy
|
||||||
|
|
||||||
|
// Close it again — leave the page exactly as found.
|
||||||
|
await firstToggle.click();
|
||||||
|
await expect(panel).toBeHidden();
|
||||||
|
|
||||||
|
// ── M3 sidebar cards present when run data exists ──────────────────
|
||||||
|
await expect(page.locator('.prab-run-spend')).toBeVisible();
|
||||||
|
await expect(page.locator('.prab-models-card')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
156
tests/06-board-generate-now.spec.ts
Normal file
156
tests/06-board-generate-now.spec.ts
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
/**
|
||||||
|
* 06-board-generate-now.spec.ts
|
||||||
|
*
|
||||||
|
* What: Smoke for the PRAutoBlogger board "Generate Now" control (v0.21.0, M4).
|
||||||
|
* Asserts that the board page renders the generate-now button and that
|
||||||
|
* clicking it sends the kick-off AJAX request without a PHP fatal.
|
||||||
|
* Read-only assertions only — this test NEVER waits for article generation
|
||||||
|
* to complete (that would make LLM API calls in CI).
|
||||||
|
*
|
||||||
|
* SKIP-IF-ABSENT (M4 binding): the generate-now surface ships with v0.21.0
|
||||||
|
* (prautoblogger PR #166). This spec guards against the board container
|
||||||
|
* (#prab-board) being absent or the generate-now button (#prab-generate-now)
|
||||||
|
* missing. When those selectors are absent (v0.21.0 not yet deployed), the
|
||||||
|
* entire test suite skips with a loud annotation so this PR can merge before
|
||||||
|
* the plugin PR — matching the M2 merge-order binding.
|
||||||
|
*
|
||||||
|
* Selectors sourced from prautoblogger v0.21.0:
|
||||||
|
* templates/admin/board-page.php: #prab-board, #prab-generate-now
|
||||||
|
* assets/js/board-generate.js: data-nonce, wp.ajax / admin-ajax.php
|
||||||
|
*
|
||||||
|
* Who triggers it: Playwright chromium project (post-auth setup).
|
||||||
|
* Dependencies: wp-admin authenticated session (from global.setup.ts).
|
||||||
|
*
|
||||||
|
* @see prautoblogger PR #166 (v0.21.0) — the surface under test.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
const ADMIN = '/wp-admin';
|
||||||
|
const BOARD_URL = `${ADMIN}/admin.php?page=prautoblogger-board`;
|
||||||
|
|
||||||
|
test.describe('WP Admin — PRAutoBlogger board Generate Now (M4)', () => {
|
||||||
|
test('board page loads and generate-now button is present (skip-if-absent)', async ({ page }) => {
|
||||||
|
// Navigate to the board page.
|
||||||
|
const res = await page.goto(BOARD_URL);
|
||||||
|
|
||||||
|
// Must be HTTP 200 (guards menu-registration regression).
|
||||||
|
expect(res?.status()).toBe(200);
|
||||||
|
|
||||||
|
// wp-admin chrome must be present.
|
||||||
|
await expect(page.locator('#wpbody')).toBeVisible();
|
||||||
|
|
||||||
|
// Body must not contain PHP fatal or wp_die error strings.
|
||||||
|
const body = await page.textContent('body');
|
||||||
|
expect(body).not.toContain('Fatal error');
|
||||||
|
expect(body).not.toContain('Invalid plugin page');
|
||||||
|
|
||||||
|
// ── SKIP-IF-ABSENT guard ────────────────────────────────────────────────
|
||||||
|
// The generate-now surface ships with v0.21.0. If the board container or
|
||||||
|
// the button is absent, the M4 plugin is not yet deployed — skip loudly.
|
||||||
|
const boardContainer = page.locator('#prab-board');
|
||||||
|
const boardPresent = await boardContainer.count() > 0;
|
||||||
|
|
||||||
|
if ( ! boardPresent ) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'skip',
|
||||||
|
description:
|
||||||
|
'[generate-now smoke] #prab-board absent: v0.21.0 (M4) not yet deployed. ' +
|
||||||
|
'Skipping generate-now assertions — they will gate once the plugin PR ships.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Board container must be visible.
|
||||||
|
await expect(boardContainer).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
// ── Generate-now button (skip-if-absent) ────────────────────────────────
|
||||||
|
const generateBtn = page.locator('#prab-generate-now');
|
||||||
|
const btnPresent = await generateBtn.count() > 0;
|
||||||
|
|
||||||
|
if ( ! btnPresent ) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'skip',
|
||||||
|
description:
|
||||||
|
'[generate-now smoke] #prab-generate-now absent: M4 button not yet in deployed build. ' +
|
||||||
|
'Skipping button assertions.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Button must be visible and carry a nonce for the AJAX call.
|
||||||
|
await expect(generateBtn).toBeVisible({ timeout: 5_000 });
|
||||||
|
const nonce = await generateBtn.getAttribute('data-nonce');
|
||||||
|
expect(nonce).toBeTruthy();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
'[generate-now smoke] Generate Now button found with nonce — M4 surface is deployed.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('generate-now AJAX responds with JSON (no fatal) — skip-if-absent', async ({ page, request }) => {
|
||||||
|
// Navigate first to establish auth cookies for the request context.
|
||||||
|
await page.goto(BOARD_URL);
|
||||||
|
|
||||||
|
const body = await page.textContent('body');
|
||||||
|
if ( ! body?.includes('prab-board') ) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'skip',
|
||||||
|
description: '[generate-now smoke] Board container absent — v0.21.0 not deployed. Skipping.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateBtn = page.locator('#prab-generate-now');
|
||||||
|
if ( await generateBtn.count() === 0 ) {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'skip',
|
||||||
|
description: '[generate-now smoke] #prab-generate-now absent — skipping AJAX test.',
|
||||||
|
});
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the nonce from the button (set by wp_localize_script).
|
||||||
|
const nonce = await generateBtn.getAttribute('data-nonce') ?? '';
|
||||||
|
|
||||||
|
// Fire the kick-off AJAX action (same as board-generate.js would).
|
||||||
|
// We use the request context to intercept without actually triggering
|
||||||
|
// the full pipeline — the action is idempotent (kick_off() guards against
|
||||||
|
// duplicate scheduling with wp_next_scheduled()).
|
||||||
|
//
|
||||||
|
// NOTE: We assert the response is valid JSON with a 'success' or 'data'
|
||||||
|
// key only. We do NOT check that generation actually runs (LLM calls).
|
||||||
|
const adminAjax = `${ADMIN}/admin-ajax.php`;
|
||||||
|
const formData = new URLSearchParams({
|
||||||
|
action: 'prautoblogger_generate_now',
|
||||||
|
nonce,
|
||||||
|
});
|
||||||
|
|
||||||
|
const ajaxRes = await request.post(adminAjax, {
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
data: formData.toString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Must be HTTP 200 (not 403/500).
|
||||||
|
expect(ajaxRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Response must be valid JSON (no PHP fatal/notice dumped as HTML).
|
||||||
|
const text = await ajaxRes.text();
|
||||||
|
let parsed: unknown;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
throw new Error(
|
||||||
|
`[generate-now smoke] AJAX response is not valid JSON — possible PHP fatal.\nRaw: ${text.slice(0, 500)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// WordPress wp_send_json_success / _error always wraps in { success: bool }.
|
||||||
|
expect(parsed).toHaveProperty('success');
|
||||||
|
console.log('[generate-now smoke] AJAX response:', JSON.stringify(parsed).slice(0, 200));
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user