Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions plugins/spryker-ai-dev-sdk/skills/spryker-feature-install/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ list, and keep the phase table in `$STATE/state.md`: it survives a compaction.
`.ai-dev/feature-install/<feature-slug>/` in the project. Substitute each one inline as a literal
path; never set a shell variable and never `cd`. Run every script from the project root.

**Tool output.** `run-tools.php` prints one line per tool and writes the full output to files in
`$STATE`; `compare-baselines.php` prints one line per check. Read these lines. Open a log file
only for the failing part and search it for that part; never read the whole file.

**Delegation.** Invoke skills by slash command (`/spryker-refresher`, or
`/spryker-ai-dev-sdk:spryker-refresher` on a plugin install). Agent names carry the plugin prefix
on a plugin install, and the separator differs by harness (see
Expand Down Expand Up @@ -150,11 +154,14 @@ or a package name.** Record in `state.md` that the search ran through a fallback
SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline php $UP/check-config-constants.php || true
SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline php $UP/check-dead-overrides.php snapshot
SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline php $UP/twig-shadow-map.php snapshot
script -q /dev/null docker/sdk cli php -d memory_limit=2048M vendor/bin/phpstan analyze -c phpstan.neon src/ -l 6 2>&1 | tee $STATE/baseline/phpstan-baseline-run.txt
script -q /dev/null docker/sdk cli vendor/bin/console code:sniff:style 2>&1 | tee $STATE/baseline/sniff-baseline.txt
script -q /dev/null docker/sdk testing codecept run --no-exit 2>&1 | tee $STATE/baseline/codecept-baseline.txt
SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline php $UP/run-tools.php baseline phpstan sniffer tests --tests-args=--no-exit
SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline SPRYKER_BACKOFFICE_USER=<user> SPRYKER_BACKOFFICE_PASSWORD=<password> php $UP/backoffice-smoke.php --url <zed base url> --baseline
```
`run-tools.php` writes `phpstan-baseline-run.txt`, `sniff-baseline.txt` and
`codecept-baseline.txt`, and pins the invocation in `tool-invocation.json` for Phase 6. It detects
the sniffer entry point; pass `--sniffer "<command>"` when it names the wrong one,
`--env NAME=VALUE` for each environment variable the developer sets for the tests, and
`--codecept-options "<options>"` once for each test configuration the project runs.
For the storage and search counts, copy `$UP/storage-search-counts.php` into `$STATE/baseline/`
and run it in the container with `--snapshot before`.
4. Check the baselines: `php $FI/compare-baselines.php $STATE` — every line under "Baselines" is
Expand Down Expand Up @@ -323,9 +330,12 @@ widgets; every vendor template the project overrides has lost the vendor's calls
acceptance criterion, in the guide's words. Record `verdict` PASS, FAIL or BLOCKED with the
evidence path. Weigh a FAIL as a hypothesis before acting: browser problems look like feature
failures.
3. Run the baseline tools again, into `$STATE/after/` with the same commands as in Phase 0:
`phpstan-after.txt`, `sniff-after.txt`, `codecept-after.txt`; the Back Office crawl without
`--baseline` (same `SPRYKER_UPGRADE_STATE_DIR`: it marks each failure that is in the baseline);
3. Run the baseline tools again, into `$STATE/after/` with the invocation Phase 0 pinned:
`SPRYKER_UPGRADE_STATE_DIR=$STATE/after php $UP/run-tools.php after phpstan sniffer tests
--tests-args=--no-exit --pin-dir $STATE/baseline` (it writes `phpstan-after.txt`,
`sniff-after.txt`, `codecept-after.txt`); the Back Office crawl without
`--baseline` (`SPRYKER_UPGRADE_STATE_DIR=$STATE/baseline` as in Phase 0: it marks each failure
that is in the baseline);
the storage and search counts with `--snapshot after`, then `--compare before after`. Run each
frontend build the project has into `after/yves-build.txt`, `after/zed-build.txt`,
`after/mp-build.txt`, each ending with its exit code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,7 @@

function cb_text(string $file): ?string
{
return is_file($file) ? bl_plain_text((string)file_get_contents($file)) : null;
}

function cb_phpstan_errors(string $text): ?int
{
if (preg_match('/Found (\d+) (?:\S+ )?errors?/', $text, $m)) {
return (int)$m[1];
}

return preg_match('/\[OK\] No errors/', $text) ? 0 : null;
}

function cb_sniff_findings(string $text): ?int
{
if (preg_match('/A TOTAL OF (\d+) ERRORS? AND (\d+) WARNINGS?/', $text, $m)) {
return (int)$m[1] + (int)$m[2];
}
if (preg_match_all('/FOUND (\d+) ERRORS?(?: AND (\d+) WARNINGS?)?/', $text, $m, PREG_SET_ORDER)) {
return array_sum(array_map(static fn (array $hit): int => (int)$hit[1] + (int)($hit[2] ?? 0), $m));
}

return bl_content_problem('sniff-baseline.txt', $text) === null ? 0 : null;
}

/**
* @return array{total: ?int, failing: list<string>}
*/
function cb_codecept(string $text): array
{
$failing = [];
if (preg_match_all('/^\s*\d+\) (\S.*?)\s*$/m', $text, $m)) {
$failing = array_values(array_unique(array_map('trim', $m[1])));
}
$total = null;
if (preg_match_all('/Tests: \d+, Assertions: \d+(?:, Errors: (\d+))?(?:, Failures: (\d+))?/', $text, $m, PREG_SET_ORDER)) {
$total = array_sum(array_map(static fn (array $hit): int => (int)($hit[1] ?? 0) + (int)($hit[2] ?? 0), $m));
} elseif (preg_match('/\bOK \(\d+ tests?/', $text)) {
$total = 0;
}

return ['total' => $total, 'failing' => $failing];
return is_file($file) ? to_plain_text((string)file_get_contents($file)) : null;
}

/**
Expand All @@ -109,19 +69,19 @@ function cb_evaluate(string $stateDir): array
$after = cb_text($afterDir . '/phpstan-after.txt');
$checks['phpstan'] = match (true) {
$after === null => 'missing after/phpstan-after.txt',
cb_phpstan_errors($after) === null => 'after/phpstan-after.txt has no PHPStan result line',
$before === null || cb_phpstan_errors($before) === null => 'no valid baseline to compare with',
cb_phpstan_errors($after) > cb_phpstan_errors($before) => sprintf('errors grew from %d to %d', cb_phpstan_errors($before), cb_phpstan_errors($after)),
to_phpstan_count($after) === null => 'after/phpstan-after.txt has no PHPStan result line',
$before === null || to_phpstan_count($before) === null => 'no valid baseline to compare with',
to_phpstan_count($after) > to_phpstan_count($before) => sprintf('errors grew from %d to %d', to_phpstan_count($before), to_phpstan_count($after)),
default => null,
};

$before = cb_text($baselineDir . '/sniff-baseline.txt');
$after = cb_text($afterDir . '/sniff-after.txt');
$checks['sniffer'] = match (true) {
$after === null => 'missing after/sniff-after.txt',
cb_sniff_findings($after) === null => 'after/sniff-after.txt has no sniffer result',
$before === null || cb_sniff_findings($before) === null => 'no valid baseline to compare with',
cb_sniff_findings($after) > cb_sniff_findings($before) => sprintf('findings grew from %d to %d', cb_sniff_findings($before), cb_sniff_findings($after)),
to_sniff_count($after) === null => 'after/sniff-after.txt has no sniffer result',
$before === null || to_sniff_count($before) === null => 'no valid baseline to compare with',
to_sniff_count($after) > to_sniff_count($before) => sprintf('findings grew from %d to %d', to_sniff_count($before), to_sniff_count($after)),
default => null,
};

Expand All @@ -132,8 +92,8 @@ function cb_evaluate(string $stateDir): array
} elseif ($before === null) {
$checks['tests'] = 'no valid baseline to compare with';
} else {
$old = cb_codecept($before);
$new = cb_codecept($after);
$old = to_codecept_summary($before);
$new = to_codecept_summary($after);
$newFailures = array_values(array_diff($new['failing'], $old['failing']));
$checks['tests'] = match (true) {
$new['total'] === null => 'after/codecept-after.txt has no summary line',
Expand Down
50 changes: 46 additions & 4 deletions plugins/spryker-ai-dev-sdk/skills/spryker-upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ SPRYKER_PROJECT_ROOT=/path/to/project # skip discovery
SPRYKER_UPGRADE_STATE_DIR=/path/to/state # move baselines/reports (e.g. a CI cache directory)
```

## The twenty-one scripts
## The twenty-three scripts

| Script | Phase | What it answers |
|---|---|---|
| `check-added-comments.php` | 0 (`--record-base`), every lane, 7 | were explanatory comments or suppressions added since the upgrade began? |
| `check-baselines.php` | 0 (gate) | do all Phase 0 baselines exist, so Phase 1 may start? |
| `run-tools.php` | 0, 1.2, 3, 5, 5.5 | what did PHPStan, the sniffer, the evaluator and the test suite report, with the invocation Phase 0 pinned? |
| `compare-tool-runs.php` | 1.2, 3, 5, 5.5 | which PHPStan errors, sniffer violations, evaluator findings and failing tests are new against the baselines? |
| `backoffice-smoke.php` | 0 (`--baseline`), 4.9, 6.5 | does every Back Office navigation page and table data endpoint still answer? |
| `check-platform-alignment.php` | 0, 1.2 | will a lock resolved on this host install on the project's image? |
| `check-test-coverage.php` | 0, 0.5 | which customised modules would not notice if the upgrade broke them? |
Expand All @@ -53,7 +55,8 @@ SPRYKER_UPGRADE_STATE_DIR=/path/to/state # move baselines/reports (e.g. a CI

Phase 0 (`snapshot`) and Phase 6.1 (`diff`) also run `yves-integration-scan.php` from the sibling `yves-twig-integration` skill: which widgets the upgrade added that no template the project renders calls. Its findings are suggestions for the developer, not upgrade damage.

`bootstrap.php` is the shared library the scripts load. `upgrade-scripts.test.php` is the
`bootstrap.php` is the shared library the scripts load; `tool-output.php` parses the tool output
for `check-baselines.php`, `run-tools.php`, `compare-tool-runs.php` and `spryker-feature-install`. `upgrade-scripts.test.php` is the
maintainer test suite for the scripts (`php $UP/upgrade-scripts.test.php`); it is not part of an
upgrade run.

Expand Down Expand Up @@ -94,7 +97,8 @@ php $UP/check-plugin-usage.php || true # record pre-existing damage
php $UP/check-config-constants.php || true
php $UP/check-constant-overrides.php --snapshot
cp composer.lock .spryker-upgrade/state/composer.lock.before
# ... PHPStan, sniffer, evaluator and codecept runs tee'd into the state dir (see SKILL.md Phase 0)
php $UP/run-tools.php baseline phpstan sniffer evaluator
php $UP/run-tools.php baseline codecept-build tests --tests-args=--no-exit
php $UP/backoffice-smoke.php --url <zed base url> --baseline
cp $UP/storage-search-counts.php .spryker-upgrade/state/ # queues drained first
docker/sdk cli php .spryker-upgrade/state/storage-search-counts.php --snapshot before
Expand Down Expand Up @@ -170,7 +174,7 @@ php $UP/check-baselines.php --no-data # only when the environment cannot
Checks the state directory for `base-ref`, `codecept-baseline.txt`, `phpstan-baseline-run.txt`,
`sniff-baseline.txt`, `evaluator-baseline.txt`, `backoffice-smoke-baseline.json`,
`constant-overrides-baseline.json` and `storage-search-counts-before.json`, and that each holds a real
result of its tool: `2>&1 | tee` creates the file even when the command failed. The check is a
result of its tool: `run-tools.php` writes the file also when the tool did not run. The check is a
codecept summary line (`OK (`, `Tests:`, `FAILURES!`), a PHPStan `[OK]` or `Found N errors` line,
sniffer or evaluator output that is not only a tool error or usage message, a commit hash in
`base-ref`, a `results` list in the Back Office baseline, an `overrides` list in the constant-overrides
Expand All @@ -182,6 +186,44 @@ the same way when they exist. It names the command that produces each missing fi
a result. Every "after" check of the upgrade is compared against a "before" run; without it a new
failure cannot be told from a pre-existing one. Exit 0 all present with a result, 1 otherwise.

## run-tools.php — PHPStan, sniffer, evaluator and tests in one call

```bash
php $UP/run-tools.php baseline phpstan sniffer evaluator codecept-build tests --tests-args=--no-exit
php $UP/run-tools.php verify evaluator phpstan sniffer
php $UP/run-tools.php verify codecept-build tests --tests-args="-x Acceptance"
```

Runs each named tool in the container with the commands of the phases (inside `script` for a
pseudo-terminal, in its macOS or Linux form), writes the full output to `<tool>-<run>.txt` in the
state directory (`phpstan-baseline-run.txt` for the baseline) with `exit <code>` as the last line,
and prints one line per tool: exit code, result (error count, or tests passed/failed/skipped and the
failing suites) and log file. A tool whose output holds no result is reported as "did not run".
The baseline run pins the sniffer entry point (detected, or `--sniffer`), the `--env` variables and
the `--codecept-options` in `tool-invocation.json`; later runs use the pin (`--pin-dir` reads it from
another directory) and refuse values that differ from it. A project with several test configurations
gives `--codecept-options` once for each (`--codecept-options "-c codeception.api.yml"`): the tests
tool runs `codecept run` once per configuration into one log, and a configuration that did not start
makes it "did not run". `tool-runs-<run>.json` holds the commands, exit codes, the tests per suite
and the names of the failing tests; it is written after each tool, so a stopped run keeps the tools
that finished. Exit 0 every tool ran, 1 a tool did not run, 2 usage or no pin.

## compare-tool-runs.php — what is new against the baselines

```bash
php $UP/compare-tool-runs.php verify # every tool with a log of the run
php $UP/compare-tool-runs.php final tests --limit 20
php $UP/compare-tool-runs.php detect phpstan --baseline phase0
```

Compares the logs of a run with each tool's baseline: `*-post-tooling.txt` when it exists, else the
Phase 0 file (`--baseline phase0` forces the Phase 0 file; the post-tooling run is always compared
with it). Prints one verdict line per tool and at most `--limit` (default 10) new entries: PHPStan
errors and sniffer violations by file and message, evaluator violations, and tests that fail now
and did not fail in the baseline, per suite. The full lists go to `tool-comparison-<run>.json`.
Exit 0 no regression, 1 regression or a run without a result, 2 usage, a missing log or a missing
baseline.

## backoffice-smoke.php — crawl the whole Back Office

```bash
Expand Down
Loading
Loading