Repository navigation
feat(php-compat): show the estimate and progress before a table-format check - #552
Conversation
A check of a large site can run for most of an hour with no output, which reads as a hung command. With the default table format the command now runs the estimate first, under the same site lock, and prints how long the check should take before it starts. While the check runs, a terminal gets one self-updating line with the time elapsed against that estimate; it is cleared before the result. Piped output gets only the phase lines. A failed estimate is reported in one line and the check runs anyway. When the estimate finds no code, that is the result, as the check would find the same. A --cancel or a site delete during the estimate stops the run as before, and an estimate container left by a timeout is removed before the check starts. --timeout still covers the scan only. --format=json is unchanged: no estimate runs and stdout holds only the JSON document.
The table scenarios expect the estimate and check lines before the verdict. New scenarios cover a failed estimate that falls through to the check, --cancel during the estimate, and the progress line on a terminal. The JSON scenario asserts that no estimate runs and stdout holds only the document.
The STDOUT steps strip ANSI escape sequences, so the scenario could never see the line clearing it asserts. Piping the terminal output through cat -v keeps them visible.
…stimate A paused estimate makes the client hit its time limit: the scenario checks that the estimate container is gone before the check runs and that the check still finishes. Deleting the site during the estimate makes the check report cancelled. The terminal scenario now checks ee's exit status and reads the saved output through cat -v in a separate step.
…e removal Progress and phase lines now go to stderr, so stdout holds only the result again: `| head`, `| grep`, `| tee` and `> file` see the table as before, while the terminal still shows the progress; the self-updating line is shown when stderr is a terminal. The first table check on a host now says it is getting the scanner image before the pull, which can take minutes. The estimate container's label is kept until its removal worked, so a signal or a cancel that cuts the mid-run removal short leaves cleanup() able to retry it; this also covers plain --estimate runs. Smaller: a cancelled estimate is no longer logged as a failed one, the progress line is cleared before the debug line that follows the scan, and an estimate of a site with no PHP files of its own isn't printed as "about 1 second".
…ng the estimate The table scenarios read the progress lines from stderr and the result from the start of stdout again; the JSON scenario asserts an empty stderr. New checks: no check runs after the estimate finds no code, a second check during the estimate is busy before printing anything, and --timeout in the table format applies to the scan only. The suite's cleanup also removes estimate containers of its sites by their label, so a failed run can't leave a paused one for the next scenario.
A table-format --estimate also pulls the scanner image the first time, so it gets the same line before the pull. The line no longer claims the pull happens once per EasyEngine version: it also runs when a local image has to be pulled again.
…ing as gone A --cancel during an estimate and the stopped run's own cleanup both remove the estimate container. Docker answers the second docker rm -f with "removal of container … is already in progress", which --cancel reported as "could not remove the estimate container". That answer now counts as removed, as "No such container" already did, both for --cancel and for the run's own cleanup.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Feature Merge Risk:
|
A check of a large site can run for most of an hour with no output, which reads as a hung command. With the default table format,
ee site php-compatnow estimates how long the check will take before it starts, prints that, and shows the time elapsed while the check runs.What users see
On a terminal, the
Checking: … elapsedline rewrites itself about once a second and is cleared before the result is printed. When stderr is not a terminal there is no live line, only the phase lines. The first check after the scanner image changes also prints "Getting the easyengine/compat-scanner image. This can take a few minutes." before the pull, for--estimatein table format too.The estimate reuses the existing estimate container and parsing, and runs under the same site lock as the check, so no other check can start between the two. If the estimate fails (it times out, the container dies, or its output is invalid), one line says so and the check runs anyway; the estimate is advisory. When the estimate finds no code, that is the result, since the check lists the files the same way. A second check while the first is still estimating reports
busyexactly as before.Output channels and JSON
The phase and progress lines go to stderr; stdout holds only the result, as before. So
| head,| grep,| teeand> filesee the same table as before, while the terminal still shows progress. The progress lines are written withfwrite(), so a lost terminal doesn't stop a long check.--format=jsonis unchanged: no estimate runs, stdout is the same single JSON document, stderr stays empty and the exit codes are the same. This was compared before and after on a WordPress site with about 14,500 PHP files and on a php site: the documents were identical apart fromduration_s.--estimateoutput and--cancelare unchanged too.--timeoutstill covers the scan only; the estimate before it isn't counted. ee.log gets one more line for the estimate, in the existing style (status and counts only).Cancel and delete during the estimate
The estimate container carries the same labels as before, so
ee site php-compat <site> --cancelandee site deletestop it during the estimate phase as they stop the check: the run reportscancelledand no container is left. An estimate container that a timeout leaves running is removed before the check starts, and its label is kept until the removal worked, socleanup()retries a removal that a signal or a cancel cut short. When--canceland the stopped run's cleanup remove the same estimate container at once, Docker answers the seconddocker rm -fwith "removal of container … is already in progress"; that now counts as removed, as "No such container" already did, instead of making--cancelreport that it couldn't remove the container (this could also happen before with--estimateand--cancel).Tests
Behat (
features/php-compat.feature):--cancelandee site deleteduring the estimate;--timeoutin table format;The suite's cleanup also removes leftover estimate containers by their label.
All php-compat scenarios pass on PHP 7.4 and 8.5 (main and wp lanes). The change was also run on a live host on real sites, including:
| head -1;> file;--debug;Summary by CodeRabbit