Skip to content

test(site-type-php): add a Behat suite and CI workflow - #119

Open
mrrobot47 wants to merge 35 commits into
EasyEngine:developfrom
mrrobot47:test/behat-suite-r3
Open

mrrobot47 wants to merge 35 commits into
EasyEngine:developfrom
mrrobot47:test/behat-suite-r3

Conversation

@mrrobot47

Copy link
Copy Markdown
Member

Extends the three old feature files into a Behat suite for site-type-php (features/: 146 scenarios, outline rows counted) and replaces test_and_build.yml with a Behat workflow that runs it on every pull request, on pushes to develop and master, and on demand.

It covers PHP site create and its options, the global, local and remote database options, PHP versions (current and legacy images), redis cache and site clean, the public dir, alias domains, SSL (self-signed, custom, wildcard refusals, one Let's Encrypt issuance), www redirects, labels, info, the site lifecycle and delete. features/COVERAGE.md maps each command, flag and behaviour to its scenarios.

  • The workflow runs the suite inside a fresh core checkout: core develop is cloned, every easyengine/* package is set to dev-develop, and this package is installed from the pull request's checkout through a Composer path repository, so the code under test is the PR's. The old job tested the Packagist dev-develop package instead.
  • Lanes: main (133 scenarios), slow (12, legacy PHP images) and le (1), each on PHP 7.4 and 8.0 to 8.5. The main lane's jobs are named Behat Tests - PHP <version>, so the required checks keep matching. The main lane also builds the phar without dev autoloading, as the old job did. @destructive scenarios run there too, since the runner is thrown away.
  • @le runs against a local Pebble ACME server (.github/behat/pebble-setup.sh). Every other lane points the Let's Encrypt host at a blackhole and checks that the real service can't be reached, and on CI the suite refuses to start unless one of the two is in place, so no run can reach the real Let's Encrypt.
  • Scenarios written for open bugs (14) are left out for now: they assert the fixed behaviour, so each comes back with its fix. Every scenario in this PR gates, and COVERAGE.md lists the bugs that aren't covered yet.

Merge after EasyEngine/easyengine#1950: core's test job still runs this package's features unfiltered, and #1950 drops that, since the new suite refuses to start on CI without Pebble or the Let's Encrypt blackhole.

To run it locally (as root, on a test machine, since the suite creates and deletes *.test sites): copy features/ over a core checkout's features/ and run sudo -E vendor/bin/behat --tags='~@le' from the core root; add ~@destructive to skip the scenarios that change global services or config, and ~@slow to skip the legacy PHP images.

Green run on my fork (PHP 7.4 and 8.0 to 8.5, every lane): https://github.com/mrrobot47/site-type-php/actions/runs/39377513357

…red steps

Start from site-command's context and fix its traps: the unanchored I-run regex that matched any step with a double-quoted string, assertions that always read the first command, the inverted container-count check, compose-v1 container names, the vacuous mysql checks (DB-1) and `docker exec -it` (CACHE-1). Cleanup now deletes only this suite's bh-site-type-php-* sites and their leftovers instead of every site.

Add a marked section of generic steps (command result, JSON, sites table, files, docker services/volumes/networks, HTTP with --resolve or Host, TLS certificates, global db/redis, hosts file, idempotent site givens). Commands run with stdin on /dev/null so docker never allocates a TTY.
Usage and help, defaults in the sites table, generated files, compose file, containers, volumes, network, HTTP, name normalisation, duplicate and invalid input, EE3 compat flags, labels and www redirects. Known bugs: loose --php matching, --php without --type, SEC-1 and the volume prefix collision.
Global db, custom db credentials, --local-db, remote --dbhost, --skip-check and site delete cleanup. Known bugs: DB-1, remote db never verified, and rollbacks that drop another site's database or user.
Global and local redis page cache (HIT/BYPASS, keys, networks), cache flag combinations with local and global db, and site clean. Known bugs: MIG-16, CACHE-1 and clean missing the php page cache key format and local redis.
Create on every supported version and latest, and site update --php including backup, custom.ini, 5.6 sendmail handling and error paths.
Relative, full, nested and sanitised document roots, with cache, and the bare --public-dir known bug.
Create with plain and wildcard aliases, conflicts, trimming, and site update --add/--delete-alias-domains with every error path. Known bugs: existing site as alias, blank entries and AUTH-1.
Self-signed, custom, inherit and one Let's Encrypt create (@le), argument errors, and site update --ssl. Known bug: SSL of a --ssl=self site can't be turned off.
site info (table, json, from the site directory), list filters, enable, disable, refresh, restart, reload, proxy cache (@destructive) and delete.
Map every create flag, php subcommand and side effect to its scenarios, list the known and newly suspected bugs, tags, naming rules and runtime.
The cleanup no longer drops a database or user still referenced by any site row, removes a hosts line only when every name on it is the suite's, clears the suite's redis page-cache keys and removes the SEC-1 site dir. The suite refuses to start next to a foreign site whose volume prefix or db names could collide, and the db setup steps only accept suite names. The --dbuser data-loss scenario gets its own site (the --dbname one drops site 20's database), and the SEC-1 payload no longer uses ${IFS}, which the lowercased name turns into an empty variable.
site info from the site dir runs from the site root (app is a symlink into the volume and ee reads the physical pwd). --ssl=off --wildcard now asserts its own error on a wildcard site, with a separate normal-to-wildcard scenario. Failing creates that really roll back assert the dir, volumes, containers and network are gone. The redirect delete check first asserts the conf existed, the global/local redis combo scenarios check the site's real page cache instead of a set/get on redis, the list status is checked for the site itself, and 8.4.1 moves to the loose --php known bug (it passes validation on PHP 7). The bare --public-dir known bug accepts either fix. HTTP checks after a restart, reload or cert change poll, and the DB connect step waits for a fresh MariaDB. The blank and space alias known bugs are tagged @destructive (they break the nginx-proxy config until rolled back), the LE scenario checks le-mail is configured, the fpm and nginx status pages are covered, and every known bug comment carries its PHPT ID.
…numbers

bh-site-type-php-81.test is also the custom-cert site of ssl.feature; the PHPT-4 pair is now 2-7/27, which no other scenario uses.
Maps every known bug to its issues.md PHPT ID, corrects the claims that were only vacuously covered (rollback, --ssl=off --wildcard, directory auto-detect, LE revocation, --skip-check), and documents the cleanup and data-loss guards, the new @destructive scenarios and the LE duplicate-certificate limit.
…ment

CI runs @le against Pebble: EE_BEHAT_LE_ISSUER is its intermediate CN and EE_BEHAT_LE_DNS_SERVER the runner's resolver. Defaults stay Let's Encrypt and 1.1.1.1.
Behat 3.8 drops a trailing unmatched ( not)? group, so every positive form of these steps failed with "Can not find a matching value for an argument $not". ( not|) always participates and yields an empty string.
… usage in two parts

A fresh local MariaDB denies root until its first-start init is done, the first HTTPS request right after a --ssl=self create can still hit the previous proxy config, and the create synopsis has a stray double space before [--with-db].
…der timeout

Without --foreground, timeout puts ee in a background process group; the docker exec -it of a cache purge then stops on SIGTTOU under a TTY (with timeout itself), so the cleanup hangs. -k 30 because ee ignores SIGTERM (MIG-9).
…ngine#114)

The blank-entry and invalid-hostname alias scenarios pass on develop now, so they are regular regression scenarios (the @destructive tags stay: a regression would break the proxy config for every site).
With the fix/site-name-collisions branches of site-command and site-type-php, --dbname/--dbuser of another site and a colliding volume prefix are refused before anything is created. The PHPT-4 scenario now asserts the refusal (existing sites keep their volume names), and a new scenario covers the numbered suffix for a taken default db name.
It passes with the SC-3 fix on site-command fix/proxy-cache-rollback-and-le-alias and fails on develop until it merges.
SEC-1 is fixed (site-type-php#117), so its scenario is regular. The wildcard-update refusal is checked with --ssl=le, since self-signed certificates are always wildcard (site-command 5c34be8).
…iline output

compareContents() compared list elements by position, so [1,3,5] wasn't found in [1,2,3,4,5], and a missing key or property raised a notice. Both something-like steps only used the first line of the expected text.
The something-like step now compares the whole expected text, and the second line of these errors ends with a space, so each line is checked on its own.
EE's hardcoded Let's Encrypt endpoint is redirected to a local Pebble on the runner (hosts entry, throwaway CA, resolved routing for the test domain). No product code changes.
Tests the package checkout inside a fresh core develop checkout through a Composer path repository. Lanes: main, slow (every PHP version image) and known-bug (continue-on-error). @le runs in behat-le.yml.
Run PHP 7.4 and 8.5, strip control characters from the junit files before building failures.txt, and cap the Behat step at 75 minutes so a hung run still uploads its logs. The @le lanes against Pebble move into behat.yml (lanes named le*), replacing behat-le.yml. Diagnostics: the host addresses and routes, and the docker-compose version after the first run (MIG-20).
EE's first run downloads docker-compose 2.27.0 without --fail (MIG-10); on a GitHub error it moves the HTML error page over the binary, as on an admin-tools-command runner. Fetch 2.27.0 again with --fail and retries in that case.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Root-level cleanup and system-wide DNS, firewall and certificate-trust changes require human validation before approval.

No open issues 🎉

What changed in this PR

Expands site-type-php’s Behat coverage and replaces the existing CI workflow so tests exercise the checked-out package inside EasyEngine core.

Changes:

  • Adds 146 scenarios covering PHP site creation, configuration and lifecycle.
  • Runs main, slow and certificate lanes across seven PHP versions.
  • Adds scoped cleanup, local Pebble certificate testing and coverage documentation.
File Description
features/​ssl.feature Tests SSL configuration and certificate handling.
features/​site.feature Tests command availability, help and usage errors.
features/​redirect.feature Tests www redirects and their cleanup.
features/​public-dir.feature Tests custom document roots.
features/​php-version.feature Tests PHP versions and upgrades.
features/​lifecycle.feature Tests site management and deletion.
features/​labels.feature Checks container, volume and network labels.
features/​database.feature Tests database options and ownership safeguards.
features/​create.feature Tests creation defaults, validation and generated resources.
features/​COVERAGE.md Documents coverage, exclusions and execution requirements.
features/​cache.feature Tests Redis cache configurations.
features/​bootstrap/​support.php Improves nested content comparisons.
features/​bootstrap/​FeatureContext.php Adds assertions, fixtures, cleanup and ACME guards.
features/​alias-domains.feature Tests alias creation, validation and updates.
.github/​workflows/​test_and_build.yml Removes the previous workflow.
.github/​workflows/​behat.yml Adds matrix testing against the checked-out package.
.github/​behat/​pebble-setup.sh Manages Pebble, network isolation and teardown.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants