Skip to content

v0.1.35

Latest

Choose a tag to compare

@ogorzalka ogorzalka released this 23 Nov 11:43
0210757

Added

  • Adapter contract tests: a template and a pattern, stubs/contract/ (issue #110). A port with several adapters is tested once, against all of them: the adapters are a Pest dataset (one row each), the contract is a file of it() with ->with('adapters'), and a new adapter is a new row; no abstract test class is needed (CONV-12 stays satisfied). The template is a worked example for a toy port (Store) with the three files to copy (Datasets/Contract.php, Datasets/Stores.php, StoreContractTest.php), and contractCase() for a difference the contract found and nobody has decided yet: the case still runs, is reported as skipped with its reason while it fails, and fails the day it passes, so a fix cannot hide in the list. tests/Unit/ContractStubTest.php runs a real Pest on the template (passes on good adapters, fails on a bad one, keeps a listed difference as a skip, fails on a listed difference that was fixed). The README has a chapter, the measured cost on media and the reason no static rule exists yet. Nothing runs by itself: no job, input or rule changes; a repository adds the suite to its phpunit.xml after copying the files.
  • Four observed Semgrep rules follow what a request sends to a dangerous call: SEC-10 to SEC-13 (issue #108). presets/semgrep/observed.yml is back, with taint rules (inside one function, not across files) that run in a new Security patterns (observed) step of pollora-qa check, observed by default so that it never blocks (the report has one step more: the jq length of ci.yml is now 14). pollora.sec-10.request-redirect reports a request value in wp_redirect(), redirect(), redirect()->away(), Redirect::to() or a Location header (open redirect; wp_validate_redirect(), home_url(), admin_url() and the like clear it); pollora.sec-11.request-http-call the request as the URL of wp_remote_get/post/head/request(), curl_init(), CURLOPT_URL or Http::get() (SSRF; wp_safe_remote_*() and wp_http_validate_url() clear it, the body and the headers are not looked at); pollora.sec-12.request-path the request as the path of file_get_contents(), include, readfile(), unlink(), fopen(), get_template_part() and the other file functions (traversal, php://; basename(), sanitize_file_name() and an allow-list clear it); pollora.sec-13.request-echo the request in echo, printf() or wp_die() without esc_* (reflected XSS; sanitize_text_field() is an input filter, not an escape). Sources: $_GET, $_POST, $_REQUEST, $_COOKIE, the request headers and URL of $_SERVER, filter_input(), and a Laravel request ($request->input(), request(), the Request facade). Measured over the 45 repositories (2,684 PHP files, Semgrep 1.186.0): 0 report, hence observed; every use of the request in the ecosystem was read by hand (80 superglobal reads, 9 wp_redirect, 10 wp_remote_*, 4 Http::, 4 filter_input(), 12 Laravel reads) and none is an unvalidated flow. Not shipped: the syntactic "superglobal read without sanitize_*" rule (6 reports, 6 false positives), and four candidates already covered by SEC-02 (wp_ajax_nopriv_ without a nonce), SEC-05 (extract), SEC-10 (header()) or by SEC-13. The fixtures test now runs common.yml and observed.yml together, with annotated positive and negative cases for each rule. New: Plan::SEMGREP_OBSERVED, catalogue rules SEC-10 to SEC-13 (observed).
  • A template can carry an optional .harness.json, read by template.yml (#107). The skeleton and the themes have no file, so the type coverage floor of CONV-11 (measured: skeleton 88.3 %, theme-apiary 87.3 %) could not be recorded and a drop went unseen. template.yml gains a Ratchet (QA-01) job, last in the file, that looks for .harness.json or .github/harness.json (a directory the release archives leave out) and, only when one exists, checks the harness out, installs nikic/php-parser alone (no composer install of the template, no autoloader) and runs the new pollora-qa check --template: the ratchet of the file, with the mode input of the workflow deciding whether a drop blocks (enforce) or reports (observe), and observed: ratchet reporting it. The profile may be left out of the file (it is then template; project is accepted, any other is refused), a bad value or key names the file. Compatibility: a template without the file is checked exactly as before (the new job passes at once with a notice, no other job, name, needs, if or input changes; the new job is skipped steps only). New: Plan::template(), HarnessConfig::loadForTemplate(), loadAny(), locateForTemplate(), TEMPLATE_FILE, and --config=FILE on check (with --template), ratchet and init. ratchet --update records in that file (never adds mode, keeps unknown keys), and init --profile=template now writes only that file with the type coverage floor measured now, rounded down to a tenth, instead of the package scaffolding a template could not use; a package profile is unchanged. See A .harness.json for a template in the README.
  • allow_rules exempts some classes of a rule, not only the whole rule (classes). CONV-08 has hundreds of open classes in 20 repositories, a few of which are real extension points: exempting the rule would stop judging all of them. An entry may now carry "classes": ["Acme\\Models\\*", "Acme\\Foo"] (a fully qualified class name or a namespace prefix ending in \\*, nothing else) for CONV-02, CONV-08 and CONV-09. The classes are removed from the problems of the rule and named (exempted: CONV-08 — <reason> — N classes: …, in a skipped test and in the notes of the Architecture and Tests and architecture gates); a pattern that matches no class, or none that the rule reports, is a stale exemption warning (an incomplete test, never a failure); an exemption of an observed rule stays declared, not applied. Several entries may name one rule; an entry limited to classes and a whole-rule entry for the same rule make the file invalid (InvalidConfig::ruleExemptionConflict), as do a bad pattern, an empty list, or classes on another rule. Compatibility: classes is optional and additive; an entry without it, and every existing .harness.json, behave exactly as before (toArray() writes no classes key). New: Config\ClassPattern, Architecture\ClassExemptions, ExemptionEffect, Exempted.
  • A ratchet metric exempted_classes: the (rule, class) pairs the per-class exemptions remove, lower is better. It counts a class only when the rule reports it, so a final class under an exempted namespace costs nothing and a new open class raises the figure and fails QA-01 against the recorded ceiling: a namespace prefix cannot widen unnoticed. exempted_rules keeps counting whole-rule entries only. Measured only in a repository that has a classes entry or already records the key (unmeasured otherwise), so an existing .harness.json is unchanged; ratchet --update records and lowers it, --metric=exempted_classes:N works.
  • CONV-02 can be exempted (allow_rules). It joins RuleExemption::EXEMPTIBLE and Plan::ARCHITECTURE_RULES (the test that keeps them equal still holds); its status stays observed.
  • promote-report measures many repositories in one run. pollora-qa promote-report <path>... or --root=<dir> [--only=a,b] prints a rule x repository matrix (text) or, with --json, {repositories, matrix}: for each repository the rows of the single report, its static type_coverage and the floor to record in ratchet.type_coverage (rounded down to 0.1 point so that measurement noise cannot fail the ratchet), and one {rule, repository, verdict, count} cell per rule. A directory without composer.json is not-applicable; an unreadable directory or an invalid .harness.json is named and gives status 1 (never counted clean). Without argument the report of the current repository is unchanged. The promotion study of the 45 repositories is now replayable without an agent.
  • Integration tests against a real WordPress: an optional WordPress integration job in php-package.yml. Three new optional inputs, all off or neutral by default: wordpress-integration (the suite directory, for example tests/Integration; empty, the default, skips the job), wordpress-version (latest, nightly or a version number) and wordpress-plugins (wordpress.org slugs). The job, named WordPress integration PHP <version>, installs WordPress with WP-CLI against a digest-pinned MySQL 8.0 service container, caches the downloads, and starts the test:integration script, phpunit.integration.xml or the directory, on PHP 8.3 and 8.4, with a 20-minute timeout. It is skipped while the input is empty and no other job depends on it: no job name, needs, if or input of the existing jobs changes. stubs/wordpress/ holds the bootstrap, the PHPUnit configuration and a test that proves a real WordPress is loaded; the README explains the cost and when to turn it on.

Changed

  • CONV-09, PERF-01 and PERF-07 are enforced: they block in enforce mode for every repository that raises the harness to the next version. Measured with promote-report --root over the 36 directories of the ecosystem that have a composer.json (read only, the git status of the 46 checkouts identical before and after): no would-block anywhere, CONV-09 clean in 34 repositories (1 not applicable), PERF-01 and PERF-07 clean in the framework, the only repository that declares budgets, and not applicable in the 35 others. The framework's four facades (Option::forget(), PostType, Taxonomy, WordPressError) were fixed in its pull request #670, and develop reads CONV-09 clean. CONV-09 passes from the incomplete (observed) block of tests/Arch.php to the blocking one with the same message as the other rules, and allow_rules exempts it whole or, with classes, facade by facade. The Performance budgets step leaves Plan::OBSERVED_BY_DEFAULT: it fails like the other steps in enforce mode (a budget that went up, an invalid budgets file, nightly measures that are not wired), and stays skipped with its reason, never a failure, in a repository that declares neither. The number of steps of check does not change (13); a repository that stays on 0.1.34 is not affected. CONV-02, CONV-08, CONV-11 and CONV-12 stay observed; the catalogue now counts 35 enforced, 4 observed and 1 planned rule.
  • promote-report takes the per-class exemptions into account. The text says CONV-08 would block (15 found, 12 exempted by allow_rules in 4 classes: 3 remaining) (or clean when nothing remains) and lists the stale patterns. In the JSON, count is what remains after the exemptions (unchanged without any), and each row gains found, exempted_problems, exempted_classes and stale.

Fixed

  • The WordPress integration job no longer breaks on two defects found by deploying it on eleven packages. (1) The wp-config.php the job generated defined DISABLE_WP_CRON (and the WP_DEBUG* constants) without defined() ||, while the bootstrap template defines it before wp-load.php: the Constant DISABLE_WP_CRON already defined warning failed the tests that compare the output of a sub-process and made Pest exit without a test. Every constant of the generated wp-config.php is now guarded, and the template guards WP_USE_THEMES too. (2) Pest loads tests/Pest.php and tests/Helpers/* before the PHPUnit bootstrap, so the doubles of WordPress they declare (WP_Error, wp_parse_args(), WP_CLI...) collided with the real WordPress (Cannot redeclare class WP_Error, exit 255 without a message). Without a test:integration script, the job now runs pest --test-directory=<wordpress-integration> -c phpunit.integration.xml; the templates carry the command, a new stubs/wordpress/unit-bootstrap.php.stub (where the doubles go: tests/bootstrap.php, referenced by phpunit.xml.dist) and a README chapter on why Pest.php must not declare them. The comment of phpunit.integration.xml.stub is checked as well-formed XML. Compatibility: a repository that does not turn the input on sees no change (same jobs, names, needs and if); one that does and has a test:integration script runs the same command as before. tests/Unit/WordPressIntegrationRunTest.php runs the generated wp-config.php constants, the template bootstrap and the step's command in a project against a fake wp-load.php (three of its tests fail without the correction).

  • Per-class exemptions no longer need ext-mbstring. The label of the test that names an exemption was cut with mb_strimwidth, which the dependency analysis (ARCH-07) reported as a shadow dependency: the harness would have required an extension from every repository it is installed in. Support\Text::shorten() does the same with PCRE only (characters, never half a multi-byte character, invalid UTF-8 returned as it is).

  • The WordPress integration template passes PHPStan, and the README says to export-ignore the suite. The first pilot of the job (Pollora/hook, PHP 8.3 and 8.4 both green in 37 s and 46 s) showed two defects of the template, not of the job: ->not->toBe('') in WordPressLoadedTest.php.stub fails PHPStan level 5 on a repository that analyses its tests (Access to an undefined property Pest\Mixins\Expectation::$not), now positive expectations; and phpunit.integration.xml at the root is a development file that the Distribution archive step (QA-06) reports, so the README now tells to run pollora-qa archive --fix.

  • The dependency audits try again when the network fails, and never when they have found something (SEC-09). composer audit failed twice in an hour on curl error 28 while downloading https://packagist.org/api/security-advisories/: Connection timed out, an incident of Packagist unrelated to the code. The Dependency audit step (Check\ComposerAudit) now attempts the call 3 times in all, 5 s then 15 s apart, only when the output is a transport failure (timeout, DNS, refused or reset connection, TLS handshake, HTTP 5xx or 429: Support\TransportErrors); advisories found, a lock file error or any other output fail at once, with no second attempt. An advisory API still unreachable after the attempts FAILS the step (never a pass) with advisory API unreachable after 3 attempts, a text that says it is a network failure and not a vulnerability. The npm audit (Npm\NpmAudit) does the same for a registry error (EAI_AGAIN, ETIMEDOUT, ECONNRESET, HTTP 5xx and so on); its other failures keep failing at once. New command pollora-qa composer-audit [--locked], the same code, which the reusable workflow template.yml now runs (it checks the harness out as its npm audit job does); the job names and the inputs are unchanged. The other network calls of the workflows (the gitleaks image, pipx install semgrep) are not attempted again.

  • init run again no longer erases settings. It rebuilt the configuration without mutation, npm_audit, services and slow_step_share. It now keeps every key it does not decide, and HarnessConfig::save() (used by init and ratchet --update) carries over a top-level key this version does not know, as it was. HarnessConfig::withMutation() also dropped performance.

  • pollora-qa help aligns the commands whatever the length of their names: the column is as wide as the longest (promote-report overflowed the fixed 9 characters).

  • README: the Status section says the performance budgets are delivered and that integration tests against a real WordPress and adapter contract tests remain.

  • Layers::psr4() no longer reads a missing composer.json through a suppressed warning (a directory without one is simply empty).

Documentation

  • CONV-01 stays planned, and the README says why. Four readings of "the common case needs no configuration" were measured over the 45 repositories (long required parameter lists on public factories and registries, constructors with many scalars, required boolean flags, any public method with 4 or more required parameters): the best one reports 22 methods, 5 real, so no code was added. The figures are in the README, under Status.