jdecool/scaleway-runtimepublic Fork
⑂ b1ce229
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

Merge pull request #2 from jdecool/feat/scaleway-doctorUnverified

Check Platform Requirements against a measured Function Runtime
Jérémy DECOOL committed 2026-11-22T14:24:25+01:00 Browse files
b1ce229 parents: 8b0e3ef 7df8b59
added .github/workflows/function-runtimes.yml +82 -0
new file mode 100644
@@ -0,0 +1,82 @@
1+name: Function Runtime Catalogue
2+
3+# Scaleway updates its Function Runtimes without notice: measure them again every week, and propose the changes.
4+on:
5+ schedule:
6+ - cron: '0 5 * * 1'
7+ workflow_dispatch:
8+
9+permissions:
10+ contents: write
11+ pull-requests: write
12+
13+concurrency:
14+ # The probe's namespace and function names are fixed: two runs would deploy over each other.
15+ group: function-runtime-catalogue
16+
17+jobs:
18+ measure:
19+ name: Measure the Function Runtimes
20+ runs-on: ubuntu-latest
21+ env:
22+ # A key limited to Serverless Functions, in a project dedicated to the probe.
23+ SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
24+ SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
25+ SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
26+ steps:
27+ - uses: actions/checkout@v7
28+
29+ - uses: shivammathur/setup-php@v2
30+ with:
31+ php-version: '8.5'
32+ coverage: none
33+
34+ - uses: ramsey/composer-install@v4
35+
36+ - uses: hashicorp/setup-terraform@v3
37+ with:
38+ terraform_wrapper: false
39+
40+ - name: Measure each Function Runtime with the probe
41+ run: |
42+ terraform -chdir=probe/terraform init -input=false
43+ for runtime in php84 php85; do
44+ terraform -chdir=probe/terraform apply -auto-approve -input=false -var "runtime=$runtime"
45+ endpoint=$(terraform -chdir=probe/terraform output -raw endpoint)
46+ fixture="tests/Fixtures/FunctionRuntimes/$runtime.json"
47+ # A replaced function keeps answering with the previous Function Runtime for a while.
48+ timeout 300 bash -c "until curl -sSf '$endpoint/?mode=runtime' -o '$fixture' && grep -q '\"phpVersion\": \"${runtime:3:1}\.${runtime:4:1}\.' '$fixture'; do sleep 5; done"
49+ done
50+
51+ - name: Destroy the probe
52+ if: always()
53+ run: terraform -chdir=probe/terraform destroy -auto-approve -input=false
54+
55+ - name: Regenerate the catalogue
56+ id: catalogue
57+ run: |
58+ changes=$(php probe/catalogue.php)
59+ echo "$changes"
60+ { echo 'changes<<EOF'; echo "$changes"; echo 'EOF'; } >> "$GITHUB_OUTPUT"
61+
62+ # Nothing but new measurement dates leaves the catalogue as it is.
63+ - name: Open or update the pull request
64+ if: steps.catalogue.outputs.changes != ''
65+ uses: peter-evans/create-pull-request@v7
66+ with:
67+ # Pull requests opened with the default token do not trigger the CI that checks the catalogue.
68+ token: ${{ secrets.CATALOGUE_PR_TOKEN || github.token }}
69+ branch: catalogue-update
70+ add-paths: |
71+ resources/function-runtimes.php
72+ tests/Fixtures/FunctionRuntimes
73+ commit-message: 'feat: update the Function Runtime Catalogue to the latest measurement'
74+ title: Update the Function Runtime Catalogue
75+ body: |
76+ The weekly measurement of the Function Runtimes found changes on Scaleway:
77+
78+ ```text
79+ ${{ steps.catalogue.outputs.changes }}
80+ ```
81+
82+ Merging does not release: users get the new catalogue with the next version of `jdecool/scaleway-runtime`.
new file mode 100644
@@ -0,0 +1,82 @@
1+name: Function Runtime Catalogue
2+
3+# Scaleway updates its Function Runtimes without notice: measure them again every week, and propose the changes.
4+on:
5+ schedule:
6+ - cron: '0 5 * * 1'
7+ workflow_dispatch:
8+
9+permissions:
10+ contents: write
11+ pull-requests: write
12+
13+concurrency:
14+ # The probe's namespace and function names are fixed: two runs would deploy over each other.
15+ group: function-runtime-catalogue
16+
17+jobs:
18+ measure:
19+ name: Measure the Function Runtimes
20+ runs-on: ubuntu-latest
21+ env:
22+ # A key limited to Serverless Functions, in a project dedicated to the probe.
23+ SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
24+ SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
25+ SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
26+ steps:
27+ - uses: actions/checkout@v7
28+
29+ - uses: shivammathur/setup-php@v2
30+ with:
31+ php-version: '8.5'
32+ coverage: none
33+
34+ - uses: ramsey/composer-install@v4
35+
36+ - uses: hashicorp/setup-terraform@v3
37+ with:
38+ terraform_wrapper: false
39+
40+ - name: Measure each Function Runtime with the probe
41+ run: |
42+ terraform -chdir=probe/terraform init -input=false
43+ for runtime in php84 php85; do
44+ terraform -chdir=probe/terraform apply -auto-approve -input=false -var "runtime=$runtime"
45+ endpoint=$(terraform -chdir=probe/terraform output -raw endpoint)
46+ fixture="tests/Fixtures/FunctionRuntimes/$runtime.json"
47+ # A replaced function keeps answering with the previous Function Runtime for a while.
48+ timeout 300 bash -c "until curl -sSf '$endpoint/?mode=runtime' -o '$fixture' && grep -q '\"phpVersion\": \"${runtime:3:1}\.${runtime:4:1}\.' '$fixture'; do sleep 5; done"
49+ done
50+
51+ - name: Destroy the probe
52+ if: always()
53+ run: terraform -chdir=probe/terraform destroy -auto-approve -input=false
54+
55+ - name: Regenerate the catalogue
56+ id: catalogue
57+ run: |
58+ changes=$(php probe/catalogue.php)
59+ echo "$changes"
60+ { echo 'changes<<EOF'; echo "$changes"; echo 'EOF'; } >> "$GITHUB_OUTPUT"
61+
62+ # Nothing but new measurement dates leaves the catalogue as it is.
63+ - name: Open or update the pull request
64+ if: steps.catalogue.outputs.changes != ''
65+ uses: peter-evans/create-pull-request@v7
66+ with:
67+ # Pull requests opened with the default token do not trigger the CI that checks the catalogue.
68+ token: ${{ secrets.CATALOGUE_PR_TOKEN || github.token }}
69+ branch: catalogue-update
70+ add-paths: |
71+ resources/function-runtimes.php
72+ tests/Fixtures/FunctionRuntimes
73+ commit-message: 'feat: update the Function Runtime Catalogue to the latest measurement'
74+ title: Update the Function Runtime Catalogue
75+ body: |
76+ The weekly measurement of the Function Runtimes found changes on Scaleway:
77+
78+ ```text
79+ ${{ steps.catalogue.outputs.changes }}
80+ ```
81+
82+ Merging does not release: users get the new catalogue with the next version of `jdecool/scaleway-runtime`.
modified .php-cs-fixer.dist.php +1 -1
@@ -6,7 +6,7 @@ $finder = (new PhpCsFixer\Finder())
66 ->in([__DIR__.'/src', __DIR__.'/tests', __DIR__.'/resources'])
77 // The stub users commit stays as short as possible.
88 ->notPath('handler.php')
9- ->append([__FILE__, __DIR__.'/bin/scaleway-init', __DIR__.'/bin/scaleway-package', __DIR__.'/bin/scaleway-serve']);
9+ ->append([__FILE__, __DIR__.'/bin/scaleway-doctor', __DIR__.'/bin/scaleway-init', __DIR__.'/bin/scaleway-package', __DIR__.'/bin/scaleway-serve']);
1010
1111 return (new PhpCsFixer\Config())
1212 ->setRiskyAllowed(true)
@@ -6,7 +6,7 @@ $finder = (new PhpCsFixer\Finder())
6 ->in([__DIR__.'/src', __DIR__.'/tests', __DIR__.'/resources'])6 ->in([__DIR__.'/src', __DIR__.'/tests', __DIR__.'/resources'])
7 // The stub users commit stays as short as possible.7 // The stub users commit stays as short as possible.
8 ->notPath('handler.php')8 ->notPath('handler.php')
9- ->append([__FILE__, __DIR__.'/bin/scaleway-init', __DIR__.'/bin/scaleway-package', __DIR__.'/bin/scaleway-serve']);9+ ->append([__FILE__, __DIR__.'/bin/scaleway-doctor', __DIR__.'/bin/scaleway-init', __DIR__.'/bin/scaleway-package', __DIR__.'/bin/scaleway-serve']);
10 10
11 return (new PhpCsFixer\Config())11 return (new PhpCsFixer\Config())
12 ->setRiskyAllowed(true)12 ->setRiskyAllowed(true)
modified GLOSSARY.md +12 -0
@@ -53,3 +53,15 @@ _Avoid_: Local runtime, dev server
5353 **Static File**:
5454 A file present under the application's web root when an HTTP Invocation asks for it, answered as it is, without building the Application.
5555 _Avoid_: Asset (the Symfony component), public file
56+
57+**Function Runtime**:
58+The PHP environment managed by Scaleway that a function declares, named like `php84`, with its PHP version and loaded extensions.
59+_Avoid_: Runtime (the Symfony component and this package), target, platform
60+
61+**Function Runtime Catalogue**:
62+The record, shipped with the package, of the PHP version and extensions measured on each supported Function Runtime, with the date of the measurement.
63+_Avoid_: Runtime catalogue, inventory
64+
65+**Platform Requirement**:
66+A `php` or `ext-*` constraint that the application or one of its production packages declares, as Composer defines it.
67+_Avoid_: Dependency, system requirement
@@ -53,3 +53,15 @@ _Avoid_: Local runtime, dev server
53 **Static File**:53 **Static File**:
54 A file present under the application's web root when an HTTP Invocation asks for it, answered as it is, without building the Application.54 A file present under the application's web root when an HTTP Invocation asks for it, answered as it is, without building the Application.
55 _Avoid_: Asset (the Symfony component), public file55 _Avoid_: Asset (the Symfony component), public file
56+
57+**Function Runtime**:
58+The PHP environment managed by Scaleway that a function declares, named like `php84`, with its PHP version and loaded extensions.
59+_Avoid_: Runtime (the Symfony component and this package), target, platform
60+
61+**Function Runtime Catalogue**:
62+The record, shipped with the package, of the PHP version and extensions measured on each supported Function Runtime, with the date of the measurement.
63+_Avoid_: Runtime catalogue, inventory
64+
65+**Platform Requirement**:
66+A `php` or `ext-*` constraint that the application or one of its production packages declares, as Composer defines it.
67+_Avoid_: Dependency, system requirement
modified README.md +55 -2
@@ -20,6 +20,7 @@ Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOS
2020 - [Supported Applications](#supported-applications)
2121 - [Static Files](#static-files)
2222 - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations)
23+- [Compatibility check](#compatibility-check)
2324 - [Packaging](#packaging)
2425 - [Deployment](#deployment)
2526 - [Logs](#logs)
@@ -410,12 +411,62 @@ Keep in mind that:
410411
411412 See [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md) for the alternatives considered.
412413
414+## Compatibility check
415+
416+```sh
417+vendor/bin/scaleway-doctor --runtime=php84
418+```
419+
420+A Platform Requirement (`php` or `ext-*`) the Function Runtime does not meet makes Scaleway's `composer install` fail at deploy time, without failing the deployment: every Invocation then answers a `500` (see [Composer at deploy time](#composer-at-deploy-time)).
421+`scaleway-doctor` checks, before you deploy, the Platform Requirements that install checks, against the Function Runtime the function declares, named by `--runtime` (`php84` or `php85`).
422+It never guesses it from your local PHP.
423+It reads `composer.json` and `composer.lock`, needs neither Scaleway credentials nor network access, and refuses a stale lock as [`scaleway-package`](#packaging) does.
424+
425+It checks what `composer install --no-dev` checks on Scaleway:
426+
427+- the root requirements the lock records, and those of every locked production package, development ones excluded;
428+- each one met by the Function Runtime, or by a `provide` or `replace` of the application or of a locked package;
429+- constraints evaluated by Composer's own engine, against the PHP and extension versions Composer would see on Scaleway.
430+
431+Each requirement is:
432+
433+- **satisfied**, when the measured version matches;
434+- **incompatible**, when the extension is not loaded, or the measured version of PHP or of the extension does not match;
435+- **unknown**, for the platform packages the catalogue does not measure, as `lib-icu` or `php-64bit`.
436+
437+Composer's own APIs (`composer`, `composer-plugin-api`, `composer-runtime-api`) are not checked: Scaleway installs with Composer 2.
438+
439+The report, on stderr, lists the incompatible and unknown requirements, with what declares them and what the Function Runtime provides:
440+
441+```text
442+INCOMPATIBLE ext-foo * required by acme/bar v2.1.0 php84: not loaded (measured 2026-11-22)
443+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions.
444+UNKNOWN lib-icu >=72 required by symfony/intl v8.0.3 not in the Function Runtime Catalogue
445+
446+48 satisfied, 1 unknown, 1 incompatible on php84 (measured 2026-11-22)
447+This covers declared Platform Requirements only, not whether the application runs.
448+```
449+
450+It exits with `0` when every requirement is satisfied or only unknowns remain, and with `1` on an incompatible requirement or an invalid input.
451+For an incompatible requirement, it names the other Function Runtimes that meet it, if any.
452+Otherwise, custom extensions or versions need [Serverless Containers](https://www.scaleway.com/en/serverless-containers/), which this package does not target.
453+
454+What each Function Runtime provides comes from the Function Runtime Catalogue shipped with the package, [resources/function-runtimes.php](resources/function-runtimes.php).
455+It holds measurements only, made on Scaleway with the [probe](probe), each a complete inventory: an extension it does not list is not loaded.
456+A measurement describes the Function Runtime on its date, which the report shows, not a guarantee that Scaleway keeps the same versions.
457+The measured PHP patch version is authoritative: if Scaleway has upgraded PHP since, update the package for a newer catalogue.
458+
459+The [Emulator](#local-development-with-the-emulator) runs on your local PHP, which may load extensions or versions the Function Runtime lacks: an application working locally can still fail to install on Scaleway, which is what this check catches.
460+A successful check covers declared Platform Requirements only: an extension used without being required is not checked, and calling a route after the deployment, as [Composer at deploy time](#composer-at-deploy-time) shows, remains the proof that it works.
461+
413462 ## Packaging
414463
415464 ```sh
416-vendor/bin/scaleway-package [function.zip]
465+vendor/bin/scaleway-package [--runtime=php84] [function.zip]
417466 ```
418467
468+With `--runtime`, it first runs the [compatibility check](#compatibility-check) against that Function Runtime, and refuses to build the zip on an incompatible Platform Requirement.
469+
419470 It zips your application as it is, `composer.json` and `composer.lock` included, but without `vendor/` nor `var/`: Scaleway runs `composer install --no-dev` from the shipped lock at deploy time, Composer scripts included, and replaces any shipped `vendor/` ([ADR 0008](docs/adr/0008-let-scaleway-install-the-dependencies.md)).
420471 Executable bits are kept, and symbolic links are followed: their target is zipped.
421472
@@ -590,6 +641,7 @@ Headers whose name holds an underscore (`X_Real_Ip`) are dropped, as nginx and A
590641 Scaleway runs `composer install --no-dev` in the function's directory when the zip holds a `composer.json` at its root, replacing any shipped `vendor/`.
591642 Every locked package must therefore be downloadable from Scaleway, and the function's environment variables are not available to Composer scripts.
592643 The lock must also install on the function's runtime: set `config.platform.php` in `composer.json` to its PHP version (`8.4` for `php84`, `8.5` for `php85`) so that `composer update` resolves for it.
644+`config.platform` only steers Composer's resolution: run the [compatibility check](#compatibility-check), or package with `--runtime`, to check the lock against what Scaleway provides.
593645 A failing install or script does not fail the deployment, and Scaleway serves the new code anyway, never the previous version ([measured](docs/probe-results.md#failed-scripts-and-installs)):
594646
595647 - a failing script runs once `vendor/` and its autoloader are complete, so the new code works, without what the script should have done (a warmed cache, generated files...);
@@ -620,13 +672,14 @@ composer cs-fix # applies the coding style
620672 CI runs `composer validate --strict` and `composer check` on PHP 8.4 and 8.5, each against Symfony 7.4 and 8.x, the whole Symfony stack being pinned through Flex's `SYMFONY_REQUIRE`.
621673 It also runs the [end-to-end scenarios](example/e2e/run.sh) of the [example application](example) through the Emulator, in dev and on its zip installed like Scaleway does ([e2e/deploy-locally.sh](example/e2e/deploy-locally.sh)).
622674 The example installs the runtime of the checkout with `composer link-runtime`, see its [README](example/README.md#run-it-locally).
675+A weekly workflow measures the Function Runtimes on Scaleway again, and opens a pull request when the catalogue changes, see [docs/probe-results.md](docs/probe-results.md#function-runtime-catalogue).
623676
624677 The repository holds:
625678
626679 - `src/`, `bin/`, `resources/`: the package;
627680 - `tests/`: PHPUnit tests, packaging included;
628681 - `example/`: a demo Symfony application requiring the package, with Terraform code to deploy it;
629-- `probe/`: a dependency-free function measuring the platform facts, and its [results](docs/probe-results.md);
682+- `probe/`: a dependency-free function measuring the platform facts, its [results](docs/probe-results.md), and the generator of the [Function Runtime Catalogue](docs/probe-results.md#function-runtime-catalogue);
630683 - `docs/`: the [ADRs](docs/adr).
631684
632685 ## License
@@ -20,6 +20,7 @@ Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOS
20 - [Supported Applications](#supported-applications)20 - [Supported Applications](#supported-applications)
21 - [Static Files](#static-files)21 - [Static Files](#static-files)
22 - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations)22 - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations)
23+- [Compatibility check](#compatibility-check)
23 - [Packaging](#packaging)24 - [Packaging](#packaging)
24 - [Deployment](#deployment)25 - [Deployment](#deployment)
25 - [Logs](#logs)26 - [Logs](#logs)
@@ -410,12 +411,62 @@ Keep in mind that:
410 411
411 See [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md) for the alternatives considered.412 See [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md) for the alternatives considered.
412 413
414+## Compatibility check
415+
416+```sh
417+vendor/bin/scaleway-doctor --runtime=php84
418+```
419+
420+A Platform Requirement (`php` or `ext-*`) the Function Runtime does not meet makes Scaleway's `composer install` fail at deploy time, without failing the deployment: every Invocation then answers a `500` (see [Composer at deploy time](#composer-at-deploy-time)).
421+`scaleway-doctor` checks, before you deploy, the Platform Requirements that install checks, against the Function Runtime the function declares, named by `--runtime` (`php84` or `php85`).
422+It never guesses it from your local PHP.
423+It reads `composer.json` and `composer.lock`, needs neither Scaleway credentials nor network access, and refuses a stale lock as [`scaleway-package`](#packaging) does.
424+
425+It checks what `composer install --no-dev` checks on Scaleway:
426+
427+- the root requirements the lock records, and those of every locked production package, development ones excluded;
428+- each one met by the Function Runtime, or by a `provide` or `replace` of the application or of a locked package;
429+- constraints evaluated by Composer's own engine, against the PHP and extension versions Composer would see on Scaleway.
430+
431+Each requirement is:
432+
433+- **satisfied**, when the measured version matches;
434+- **incompatible**, when the extension is not loaded, or the measured version of PHP or of the extension does not match;
435+- **unknown**, for the platform packages the catalogue does not measure, as `lib-icu` or `php-64bit`.
436+
437+Composer's own APIs (`composer`, `composer-plugin-api`, `composer-runtime-api`) are not checked: Scaleway installs with Composer 2.
438+
439+The report, on stderr, lists the incompatible and unknown requirements, with what declares them and what the Function Runtime provides:
440+
441+```text
442+INCOMPATIBLE ext-foo * required by acme/bar v2.1.0 php84: not loaded (measured 2026-11-22)
443+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions.
444+UNKNOWN lib-icu >=72 required by symfony/intl v8.0.3 not in the Function Runtime Catalogue
445+
446+48 satisfied, 1 unknown, 1 incompatible on php84 (measured 2026-11-22)
447+This covers declared Platform Requirements only, not whether the application runs.
448+```
449+
450+It exits with `0` when every requirement is satisfied or only unknowns remain, and with `1` on an incompatible requirement or an invalid input.
451+For an incompatible requirement, it names the other Function Runtimes that meet it, if any.
452+Otherwise, custom extensions or versions need [Serverless Containers](https://www.scaleway.com/en/serverless-containers/), which this package does not target.
453+
454+What each Function Runtime provides comes from the Function Runtime Catalogue shipped with the package, [resources/function-runtimes.php](resources/function-runtimes.php).
455+It holds measurements only, made on Scaleway with the [probe](probe), each a complete inventory: an extension it does not list is not loaded.
456+A measurement describes the Function Runtime on its date, which the report shows, not a guarantee that Scaleway keeps the same versions.
457+The measured PHP patch version is authoritative: if Scaleway has upgraded PHP since, update the package for a newer catalogue.
458+
459+The [Emulator](#local-development-with-the-emulator) runs on your local PHP, which may load extensions or versions the Function Runtime lacks: an application working locally can still fail to install on Scaleway, which is what this check catches.
460+A successful check covers declared Platform Requirements only: an extension used without being required is not checked, and calling a route after the deployment, as [Composer at deploy time](#composer-at-deploy-time) shows, remains the proof that it works.
461+
413 ## Packaging462 ## Packaging
414 463
415 ```sh464 ```sh
416-vendor/bin/scaleway-package [function.zip]465+vendor/bin/scaleway-package [--runtime=php84] [function.zip]
417 ```466 ```
418 467
468+With `--runtime`, it first runs the [compatibility check](#compatibility-check) against that Function Runtime, and refuses to build the zip on an incompatible Platform Requirement.
469+
419 It zips your application as it is, `composer.json` and `composer.lock` included, but without `vendor/` nor `var/`: Scaleway runs `composer install --no-dev` from the shipped lock at deploy time, Composer scripts included, and replaces any shipped `vendor/` ([ADR 0008](docs/adr/0008-let-scaleway-install-the-dependencies.md)).470 It zips your application as it is, `composer.json` and `composer.lock` included, but without `vendor/` nor `var/`: Scaleway runs `composer install --no-dev` from the shipped lock at deploy time, Composer scripts included, and replaces any shipped `vendor/` ([ADR 0008](docs/adr/0008-let-scaleway-install-the-dependencies.md)).
420 Executable bits are kept, and symbolic links are followed: their target is zipped.471 Executable bits are kept, and symbolic links are followed: their target is zipped.
421 472
@@ -590,6 +641,7 @@ Headers whose name holds an underscore (`X_Real_Ip`) are dropped, as nginx and A
590 Scaleway runs `composer install --no-dev` in the function's directory when the zip holds a `composer.json` at its root, replacing any shipped `vendor/`.641 Scaleway runs `composer install --no-dev` in the function's directory when the zip holds a `composer.json` at its root, replacing any shipped `vendor/`.
591 Every locked package must therefore be downloadable from Scaleway, and the function's environment variables are not available to Composer scripts.642 Every locked package must therefore be downloadable from Scaleway, and the function's environment variables are not available to Composer scripts.
592 The lock must also install on the function's runtime: set `config.platform.php` in `composer.json` to its PHP version (`8.4` for `php84`, `8.5` for `php85`) so that `composer update` resolves for it.643 The lock must also install on the function's runtime: set `config.platform.php` in `composer.json` to its PHP version (`8.4` for `php84`, `8.5` for `php85`) so that `composer update` resolves for it.
644+`config.platform` only steers Composer's resolution: run the [compatibility check](#compatibility-check), or package with `--runtime`, to check the lock against what Scaleway provides.
593 A failing install or script does not fail the deployment, and Scaleway serves the new code anyway, never the previous version ([measured](docs/probe-results.md#failed-scripts-and-installs)):645 A failing install or script does not fail the deployment, and Scaleway serves the new code anyway, never the previous version ([measured](docs/probe-results.md#failed-scripts-and-installs)):
594 646
595 - a failing script runs once `vendor/` and its autoloader are complete, so the new code works, without what the script should have done (a warmed cache, generated files...);647 - a failing script runs once `vendor/` and its autoloader are complete, so the new code works, without what the script should have done (a warmed cache, generated files...);
@@ -620,13 +672,14 @@ composer cs-fix # applies the coding style
620 CI runs `composer validate --strict` and `composer check` on PHP 8.4 and 8.5, each against Symfony 7.4 and 8.x, the whole Symfony stack being pinned through Flex's `SYMFONY_REQUIRE`.672 CI runs `composer validate --strict` and `composer check` on PHP 8.4 and 8.5, each against Symfony 7.4 and 8.x, the whole Symfony stack being pinned through Flex's `SYMFONY_REQUIRE`.
621 It also runs the [end-to-end scenarios](example/e2e/run.sh) of the [example application](example) through the Emulator, in dev and on its zip installed like Scaleway does ([e2e/deploy-locally.sh](example/e2e/deploy-locally.sh)).673 It also runs the [end-to-end scenarios](example/e2e/run.sh) of the [example application](example) through the Emulator, in dev and on its zip installed like Scaleway does ([e2e/deploy-locally.sh](example/e2e/deploy-locally.sh)).
622 The example installs the runtime of the checkout with `composer link-runtime`, see its [README](example/README.md#run-it-locally).674 The example installs the runtime of the checkout with `composer link-runtime`, see its [README](example/README.md#run-it-locally).
675+A weekly workflow measures the Function Runtimes on Scaleway again, and opens a pull request when the catalogue changes, see [docs/probe-results.md](docs/probe-results.md#function-runtime-catalogue).
623 676
624 The repository holds:677 The repository holds:
625 678
626 - `src/`, `bin/`, `resources/`: the package;679 - `src/`, `bin/`, `resources/`: the package;
627 - `tests/`: PHPUnit tests, packaging included;680 - `tests/`: PHPUnit tests, packaging included;
628 - `example/`: a demo Symfony application requiring the package, with Terraform code to deploy it;681 - `example/`: a demo Symfony application requiring the package, with Terraform code to deploy it;
629-- `probe/`: a dependency-free function measuring the platform facts, and its [results](docs/probe-results.md);682+- `probe/`: a dependency-free function measuring the platform facts, its [results](docs/probe-results.md), and the generator of the [Function Runtime Catalogue](docs/probe-results.md#function-runtime-catalogue);
630 - `docs/`: the [ADRs](docs/adr).683 - `docs/`: the [ADRs](docs/adr).
631 684
632 ## License685 ## License
added bin/scaleway-doctor +28 -0
new file mode 100755
@@ -0,0 +1,28 @@
1+#!/usr/bin/env php
2+<?php
3+
4+declare(strict_types=1);
5+
6+use Composer\InstalledVersions;
7+use JDecool\ScalewayRuntime\Doctor;
8+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
9+
10+require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';
11+
12+$usage = 'Usage: scaleway-doctor --runtime=<function-runtime> (php84 or php85, as declared on the function)';
13+$arguments = array_slice($argv ?? [], 1);
14+if ([] !== array_intersect($arguments, ['-h', '--help'])) {
15+ echo $usage, \PHP_EOL;
16+ exit(0);
17+}
18+if (1 !== count($arguments) || 1 !== preg_match('/^--runtime=(.+)$/', $arguments[0], $match)) {
19+ fwrite(\STDERR, $usage.\PHP_EOL);
20+ exit(1);
21+}
22+
23+try {
24+ exit(new Doctor(FunctionRuntimeCatalogue::load(), \STDERR)->check((string) realpath(InstalledVersions::getRootPackage()['install_path']), $match[1]) ? 0 : 1);
25+} catch (Throwable $e) {
26+ fwrite(\STDERR, 'Check failed: '.$e->getMessage().\PHP_EOL);
27+ exit(1);
28+}
new file mode 100755
@@ -0,0 +1,28 @@
1+#!/usr/bin/env php
2+<?php
3+
4+declare(strict_types=1);
5+
6+use Composer\InstalledVersions;
7+use JDecool\ScalewayRuntime\Doctor;
8+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
9+
10+require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';
11+
12+$usage = 'Usage: scaleway-doctor --runtime=<function-runtime> (php84 or php85, as declared on the function)';
13+$arguments = array_slice($argv ?? [], 1);
14+if ([] !== array_intersect($arguments, ['-h', '--help'])) {
15+ echo $usage, \PHP_EOL;
16+ exit(0);
17+}
18+if (1 !== count($arguments) || 1 !== preg_match('/^--runtime=(.+)$/', $arguments[0], $match)) {
19+ fwrite(\STDERR, $usage.\PHP_EOL);
20+ exit(1);
21+}
22+
23+try {
24+ exit(new Doctor(FunctionRuntimeCatalogue::load(), \STDERR)->check((string) realpath(InstalledVersions::getRootPackage()['install_path']), $match[1]) ? 0 : 1);
25+} catch (Throwable $e) {
26+ fwrite(\STDERR, 'Check failed: '.$e->getMessage().\PHP_EOL);
27+ exit(1);
28+}
modified bin/scaleway-package +17 -4
@@ -8,13 +8,26 @@ use JDecool\ScalewayRuntime\Packager;
88
99 require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';
1010
11-if (in_array($argv[1] ?? null, ['-h', '--help'], true)) {
12- echo 'Usage: scaleway-package [<zip-file>] (default: function.zip)', \PHP_EOL;
13- exit(0);
11+$usage = 'Usage: scaleway-package [--runtime=<function-runtime>] [<zip-file>] (default: function.zip; --runtime checks the Platform Requirements against php84 or php85 first)';
12+$functionRuntime = null;
13+$zipFiles = [];
14+foreach (array_slice($argv ?? [], 1) as $argument) {
15+ if (in_array($argument, ['-h', '--help'], true)) {
16+ echo $usage, \PHP_EOL;
17+ exit(0);
18+ }
19+ if (1 === preg_match('/^--runtime=(.+)$/', $argument, $match)) {
20+ $functionRuntime = $match[1];
21+ } elseif (str_starts_with($argument, '-') || [] !== $zipFiles) {
22+ fwrite(\STDERR, $usage.\PHP_EOL);
23+ exit(1);
24+ } else {
25+ $zipFiles[] = $argument;
26+ }
1427 }
1528
1629 try {
17- (new Packager((string) realpath(InstalledVersions::getRootPackage()['install_path']), \STDERR))->package($argv[1] ?? 'function.zip');
30+ (new Packager((string) realpath(InstalledVersions::getRootPackage()['install_path']), \STDERR))->package($zipFiles[0] ?? 'function.zip', $functionRuntime);
1831 } catch (Throwable $e) {
1932 fwrite(\STDERR, 'Packaging failed: '.$e->getMessage().\PHP_EOL);
2033 exit(1);
@@ -8,13 +8,26 @@ use JDecool\ScalewayRuntime\Packager;
8 8
9 require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';9 require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php';
10 10
11-if (in_array($argv[1] ?? null, ['-h', '--help'], true)) {11+$usage = 'Usage: scaleway-package [--runtime=<function-runtime>] [<zip-file>] (default: function.zip; --runtime checks the Platform Requirements against php84 or php85 first)';
12- echo 'Usage: scaleway-package [<zip-file>] (default: function.zip)', \PHP_EOL;12+$functionRuntime = null;
13- exit(0);13+$zipFiles = [];
14+foreach (array_slice($argv ?? [], 1) as $argument) {
15+ if (in_array($argument, ['-h', '--help'], true)) {
16+ echo $usage, \PHP_EOL;
17+ exit(0);
18+ }
19+ if (1 === preg_match('/^--runtime=(.+)$/', $argument, $match)) {
20+ $functionRuntime = $match[1];
21+ } elseif (str_starts_with($argument, '-') || [] !== $zipFiles) {
22+ fwrite(\STDERR, $usage.\PHP_EOL);
23+ exit(1);
24+ } else {
25+ $zipFiles[] = $argument;
26+ }
14 }27 }
15 28
16 try {29 try {
17- (new Packager((string) realpath(InstalledVersions::getRootPackage()['install_path']), \STDERR))->package($argv[1] ?? 'function.zip');30+ (new Packager((string) realpath(InstalledVersions::getRootPackage()['install_path']), \STDERR))->package($zipFiles[0] ?? 'function.zip', $functionRuntime);
18 } catch (Throwable $e) {31 } catch (Throwable $e) {
19 fwrite(\STDERR, 'Packaging failed: '.$e->getMessage().\PHP_EOL);32 fwrite(\STDERR, 'Packaging failed: '.$e->getMessage().\PHP_EOL);
20 exit(1);33 exit(1);
modified composer.json +2 -0
@@ -17,6 +17,7 @@
1717 ],
1818 "require": {
1919 "php": ">=8.4",
20+ "composer/semver": "^3.4",
2021 "riverline/multipart-parser": "^2.3",
2122 "symfony/http-foundation": "^7.4 || ^8.0",
2223 "symfony/http-kernel": "^7.4 || ^8.0",
@@ -53,6 +54,7 @@
5354 }
5455 },
5556 "bin": [
57+ "bin/scaleway-doctor",
5658 "bin/scaleway-init",
5759 "bin/scaleway-package",
5860 "bin/scaleway-serve"
@@ -17,6 +17,7 @@
17 ],17 ],
18 "require": {18 "require": {
19 "php": ">=8.4",19 "php": ">=8.4",
20+ "composer/semver": "^3.4",
20 "riverline/multipart-parser": "^2.3",21 "riverline/multipart-parser": "^2.3",
21 "symfony/http-foundation": "^7.4 || ^8.0",22 "symfony/http-foundation": "^7.4 || ^8.0",
22 "symfony/http-kernel": "^7.4 || ^8.0",23 "symfony/http-kernel": "^7.4 || ^8.0",
@@ -53,6 +54,7 @@
53 }54 }
54 },55 },
55 "bin": [56 "bin": [
57+ "bin/scaleway-doctor",
56 "bin/scaleway-init",58 "bin/scaleway-init",
57 "bin/scaleway-package",59 "bin/scaleway-package",
58 "bin/scaleway-serve"60 "bin/scaleway-serve"
added docs/adr/0013-check-platform-requirements-against-an-explicit-function-runtime.md +30 -0
new file mode 100644
@@ -0,0 +1,30 @@
1+# Check declared Platform Requirements against an explicit Function Runtime
2+
3+A Platform Requirement the Function Runtime does not meet makes Scaleway's `composer install` fail at deploy time without failing the deployment: the function is `ready` without any `vendor/`, and every Invocation answers a `500` ([probe results](../probe-results.md#failed-scripts-and-installs)).
4+We therefore check, before packaging, the Platform Requirements that install checks, against a catalogue of what each Function Runtime was measured to provide.
5+`scaleway-doctor --runtime=<name>` runs the check alone, and `scaleway-package --runtime=<name>` runs it before writing the zip.
6+
7+The check reads the lock as Scaleway's `composer install --no-dev` does: the requirements of the locked `packages` and the root ones the lock records under `platform`, met by the Function Runtime or by a `provide` or `replace`.
8+Constraints are evaluated with `composer/semver`, Composer's own engine, and the catalogue names and versions PHP and its extensions as Composer's `PlatformRepository` does, down to its fallback versions, so that the outcome predicts what the install on Scaleway will do.
9+
10+The catalogue holds measurements only, each a complete inventory made by the probe on Scaleway, dated, and generated from probe output committed in the repository.
11+A weekly workflow measures each Function Runtime again and opens a pull request when something changed; publishing it stays a maintainer's decision.
12+
13+## Considered Options
14+
15+- Inferring the Function Runtime from the local PHP: rejected, the local PHP says nothing about what the function declares.
16+- Comparing with the local PHP environment: rejected, local availability never establishes what Scaleway provides, and the Emulator running on the local PHP is precisely what hides such an incompatibility.
17+- Catalogue entries derived from Scaleway's documentation: rejected, it lists neither every extension nor their versions, and every supported Function Runtime can be measured.
18+- Downloading the catalogue at run time: rejected, the check must work offline and without Scaleway credentials, and a release keeps the check reproducible.
19+- Reimplementing Composer's constraints: rejected, `^`, `~`, `||` and stabilities are easy to get subtly wrong, and `composer/semver` is small and dependency-free.
20+- Documenting `config.platform.php` instead of checking: rejected, it only states Composer's resolution assumptions, not what Scaleway provides.
21+
22+## Consequences
23+
24+- A confirmed incompatibility blocks packaging, as the deployment would serve nothing but `500`s; an unknown only warns, as blocking on missing evidence would refuse working applications.
25+- Requirements the probe does not measure, `lib-*` and `php-64bit` among them, stay unknown; Composer's own APIs are ignored, Scaleway installing with Composer 2.
26+- The measured PHP patch version is authoritative: a requirement on a newer patch is refused until the catalogue records the upgrade.
27+- A measurement describes the Function Runtime on its date, not a guarantee: an extension Scaleway removes after it is caught by `scaleway-check` after the deployment, and by the next weekly measurement.
28+- `composer/semver` ships with every application, although only the check uses it.
29+- A successful check covers declared Platform Requirements only, not whether the application runs.
30+- Installing custom native extensions and a Serverless Containers target remain separate work, which the check points to.
new file mode 100644
@@ -0,0 +1,30 @@
1+# Check declared Platform Requirements against an explicit Function Runtime
2+
3+A Platform Requirement the Function Runtime does not meet makes Scaleway's `composer install` fail at deploy time without failing the deployment: the function is `ready` without any `vendor/`, and every Invocation answers a `500` ([probe results](../probe-results.md#failed-scripts-and-installs)).
4+We therefore check, before packaging, the Platform Requirements that install checks, against a catalogue of what each Function Runtime was measured to provide.
5+`scaleway-doctor --runtime=<name>` runs the check alone, and `scaleway-package --runtime=<name>` runs it before writing the zip.
6+
7+The check reads the lock as Scaleway's `composer install --no-dev` does: the requirements of the locked `packages` and the root ones the lock records under `platform`, met by the Function Runtime or by a `provide` or `replace`.
8+Constraints are evaluated with `composer/semver`, Composer's own engine, and the catalogue names and versions PHP and its extensions as Composer's `PlatformRepository` does, down to its fallback versions, so that the outcome predicts what the install on Scaleway will do.
9+
10+The catalogue holds measurements only, each a complete inventory made by the probe on Scaleway, dated, and generated from probe output committed in the repository.
11+A weekly workflow measures each Function Runtime again and opens a pull request when something changed; publishing it stays a maintainer's decision.
12+
13+## Considered Options
14+
15+- Inferring the Function Runtime from the local PHP: rejected, the local PHP says nothing about what the function declares.
16+- Comparing with the local PHP environment: rejected, local availability never establishes what Scaleway provides, and the Emulator running on the local PHP is precisely what hides such an incompatibility.
17+- Catalogue entries derived from Scaleway's documentation: rejected, it lists neither every extension nor their versions, and every supported Function Runtime can be measured.
18+- Downloading the catalogue at run time: rejected, the check must work offline and without Scaleway credentials, and a release keeps the check reproducible.
19+- Reimplementing Composer's constraints: rejected, `^`, `~`, `||` and stabilities are easy to get subtly wrong, and `composer/semver` is small and dependency-free.
20+- Documenting `config.platform.php` instead of checking: rejected, it only states Composer's resolution assumptions, not what Scaleway provides.
21+
22+## Consequences
23+
24+- A confirmed incompatibility blocks packaging, as the deployment would serve nothing but `500`s; an unknown only warns, as blocking on missing evidence would refuse working applications.
25+- Requirements the probe does not measure, `lib-*` and `php-64bit` among them, stay unknown; Composer's own APIs are ignored, Scaleway installing with Composer 2.
26+- The measured PHP patch version is authoritative: a requirement on a newer patch is refused until the catalogue records the upgrade.
27+- A measurement describes the Function Runtime on its date, not a guarantee: an extension Scaleway removes after it is caught by `scaleway-check` after the deployment, and by the next weekly measurement.
28+- `composer/semver` ships with every application, although only the check uses it.
29+- A successful check covers declared Platform Requirements only, not whether the application runs.
30+- Installing custom native extensions and a Serverless Containers target remain separate work, which the check points to.
modified docs/probe-results.md +33 -0
@@ -45,6 +45,39 @@ Measured on 2026-11-14 on `php85` with a scratch function requiring `psr/log`, w
4545 - Nothing tells a failed deployment from a successful one: the status, `error_message`, `build_message` and `runtime_message` (empty) are the same, and Composer's output reaches neither Cockpit (no entry under the function's `resource_id`, nor anywhere in the project's logs) nor any `scw function` command.
4646 - The new instance logs `Function is not ready to serve requests yet...` and `Function is now ready to serve requests!` as usual, and the previous one `Forked function has terminated` about 40 seconds later.
4747
48+## Function Runtime Catalogue
49+
50+Measured on 2026-11-22 with the probe's `runtime` mode on `php84` and `php85`, region `fr-par`, the probe deployed with its Terraform for each, then destroyed.
51+
52+| Function Runtime | PHP | Loaded extensions | Without `phpversion()` |
53+| --- | --- | --- | --- |
54+| `php84` | 8.4.28 | 123 | none |
55+| `php85` | 8.5.13 | 120 | none |
56+
57+- `php84` loads `geospatial`, `memcache`, `parle`, `php_trie` and `Stomp`, which `php85` does not; `php85` loads `lexbor` and `uri`, new in PHP 8.5.
58+- Bundled extensions report the PHP version; `dom` reports `20031129`, and `mysqlnd` reports `mysqlnd 8.4.28`, which Composer cannot parse and sees as version `0`, as the catalogue records it.
59+- Scaleway upgraded PHP on both Function Runtimes within eight days, without notice: `php84` from 8.4.27 to 8.4.28, `php85` from 8.5.12 to 8.5.13.
60+
61+The raw outputs are [tests/Fixtures/FunctionRuntimes](../tests/Fixtures/FunctionRuntimes), from which [probe/catalogue.php](../probe/catalogue.php) generates [resources/function-runtimes.php](../resources/function-runtimes.php), naming and versioning PHP and its extensions as Composer's `PlatformRepository` does.
62+A test fails when the catalogue is not the one the fixtures generate.
63+The list of Function Runtimes follows [Scaleway's runtime reference](https://www.scaleway.com/en/docs/serverless-functions/reference-content/functions-runtimes/), restricted to those the package's `php` requirement allows.
64+
65+### Updating the catalogue
66+
67+The [Function Runtime Catalogue workflow](../.github/workflows/function-runtimes.yml) runs every Monday, and by hand from the Actions tab before each release:
68+
69+1. it deploys the probe on each Function Runtime, saves its `?mode=runtime` output as the fixture, and destroys the probe whatever the outcome;
70+2. it regenerates the catalogue, and does nothing more when only the measurement dates changed;
71+3. otherwise it opens a pull request from the `catalogue-update` branch, or force-pushes the open one, listing the changes.
72+
73+It needs the repository secrets `SCW_ACCESS_KEY`, `SCW_SECRET_KEY` and `SCW_DEFAULT_PROJECT_ID`, for an API key limited to Serverless Functions in a project dedicated to the probe.
74+Pull requests opened with the default token do not trigger the CI: set a `CATALOGUE_PR_TOKEN` secret, a fine-grained token with the contents and pull requests permissions, for the CI to check them.
75+A failed deployment or query fails the job, without retry.
76+Merging does not release: users get the new catalogue with the next version.
77+
78+By hand, deploy the probe as its [README](../probe/README.md) says, save `curl -sS "$PROBE_URL/?mode=runtime"` as `tests/Fixtures/FunctionRuntimes/<runtime>.json` for each Function Runtime, and run `php probe/catalogue.php`, which prints what changed.
79+A new Function Runtime gets its own fixture; the script names it after the PHP version measured, and refuses two fixtures of the same one.
80+
4881 ## HTTP Event
4982
5083 Keys: `resource`, `path`, `httpMethod`, `headers`, `multiValueHeaders` (null), `queryStringParameters`, `multiValueQueryStringParameters` (null), `pathParameters` (null), `stageVariables`, `requestContext` (with `httpMethod`), `body`, `isBase64Encoded`.
@@ -45,6 +45,39 @@ Measured on 2026-11-14 on `php85` with a scratch function requiring `psr/log`, w
45 - Nothing tells a failed deployment from a successful one: the status, `error_message`, `build_message` and `runtime_message` (empty) are the same, and Composer's output reaches neither Cockpit (no entry under the function's `resource_id`, nor anywhere in the project's logs) nor any `scw function` command.45 - Nothing tells a failed deployment from a successful one: the status, `error_message`, `build_message` and `runtime_message` (empty) are the same, and Composer's output reaches neither Cockpit (no entry under the function's `resource_id`, nor anywhere in the project's logs) nor any `scw function` command.
46 - The new instance logs `Function is not ready to serve requests yet...` and `Function is now ready to serve requests!` as usual, and the previous one `Forked function has terminated` about 40 seconds later.46 - The new instance logs `Function is not ready to serve requests yet...` and `Function is now ready to serve requests!` as usual, and the previous one `Forked function has terminated` about 40 seconds later.
47 47
48+## Function Runtime Catalogue
49+
50+Measured on 2026-11-22 with the probe's `runtime` mode on `php84` and `php85`, region `fr-par`, the probe deployed with its Terraform for each, then destroyed.
51+
52+| Function Runtime | PHP | Loaded extensions | Without `phpversion()` |
53+| --- | --- | --- | --- |
54+| `php84` | 8.4.28 | 123 | none |
55+| `php85` | 8.5.13 | 120 | none |
56+
57+- `php84` loads `geospatial`, `memcache`, `parle`, `php_trie` and `Stomp`, which `php85` does not; `php85` loads `lexbor` and `uri`, new in PHP 8.5.
58+- Bundled extensions report the PHP version; `dom` reports `20031129`, and `mysqlnd` reports `mysqlnd 8.4.28`, which Composer cannot parse and sees as version `0`, as the catalogue records it.
59+- Scaleway upgraded PHP on both Function Runtimes within eight days, without notice: `php84` from 8.4.27 to 8.4.28, `php85` from 8.5.12 to 8.5.13.
60+
61+The raw outputs are [tests/Fixtures/FunctionRuntimes](../tests/Fixtures/FunctionRuntimes), from which [probe/catalogue.php](../probe/catalogue.php) generates [resources/function-runtimes.php](../resources/function-runtimes.php), naming and versioning PHP and its extensions as Composer's `PlatformRepository` does.
62+A test fails when the catalogue is not the one the fixtures generate.
63+The list of Function Runtimes follows [Scaleway's runtime reference](https://www.scaleway.com/en/docs/serverless-functions/reference-content/functions-runtimes/), restricted to those the package's `php` requirement allows.
64+
65+### Updating the catalogue
66+
67+The [Function Runtime Catalogue workflow](../.github/workflows/function-runtimes.yml) runs every Monday, and by hand from the Actions tab before each release:
68+
69+1. it deploys the probe on each Function Runtime, saves its `?mode=runtime` output as the fixture, and destroys the probe whatever the outcome;
70+2. it regenerates the catalogue, and does nothing more when only the measurement dates changed;
71+3. otherwise it opens a pull request from the `catalogue-update` branch, or force-pushes the open one, listing the changes.
72+
73+It needs the repository secrets `SCW_ACCESS_KEY`, `SCW_SECRET_KEY` and `SCW_DEFAULT_PROJECT_ID`, for an API key limited to Serverless Functions in a project dedicated to the probe.
74+Pull requests opened with the default token do not trigger the CI: set a `CATALOGUE_PR_TOKEN` secret, a fine-grained token with the contents and pull requests permissions, for the CI to check them.
75+A failed deployment or query fails the job, without retry.
76+Merging does not release: users get the new catalogue with the next version.
77+
78+By hand, deploy the probe as its [README](../probe/README.md) says, save `curl -sS "$PROBE_URL/?mode=runtime"` as `tests/Fixtures/FunctionRuntimes/<runtime>.json` for each Function Runtime, and run `php probe/catalogue.php`, which prints what changed.
79+A new Function Runtime gets its own fixture; the script names it after the PHP version measured, and refuses two fixtures of the same one.
80+
48 ## HTTP Event81 ## HTTP Event
49 82
50 Keys: `resource`, `path`, `httpMethod`, `headers`, `multiValueHeaders` (null), `queryStringParameters`, `multiValueQueryStringParameters` (null), `pathParameters` (null), `stageVariables`, `requestContext` (with `httpMethod`), `body`, `isBase64Encoded`.83 Keys: `resource`, `path`, `httpMethod`, `headers`, `multiValueHeaders` (null), `queryStringParameters`, `multiValueQueryStringParameters` (null), `pathParameters` (null), `stageVariables`, `requestContext` (with `httpMethod`), `body`, `isBase64Encoded`.
modified phpstan.neon.dist +1 -0
@@ -8,6 +8,7 @@ parameters:
88 - src
99 - tests
1010 - resources
11+ - bin/scaleway-doctor
1112 - bin/scaleway-init
1213 - bin/scaleway-package
1314 - bin/scaleway-serve
@@ -8,6 +8,7 @@ parameters:
8 - src8 - src
9 - tests9 - tests
10 - resources10 - resources
11+ - bin/scaleway-doctor
11 - bin/scaleway-init12 - bin/scaleway-init
12 - bin/scaleway-package13 - bin/scaleway-package
13 - bin/scaleway-serve14 - bin/scaleway-serve
modified probe/README.md +6 -0
@@ -72,6 +72,12 @@ curl -sS -I "$PROBE_URL/" > 08-head.txt
7272 sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson
7373 ```
7474
75+To update the [Function Runtime Catalogue](../docs/probe-results.md#function-runtime-catalogue), save the PHP version and the extensions of each Function Runtime, dated, in the fixtures it is generated from:
76+
77+```sh
78+curl -sS "$PROBE_URL/?mode=runtime" > ../tests/Fixtures/FunctionRuntimes/php85.json
79+```
80+
7581 10. Export the function's logs of the last hour, CRON lines included, from Cockpit's Grafana or with the Loki query of the [README](../README.md#logs).
7682
7783 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields.
@@ -72,6 +72,12 @@ curl -sS -I "$PROBE_URL/" > 08-head.txt
72 sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson72 sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson
73 ```73 ```
74 74
75+To update the [Function Runtime Catalogue](../docs/probe-results.md#function-runtime-catalogue), save the PHP version and the extensions of each Function Runtime, dated, in the fixtures it is generated from:
76+
77+```sh
78+curl -sS "$PROBE_URL/?mode=runtime" > ../tests/Fixtures/FunctionRuntimes/php85.json
79+```
80+
75 10. Export the function's logs of the last hour, CRON lines included, from Cockpit's Grafana or with the Loki query of the [README](../README.md#logs).81 10. Export the function's logs of the last hour, CRON lines included, from Cockpit's Grafana or with the Loki query of the [README](../README.md#logs).
76 82
77 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields.83 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields.
added probe/catalogue.php +21 -0
new file mode 100644
@@ -0,0 +1,21 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+/*
6+ * Regenerates resources/function-runtimes.php from the probe outputs in tests/Fixtures/FunctionRuntimes,
7+ * saved with the probe's "runtime" mode, and prints what changed: see docs/probe-results.md#function-runtime-catalogue.
8+ */
9+
10+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
11+
12+require __DIR__.'/../vendor/autoload.php';
13+
14+$old = FunctionRuntimeCatalogue::load();
15+$files = glob(__DIR__.'/../tests/Fixtures/FunctionRuntimes/*.json') ?: [];
16+file_put_contents(FunctionRuntimeCatalogue::FILE, FunctionRuntimeCatalogue::generate(array_map(static fn (string $file): string => (string) file_get_contents($file), $files)));
17+
18+// Prints what changed, nothing when only the measurement dates did: the freshness workflow opens a pull request on output.
19+foreach (FunctionRuntimeCatalogue::load()->changes($old) as $change) {
20+ echo $change, \PHP_EOL;
21+}
new file mode 100644
@@ -0,0 +1,21 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+/*
6+ * Regenerates resources/function-runtimes.php from the probe outputs in tests/Fixtures/FunctionRuntimes,
7+ * saved with the probe's "runtime" mode, and prints what changed: see docs/probe-results.md#function-runtime-catalogue.
8+ */
9+
10+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
11+
12+require __DIR__.'/../vendor/autoload.php';
13+
14+$old = FunctionRuntimeCatalogue::load();
15+$files = glob(__DIR__.'/../tests/Fixtures/FunctionRuntimes/*.json') ?: [];
16+file_put_contents(FunctionRuntimeCatalogue::FILE, FunctionRuntimeCatalogue::generate(array_map(static fn (string $file): string => (string) file_get_contents($file), $files)));
17+
18+// Prints what changed, nothing when only the measurement dates did: the freshness workflow opens a pull request on output.
19+foreach (FunctionRuntimeCatalogue::load()->changes($old) as $change) {
20+ echo $change, \PHP_EOL;
21+}
modified probe/function/handler.php +9 -0
@@ -112,6 +112,15 @@ function handle($event, $context)
112112 case 'exception':
113113 throw new RuntimeException('probe: exception escaping the handler');
114114
115+ case 'runtime':
116+ // Only what the Function Runtime Catalogue is generated from, so that its output can be committed as it is.
117+ return json_response([
118+ 'measuredAt' => gmdate('Y-m-d\\TH:i:s\\Z'),
119+ 'phpVersion' => PHP_VERSION,
120+ // false when an extension reports no version: Platform Requirements on its version stay unknown.
121+ 'extensions' => array_combine($extensions = get_loaded_extensions(), array_map(static fn (string $name) => phpversion($name), $extensions)),
122+ ]);
123+
115124 case 'history':
116125 return ['statusCode' => 200, 'headers' => ['Content-Type' => 'application/x-ndjson'], 'body' => (string) @file_get_contents(PROBE_HISTORY)];
117126
@@ -112,6 +112,15 @@ function handle($event, $context)
112 case 'exception':112 case 'exception':
113 throw new RuntimeException('probe: exception escaping the handler');113 throw new RuntimeException('probe: exception escaping the handler');
114 114
115+ case 'runtime':
116+ // Only what the Function Runtime Catalogue is generated from, so that its output can be committed as it is.
117+ return json_response([
118+ 'measuredAt' => gmdate('Y-m-d\\TH:i:s\\Z'),
119+ 'phpVersion' => PHP_VERSION,
120+ // false when an extension reports no version: Platform Requirements on its version stay unknown.
121+ 'extensions' => array_combine($extensions = get_loaded_extensions(), array_map(static fn (string $name) => phpversion($name), $extensions)),
122+ ]);
123+
115 case 'history':124 case 'history':
116 return ['statusCode' => 200, 'headers' => ['Content-Type' => 'application/x-ndjson'], 'body' => (string) @file_get_contents(PROBE_HISTORY)];125 return ['statusCode' => 200, 'headers' => ['Content-Type' => 'application/x-ndjson'], 'body' => (string) @file_get_contents(PROBE_HISTORY)];
117 126
added resources/function-runtimes.php +259 -0
new file mode 100644
@@ -0,0 +1,259 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+// Generated by probe/catalogue.php from tests/Fixtures/FunctionRuntimes: do not edit by hand.
6+
7+return [
8+ 'php84' => [
9+ 'measuredAt' => '2026-11-22T11:47:13Z',
10+ 'php' => '8.4.28',
11+ 'extensions' => [
12+ 'ext-amqp' => '2.2.0',
13+ 'ext-apcu' => '5.1.28',
14+ 'ext-ast' => '1.1.4',
15+ 'ext-bcmath' => '8.4.28',
16+ 'ext-bz2' => '8.4.28',
17+ 'ext-calendar' => '8.4.28',
18+ 'ext-csv' => '0.3.0',
19+ 'ext-ctype' => '8.4.28',
20+ 'ext-curl' => '8.4.28',
21+ 'ext-date' => '8.4.28',
22+ 'ext-dba' => '8.4.28',
23+ 'ext-decimal' => '2.0.1',
24+ 'ext-dom' => '20031129',
25+ 'ext-ds' => '2.0.0',
26+ 'ext-enchant' => '8.4.28',
27+ 'ext-ev' => '1.3.1',
28+ 'ext-event' => '3.2.0',
29+ 'ext-excimer' => '1.2.6',
30+ 'ext-exif' => '8.4.28',
31+ 'ext-ffi' => '8.4.28',
32+ 'ext-fileinfo' => '8.4.28',
33+ 'ext-filter' => '8.4.28',
34+ 'ext-gd' => '8.4.28',
35+ 'ext-geospatial' => '0.3.5',
36+ 'ext-gettext' => '8.4.28',
37+ 'ext-gmp' => '8.4.28',
38+ 'ext-gnupg' => '1.5.4',
39+ 'ext-grpc' => '1.85.0',
40+ 'ext-hash' => '8.4.28',
41+ 'ext-iconv' => '8.4.28',
42+ 'ext-igbinary' => '3.2.17RC1',
43+ 'ext-imap' => '1.0.3',
44+ 'ext-inotify' => '3.0.1',
45+ 'ext-intl' => '8.4.28',
46+ 'ext-ion' => '0.2.1',
47+ 'ext-json' => '8.4.28',
48+ 'ext-json_post' => '1.1.0',
49+ 'ext-ldap' => '8.4.28',
50+ 'ext-libsmbclient' => '1.2.0dev',
51+ 'ext-libxml' => '8.4.28',
52+ 'ext-luasandbox' => '4.1.3',
53+ 'ext-lz4' => '0.4.3',
54+ 'ext-lzf' => '1.7.0',
55+ 'ext-mailparse' => '3.2.0',
56+ 'ext-maxminddb' => '1.15.0',
57+ 'ext-mbstring' => '8.4.28',
58+ 'ext-memcache' => '8.2',
59+ 'ext-memcached' => '3.4.0',
60+ 'ext-mongodb' => '2.5.8',
61+ 'ext-msgpack' => '3.0.1',
62+ 'ext-mysqli' => '8.4.28',
63+ 'ext-mysqlnd' => '0',
64+ 'ext-oauth' => '2.0.10',
65+ 'ext-oci8' => '3.4.1',
66+ 'ext-odbc' => '8.4.28',
67+ 'ext-openssl' => '8.4.28',
68+ 'ext-parle' => '0.8.5',
69+ 'ext-pcntl' => '8.4.28',
70+ 'ext-pcov' => '1.0.12',
71+ 'ext-pcre' => '8.4.28',
72+ 'ext-pdo' => '8.4.28',
73+ 'ext-pdo_dblib' => '8.4.28',
74+ 'ext-pdo_firebird' => '8.4.28',
75+ 'ext-pdo_mysql' => '8.4.28',
76+ 'ext-pdo_oci' => '1.2.0',
77+ 'ext-pdo_odbc' => '8.4.28',
78+ 'ext-pdo_pgsql' => '8.4.28',
79+ 'ext-pdo_sqlite' => '8.4.28',
80+ 'ext-pdo_sqlsrv' => '5.13.3',
81+ 'ext-pgsql' => '8.4.28',
82+ 'ext-phar' => '8.4.28',
83+ 'ext-php_trie' => '0.1.2',
84+ 'ext-posix' => '8.4.28',
85+ 'ext-protobuf' => '5.36.2',
86+ 'ext-pspell' => '1.0.1',
87+ 'ext-random' => '8.4.28',
88+ 'ext-rdkafka' => '6.0.5',
89+ 'ext-readline' => '8.4.28',
90+ 'ext-redis' => '6.3.0',
91+ 'ext-reflection' => '8.4.28',
92+ 'ext-session' => '8.4.28',
93+ 'ext-shmop' => '8.4.28',
94+ 'ext-simdjson' => '4.0.0',
95+ 'ext-simplexml' => '8.4.28',
96+ 'ext-smbclient' => '1.2.0dev',
97+ 'ext-snappy' => '0.2.1',
98+ 'ext-snmp' => '8.4.28',
99+ 'ext-soap' => '8.4.28',
100+ 'ext-sockets' => '8.4.28',
101+ 'ext-sodium' => '8.4.28',
102+ 'ext-solr' => '2.9.3',
103+ 'ext-spl' => '8.4.28',
104+ 'ext-spx' => '0.4.21',
105+ 'ext-sqlite3' => '8.4.28',
106+ 'ext-sqlsrv' => '5.13.3',
107+ 'ext-ssh2' => '1.6.1',
108+ 'ext-stomp' => '2.0.3',
109+ 'ext-sysvmsg' => '8.4.28',
110+ 'ext-sysvsem' => '8.4.28',
111+ 'ext-sysvshm' => '8.4.28',
112+ 'ext-tidy' => '8.4.28',
113+ 'ext-timezonedb' => '2026.6',
114+ 'ext-tokenizer' => '8.4.28',
115+ 'ext-uploadprogress' => '2.0.2',
116+ 'ext-uuid' => '1.3.0',
117+ 'ext-vips' => '1.0.13',
118+ 'ext-xdiff' => '2.2.0',
119+ 'ext-xlswriter' => '3.0.0',
120+ 'ext-xml' => '8.4.28',
121+ 'ext-xmldiff' => '1.1.6',
122+ 'ext-xmlreader' => '8.4.28',
123+ 'ext-xmlrpc' => '1.0.0RC3',
124+ 'ext-xmlwriter' => '8.4.28',
125+ 'ext-xsl' => '8.4.28',
126+ 'ext-yac' => '3.0.2',
127+ 'ext-yaml' => '2.3.0',
128+ 'ext-zend-opcache' => '8.4.28',
129+ 'ext-zephir_parser' => '2.11.0',
130+ 'ext-zip' => '1.22.8',
131+ 'ext-zlib' => '8.4.28',
132+ 'ext-zstd' => '0.18.0',
133+ ],
134+ ],
135+ 'php85' => [
136+ 'measuredAt' => '2026-11-22T11:44:54Z',
137+ 'php' => '8.5.13',
138+ 'extensions' => [
139+ 'ext-amqp' => '2.2.0',
140+ 'ext-apcu' => '5.1.28',
141+ 'ext-ast' => '1.1.4',
142+ 'ext-bcmath' => '8.5.13',
143+ 'ext-bz2' => '8.5.13',
144+ 'ext-calendar' => '8.5.13',
145+ 'ext-csv' => '0.3.0',
146+ 'ext-ctype' => '8.5.13',
147+ 'ext-curl' => '8.5.13',
148+ 'ext-date' => '8.5.13',
149+ 'ext-dba' => '8.5.13',
150+ 'ext-decimal' => '2.0.1',
151+ 'ext-dom' => '20031129',
152+ 'ext-ds' => '2.0.0',
153+ 'ext-enchant' => '8.5.13',
154+ 'ext-ev' => '1.3.1',
155+ 'ext-event' => '3.2.0',
156+ 'ext-excimer' => '1.2.6',
157+ 'ext-exif' => '8.5.13',
158+ 'ext-ffi' => '8.5.13',
159+ 'ext-fileinfo' => '8.5.13',
160+ 'ext-filter' => '8.5.13',
161+ 'ext-gd' => '8.5.13',
162+ 'ext-gettext' => '8.5.13',
163+ 'ext-gmp' => '8.5.13',
164+ 'ext-gnupg' => '1.5.4',
165+ 'ext-grpc' => '1.85.0',
166+ 'ext-hash' => '8.5.13',
167+ 'ext-iconv' => '8.5.13',
168+ 'ext-igbinary' => '3.2.17RC1',
169+ 'ext-imap' => '1.0.3',
170+ 'ext-inotify' => '3.0.1',
171+ 'ext-intl' => '8.5.13',
172+ 'ext-ion' => '0.2.1',
173+ 'ext-json' => '8.5.13',
174+ 'ext-json_post' => '1.1.0',
175+ 'ext-ldap' => '8.5.13',
176+ 'ext-lexbor' => '8.5.13',
177+ 'ext-libsmbclient' => '1.2.0dev',
178+ 'ext-libxml' => '8.5.13',
179+ 'ext-luasandbox' => '4.1.3',
180+ 'ext-lz4' => '0.4.3',
181+ 'ext-lzf' => '1.7.0',
182+ 'ext-mailparse' => '3.2.0',
183+ 'ext-maxminddb' => '1.15.0',
184+ 'ext-mbstring' => '8.5.13',
185+ 'ext-memcached' => '3.4.0',
186+ 'ext-mongodb' => '2.5.8',
187+ 'ext-msgpack' => '3.0.1',
188+ 'ext-mysqli' => '8.5.13',
189+ 'ext-mysqlnd' => '0',
190+ 'ext-oauth' => '2.0.10',
191+ 'ext-oci8' => '3.4.1',
192+ 'ext-odbc' => '8.5.13',
193+ 'ext-openssl' => '8.5.13',
194+ 'ext-pcntl' => '8.5.13',
195+ 'ext-pcov' => '1.0.12',
196+ 'ext-pcre' => '8.5.13',
197+ 'ext-pdo' => '8.5.13',
198+ 'ext-pdo_dblib' => '8.5.13',
199+ 'ext-pdo_firebird' => '8.5.13',
200+ 'ext-pdo_mysql' => '8.5.13',
201+ 'ext-pdo_oci' => '1.2.0',
202+ 'ext-pdo_odbc' => '8.5.13',
203+ 'ext-pdo_pgsql' => '8.5.13',
204+ 'ext-pdo_sqlite' => '8.5.13',
205+ 'ext-pdo_sqlsrv' => '5.13.3',
206+ 'ext-pgsql' => '8.5.13',
207+ 'ext-phar' => '8.5.13',
208+ 'ext-posix' => '8.5.13',
209+ 'ext-protobuf' => '5.36.2',
210+ 'ext-pspell' => '1.0.1',
211+ 'ext-random' => '8.5.13',
212+ 'ext-rdkafka' => '6.0.5',
213+ 'ext-readline' => '8.5.13',
214+ 'ext-redis' => '6.3.0',
215+ 'ext-reflection' => '8.5.13',
216+ 'ext-session' => '8.5.13',
217+ 'ext-shmop' => '8.5.13',
218+ 'ext-simdjson' => '4.0.0',
219+ 'ext-simplexml' => '8.5.13',
220+ 'ext-smbclient' => '1.2.0dev',
221+ 'ext-snappy' => '0.2.1',
222+ 'ext-snmp' => '8.5.13',
223+ 'ext-soap' => '8.5.13',
224+ 'ext-sockets' => '8.5.13',
225+ 'ext-sodium' => '8.5.13',
226+ 'ext-solr' => '2.9.3',
227+ 'ext-spl' => '8.5.13',
228+ 'ext-spx' => '0.4.21',
229+ 'ext-sqlite3' => '8.5.13',
230+ 'ext-sqlsrv' => '5.13.3',
231+ 'ext-ssh2' => '1.6.1',
232+ 'ext-sysvmsg' => '8.5.13',
233+ 'ext-sysvsem' => '8.5.13',
234+ 'ext-sysvshm' => '8.5.13',
235+ 'ext-tidy' => '8.5.13',
236+ 'ext-timezonedb' => '2026.6',
237+ 'ext-tokenizer' => '8.5.13',
238+ 'ext-uploadprogress' => '2.0.2',
239+ 'ext-uri' => '8.5.13',
240+ 'ext-uuid' => '1.3.0',
241+ 'ext-vips' => '1.0.13',
242+ 'ext-xdiff' => '2.2.0',
243+ 'ext-xlswriter' => '3.0.0',
244+ 'ext-xml' => '8.5.13',
245+ 'ext-xmldiff' => '1.1.6',
246+ 'ext-xmlreader' => '8.5.13',
247+ 'ext-xmlrpc' => '1.0.0RC3',
248+ 'ext-xmlwriter' => '8.5.13',
249+ 'ext-xsl' => '8.5.13',
250+ 'ext-yac' => '3.0.2',
251+ 'ext-yaml' => '2.3.0',
252+ 'ext-zend-opcache' => '8.5.13',
253+ 'ext-zephir_parser' => '2.11.0',
254+ 'ext-zip' => '1.22.8',
255+ 'ext-zlib' => '8.5.13',
256+ 'ext-zstd' => '0.18.0',
257+ ],
258+ ],
259+];
new file mode 100644
@@ -0,0 +1,259 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+// Generated by probe/catalogue.php from tests/Fixtures/FunctionRuntimes: do not edit by hand.
6+
7+return [
8+ 'php84' => [
9+ 'measuredAt' => '2026-11-22T11:47:13Z',
10+ 'php' => '8.4.28',
11+ 'extensions' => [
12+ 'ext-amqp' => '2.2.0',
13+ 'ext-apcu' => '5.1.28',
14+ 'ext-ast' => '1.1.4',
15+ 'ext-bcmath' => '8.4.28',
16+ 'ext-bz2' => '8.4.28',
17+ 'ext-calendar' => '8.4.28',
18+ 'ext-csv' => '0.3.0',
19+ 'ext-ctype' => '8.4.28',
20+ 'ext-curl' => '8.4.28',
21+ 'ext-date' => '8.4.28',
22+ 'ext-dba' => '8.4.28',
23+ 'ext-decimal' => '2.0.1',
24+ 'ext-dom' => '20031129',
25+ 'ext-ds' => '2.0.0',
26+ 'ext-enchant' => '8.4.28',
27+ 'ext-ev' => '1.3.1',
28+ 'ext-event' => '3.2.0',
29+ 'ext-excimer' => '1.2.6',
30+ 'ext-exif' => '8.4.28',
31+ 'ext-ffi' => '8.4.28',
32+ 'ext-fileinfo' => '8.4.28',
33+ 'ext-filter' => '8.4.28',
34+ 'ext-gd' => '8.4.28',
35+ 'ext-geospatial' => '0.3.5',
36+ 'ext-gettext' => '8.4.28',
37+ 'ext-gmp' => '8.4.28',
38+ 'ext-gnupg' => '1.5.4',
39+ 'ext-grpc' => '1.85.0',
40+ 'ext-hash' => '8.4.28',
41+ 'ext-iconv' => '8.4.28',
42+ 'ext-igbinary' => '3.2.17RC1',
43+ 'ext-imap' => '1.0.3',
44+ 'ext-inotify' => '3.0.1',
45+ 'ext-intl' => '8.4.28',
46+ 'ext-ion' => '0.2.1',
47+ 'ext-json' => '8.4.28',
48+ 'ext-json_post' => '1.1.0',
49+ 'ext-ldap' => '8.4.28',
50+ 'ext-libsmbclient' => '1.2.0dev',
51+ 'ext-libxml' => '8.4.28',
52+ 'ext-luasandbox' => '4.1.3',
53+ 'ext-lz4' => '0.4.3',
54+ 'ext-lzf' => '1.7.0',
55+ 'ext-mailparse' => '3.2.0',
56+ 'ext-maxminddb' => '1.15.0',
57+ 'ext-mbstring' => '8.4.28',
58+ 'ext-memcache' => '8.2',
59+ 'ext-memcached' => '3.4.0',
60+ 'ext-mongodb' => '2.5.8',
61+ 'ext-msgpack' => '3.0.1',
62+ 'ext-mysqli' => '8.4.28',
63+ 'ext-mysqlnd' => '0',
64+ 'ext-oauth' => '2.0.10',
65+ 'ext-oci8' => '3.4.1',
66+ 'ext-odbc' => '8.4.28',
67+ 'ext-openssl' => '8.4.28',
68+ 'ext-parle' => '0.8.5',
69+ 'ext-pcntl' => '8.4.28',
70+ 'ext-pcov' => '1.0.12',
71+ 'ext-pcre' => '8.4.28',
72+ 'ext-pdo' => '8.4.28',
73+ 'ext-pdo_dblib' => '8.4.28',
74+ 'ext-pdo_firebird' => '8.4.28',
75+ 'ext-pdo_mysql' => '8.4.28',
76+ 'ext-pdo_oci' => '1.2.0',
77+ 'ext-pdo_odbc' => '8.4.28',
78+ 'ext-pdo_pgsql' => '8.4.28',
79+ 'ext-pdo_sqlite' => '8.4.28',
80+ 'ext-pdo_sqlsrv' => '5.13.3',
81+ 'ext-pgsql' => '8.4.28',
82+ 'ext-phar' => '8.4.28',
83+ 'ext-php_trie' => '0.1.2',
84+ 'ext-posix' => '8.4.28',
85+ 'ext-protobuf' => '5.36.2',
86+ 'ext-pspell' => '1.0.1',
87+ 'ext-random' => '8.4.28',
88+ 'ext-rdkafka' => '6.0.5',
89+ 'ext-readline' => '8.4.28',
90+ 'ext-redis' => '6.3.0',
91+ 'ext-reflection' => '8.4.28',
92+ 'ext-session' => '8.4.28',
93+ 'ext-shmop' => '8.4.28',
94+ 'ext-simdjson' => '4.0.0',
95+ 'ext-simplexml' => '8.4.28',
96+ 'ext-smbclient' => '1.2.0dev',
97+ 'ext-snappy' => '0.2.1',
98+ 'ext-snmp' => '8.4.28',
99+ 'ext-soap' => '8.4.28',
100+ 'ext-sockets' => '8.4.28',
101+ 'ext-sodium' => '8.4.28',
102+ 'ext-solr' => '2.9.3',
103+ 'ext-spl' => '8.4.28',
104+ 'ext-spx' => '0.4.21',
105+ 'ext-sqlite3' => '8.4.28',
106+ 'ext-sqlsrv' => '5.13.3',
107+ 'ext-ssh2' => '1.6.1',
108+ 'ext-stomp' => '2.0.3',
109+ 'ext-sysvmsg' => '8.4.28',
110+ 'ext-sysvsem' => '8.4.28',
111+ 'ext-sysvshm' => '8.4.28',
112+ 'ext-tidy' => '8.4.28',
113+ 'ext-timezonedb' => '2026.6',
114+ 'ext-tokenizer' => '8.4.28',
115+ 'ext-uploadprogress' => '2.0.2',
116+ 'ext-uuid' => '1.3.0',
117+ 'ext-vips' => '1.0.13',
118+ 'ext-xdiff' => '2.2.0',
119+ 'ext-xlswriter' => '3.0.0',
120+ 'ext-xml' => '8.4.28',
121+ 'ext-xmldiff' => '1.1.6',
122+ 'ext-xmlreader' => '8.4.28',
123+ 'ext-xmlrpc' => '1.0.0RC3',
124+ 'ext-xmlwriter' => '8.4.28',
125+ 'ext-xsl' => '8.4.28',
126+ 'ext-yac' => '3.0.2',
127+ 'ext-yaml' => '2.3.0',
128+ 'ext-zend-opcache' => '8.4.28',
129+ 'ext-zephir_parser' => '2.11.0',
130+ 'ext-zip' => '1.22.8',
131+ 'ext-zlib' => '8.4.28',
132+ 'ext-zstd' => '0.18.0',
133+ ],
134+ ],
135+ 'php85' => [
136+ 'measuredAt' => '2026-11-22T11:44:54Z',
137+ 'php' => '8.5.13',
138+ 'extensions' => [
139+ 'ext-amqp' => '2.2.0',
140+ 'ext-apcu' => '5.1.28',
141+ 'ext-ast' => '1.1.4',
142+ 'ext-bcmath' => '8.5.13',
143+ 'ext-bz2' => '8.5.13',
144+ 'ext-calendar' => '8.5.13',
145+ 'ext-csv' => '0.3.0',
146+ 'ext-ctype' => '8.5.13',
147+ 'ext-curl' => '8.5.13',
148+ 'ext-date' => '8.5.13',
149+ 'ext-dba' => '8.5.13',
150+ 'ext-decimal' => '2.0.1',
151+ 'ext-dom' => '20031129',
152+ 'ext-ds' => '2.0.0',
153+ 'ext-enchant' => '8.5.13',
154+ 'ext-ev' => '1.3.1',
155+ 'ext-event' => '3.2.0',
156+ 'ext-excimer' => '1.2.6',
157+ 'ext-exif' => '8.5.13',
158+ 'ext-ffi' => '8.5.13',
159+ 'ext-fileinfo' => '8.5.13',
160+ 'ext-filter' => '8.5.13',
161+ 'ext-gd' => '8.5.13',
162+ 'ext-gettext' => '8.5.13',
163+ 'ext-gmp' => '8.5.13',
164+ 'ext-gnupg' => '1.5.4',
165+ 'ext-grpc' => '1.85.0',
166+ 'ext-hash' => '8.5.13',
167+ 'ext-iconv' => '8.5.13',
168+ 'ext-igbinary' => '3.2.17RC1',
169+ 'ext-imap' => '1.0.3',
170+ 'ext-inotify' => '3.0.1',
171+ 'ext-intl' => '8.5.13',
172+ 'ext-ion' => '0.2.1',
173+ 'ext-json' => '8.5.13',
174+ 'ext-json_post' => '1.1.0',
175+ 'ext-ldap' => '8.5.13',
176+ 'ext-lexbor' => '8.5.13',
177+ 'ext-libsmbclient' => '1.2.0dev',
178+ 'ext-libxml' => '8.5.13',
179+ 'ext-luasandbox' => '4.1.3',
180+ 'ext-lz4' => '0.4.3',
181+ 'ext-lzf' => '1.7.0',
182+ 'ext-mailparse' => '3.2.0',
183+ 'ext-maxminddb' => '1.15.0',
184+ 'ext-mbstring' => '8.5.13',
185+ 'ext-memcached' => '3.4.0',
186+ 'ext-mongodb' => '2.5.8',
187+ 'ext-msgpack' => '3.0.1',
188+ 'ext-mysqli' => '8.5.13',
189+ 'ext-mysqlnd' => '0',
190+ 'ext-oauth' => '2.0.10',
191+ 'ext-oci8' => '3.4.1',
192+ 'ext-odbc' => '8.5.13',
193+ 'ext-openssl' => '8.5.13',
194+ 'ext-pcntl' => '8.5.13',
195+ 'ext-pcov' => '1.0.12',
196+ 'ext-pcre' => '8.5.13',
197+ 'ext-pdo' => '8.5.13',
198+ 'ext-pdo_dblib' => '8.5.13',
199+ 'ext-pdo_firebird' => '8.5.13',
200+ 'ext-pdo_mysql' => '8.5.13',
201+ 'ext-pdo_oci' => '1.2.0',
202+ 'ext-pdo_odbc' => '8.5.13',
203+ 'ext-pdo_pgsql' => '8.5.13',
204+ 'ext-pdo_sqlite' => '8.5.13',
205+ 'ext-pdo_sqlsrv' => '5.13.3',
206+ 'ext-pgsql' => '8.5.13',
207+ 'ext-phar' => '8.5.13',
208+ 'ext-posix' => '8.5.13',
209+ 'ext-protobuf' => '5.36.2',
210+ 'ext-pspell' => '1.0.1',
211+ 'ext-random' => '8.5.13',
212+ 'ext-rdkafka' => '6.0.5',
213+ 'ext-readline' => '8.5.13',
214+ 'ext-redis' => '6.3.0',
215+ 'ext-reflection' => '8.5.13',
216+ 'ext-session' => '8.5.13',
217+ 'ext-shmop' => '8.5.13',
218+ 'ext-simdjson' => '4.0.0',
219+ 'ext-simplexml' => '8.5.13',
220+ 'ext-smbclient' => '1.2.0dev',
221+ 'ext-snappy' => '0.2.1',
222+ 'ext-snmp' => '8.5.13',
223+ 'ext-soap' => '8.5.13',
224+ 'ext-sockets' => '8.5.13',
225+ 'ext-sodium' => '8.5.13',
226+ 'ext-solr' => '2.9.3',
227+ 'ext-spl' => '8.5.13',
228+ 'ext-spx' => '0.4.21',
229+ 'ext-sqlite3' => '8.5.13',
230+ 'ext-sqlsrv' => '5.13.3',
231+ 'ext-ssh2' => '1.6.1',
232+ 'ext-sysvmsg' => '8.5.13',
233+ 'ext-sysvsem' => '8.5.13',
234+ 'ext-sysvshm' => '8.5.13',
235+ 'ext-tidy' => '8.5.13',
236+ 'ext-timezonedb' => '2026.6',
237+ 'ext-tokenizer' => '8.5.13',
238+ 'ext-uploadprogress' => '2.0.2',
239+ 'ext-uri' => '8.5.13',
240+ 'ext-uuid' => '1.3.0',
241+ 'ext-vips' => '1.0.13',
242+ 'ext-xdiff' => '2.2.0',
243+ 'ext-xlswriter' => '3.0.0',
244+ 'ext-xml' => '8.5.13',
245+ 'ext-xmldiff' => '1.1.6',
246+ 'ext-xmlreader' => '8.5.13',
247+ 'ext-xmlrpc' => '1.0.0RC3',
248+ 'ext-xmlwriter' => '8.5.13',
249+ 'ext-xsl' => '8.5.13',
250+ 'ext-yac' => '3.0.2',
251+ 'ext-yaml' => '2.3.0',
252+ 'ext-zend-opcache' => '8.5.13',
253+ 'ext-zephir_parser' => '2.11.0',
254+ 'ext-zip' => '1.22.8',
255+ 'ext-zlib' => '8.5.13',
256+ 'ext-zstd' => '0.18.0',
257+ ],
258+ ],
259+];
added src/Doctor.php +247 -0
new file mode 100644
@@ -0,0 +1,247 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime;
6+
7+use Composer\Semver\Constraint\Constraint;
8+use Composer\Semver\Constraint\ConstraintInterface;
9+use Composer\Semver\Constraint\MatchAllConstraint;
10+use Composer\Semver\VersionParser;
11+
12+/**
13+ * Checks the Platform Requirements Scaleway's "composer install --no-dev" checks against a Function Runtime of the
14+ * catalogue: an unmet one fails that install silently, and every Invocation then answers a 500.
15+ * See docs/adr/0013-check-platform-requirements-against-an-explicit-function-runtime.md.
16+ *
17+ * @phpstan-import-type FunctionRuntime from FunctionRuntimeCatalogue
18+ */
19+final readonly class Doctor
20+{
21+ // Composer's PlatformRepository::PLATFORM_PACKAGE_REGEX: any other name is a package, not a Platform Requirement.
22+ private const string PLATFORM_PACKAGE = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD';
23+
24+ // Scaleway installs with Composer 2, whose APIs every package of the ecosystem accepts.
25+ private const array IGNORED = ['composer', 'composer-plugin-api', 'composer-runtime-api'];
26+
27+ private const string SATISFIED = 'SATISFIED';
28+ private const string INCOMPATIBLE = 'INCOMPATIBLE';
29+ private const string UNKNOWN = 'UNKNOWN';
30+
31+ private VersionParser $parser;
32+
33+ /**
34+ * @param resource $log
35+ */
36+ public function __construct(
37+ private FunctionRuntimeCatalogue $catalogue,
38+ private mixed $log,
39+ ) {
40+ $this->parser = new VersionParser();
41+ }
42+
43+ /**
44+ * Writes the report to the log.
45+ *
46+ * @return bool false when a Platform Requirement is incompatible
47+ */
48+ public function check(string $appDir, string $functionRuntime): bool
49+ {
50+ $target = $this->catalogue->get($functionRuntime);
51+ foreach (['composer.json' => 'run "composer init"', 'composer.lock' => 'run "composer update" and commit it, Scaleway installs the dependencies from it'] as $file => $hint) {
52+ if (!is_file($appDir.'/'.$file)) {
53+ throw new \RuntimeException(\sprintf('"%s" is missing in "%s": %s.', $file, $appDir, $hint));
54+ }
55+ }
56+ $composerJson = (string) file_get_contents($appDir.'/composer.json');
57+ $composerLock = (string) file_get_contents($appDir.'/composer.lock');
58+ Packager::checkLock($composerJson, $composerLock);
59+ /** @var array<mixed> $composer checked by checkLock() */
60+ $composer = json_decode($composerJson, true);
61+ /** @var array<mixed> $lock checked by checkLock() */
62+ $lock = json_decode($composerLock, true);
63+
64+ $packages = array_values(array_filter(\is_array($lock['packages'] ?? null) ? $lock['packages'] : [], \is_array(...)));
65+ $providers = $this->providers($composer, $packages);
66+
67+ $counts = [self::SATISFIED => 0, self::UNKNOWN => 0, self::INCOMPATIBLE => 0];
68+ $rows = [];
69+ foreach ($this->requirements($lock, $packages) as [$declarer, $name, $constraint]) {
70+ $required = $this->constraint($constraint, $declarer);
71+ $outcome = $this->outcome($name, $required, $target, $providers);
72+ ++$counts[$outcome];
73+ if (self::SATISFIED === $outcome) {
74+ continue;
75+ }
76+ $rows[] = [$outcome, $name.' '.$constraint, 'required by '.$declarer, $this->targetValue($functionRuntime, $target, $name, $outcome)];
77+ if (self::INCOMPATIBLE === $outcome) {
78+ $rows[] = ['', $this->suggestion($functionRuntime, $name, $required, $providers)];
79+ }
80+ }
81+
82+ $this->report($rows);
83+ $this->write(\sprintf('%d satisfied, %d unknown, %d incompatible on %s (measured %s)', $counts[self::SATISFIED], $counts[self::UNKNOWN], $counts[self::INCOMPATIBLE], $functionRuntime, self::date($target)));
84+ $this->write('This covers declared Platform Requirements only, not whether the application runs.');
85+
86+ return 0 === $counts[self::INCOMPATIBLE];
87+ }
88+
89+ /**
90+ * What Composer checks when installing a lock without its dev packages: the root requirements it recorded under
91+ * "platform", and the requirements of every package it installs.
92+ *
93+ * @param array<mixed> $lock
94+ * @param list<array<mixed>> $packages
95+ *
96+ * @return list<array{string, string, string}> declarer, lowercase name and constraint of each Platform Requirement
97+ */
98+ private function requirements(array $lock, array $packages): array
99+ {
100+ $requirements = [];
101+ $add = static function (string $declarer, mixed $links) use (&$requirements): void {
102+ foreach (\is_array($links) ? $links : [] as $name => $constraint) {
103+ $name = strtolower((string) $name);
104+ if (\is_string($constraint) && 1 === preg_match(self::PLATFORM_PACKAGE, $name) && !\in_array($name, self::IGNORED, true)) {
105+ $requirements[] = [$declarer, $name, $constraint];
106+ }
107+ }
108+ };
109+ $add('the application', $lock['platform'] ?? null);
110+ foreach ($packages as $package) {
111+ $add(self::name($package), $package['require'] ?? null);
112+ }
113+
114+ return $requirements;
115+ }
116+
117+ /**
118+ * @param array<mixed> $composer
119+ * @param list<array<mixed>> $packages
120+ *
121+ * @return array<string, list<ConstraintInterface>> what the application and its packages provide or replace, by name
122+ */
123+ private function providers(array $composer, array $packages): array
124+ {
125+ $providers = [];
126+ foreach ([['the application', $composer], ...array_map(static fn (array $package): array => [self::name($package), $package], $packages)] as [$declarer, $package]) {
127+ foreach (['provide', 'replace'] as $section) {
128+ foreach (\is_array($package[$section] ?? null) ? $package[$section] : [] as $name => $constraint) {
129+ if (!\is_string($constraint)) {
130+ continue;
131+ }
132+ // The root package has no version of its own here: its "self.version" links match any.
133+ $providers[strtolower((string) $name)][] = 'self.version' === $constraint
134+ ? (\is_string($package['version'] ?? null) ? $this->constraint('=='.$package['version'], $declarer) : new MatchAllConstraint())
135+ : $this->constraint($constraint, $declarer);
136+ }
137+ }
138+ }
139+
140+ return $providers;
141+ }
142+
143+ /**
144+ * @param FunctionRuntime $target
145+ * @param array<string, list<ConstraintInterface>> $providers
146+ */
147+ private function outcome(string $name, ConstraintInterface $required, array $target, array $providers): string
148+ {
149+ foreach ($providers[$name] ?? [] as $provided) {
150+ if ($required->matches($provided)) {
151+ return self::SATISFIED;
152+ }
153+ }
154+ $version = match (true) {
155+ 'php' === $name => $target['php'],
156+ str_starts_with($name, 'ext-') => $target['extensions'][$name] ?? null,
157+ // lib-*, php-64bit and the like are not measured.
158+ default => false,
159+ };
160+ if (false === $version) {
161+ return self::UNKNOWN;
162+ }
163+
164+ return null !== $version && $required->matches(new Constraint('==', $this->parser->normalize($version))) ? self::SATISFIED : self::INCOMPATIBLE;
165+ }
166+
167+ /**
168+ * @param FunctionRuntime $target
169+ */
170+ private function targetValue(string $functionRuntime, array $target, string $name, string $outcome): string
171+ {
172+ if (self::UNKNOWN === $outcome) {
173+ return 'not in the Function Runtime Catalogue';
174+ }
175+ $version = 'php' === $name ? $target['php'] : ($target['extensions'][$name] ?? null);
176+
177+ return \sprintf('%s: %s (measured %s)', $functionRuntime, $version ?? 'not loaded', self::date($target));
178+ }
179+
180+ /**
181+ * @param array<string, list<ConstraintInterface>> $providers
182+ */
183+ private function suggestion(string $functionRuntime, string $name, ConstraintInterface $required, array $providers): string
184+ {
185+ $others = array_keys(array_filter(
186+ $this->catalogue->functionRuntimes,
187+ fn (array $other, string $otherName): bool => $otherName !== $functionRuntime && self::SATISFIED === $this->outcome($name, $required, $other, $providers),
188+ \ARRAY_FILTER_USE_BOTH,
189+ ));
190+ $suggestion = [] === $others
191+ ? 'No measured Function Runtime meets it: use Serverless Containers for custom extensions or versions.'
192+ : \sprintf('%s %s it: deploy on %s, or use Serverless Containers for custom extensions or versions.', implode(', ', $others), 1 === \count($others) ? 'meets' : 'meet', implode(' or ', $others));
193+
194+ // The catalogue may predate a PHP upgrade Scaleway made since.
195+ return 'php' === $name ? $suggestion.' If Scaleway has upgraded PHP since the measurement, update jdecool/scaleway-runtime or re-run its probe.' : $suggestion;
196+ }
197+
198+ private function constraint(string $constraint, string $declarer): ConstraintInterface
199+ {
200+ try {
201+ return $this->parser->parseConstraints($constraint);
202+ } catch (\UnexpectedValueException $e) {
203+ throw new \UnexpectedValueException(\sprintf('The invalid constraint "%s" is declared by %s: %s', $constraint, $declarer, $e->getMessage()), 0, $e);
204+ }
205+ }
206+
207+ /**
208+ * @param list<list<string>> $rows
209+ */
210+ private function report(array $rows): void
211+ {
212+ $widths = [];
213+ foreach ($rows as $row) {
214+ foreach (\array_slice($row, 0, -1) as $column => $cell) {
215+ $widths[$column] = max($widths[$column] ?? 0, \strlen($cell));
216+ }
217+ }
218+ foreach ($rows as $row) {
219+ $last = array_pop($row);
220+ $this->write(implode('', array_map(static fn (string $cell, int $column): string => str_pad($cell, $widths[$column] + 2), $row, array_keys($row))).$last);
221+ }
222+ if ([] !== $rows) {
223+ $this->write('');
224+ }
225+ }
226+
227+ /**
228+ * @param array<mixed> $package
229+ */
230+ private static function name(array $package): string
231+ {
232+ return trim((\is_string($package['name'] ?? null) ? $package['name'] : 'a package').' '.(\is_string($package['version'] ?? null) ? $package['version'] : ''));
233+ }
234+
235+ /**
236+ * @param FunctionRuntime $target
237+ */
238+ private static function date(array $target): string
239+ {
240+ return substr($target['measuredAt'], 0, 10);
241+ }
242+
243+ private function write(string $line): void
244+ {
245+ fwrite($this->log, $line.\PHP_EOL);
246+ }
247+}
new file mode 100644
@@ -0,0 +1,247 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime;
6+
7+use Composer\Semver\Constraint\Constraint;
8+use Composer\Semver\Constraint\ConstraintInterface;
9+use Composer\Semver\Constraint\MatchAllConstraint;
10+use Composer\Semver\VersionParser;
11+
12+/**
13+ * Checks the Platform Requirements Scaleway's "composer install --no-dev" checks against a Function Runtime of the
14+ * catalogue: an unmet one fails that install silently, and every Invocation then answers a 500.
15+ * See docs/adr/0013-check-platform-requirements-against-an-explicit-function-runtime.md.
16+ *
17+ * @phpstan-import-type FunctionRuntime from FunctionRuntimeCatalogue
18+ */
19+final readonly class Doctor
20+{
21+ // Composer's PlatformRepository::PLATFORM_PACKAGE_REGEX: any other name is a package, not a Platform Requirement.
22+ private const string PLATFORM_PACKAGE = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD';
23+
24+ // Scaleway installs with Composer 2, whose APIs every package of the ecosystem accepts.
25+ private const array IGNORED = ['composer', 'composer-plugin-api', 'composer-runtime-api'];
26+
27+ private const string SATISFIED = 'SATISFIED';
28+ private const string INCOMPATIBLE = 'INCOMPATIBLE';
29+ private const string UNKNOWN = 'UNKNOWN';
30+
31+ private VersionParser $parser;
32+
33+ /**
34+ * @param resource $log
35+ */
36+ public function __construct(
37+ private FunctionRuntimeCatalogue $catalogue,
38+ private mixed $log,
39+ ) {
40+ $this->parser = new VersionParser();
41+ }
42+
43+ /**
44+ * Writes the report to the log.
45+ *
46+ * @return bool false when a Platform Requirement is incompatible
47+ */
48+ public function check(string $appDir, string $functionRuntime): bool
49+ {
50+ $target = $this->catalogue->get($functionRuntime);
51+ foreach (['composer.json' => 'run "composer init"', 'composer.lock' => 'run "composer update" and commit it, Scaleway installs the dependencies from it'] as $file => $hint) {
52+ if (!is_file($appDir.'/'.$file)) {
53+ throw new \RuntimeException(\sprintf('"%s" is missing in "%s": %s.', $file, $appDir, $hint));
54+ }
55+ }
56+ $composerJson = (string) file_get_contents($appDir.'/composer.json');
57+ $composerLock = (string) file_get_contents($appDir.'/composer.lock');
58+ Packager::checkLock($composerJson, $composerLock);
59+ /** @var array<mixed> $composer checked by checkLock() */
60+ $composer = json_decode($composerJson, true);
61+ /** @var array<mixed> $lock checked by checkLock() */
62+ $lock = json_decode($composerLock, true);
63+
64+ $packages = array_values(array_filter(\is_array($lock['packages'] ?? null) ? $lock['packages'] : [], \is_array(...)));
65+ $providers = $this->providers($composer, $packages);
66+
67+ $counts = [self::SATISFIED => 0, self::UNKNOWN => 0, self::INCOMPATIBLE => 0];
68+ $rows = [];
69+ foreach ($this->requirements($lock, $packages) as [$declarer, $name, $constraint]) {
70+ $required = $this->constraint($constraint, $declarer);
71+ $outcome = $this->outcome($name, $required, $target, $providers);
72+ ++$counts[$outcome];
73+ if (self::SATISFIED === $outcome) {
74+ continue;
75+ }
76+ $rows[] = [$outcome, $name.' '.$constraint, 'required by '.$declarer, $this->targetValue($functionRuntime, $target, $name, $outcome)];
77+ if (self::INCOMPATIBLE === $outcome) {
78+ $rows[] = ['', $this->suggestion($functionRuntime, $name, $required, $providers)];
79+ }
80+ }
81+
82+ $this->report($rows);
83+ $this->write(\sprintf('%d satisfied, %d unknown, %d incompatible on %s (measured %s)', $counts[self::SATISFIED], $counts[self::UNKNOWN], $counts[self::INCOMPATIBLE], $functionRuntime, self::date($target)));
84+ $this->write('This covers declared Platform Requirements only, not whether the application runs.');
85+
86+ return 0 === $counts[self::INCOMPATIBLE];
87+ }
88+
89+ /**
90+ * What Composer checks when installing a lock without its dev packages: the root requirements it recorded under
91+ * "platform", and the requirements of every package it installs.
92+ *
93+ * @param array<mixed> $lock
94+ * @param list<array<mixed>> $packages
95+ *
96+ * @return list<array{string, string, string}> declarer, lowercase name and constraint of each Platform Requirement
97+ */
98+ private function requirements(array $lock, array $packages): array
99+ {
100+ $requirements = [];
101+ $add = static function (string $declarer, mixed $links) use (&$requirements): void {
102+ foreach (\is_array($links) ? $links : [] as $name => $constraint) {
103+ $name = strtolower((string) $name);
104+ if (\is_string($constraint) && 1 === preg_match(self::PLATFORM_PACKAGE, $name) && !\in_array($name, self::IGNORED, true)) {
105+ $requirements[] = [$declarer, $name, $constraint];
106+ }
107+ }
108+ };
109+ $add('the application', $lock['platform'] ?? null);
110+ foreach ($packages as $package) {
111+ $add(self::name($package), $package['require'] ?? null);
112+ }
113+
114+ return $requirements;
115+ }
116+
117+ /**
118+ * @param array<mixed> $composer
119+ * @param list<array<mixed>> $packages
120+ *
121+ * @return array<string, list<ConstraintInterface>> what the application and its packages provide or replace, by name
122+ */
123+ private function providers(array $composer, array $packages): array
124+ {
125+ $providers = [];
126+ foreach ([['the application', $composer], ...array_map(static fn (array $package): array => [self::name($package), $package], $packages)] as [$declarer, $package]) {
127+ foreach (['provide', 'replace'] as $section) {
128+ foreach (\is_array($package[$section] ?? null) ? $package[$section] : [] as $name => $constraint) {
129+ if (!\is_string($constraint)) {
130+ continue;
131+ }
132+ // The root package has no version of its own here: its "self.version" links match any.
133+ $providers[strtolower((string) $name)][] = 'self.version' === $constraint
134+ ? (\is_string($package['version'] ?? null) ? $this->constraint('=='.$package['version'], $declarer) : new MatchAllConstraint())
135+ : $this->constraint($constraint, $declarer);
136+ }
137+ }
138+ }
139+
140+ return $providers;
141+ }
142+
143+ /**
144+ * @param FunctionRuntime $target
145+ * @param array<string, list<ConstraintInterface>> $providers
146+ */
147+ private function outcome(string $name, ConstraintInterface $required, array $target, array $providers): string
148+ {
149+ foreach ($providers[$name] ?? [] as $provided) {
150+ if ($required->matches($provided)) {
151+ return self::SATISFIED;
152+ }
153+ }
154+ $version = match (true) {
155+ 'php' === $name => $target['php'],
156+ str_starts_with($name, 'ext-') => $target['extensions'][$name] ?? null,
157+ // lib-*, php-64bit and the like are not measured.
158+ default => false,
159+ };
160+ if (false === $version) {
161+ return self::UNKNOWN;
162+ }
163+
164+ return null !== $version && $required->matches(new Constraint('==', $this->parser->normalize($version))) ? self::SATISFIED : self::INCOMPATIBLE;
165+ }
166+
167+ /**
168+ * @param FunctionRuntime $target
169+ */
170+ private function targetValue(string $functionRuntime, array $target, string $name, string $outcome): string
171+ {
172+ if (self::UNKNOWN === $outcome) {
173+ return 'not in the Function Runtime Catalogue';
174+ }
175+ $version = 'php' === $name ? $target['php'] : ($target['extensions'][$name] ?? null);
176+
177+ return \sprintf('%s: %s (measured %s)', $functionRuntime, $version ?? 'not loaded', self::date($target));
178+ }
179+
180+ /**
181+ * @param array<string, list<ConstraintInterface>> $providers
182+ */
183+ private function suggestion(string $functionRuntime, string $name, ConstraintInterface $required, array $providers): string
184+ {
185+ $others = array_keys(array_filter(
186+ $this->catalogue->functionRuntimes,
187+ fn (array $other, string $otherName): bool => $otherName !== $functionRuntime && self::SATISFIED === $this->outcome($name, $required, $other, $providers),
188+ \ARRAY_FILTER_USE_BOTH,
189+ ));
190+ $suggestion = [] === $others
191+ ? 'No measured Function Runtime meets it: use Serverless Containers for custom extensions or versions.'
192+ : \sprintf('%s %s it: deploy on %s, or use Serverless Containers for custom extensions or versions.', implode(', ', $others), 1 === \count($others) ? 'meets' : 'meet', implode(' or ', $others));
193+
194+ // The catalogue may predate a PHP upgrade Scaleway made since.
195+ return 'php' === $name ? $suggestion.' If Scaleway has upgraded PHP since the measurement, update jdecool/scaleway-runtime or re-run its probe.' : $suggestion;
196+ }
197+
198+ private function constraint(string $constraint, string $declarer): ConstraintInterface
199+ {
200+ try {
201+ return $this->parser->parseConstraints($constraint);
202+ } catch (\UnexpectedValueException $e) {
203+ throw new \UnexpectedValueException(\sprintf('The invalid constraint "%s" is declared by %s: %s', $constraint, $declarer, $e->getMessage()), 0, $e);
204+ }
205+ }
206+
207+ /**
208+ * @param list<list<string>> $rows
209+ */
210+ private function report(array $rows): void
211+ {
212+ $widths = [];
213+ foreach ($rows as $row) {
214+ foreach (\array_slice($row, 0, -1) as $column => $cell) {
215+ $widths[$column] = max($widths[$column] ?? 0, \strlen($cell));
216+ }
217+ }
218+ foreach ($rows as $row) {
219+ $last = array_pop($row);
220+ $this->write(implode('', array_map(static fn (string $cell, int $column): string => str_pad($cell, $widths[$column] + 2), $row, array_keys($row))).$last);
221+ }
222+ if ([] !== $rows) {
223+ $this->write('');
224+ }
225+ }
226+
227+ /**
228+ * @param array<mixed> $package
229+ */
230+ private static function name(array $package): string
231+ {
232+ return trim((\is_string($package['name'] ?? null) ? $package['name'] : 'a package').' '.(\is_string($package['version'] ?? null) ? $package['version'] : ''));
233+ }
234+
235+ /**
236+ * @param FunctionRuntime $target
237+ */
238+ private static function date(array $target): string
239+ {
240+ return substr($target['measuredAt'], 0, 10);
241+ }
242+
243+ private function write(string $line): void
244+ {
245+ fwrite($this->log, $line.\PHP_EOL);
246+ }
247+}
added src/FunctionRuntimeCatalogue.php +167 -0
new file mode 100644
@@ -0,0 +1,167 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime;
6+
7+use Composer\Semver\VersionParser;
8+
9+/**
10+ * The PHP version and the extensions measured on each supported Function Runtime, named and versioned as Composer sees
11+ * them there, generated from the probe's output (see docs/probe-results.md#function-runtime-catalogue).
12+ *
13+ * @phpstan-type FunctionRuntime array{measuredAt: string, php: string, extensions: array<string, string>}
14+ */
15+final readonly class FunctionRuntimeCatalogue
16+{
17+ public const string FILE = __DIR__.'/../resources/function-runtimes.php';
18+
19+ /**
20+ * @param array<string, FunctionRuntime> $functionRuntimes by name, as "php84"
21+ */
22+ public function __construct(
23+ public array $functionRuntimes,
24+ ) {
25+ }
26+
27+ public static function load(): self
28+ {
29+ /** @var array<string, FunctionRuntime> $functionRuntimes */
30+ $functionRuntimes = require self::FILE;
31+
32+ return new self($functionRuntimes);
33+ }
34+
35+ /**
36+ * @return FunctionRuntime
37+ */
38+ public function get(string $name): array
39+ {
40+ return $this->functionRuntimes[$name] ?? throw new \InvalidArgumentException(\sprintf('"%s" is not a measured Function Runtime: use %s.', $name, implode(' or ', array_keys($this->functionRuntimes))));
41+ }
42+
43+ /**
44+ * Turns the outputs of the probe's "runtime" mode into the catalogue file. PHP and its extensions get the names and
45+ * versions of Composer's PlatformRepository, so that constraints are evaluated as Scaleway's "composer install" does.
46+ *
47+ * @param list<string> $probeOutputs
48+ */
49+ public static function generate(array $probeOutputs): string
50+ {
51+ $parser = new VersionParser();
52+ $functionRuntimes = [];
53+ foreach ($probeOutputs as $json) {
54+ $measurement = json_decode($json, true, 512, \JSON_THROW_ON_ERROR);
55+ if (!\is_array($measurement) || !\is_string($measuredAt = $measurement['measuredAt'] ?? null) || !\is_string($php = $measurement['phpVersion'] ?? null) || !\is_array($extensions = $measurement['extensions'] ?? null)) {
56+ throw new \UnexpectedValueException('A probe output must hold "measuredAt", "phpVersion" and "extensions".');
57+ }
58+ // Scaleway names its Function Runtimes after the PHP minor version.
59+ if (1 !== preg_match('/^(\d+)\.(\d+)\./', $php, $match)) {
60+ throw new \UnexpectedValueException(\sprintf('"%s" is not a PHP version.', $php));
61+ }
62+ $name = 'php'.$match[1].$match[2];
63+ if (isset($functionRuntimes[$name])) {
64+ throw new \UnexpectedValueException(\sprintf('Two probe outputs measure %s: keep one.', $name));
65+ }
66+
67+ $versions = [];
68+ foreach ($extensions as $extension => $version) {
69+ // Composer does not register these two as packages.
70+ if (\in_array($extension, ['Core', 'standard'], true)) {
71+ continue;
72+ }
73+ $versions['ext-'.str_replace(' ', '-', strtolower((string) $extension))] = self::composerVersion($parser, \is_string($version) ? $version : '0');
74+ }
75+ ksort($versions);
76+
77+ $functionRuntimes[$name] = [
78+ 'measuredAt' => $measuredAt,
79+ 'php' => self::composerPhpVersion($parser, $php),
80+ 'extensions' => $versions,
81+ ];
82+ }
83+ ksort($functionRuntimes);
84+
85+ return "<?php\n\ndeclare(strict_types=1);\n\n// Generated by probe/catalogue.php from tests/Fixtures/FunctionRuntimes: do not edit by hand.\n\nreturn ".self::export($functionRuntimes, '').";\n";
86+ }
87+
88+ /**
89+ * What changed since an older catalogue, one line each, for the pull request a new measurement opens.
90+ * Empty when only the measurement dates changed: the Function Runtimes still are as recorded.
91+ *
92+ * @return list<string>
93+ */
94+ public function changes(self $old): array
95+ {
96+ $changes = [];
97+ foreach (array_diff_key($old->functionRuntimes, $this->functionRuntimes) as $name => $_) {
98+ $changes[] = $name.': no longer measured';
99+ }
100+ foreach ($this->functionRuntimes as $name => $new) {
101+ $previous = $old->functionRuntimes[$name] ?? null;
102+ if (null === $previous) {
103+ $changes[] = \sprintf('%s: new Function Runtime, PHP %s with %d extensions', $name, $new['php'], \count($new['extensions']));
104+ continue;
105+ }
106+ $lines = $previous['php'] === $new['php'] ? [] : [\sprintf('%s: PHP %s -> %s', $name, $previous['php'], $new['php'])];
107+ foreach ($new['extensions'] + $previous['extensions'] as $extension => $_) {
108+ $before = $previous['extensions'][$extension] ?? null;
109+ $after = $new['extensions'][$extension] ?? null;
110+ $lines[] = match (true) {
111+ null === $before => \sprintf('%s: + %s %s', $name, $extension, $after),
112+ null === $after => \sprintf('%s: - %s', $name, $extension),
113+ $before !== $after => \sprintf('%s: %s %s -> %s', $name, $extension, $before, $after),
114+ default => null,
115+ };
116+ }
117+ $lines = array_values(array_filter($lines));
118+ if ([] !== $lines) {
119+ $changes = [...$changes, ...$lines, \sprintf('%s: measured %s -> %s', $name, $previous['measuredAt'], $new['measuredAt'])];
120+ }
121+ }
122+
123+ return $changes;
124+ }
125+
126+ /**
127+ * Composer keeps a parseable PHP_VERSION whole, so that "8.5.0-RC1" stays a pre-release, and cuts the others, as
128+ * "8.4.28-1+deb12", before their first "~", "+" or "-".
129+ */
130+ private static function composerPhpVersion(VersionParser $parser, string $version): string
131+ {
132+ try {
133+ $parser->normalize($version);
134+
135+ return $version;
136+ } catch (\UnexpectedValueException) {
137+ return (string) preg_replace('/^([^~+-]+).*$/', '$1', $version);
138+ }
139+ }
140+
141+ /**
142+ * Composer's fallback for a version it cannot parse, as "mysqlnd 8.4.28": its leading digits, or "0".
143+ */
144+ private static function composerVersion(VersionParser $parser, string $version): string
145+ {
146+ try {
147+ $parser->normalize($version);
148+
149+ return $version;
150+ } catch (\UnexpectedValueException) {
151+ return 1 === preg_match('/^(\d+\.\d+\.\d+(?:\.\d+)?)/', $version, $match) ? $match[1] : '0';
152+ }
153+ }
154+
155+ /**
156+ * @param array<mixed> $values
157+ */
158+ private static function export(array $values, string $indent): string
159+ {
160+ $lines = [];
161+ foreach ($values as $key => $value) {
162+ $lines[] = $indent.' '.var_export($key, true).' => '.(\is_array($value) ? self::export($value, $indent.' ') : var_export($value, true)).',';
163+ }
164+
165+ return "[\n".implode("\n", $lines)."\n".$indent.']';
166+ }
167+}
new file mode 100644
@@ -0,0 +1,167 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime;
6+
7+use Composer\Semver\VersionParser;
8+
9+/**
10+ * The PHP version and the extensions measured on each supported Function Runtime, named and versioned as Composer sees
11+ * them there, generated from the probe's output (see docs/probe-results.md#function-runtime-catalogue).
12+ *
13+ * @phpstan-type FunctionRuntime array{measuredAt: string, php: string, extensions: array<string, string>}
14+ */
15+final readonly class FunctionRuntimeCatalogue
16+{
17+ public const string FILE = __DIR__.'/../resources/function-runtimes.php';
18+
19+ /**
20+ * @param array<string, FunctionRuntime> $functionRuntimes by name, as "php84"
21+ */
22+ public function __construct(
23+ public array $functionRuntimes,
24+ ) {
25+ }
26+
27+ public static function load(): self
28+ {
29+ /** @var array<string, FunctionRuntime> $functionRuntimes */
30+ $functionRuntimes = require self::FILE;
31+
32+ return new self($functionRuntimes);
33+ }
34+
35+ /**
36+ * @return FunctionRuntime
37+ */
38+ public function get(string $name): array
39+ {
40+ return $this->functionRuntimes[$name] ?? throw new \InvalidArgumentException(\sprintf('"%s" is not a measured Function Runtime: use %s.', $name, implode(' or ', array_keys($this->functionRuntimes))));
41+ }
42+
43+ /**
44+ * Turns the outputs of the probe's "runtime" mode into the catalogue file. PHP and its extensions get the names and
45+ * versions of Composer's PlatformRepository, so that constraints are evaluated as Scaleway's "composer install" does.
46+ *
47+ * @param list<string> $probeOutputs
48+ */
49+ public static function generate(array $probeOutputs): string
50+ {
51+ $parser = new VersionParser();
52+ $functionRuntimes = [];
53+ foreach ($probeOutputs as $json) {
54+ $measurement = json_decode($json, true, 512, \JSON_THROW_ON_ERROR);
55+ if (!\is_array($measurement) || !\is_string($measuredAt = $measurement['measuredAt'] ?? null) || !\is_string($php = $measurement['phpVersion'] ?? null) || !\is_array($extensions = $measurement['extensions'] ?? null)) {
56+ throw new \UnexpectedValueException('A probe output must hold "measuredAt", "phpVersion" and "extensions".');
57+ }
58+ // Scaleway names its Function Runtimes after the PHP minor version.
59+ if (1 !== preg_match('/^(\d+)\.(\d+)\./', $php, $match)) {
60+ throw new \UnexpectedValueException(\sprintf('"%s" is not a PHP version.', $php));
61+ }
62+ $name = 'php'.$match[1].$match[2];
63+ if (isset($functionRuntimes[$name])) {
64+ throw new \UnexpectedValueException(\sprintf('Two probe outputs measure %s: keep one.', $name));
65+ }
66+
67+ $versions = [];
68+ foreach ($extensions as $extension => $version) {
69+ // Composer does not register these two as packages.
70+ if (\in_array($extension, ['Core', 'standard'], true)) {
71+ continue;
72+ }
73+ $versions['ext-'.str_replace(' ', '-', strtolower((string) $extension))] = self::composerVersion($parser, \is_string($version) ? $version : '0');
74+ }
75+ ksort($versions);
76+
77+ $functionRuntimes[$name] = [
78+ 'measuredAt' => $measuredAt,
79+ 'php' => self::composerPhpVersion($parser, $php),
80+ 'extensions' => $versions,
81+ ];
82+ }
83+ ksort($functionRuntimes);
84+
85+ return "<?php\n\ndeclare(strict_types=1);\n\n// Generated by probe/catalogue.php from tests/Fixtures/FunctionRuntimes: do not edit by hand.\n\nreturn ".self::export($functionRuntimes, '').";\n";
86+ }
87+
88+ /**
89+ * What changed since an older catalogue, one line each, for the pull request a new measurement opens.
90+ * Empty when only the measurement dates changed: the Function Runtimes still are as recorded.
91+ *
92+ * @return list<string>
93+ */
94+ public function changes(self $old): array
95+ {
96+ $changes = [];
97+ foreach (array_diff_key($old->functionRuntimes, $this->functionRuntimes) as $name => $_) {
98+ $changes[] = $name.': no longer measured';
99+ }
100+ foreach ($this->functionRuntimes as $name => $new) {
101+ $previous = $old->functionRuntimes[$name] ?? null;
102+ if (null === $previous) {
103+ $changes[] = \sprintf('%s: new Function Runtime, PHP %s with %d extensions', $name, $new['php'], \count($new['extensions']));
104+ continue;
105+ }
106+ $lines = $previous['php'] === $new['php'] ? [] : [\sprintf('%s: PHP %s -> %s', $name, $previous['php'], $new['php'])];
107+ foreach ($new['extensions'] + $previous['extensions'] as $extension => $_) {
108+ $before = $previous['extensions'][$extension] ?? null;
109+ $after = $new['extensions'][$extension] ?? null;
110+ $lines[] = match (true) {
111+ null === $before => \sprintf('%s: + %s %s', $name, $extension, $after),
112+ null === $after => \sprintf('%s: - %s', $name, $extension),
113+ $before !== $after => \sprintf('%s: %s %s -> %s', $name, $extension, $before, $after),
114+ default => null,
115+ };
116+ }
117+ $lines = array_values(array_filter($lines));
118+ if ([] !== $lines) {
119+ $changes = [...$changes, ...$lines, \sprintf('%s: measured %s -> %s', $name, $previous['measuredAt'], $new['measuredAt'])];
120+ }
121+ }
122+
123+ return $changes;
124+ }
125+
126+ /**
127+ * Composer keeps a parseable PHP_VERSION whole, so that "8.5.0-RC1" stays a pre-release, and cuts the others, as
128+ * "8.4.28-1+deb12", before their first "~", "+" or "-".
129+ */
130+ private static function composerPhpVersion(VersionParser $parser, string $version): string
131+ {
132+ try {
133+ $parser->normalize($version);
134+
135+ return $version;
136+ } catch (\UnexpectedValueException) {
137+ return (string) preg_replace('/^([^~+-]+).*$/', '$1', $version);
138+ }
139+ }
140+
141+ /**
142+ * Composer's fallback for a version it cannot parse, as "mysqlnd 8.4.28": its leading digits, or "0".
143+ */
144+ private static function composerVersion(VersionParser $parser, string $version): string
145+ {
146+ try {
147+ $parser->normalize($version);
148+
149+ return $version;
150+ } catch (\UnexpectedValueException) {
151+ return 1 === preg_match('/^(\d+\.\d+\.\d+(?:\.\d+)?)/', $version, $match) ? $match[1] : '0';
152+ }
153+ }
154+
155+ /**
156+ * @param array<mixed> $values
157+ */
158+ private static function export(array $values, string $indent): string
159+ {
160+ $lines = [];
161+ foreach ($values as $key => $value) {
162+ $lines[] = $indent.' '.var_export($key, true).' => '.(\is_array($value) ? self::export($value, $indent.' ') : var_export($value, true)).',';
163+ }
164+
165+ return "[\n".implode("\n", $lines)."\n".$indent.']';
166+ }
167+}
modified src/Packager.php +7 -1
@@ -36,7 +36,10 @@ final readonly class Packager
3636 ) {
3737 }
3838
39- public function package(string $zipFile): void
39+ /**
40+ * @param ?string $functionRuntime checks the Platform Requirements against it first, as "php84"
41+ */
42+ public function package(string $zipFile, ?string $functionRuntime = null): void
4043 {
4144 if (!class_exists(\ZipArchive::class)) {
4245 throw new \RuntimeException('The zip PHP extension is required to build the deployment zip.');
@@ -47,6 +50,9 @@ final readonly class Packager
4750 }
4851 }
4952 self::checkLock((string) file_get_contents($this->appDir.'/composer.json'), (string) file_get_contents($this->appDir.'/composer.lock'));
53+ if (null !== $functionRuntime && !new Doctor(FunctionRuntimeCatalogue::load(), $this->log)->check($this->appDir, $functionRuntime)) {
54+ throw new \RuntimeException(\sprintf('%s does not meet the Platform Requirements above: Scaleway\'s "composer install" would fail, and every Invocation answer a 500.', $functionRuntime));
55+ }
5056
5157 $this->log('Writing '.$zipFile);
5258 [$zipSize, $codeSize] = $this->zip($zipFile, $this->relativeToApp($zipFile));
@@ -36,7 +36,10 @@ final readonly class Packager
36 ) {36 ) {
37 }37 }
38 38
39- public function package(string $zipFile): void39+ /**
40+ * @param ?string $functionRuntime checks the Platform Requirements against it first, as "php84"
41+ */
42+ public function package(string $zipFile, ?string $functionRuntime = null): void
40 {43 {
41 if (!class_exists(\ZipArchive::class)) {44 if (!class_exists(\ZipArchive::class)) {
42 throw new \RuntimeException('The zip PHP extension is required to build the deployment zip.');45 throw new \RuntimeException('The zip PHP extension is required to build the deployment zip.');
@@ -47,6 +50,9 @@ final readonly class Packager
47 }50 }
48 }51 }
49 self::checkLock((string) file_get_contents($this->appDir.'/composer.json'), (string) file_get_contents($this->appDir.'/composer.lock'));52 self::checkLock((string) file_get_contents($this->appDir.'/composer.json'), (string) file_get_contents($this->appDir.'/composer.lock'));
53+ if (null !== $functionRuntime && !new Doctor(FunctionRuntimeCatalogue::load(), $this->log)->check($this->appDir, $functionRuntime)) {
54+ throw new \RuntimeException(\sprintf('%s does not meet the Platform Requirements above: Scaleway\'s "composer install" would fail, and every Invocation answer a 500.', $functionRuntime));
55+ }
50 56
51 $this->log('Writing '.$zipFile);57 $this->log('Writing '.$zipFile);
52 [$zipSize, $codeSize] = $this->zip($zipFile, $this->relativeToApp($zipFile));58 [$zipSize, $codeSize] = $this->zip($zipFile, $this->relativeToApp($zipFile));
added tests/DoctorTest.php +271 -0
new file mode 100644
@@ -0,0 +1,271 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime\Tests;
6+
7+use JDecool\ScalewayRuntime\Doctor;
8+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
9+use JDecool\ScalewayRuntime\Packager;
10+use PHPUnit\Framework\Attributes\TestWith;
11+use PHPUnit\Framework\TestCase;
12+use Symfony\Component\Filesystem\Filesystem;
13+
14+final class DoctorTest extends TestCase
15+{
16+ private const string SCOPE = 'This covers declared Platform Requirements only, not whether the application runs.';
17+
18+ private Filesystem $filesystem;
19+ private string $appDir;
20+ private FunctionRuntimeCatalogue $catalogue;
21+
22+ protected function setUp(): void
23+ {
24+ $this->filesystem = new Filesystem();
25+ $this->appDir = sys_get_temp_dir().'/scaleway-runtime-'.bin2hex(random_bytes(4));
26+ $this->catalogue = new FunctionRuntimeCatalogue([
27+ 'php84' => ['measuredAt' => '2026-11-22T11:47:13Z', 'php' => '8.4.28', 'extensions' => ['ext-ctype' => '8.4.28', 'ext-mysqlnd' => '0', 'ext-redis' => '6.3.0']],
28+ 'php85' => ['measuredAt' => '2026-11-21T09:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-ctype' => '8.5.13', 'ext-redis' => '6.3.0', 'ext-sodium' => '8.5.13']],
29+ ]);
30+ }
31+
32+ protected function tearDown(): void
33+ {
34+ $this->filesystem->remove($this->appDir);
35+ }
36+
37+ public function testSatisfiedRequirementsOnlyPrintTheSummary(): void
38+ {
39+ $this->application(['php' => '>=8.4', 'ext-ctype' => '*'], [self::package('acme/cache', ['php' => '^8.1', 'ext-Redis' => '^6.0'])]);
40+
41+ self::assertSame([true, "4 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
42+ }
43+
44+ public function testIncompatibleRequirementsAreReportedWithTheirDeclarerAndASuggestion(): void
45+ {
46+ $this->application(['php' => '^8.5'], [
47+ self::package('acme/crypto', ['ext-sodium' => '*']),
48+ self::package('acme/queue', ['ext-redis' => '^7.0']),
49+ ]);
50+
51+ self::assertSame([false, <<<'TXT'
52+ INCOMPATIBLE php ^8.5 required by the application php84: 8.4.28 (measured 2026-11-22)
53+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions. If Scaleway has upgraded PHP since the measurement, update jdecool/scaleway-runtime or re-run its probe.
54+ INCOMPATIBLE ext-sodium * required by acme/crypto v1.0.0 php84: not loaded (measured 2026-11-22)
55+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions.
56+ INCOMPATIBLE ext-redis ^7.0 required by acme/queue v1.0.0 php84: 6.3.0 (measured 2026-11-22)
57+ No measured Function Runtime meets it: use Serverless Containers for custom extensions or versions.
58+
59+ 0 satisfied, 0 unknown, 3 incompatible on php84 (measured 2026-11-22)
60+ This covers declared Platform Requirements only, not whether the application runs.
61+
62+ TXT], $this->check('php84'));
63+ }
64+
65+ public function testMeasuredPhpPatchIsAuthoritative(): void
66+ {
67+ $this->application(['php' => '>=8.4.29']);
68+
69+ [$compatible, $report] = $this->check('php84');
70+
71+ self::assertFalse($compatible);
72+ self::assertStringContainsString('INCOMPATIBLE php >=8.4.29 required by the application php84: 8.4.28 (measured 2026-11-22)', $report);
73+ }
74+
75+ public function testComposersFallbackVersionOfAnExtensionIsCompared(): void
76+ {
77+ $this->application(['ext-mysqlnd' => '>=8.0']);
78+
79+ self::assertStringContainsString('php84: 0 (measured 2026-11-22)', $this->check('php84')[1]);
80+ }
81+
82+ public function testDevelopmentRequirementsAreNotChecked(): void
83+ {
84+ $this->application(['php' => '>=8.4'], [], [
85+ 'packages-dev' => [self::package('acme/profiler', ['ext-xdebug' => '*'])],
86+ 'platform-dev' => ['ext-pcov' => '*'],
87+ ]);
88+
89+ self::assertSame([true, "1 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
90+ }
91+
92+ public function testProvidedAndReplacedExtensionsAreSatisfied(): void
93+ {
94+ $this->application(
95+ [],
96+ [
97+ self::package('acme/crypto', ['ext-sodium' => '*', 'ext-intl' => '^1.0', 'ext-gmp' => '^2.0']),
98+ self::package('acme/polyfill-sodium', [], ['provide' => ['ext-sodium' => '*']]),
99+ self::package('acme/polyfill-intl', [], ['replace' => ['ext-intl' => 'self.version']]),
100+ ],
101+ [],
102+ ['provide' => ['ext-gmp' => '2.1.0']],
103+ );
104+
105+ self::assertSame([true, "3 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
106+ }
107+
108+ public function testProviderNotMatchingTheConstraintDoesNotSatisfyIt(): void
109+ {
110+ $this->application([], [
111+ self::package('acme/crypto', ['ext-sodium' => '^2.0']),
112+ self::package('acme/polyfill-sodium', [], ['provide' => ['ext-sodium' => '1.0.0']]),
113+ ]);
114+
115+ self::assertFalse($this->check('php84')[0]);
116+ }
117+
118+ public function testUnmeasuredPlatformPackagesAreUnknownWithoutFailing(): void
119+ {
120+ $this->application(['lib-icu' => '>=72', 'php-64bit' => '*']);
121+
122+ self::assertSame([true, <<<'TXT'
123+ UNKNOWN lib-icu >=72 required by the application not in the Function Runtime Catalogue
124+ UNKNOWN php-64bit * required by the application not in the Function Runtime Catalogue
125+
126+ 0 satisfied, 2 unknown, 0 incompatible on php84 (measured 2026-11-22)
127+ This covers declared Platform Requirements only, not whether the application runs.
128+
129+ TXT], $this->check('php84'));
130+ }
131+
132+ public function testComposerApisAndPackagesAreNotPlatformRequirements(): void
133+ {
134+ $this->application(['composer-runtime-api' => '^2.2', 'symfony/runtime' => '^8.0'], [self::package('symfony/runtime', ['composer-plugin-api' => '^1.0|^2.0', 'composer' => '^2.0', 'php' => '>=8.2'])]);
135+
136+ self::assertSame([true, "1 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
137+ }
138+
139+ public function testUnmeasuredFunctionRuntimeIsRefused(): void
140+ {
141+ $this->application();
142+
143+ $this->expectExceptionMessage('"php83" is not a measured Function Runtime: use php84 or php85.');
144+
145+ $this->check('php83');
146+ }
147+
148+ #[TestWith(['composer.json'])]
149+ #[TestWith(['composer.lock'])]
150+ public function testMissingComposerFileIsRefused(string $file): void
151+ {
152+ $this->application();
153+ $this->filesystem->remove($this->appDir.'/'.$file);
154+
155+ $this->expectExceptionMessage(\sprintf('"%s" is missing in', $file));
156+
157+ $this->check('php84');
158+ }
159+
160+ public function testStaleLockIsRefused(): void
161+ {
162+ $this->application(['php' => '>=8.4']);
163+ $this->filesystem->dumpFile($this->appDir.'/composer.json', json_encode(['require' => ['php' => '>=8.5']], \JSON_THROW_ON_ERROR));
164+
165+ $this->expectExceptionMessage('composer.lock is not up to date with composer.json');
166+
167+ $this->check('php84');
168+ }
169+
170+ public function testInvalidConstraintIsRefused(): void
171+ {
172+ $this->application([], [self::package('acme/broken', ['php' => 'not a constraint'])]);
173+
174+ $this->expectExceptionMessage('The invalid constraint "not a constraint" is declared by acme/broken v1.0.0');
175+
176+ $this->check('php84');
177+ }
178+
179+ public function testInvalidConstraintOfTheApplicationIsRefused(): void
180+ {
181+ $this->application([], [], [], ['provide' => ['ext-gmp' => 'not a constraint']]);
182+
183+ $this->expectExceptionMessage('The invalid constraint "not a constraint" is declared by the application');
184+
185+ $this->check('php84');
186+ }
187+
188+ #[TestWith(['composer.json'])]
189+ #[TestWith(['composer.lock'])]
190+ public function testInvalidComposerFileIsRefused(string $file): void
191+ {
192+ $this->application();
193+ $this->filesystem->dumpFile($this->appDir.'/'.$file, '{');
194+
195+ $this->expectExceptionMessage($file.' must hold a JSON object.');
196+
197+ $this->check('php84');
198+ }
199+
200+ public function testCommandLine(): void
201+ {
202+ self::assertSame(0, self::runDoctor(['--help'])[0]);
203+ // This package's own lock, as the root package of the checkout: the report goes to stderr only.
204+ [$exitCode, $stderr, $stdout] = self::runDoctor(['--runtime=php84']);
205+ self::assertSame([0, ''], [$exitCode, $stdout]);
206+ self::assertStringContainsString('incompatible on php84', $stderr);
207+ [$exitCode, $stderr] = self::runDoctor([]);
208+ self::assertSame(1, $exitCode);
209+ self::assertStringStartsWith('Usage: scaleway-doctor --runtime=<function-runtime>', $stderr);
210+ self::assertSame(1, self::runDoctor(['--runtime=php83'])[0]);
211+ }
212+
213+ /**
214+ * @param array<string, string> $platform the root Platform Requirements, recorded by Composer in the lock
215+ * @param list<array<string, mixed>> $packages
216+ * @param array<string, mixed> $lock
217+ * @param array<string, mixed> $composer
218+ */
219+ private function application(array $platform = [], array $packages = [], array $lock = [], array $composer = []): void
220+ {
221+ $composer += ['require' => $platform];
222+ $this->filesystem->dumpFile($this->appDir.'/composer.json', json_encode($composer, \JSON_THROW_ON_ERROR));
223+ $this->filesystem->dumpFile($this->appDir.'/composer.lock', json_encode($lock + [
224+ 'content-hash' => Packager::contentHash($composer),
225+ 'packages' => $packages,
226+ 'packages-dev' => [],
227+ // Composer writes an empty JSON array, not an object.
228+ 'platform' => [] === $platform ? [] : $platform,
229+ 'platform-dev' => [],
230+ ], \JSON_THROW_ON_ERROR));
231+ }
232+
233+ /**
234+ * @param array<string, string> $require
235+ * @param array<string, mixed> $links
236+ *
237+ * @return array<string, mixed>
238+ */
239+ private static function package(string $name, array $require, array $links = []): array
240+ {
241+ return ['name' => $name, 'version' => 'v1.0.0', 'require' => $require] + $links;
242+ }
243+
244+ /**
245+ * @return array{bool, string}
246+ */
247+ private function check(string $functionRuntime): array
248+ {
249+ $log = fopen('php://memory', 'w+');
250+ self::assertNotFalse($log);
251+ $compatible = new Doctor($this->catalogue, $log)->check($this->appDir, $functionRuntime);
252+ rewind($log);
253+
254+ return [$compatible, (string) stream_get_contents($log)];
255+ }
256+
257+ /**
258+ * @param list<string> $arguments
259+ *
260+ * @return array{int, string, string} exit code, stderr and stdout
261+ */
262+ private static function runDoctor(array $arguments): array
263+ {
264+ $process = proc_open([\PHP_BINARY, __DIR__.'/../bin/scaleway-doctor', ...$arguments], [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
265+ self::assertIsResource($process);
266+ $stdout = (string) stream_get_contents($pipes[1]);
267+ $stderr = (string) stream_get_contents($pipes[2]);
268+
269+ return [proc_close($process), $stderr, $stdout];
270+ }
271+}
new file mode 100644
@@ -0,0 +1,271 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime\Tests;
6+
7+use JDecool\ScalewayRuntime\Doctor;
8+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
9+use JDecool\ScalewayRuntime\Packager;
10+use PHPUnit\Framework\Attributes\TestWith;
11+use PHPUnit\Framework\TestCase;
12+use Symfony\Component\Filesystem\Filesystem;
13+
14+final class DoctorTest extends TestCase
15+{
16+ private const string SCOPE = 'This covers declared Platform Requirements only, not whether the application runs.';
17+
18+ private Filesystem $filesystem;
19+ private string $appDir;
20+ private FunctionRuntimeCatalogue $catalogue;
21+
22+ protected function setUp(): void
23+ {
24+ $this->filesystem = new Filesystem();
25+ $this->appDir = sys_get_temp_dir().'/scaleway-runtime-'.bin2hex(random_bytes(4));
26+ $this->catalogue = new FunctionRuntimeCatalogue([
27+ 'php84' => ['measuredAt' => '2026-11-22T11:47:13Z', 'php' => '8.4.28', 'extensions' => ['ext-ctype' => '8.4.28', 'ext-mysqlnd' => '0', 'ext-redis' => '6.3.0']],
28+ 'php85' => ['measuredAt' => '2026-11-21T09:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-ctype' => '8.5.13', 'ext-redis' => '6.3.0', 'ext-sodium' => '8.5.13']],
29+ ]);
30+ }
31+
32+ protected function tearDown(): void
33+ {
34+ $this->filesystem->remove($this->appDir);
35+ }
36+
37+ public function testSatisfiedRequirementsOnlyPrintTheSummary(): void
38+ {
39+ $this->application(['php' => '>=8.4', 'ext-ctype' => '*'], [self::package('acme/cache', ['php' => '^8.1', 'ext-Redis' => '^6.0'])]);
40+
41+ self::assertSame([true, "4 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
42+ }
43+
44+ public function testIncompatibleRequirementsAreReportedWithTheirDeclarerAndASuggestion(): void
45+ {
46+ $this->application(['php' => '^8.5'], [
47+ self::package('acme/crypto', ['ext-sodium' => '*']),
48+ self::package('acme/queue', ['ext-redis' => '^7.0']),
49+ ]);
50+
51+ self::assertSame([false, <<<'TXT'
52+ INCOMPATIBLE php ^8.5 required by the application php84: 8.4.28 (measured 2026-11-22)
53+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions. If Scaleway has upgraded PHP since the measurement, update jdecool/scaleway-runtime or re-run its probe.
54+ INCOMPATIBLE ext-sodium * required by acme/crypto v1.0.0 php84: not loaded (measured 2026-11-22)
55+ php85 meets it: deploy on php85, or use Serverless Containers for custom extensions or versions.
56+ INCOMPATIBLE ext-redis ^7.0 required by acme/queue v1.0.0 php84: 6.3.0 (measured 2026-11-22)
57+ No measured Function Runtime meets it: use Serverless Containers for custom extensions or versions.
58+
59+ 0 satisfied, 0 unknown, 3 incompatible on php84 (measured 2026-11-22)
60+ This covers declared Platform Requirements only, not whether the application runs.
61+
62+ TXT], $this->check('php84'));
63+ }
64+
65+ public function testMeasuredPhpPatchIsAuthoritative(): void
66+ {
67+ $this->application(['php' => '>=8.4.29']);
68+
69+ [$compatible, $report] = $this->check('php84');
70+
71+ self::assertFalse($compatible);
72+ self::assertStringContainsString('INCOMPATIBLE php >=8.4.29 required by the application php84: 8.4.28 (measured 2026-11-22)', $report);
73+ }
74+
75+ public function testComposersFallbackVersionOfAnExtensionIsCompared(): void
76+ {
77+ $this->application(['ext-mysqlnd' => '>=8.0']);
78+
79+ self::assertStringContainsString('php84: 0 (measured 2026-11-22)', $this->check('php84')[1]);
80+ }
81+
82+ public function testDevelopmentRequirementsAreNotChecked(): void
83+ {
84+ $this->application(['php' => '>=8.4'], [], [
85+ 'packages-dev' => [self::package('acme/profiler', ['ext-xdebug' => '*'])],
86+ 'platform-dev' => ['ext-pcov' => '*'],
87+ ]);
88+
89+ self::assertSame([true, "1 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
90+ }
91+
92+ public function testProvidedAndReplacedExtensionsAreSatisfied(): void
93+ {
94+ $this->application(
95+ [],
96+ [
97+ self::package('acme/crypto', ['ext-sodium' => '*', 'ext-intl' => '^1.0', 'ext-gmp' => '^2.0']),
98+ self::package('acme/polyfill-sodium', [], ['provide' => ['ext-sodium' => '*']]),
99+ self::package('acme/polyfill-intl', [], ['replace' => ['ext-intl' => 'self.version']]),
100+ ],
101+ [],
102+ ['provide' => ['ext-gmp' => '2.1.0']],
103+ );
104+
105+ self::assertSame([true, "3 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
106+ }
107+
108+ public function testProviderNotMatchingTheConstraintDoesNotSatisfyIt(): void
109+ {
110+ $this->application([], [
111+ self::package('acme/crypto', ['ext-sodium' => '^2.0']),
112+ self::package('acme/polyfill-sodium', [], ['provide' => ['ext-sodium' => '1.0.0']]),
113+ ]);
114+
115+ self::assertFalse($this->check('php84')[0]);
116+ }
117+
118+ public function testUnmeasuredPlatformPackagesAreUnknownWithoutFailing(): void
119+ {
120+ $this->application(['lib-icu' => '>=72', 'php-64bit' => '*']);
121+
122+ self::assertSame([true, <<<'TXT'
123+ UNKNOWN lib-icu >=72 required by the application not in the Function Runtime Catalogue
124+ UNKNOWN php-64bit * required by the application not in the Function Runtime Catalogue
125+
126+ 0 satisfied, 2 unknown, 0 incompatible on php84 (measured 2026-11-22)
127+ This covers declared Platform Requirements only, not whether the application runs.
128+
129+ TXT], $this->check('php84'));
130+ }
131+
132+ public function testComposerApisAndPackagesAreNotPlatformRequirements(): void
133+ {
134+ $this->application(['composer-runtime-api' => '^2.2', 'symfony/runtime' => '^8.0'], [self::package('symfony/runtime', ['composer-plugin-api' => '^1.0|^2.0', 'composer' => '^2.0', 'php' => '>=8.2'])]);
135+
136+ self::assertSame([true, "1 satisfied, 0 unknown, 0 incompatible on php84 (measured 2026-11-22)\n".self::SCOPE."\n"], $this->check('php84'));
137+ }
138+
139+ public function testUnmeasuredFunctionRuntimeIsRefused(): void
140+ {
141+ $this->application();
142+
143+ $this->expectExceptionMessage('"php83" is not a measured Function Runtime: use php84 or php85.');
144+
145+ $this->check('php83');
146+ }
147+
148+ #[TestWith(['composer.json'])]
149+ #[TestWith(['composer.lock'])]
150+ public function testMissingComposerFileIsRefused(string $file): void
151+ {
152+ $this->application();
153+ $this->filesystem->remove($this->appDir.'/'.$file);
154+
155+ $this->expectExceptionMessage(\sprintf('"%s" is missing in', $file));
156+
157+ $this->check('php84');
158+ }
159+
160+ public function testStaleLockIsRefused(): void
161+ {
162+ $this->application(['php' => '>=8.4']);
163+ $this->filesystem->dumpFile($this->appDir.'/composer.json', json_encode(['require' => ['php' => '>=8.5']], \JSON_THROW_ON_ERROR));
164+
165+ $this->expectExceptionMessage('composer.lock is not up to date with composer.json');
166+
167+ $this->check('php84');
168+ }
169+
170+ public function testInvalidConstraintIsRefused(): void
171+ {
172+ $this->application([], [self::package('acme/broken', ['php' => 'not a constraint'])]);
173+
174+ $this->expectExceptionMessage('The invalid constraint "not a constraint" is declared by acme/broken v1.0.0');
175+
176+ $this->check('php84');
177+ }
178+
179+ public function testInvalidConstraintOfTheApplicationIsRefused(): void
180+ {
181+ $this->application([], [], [], ['provide' => ['ext-gmp' => 'not a constraint']]);
182+
183+ $this->expectExceptionMessage('The invalid constraint "not a constraint" is declared by the application');
184+
185+ $this->check('php84');
186+ }
187+
188+ #[TestWith(['composer.json'])]
189+ #[TestWith(['composer.lock'])]
190+ public function testInvalidComposerFileIsRefused(string $file): void
191+ {
192+ $this->application();
193+ $this->filesystem->dumpFile($this->appDir.'/'.$file, '{');
194+
195+ $this->expectExceptionMessage($file.' must hold a JSON object.');
196+
197+ $this->check('php84');
198+ }
199+
200+ public function testCommandLine(): void
201+ {
202+ self::assertSame(0, self::runDoctor(['--help'])[0]);
203+ // This package's own lock, as the root package of the checkout: the report goes to stderr only.
204+ [$exitCode, $stderr, $stdout] = self::runDoctor(['--runtime=php84']);
205+ self::assertSame([0, ''], [$exitCode, $stdout]);
206+ self::assertStringContainsString('incompatible on php84', $stderr);
207+ [$exitCode, $stderr] = self::runDoctor([]);
208+ self::assertSame(1, $exitCode);
209+ self::assertStringStartsWith('Usage: scaleway-doctor --runtime=<function-runtime>', $stderr);
210+ self::assertSame(1, self::runDoctor(['--runtime=php83'])[0]);
211+ }
212+
213+ /**
214+ * @param array<string, string> $platform the root Platform Requirements, recorded by Composer in the lock
215+ * @param list<array<string, mixed>> $packages
216+ * @param array<string, mixed> $lock
217+ * @param array<string, mixed> $composer
218+ */
219+ private function application(array $platform = [], array $packages = [], array $lock = [], array $composer = []): void
220+ {
221+ $composer += ['require' => $platform];
222+ $this->filesystem->dumpFile($this->appDir.'/composer.json', json_encode($composer, \JSON_THROW_ON_ERROR));
223+ $this->filesystem->dumpFile($this->appDir.'/composer.lock', json_encode($lock + [
224+ 'content-hash' => Packager::contentHash($composer),
225+ 'packages' => $packages,
226+ 'packages-dev' => [],
227+ // Composer writes an empty JSON array, not an object.
228+ 'platform' => [] === $platform ? [] : $platform,
229+ 'platform-dev' => [],
230+ ], \JSON_THROW_ON_ERROR));
231+ }
232+
233+ /**
234+ * @param array<string, string> $require
235+ * @param array<string, mixed> $links
236+ *
237+ * @return array<string, mixed>
238+ */
239+ private static function package(string $name, array $require, array $links = []): array
240+ {
241+ return ['name' => $name, 'version' => 'v1.0.0', 'require' => $require] + $links;
242+ }
243+
244+ /**
245+ * @return array{bool, string}
246+ */
247+ private function check(string $functionRuntime): array
248+ {
249+ $log = fopen('php://memory', 'w+');
250+ self::assertNotFalse($log);
251+ $compatible = new Doctor($this->catalogue, $log)->check($this->appDir, $functionRuntime);
252+ rewind($log);
253+
254+ return [$compatible, (string) stream_get_contents($log)];
255+ }
256+
257+ /**
258+ * @param list<string> $arguments
259+ *
260+ * @return array{int, string, string} exit code, stderr and stdout
261+ */
262+ private static function runDoctor(array $arguments): array
263+ {
264+ $process = proc_open([\PHP_BINARY, __DIR__.'/../bin/scaleway-doctor', ...$arguments], [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
265+ self::assertIsResource($process);
266+ $stdout = (string) stream_get_contents($pipes[1]);
267+ $stderr = (string) stream_get_contents($pipes[2]);
268+
269+ return [proc_close($process), $stderr, $stdout];
270+ }
271+}
added tests/Fixtures/FunctionRuntimes/php84.json +129 -0
new file mode 100644
@@ -0,0 +1,129 @@
1+{
2+ "measuredAt": "2026-11-22T11:47:13Z",
3+ "phpVersion": "8.4.28",
4+ "extensions": {
5+ "Core": "8.4.28",
6+ "date": "8.4.28",
7+ "libxml": "8.4.28",
8+ "openssl": "8.4.28",
9+ "pcre": "8.4.28",
10+ "sqlite3": "8.4.28",
11+ "zlib": "8.4.28",
12+ "ctype": "8.4.28",
13+ "curl": "8.4.28",
14+ "dom": "20031129",
15+ "fileinfo": "8.4.28",
16+ "filter": "8.4.28",
17+ "hash": "8.4.28",
18+ "iconv": "8.4.28",
19+ "json": "8.4.28",
20+ "mbstring": "8.4.28",
21+ "SPL": "8.4.28",
22+ "session": "8.4.28",
23+ "PDO": "8.4.28",
24+ "pdo_sqlite": "8.4.28",
25+ "bz2": "8.4.28",
26+ "posix": "8.4.28",
27+ "random": "8.4.28",
28+ "readline": "8.4.28",
29+ "Reflection": "8.4.28",
30+ "standard": "8.4.28",
31+ "SimpleXML": "8.4.28",
32+ "tokenizer": "8.4.28",
33+ "xml": "8.4.28",
34+ "xmlreader": "8.4.28",
35+ "xmlwriter": "8.4.28",
36+ "mysqlnd": "mysqlnd 8.4.28",
37+ "amqp": "2.2.0",
38+ "apcu": "5.1.28",
39+ "ast": "1.1.4",
40+ "bcmath": "8.4.28",
41+ "Phar": "8.4.28",
42+ "calendar": "8.4.28",
43+ "csv": "0.3.0",
44+ "dba": "8.4.28",
45+ "decimal": "2.0.1",
46+ "ds": "2.0.0",
47+ "enchant": "8.4.28",
48+ "sockets": "8.4.28",
49+ "excimer": "1.2.6",
50+ "exif": "8.4.28",
51+ "FFI": "8.4.28",
52+ "gd": "8.4.28",
53+ "geospatial": "0.3.5",
54+ "gettext": "8.4.28",
55+ "gmp": "8.4.28",
56+ "gnupg": "1.5.4",
57+ "grpc": "1.85.0",
58+ "igbinary": "3.2.17RC1",
59+ "imap": "1.0.3",
60+ "inotify": "3.0.1",
61+ "intl": "8.4.28",
62+ "ion": "0.2.1",
63+ "json_post": "1.1.0",
64+ "ldap": "8.4.28",
65+ "luasandbox": "4.1.3",
66+ "lz4": "0.4.3",
67+ "lzf": "1.7.0",
68+ "mailparse": "3.2.0",
69+ "maxminddb": "1.15.0",
70+ "memcache": "8.2",
71+ "mongodb": "2.5.8",
72+ "msgpack": "3.0.1",
73+ "mysqli": "8.4.28",
74+ "OAuth": "2.0.10",
75+ "odbc": "8.4.28",
76+ "parle": "0.8.5",
77+ "pcntl": "8.4.28",
78+ "pcov": "1.0.12",
79+ "pdo_dblib": "8.4.28",
80+ "PDO_Firebird": "8.4.28",
81+ "pdo_mysql": "8.4.28",
82+ "PDO_ODBC": "8.4.28",
83+ "pdo_pgsql": "8.4.28",
84+ "pdo_sqlsrv": "5.13.3",
85+ "pgsql": "8.4.28",
86+ "php_trie": "0.1.2",
87+ "protobuf": "5.36.2",
88+ "pspell": "1.0.1",
89+ "rdkafka": "6.0.5",
90+ "redis": "6.3.0",
91+ "shmop": "8.4.28",
92+ "simdjson": "4.0.0",
93+ "smbclient": "1.2.0dev",
94+ "snappy": "0.2.1",
95+ "snmp": "8.4.28",
96+ "soap": "8.4.28",
97+ "ev": "1.3.1",
98+ "sodium": "8.4.28",
99+ "solr": "2.9.3",
100+ "SPX": "0.4.21",
101+ "sqlsrv": "5.13.3",
102+ "ssh2": "1.6.1",
103+ "Stomp": "2.0.3",
104+ "sysvmsg": "8.4.28",
105+ "sysvsem": "8.4.28",
106+ "sysvshm": "8.4.28",
107+ "tidy": "8.4.28",
108+ "timezonedb": "2026.6",
109+ "uploadprogress": "2.0.2",
110+ "uuid": "1.3.0",
111+ "vips": "1.0.13",
112+ "xdiff": "2.2.0",
113+ "xlswriter": "3.0.0",
114+ "xmldiff": "1.1.6",
115+ "xmlrpc": "1.0.0RC3",
116+ "xsl": "8.4.28",
117+ "yac": "3.0.2",
118+ "yaml": "2.3.0",
119+ "zephir_parser": "2.11.0",
120+ "zip": "1.22.8",
121+ "zstd": "0.18.0",
122+ "event": "3.2.0",
123+ "memcached": "3.4.0",
124+ "oci8": "3.4.1",
125+ "PDO_OCI": "1.2.0",
126+ "libsmbclient": "1.2.0dev",
127+ "Zend OPcache": "8.4.28"
128+ }
129+}
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,129 @@
1+{
2+ "measuredAt": "2026-11-22T11:47:13Z",
3+ "phpVersion": "8.4.28",
4+ "extensions": {
5+ "Core": "8.4.28",
6+ "date": "8.4.28",
7+ "libxml": "8.4.28",
8+ "openssl": "8.4.28",
9+ "pcre": "8.4.28",
10+ "sqlite3": "8.4.28",
11+ "zlib": "8.4.28",
12+ "ctype": "8.4.28",
13+ "curl": "8.4.28",
14+ "dom": "20031129",
15+ "fileinfo": "8.4.28",
16+ "filter": "8.4.28",
17+ "hash": "8.4.28",
18+ "iconv": "8.4.28",
19+ "json": "8.4.28",
20+ "mbstring": "8.4.28",
21+ "SPL": "8.4.28",
22+ "session": "8.4.28",
23+ "PDO": "8.4.28",
24+ "pdo_sqlite": "8.4.28",
25+ "bz2": "8.4.28",
26+ "posix": "8.4.28",
27+ "random": "8.4.28",
28+ "readline": "8.4.28",
29+ "Reflection": "8.4.28",
30+ "standard": "8.4.28",
31+ "SimpleXML": "8.4.28",
32+ "tokenizer": "8.4.28",
33+ "xml": "8.4.28",
34+ "xmlreader": "8.4.28",
35+ "xmlwriter": "8.4.28",
36+ "mysqlnd": "mysqlnd 8.4.28",
37+ "amqp": "2.2.0",
38+ "apcu": "5.1.28",
39+ "ast": "1.1.4",
40+ "bcmath": "8.4.28",
41+ "Phar": "8.4.28",
42+ "calendar": "8.4.28",
43+ "csv": "0.3.0",
44+ "dba": "8.4.28",
45+ "decimal": "2.0.1",
46+ "ds": "2.0.0",
47+ "enchant": "8.4.28",
48+ "sockets": "8.4.28",
49+ "excimer": "1.2.6",
50+ "exif": "8.4.28",
51+ "FFI": "8.4.28",
52+ "gd": "8.4.28",
53+ "geospatial": "0.3.5",
54+ "gettext": "8.4.28",
55+ "gmp": "8.4.28",
56+ "gnupg": "1.5.4",
57+ "grpc": "1.85.0",
58+ "igbinary": "3.2.17RC1",
59+ "imap": "1.0.3",
60+ "inotify": "3.0.1",
61+ "intl": "8.4.28",
62+ "ion": "0.2.1",
63+ "json_post": "1.1.0",
64+ "ldap": "8.4.28",
65+ "luasandbox": "4.1.3",
66+ "lz4": "0.4.3",
67+ "lzf": "1.7.0",
68+ "mailparse": "3.2.0",
69+ "maxminddb": "1.15.0",
70+ "memcache": "8.2",
71+ "mongodb": "2.5.8",
72+ "msgpack": "3.0.1",
73+ "mysqli": "8.4.28",
74+ "OAuth": "2.0.10",
75+ "odbc": "8.4.28",
76+ "parle": "0.8.5",
77+ "pcntl": "8.4.28",
78+ "pcov": "1.0.12",
79+ "pdo_dblib": "8.4.28",
80+ "PDO_Firebird": "8.4.28",
81+ "pdo_mysql": "8.4.28",
82+ "PDO_ODBC": "8.4.28",
83+ "pdo_pgsql": "8.4.28",
84+ "pdo_sqlsrv": "5.13.3",
85+ "pgsql": "8.4.28",
86+ "php_trie": "0.1.2",
87+ "protobuf": "5.36.2",
88+ "pspell": "1.0.1",
89+ "rdkafka": "6.0.5",
90+ "redis": "6.3.0",
91+ "shmop": "8.4.28",
92+ "simdjson": "4.0.0",
93+ "smbclient": "1.2.0dev",
94+ "snappy": "0.2.1",
95+ "snmp": "8.4.28",
96+ "soap": "8.4.28",
97+ "ev": "1.3.1",
98+ "sodium": "8.4.28",
99+ "solr": "2.9.3",
100+ "SPX": "0.4.21",
101+ "sqlsrv": "5.13.3",
102+ "ssh2": "1.6.1",
103+ "Stomp": "2.0.3",
104+ "sysvmsg": "8.4.28",
105+ "sysvsem": "8.4.28",
106+ "sysvshm": "8.4.28",
107+ "tidy": "8.4.28",
108+ "timezonedb": "2026.6",
109+ "uploadprogress": "2.0.2",
110+ "uuid": "1.3.0",
111+ "vips": "1.0.13",
112+ "xdiff": "2.2.0",
113+ "xlswriter": "3.0.0",
114+ "xmldiff": "1.1.6",
115+ "xmlrpc": "1.0.0RC3",
116+ "xsl": "8.4.28",
117+ "yac": "3.0.2",
118+ "yaml": "2.3.0",
119+ "zephir_parser": "2.11.0",
120+ "zip": "1.22.8",
121+ "zstd": "0.18.0",
122+ "event": "3.2.0",
123+ "memcached": "3.4.0",
124+ "oci8": "3.4.1",
125+ "PDO_OCI": "1.2.0",
126+ "libsmbclient": "1.2.0dev",
127+ "Zend OPcache": "8.4.28"
128+ }
129+}
\ No newline at end of file\ No newline at end of file
added tests/Fixtures/FunctionRuntimes/php85.json +126 -0
new file mode 100644
@@ -0,0 +1,126 @@
1+{
2+ "measuredAt": "2026-11-22T11:44:54Z",
3+ "phpVersion": "8.5.13",
4+ "extensions": {
5+ "Core": "8.5.13",
6+ "date": "8.5.13",
7+ "lexbor": "8.5.13",
8+ "openssl": "8.5.13",
9+ "pcre": "8.5.13",
10+ "sqlite3": "8.5.13",
11+ "zlib": "8.5.13",
12+ "ctype": "8.5.13",
13+ "curl": "8.5.13",
14+ "uri": "8.5.13",
15+ "json": "8.5.13",
16+ "fileinfo": "8.5.13",
17+ "filter": "8.5.13",
18+ "hash": "8.5.13",
19+ "iconv": "8.5.13",
20+ "SPL": "8.5.13",
21+ "mbstring": "8.5.13",
22+ "Zend OPcache": "8.5.13",
23+ "session": "8.5.13",
24+ "standard": "8.5.13",
25+ "PDO": "8.5.13",
26+ "pdo_sqlite": "8.5.13",
27+ "bz2": "8.5.13",
28+ "posix": "8.5.13",
29+ "random": "8.5.13",
30+ "readline": "8.5.13",
31+ "Reflection": "8.5.13",
32+ "libxml": "8.5.13",
33+ "SimpleXML": "8.5.13",
34+ "tokenizer": "8.5.13",
35+ "dom": "20031129",
36+ "xml": "8.5.13",
37+ "xmlreader": "8.5.13",
38+ "xmlwriter": "8.5.13",
39+ "mysqlnd": "mysqlnd 8.5.13",
40+ "amqp": "2.2.0",
41+ "apcu": "5.1.28",
42+ "ast": "1.1.4",
43+ "bcmath": "8.5.13",
44+ "Phar": "8.5.13",
45+ "calendar": "8.5.13",
46+ "csv": "0.3.0",
47+ "dba": "8.5.13",
48+ "decimal": "2.0.1",
49+ "ds": "2.0.0",
50+ "enchant": "8.5.13",
51+ "sockets": "8.5.13",
52+ "excimer": "1.2.6",
53+ "exif": "8.5.13",
54+ "FFI": "8.5.13",
55+ "gd": "8.5.13",
56+ "gettext": "8.5.13",
57+ "gmp": "8.5.13",
58+ "gnupg": "1.5.4",
59+ "grpc": "1.85.0",
60+ "igbinary": "3.2.17RC1",
61+ "imap": "1.0.3",
62+ "inotify": "3.0.1",
63+ "intl": "8.5.13",
64+ "ion": "0.2.1",
65+ "json_post": "1.1.0",
66+ "ldap": "8.5.13",
67+ "luasandbox": "4.1.3",
68+ "lz4": "0.4.3",
69+ "lzf": "1.7.0",
70+ "mailparse": "3.2.0",
71+ "maxminddb": "1.15.0",
72+ "mongodb": "2.5.8",
73+ "msgpack": "3.0.1",
74+ "mysqli": "8.5.13",
75+ "OAuth": "2.0.10",
76+ "odbc": "8.5.13",
77+ "pcntl": "8.5.13",
78+ "pcov": "1.0.12",
79+ "pdo_dblib": "8.5.13",
80+ "PDO_Firebird": "8.5.13",
81+ "pdo_mysql": "8.5.13",
82+ "PDO_ODBC": "8.5.13",
83+ "pdo_pgsql": "8.5.13",
84+ "pdo_sqlsrv": "5.13.3",
85+ "pgsql": "8.5.13",
86+ "protobuf": "5.36.2",
87+ "pspell": "1.0.1",
88+ "rdkafka": "6.0.5",
89+ "redis": "6.3.0",
90+ "shmop": "8.5.13",
91+ "simdjson": "4.0.0",
92+ "smbclient": "1.2.0dev",
93+ "snappy": "0.2.1",
94+ "snmp": "8.5.13",
95+ "soap": "8.5.13",
96+ "ev": "1.3.1",
97+ "sodium": "8.5.13",
98+ "solr": "2.9.3",
99+ "SPX": "0.4.21",
100+ "sqlsrv": "5.13.3",
101+ "ssh2": "1.6.1",
102+ "sysvmsg": "8.5.13",
103+ "sysvsem": "8.5.13",
104+ "sysvshm": "8.5.13",
105+ "tidy": "8.5.13",
106+ "timezonedb": "2026.6",
107+ "uploadprogress": "2.0.2",
108+ "uuid": "1.3.0",
109+ "vips": "1.0.13",
110+ "xdiff": "2.2.0",
111+ "xlswriter": "3.0.0",
112+ "xmldiff": "1.1.6",
113+ "xmlrpc": "1.0.0RC3",
114+ "xsl": "8.5.13",
115+ "yac": "3.0.2",
116+ "yaml": "2.3.0",
117+ "zephir_parser": "2.11.0",
118+ "zip": "1.22.8",
119+ "zstd": "0.18.0",
120+ "event": "3.2.0",
121+ "memcached": "3.4.0",
122+ "oci8": "3.4.1",
123+ "PDO_OCI": "1.2.0",
124+ "libsmbclient": "1.2.0dev"
125+ }
126+}
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,126 @@
1+{
2+ "measuredAt": "2026-11-22T11:44:54Z",
3+ "phpVersion": "8.5.13",
4+ "extensions": {
5+ "Core": "8.5.13",
6+ "date": "8.5.13",
7+ "lexbor": "8.5.13",
8+ "openssl": "8.5.13",
9+ "pcre": "8.5.13",
10+ "sqlite3": "8.5.13",
11+ "zlib": "8.5.13",
12+ "ctype": "8.5.13",
13+ "curl": "8.5.13",
14+ "uri": "8.5.13",
15+ "json": "8.5.13",
16+ "fileinfo": "8.5.13",
17+ "filter": "8.5.13",
18+ "hash": "8.5.13",
19+ "iconv": "8.5.13",
20+ "SPL": "8.5.13",
21+ "mbstring": "8.5.13",
22+ "Zend OPcache": "8.5.13",
23+ "session": "8.5.13",
24+ "standard": "8.5.13",
25+ "PDO": "8.5.13",
26+ "pdo_sqlite": "8.5.13",
27+ "bz2": "8.5.13",
28+ "posix": "8.5.13",
29+ "random": "8.5.13",
30+ "readline": "8.5.13",
31+ "Reflection": "8.5.13",
32+ "libxml": "8.5.13",
33+ "SimpleXML": "8.5.13",
34+ "tokenizer": "8.5.13",
35+ "dom": "20031129",
36+ "xml": "8.5.13",
37+ "xmlreader": "8.5.13",
38+ "xmlwriter": "8.5.13",
39+ "mysqlnd": "mysqlnd 8.5.13",
40+ "amqp": "2.2.0",
41+ "apcu": "5.1.28",
42+ "ast": "1.1.4",
43+ "bcmath": "8.5.13",
44+ "Phar": "8.5.13",
45+ "calendar": "8.5.13",
46+ "csv": "0.3.0",
47+ "dba": "8.5.13",
48+ "decimal": "2.0.1",
49+ "ds": "2.0.0",
50+ "enchant": "8.5.13",
51+ "sockets": "8.5.13",
52+ "excimer": "1.2.6",
53+ "exif": "8.5.13",
54+ "FFI": "8.5.13",
55+ "gd": "8.5.13",
56+ "gettext": "8.5.13",
57+ "gmp": "8.5.13",
58+ "gnupg": "1.5.4",
59+ "grpc": "1.85.0",
60+ "igbinary": "3.2.17RC1",
61+ "imap": "1.0.3",
62+ "inotify": "3.0.1",
63+ "intl": "8.5.13",
64+ "ion": "0.2.1",
65+ "json_post": "1.1.0",
66+ "ldap": "8.5.13",
67+ "luasandbox": "4.1.3",
68+ "lz4": "0.4.3",
69+ "lzf": "1.7.0",
70+ "mailparse": "3.2.0",
71+ "maxminddb": "1.15.0",
72+ "mongodb": "2.5.8",
73+ "msgpack": "3.0.1",
74+ "mysqli": "8.5.13",
75+ "OAuth": "2.0.10",
76+ "odbc": "8.5.13",
77+ "pcntl": "8.5.13",
78+ "pcov": "1.0.12",
79+ "pdo_dblib": "8.5.13",
80+ "PDO_Firebird": "8.5.13",
81+ "pdo_mysql": "8.5.13",
82+ "PDO_ODBC": "8.5.13",
83+ "pdo_pgsql": "8.5.13",
84+ "pdo_sqlsrv": "5.13.3",
85+ "pgsql": "8.5.13",
86+ "protobuf": "5.36.2",
87+ "pspell": "1.0.1",
88+ "rdkafka": "6.0.5",
89+ "redis": "6.3.0",
90+ "shmop": "8.5.13",
91+ "simdjson": "4.0.0",
92+ "smbclient": "1.2.0dev",
93+ "snappy": "0.2.1",
94+ "snmp": "8.5.13",
95+ "soap": "8.5.13",
96+ "ev": "1.3.1",
97+ "sodium": "8.5.13",
98+ "solr": "2.9.3",
99+ "SPX": "0.4.21",
100+ "sqlsrv": "5.13.3",
101+ "ssh2": "1.6.1",
102+ "sysvmsg": "8.5.13",
103+ "sysvsem": "8.5.13",
104+ "sysvshm": "8.5.13",
105+ "tidy": "8.5.13",
106+ "timezonedb": "2026.6",
107+ "uploadprogress": "2.0.2",
108+ "uuid": "1.3.0",
109+ "vips": "1.0.13",
110+ "xdiff": "2.2.0",
111+ "xlswriter": "3.0.0",
112+ "xmldiff": "1.1.6",
113+ "xmlrpc": "1.0.0RC3",
114+ "xsl": "8.5.13",
115+ "yac": "3.0.2",
116+ "yaml": "2.3.0",
117+ "zephir_parser": "2.11.0",
118+ "zip": "1.22.8",
119+ "zstd": "0.18.0",
120+ "event": "3.2.0",
121+ "memcached": "3.4.0",
122+ "oci8": "3.4.1",
123+ "PDO_OCI": "1.2.0",
124+ "libsmbclient": "1.2.0dev"
125+ }
126+}
\ No newline at end of file\ No newline at end of file
added tests/FunctionRuntimeCatalogueTest.php +144 -0
new file mode 100644
@@ -0,0 +1,144 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime\Tests;
6+
7+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
8+use PHPUnit\Framework\TestCase;
9+
10+final class FunctionRuntimeCatalogueTest extends TestCase
11+{
12+ public function testCommittedCatalogueIsGeneratedFromTheProbeOutputs(): void
13+ {
14+ $files = glob(__DIR__.'/Fixtures/FunctionRuntimes/*.json') ?: [];
15+ self::assertNotEmpty($files);
16+
17+ self::assertSame(
18+ FunctionRuntimeCatalogue::generate(array_map(static fn (string $file): string => (string) file_get_contents($file), $files)),
19+ file_get_contents(FunctionRuntimeCatalogue::FILE),
20+ 'resources/function-runtimes.php is out of date: run "php probe/catalogue.php".',
21+ );
22+ }
23+
24+ public function testMeasuredFunctionRuntimesAreSupported(): void
25+ {
26+ $catalogue = FunctionRuntimeCatalogue::load();
27+
28+ self::assertSame(['php84', 'php85'], array_keys($catalogue->functionRuntimes));
29+ self::assertMatchesRegularExpression('/^8\.4\.\d+$/', $catalogue->get('php84')['php']);
30+ }
31+
32+ public function testNamesAndVersionsAreComposers(): void
33+ {
34+ $catalogue = self::generated([
35+ 'measuredAt' => '2026-11-22T11:47:13Z',
36+ 'phpVersion' => '8.4.28-1+deb12',
37+ 'extensions' => [
38+ 'Core' => '8.4.28',
39+ 'standard' => '8.4.28',
40+ 'Zend OPcache' => '8.4.28',
41+ 'PDO_OCI' => '1.2.0',
42+ 'mysqlnd' => 'mysqlnd 8.4.28',
43+ 'oddity' => '1.2.3 build 4',
44+ 'unversioned' => false,
45+ 'igbinary' => '3.2.17RC1',
46+ ],
47+ ]);
48+
49+ self::assertSame([
50+ 'php84' => [
51+ 'measuredAt' => '2026-11-22T11:47:13Z',
52+ 'php' => '8.4.28',
53+ 'extensions' => [
54+ 'ext-igbinary' => '3.2.17RC1',
55+ 'ext-mysqlnd' => '0',
56+ 'ext-oddity' => '1.2.3',
57+ 'ext-pdo_oci' => '1.2.0',
58+ 'ext-unversioned' => '0',
59+ 'ext-zend-opcache' => '8.4.28',
60+ ],
61+ ],
62+ ], $catalogue->functionRuntimes);
63+ }
64+
65+ public function testParseablePhpVersionIsKeptWhole(): void
66+ {
67+ $catalogue = self::generated(['measuredAt' => '2026-11-22T11:47:13Z', 'phpVersion' => '8.5.0-RC1', 'extensions' => []]);
68+
69+ self::assertSame('8.5.0-RC1', $catalogue->get('php85')['php']);
70+ }
71+
72+ public function testTwoMeasurementsOfTheSameFunctionRuntimeAreRefused(): void
73+ {
74+ $measurement = json_encode(['measuredAt' => '2026-11-22T11:47:13Z', 'phpVersion' => '8.4.28', 'extensions' => []], \JSON_THROW_ON_ERROR);
75+
76+ $this->expectExceptionMessage('Two probe outputs measure php84: keep one.');
77+
78+ FunctionRuntimeCatalogue::generate([$measurement, str_replace('8.4.28', '8.4.29', $measurement)]);
79+ }
80+
81+ public function testIncompleteMeasurementIsRefused(): void
82+ {
83+ $this->expectExceptionMessage('A probe output must hold "measuredAt", "phpVersion" and "extensions".');
84+
85+ FunctionRuntimeCatalogue::generate(['{"phpVersion": "8.4.28"}']);
86+ }
87+
88+ public function testUnmeasuredFunctionRuntimeIsRefused(): void
89+ {
90+ $this->expectExceptionMessage('"php83" is not a measured Function Runtime: use php84 or php85.');
91+
92+ FunctionRuntimeCatalogue::load()->get('php83');
93+ }
94+
95+ public function testChangesListWhatANewMeasurementChanged(): void
96+ {
97+ $old = new FunctionRuntimeCatalogue([
98+ 'php83' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.3.30', 'extensions' => []],
99+ 'php84' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.4.27', 'extensions' => ['ext-amqp' => '2.2.0', 'ext-ctype' => '8.4.27', 'ext-redis' => '6.3.0']],
100+ 'php85' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-redis' => '6.3.0']],
101+ ]);
102+ $new = new FunctionRuntimeCatalogue([
103+ 'php84' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.4.29', 'extensions' => ['ext-ctype' => '8.4.29', 'ext-foo' => '1.2.0', 'ext-redis' => '6.3.0']],
104+ 'php85' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-redis' => '6.3.0']],
105+ 'php86' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.6.0', 'extensions' => ['ext-redis' => '6.3.0']],
106+ ]);
107+
108+ self::assertSame([
109+ 'php83: no longer measured',
110+ 'php84: PHP 8.4.27 -> 8.4.29',
111+ 'php84: ext-ctype 8.4.27 -> 8.4.29',
112+ 'php84: + ext-foo 1.2.0',
113+ 'php84: - ext-amqp',
114+ 'php84: measured 2026-11-14T10:00:00Z -> 2026-11-29T10:00:00Z',
115+ 'php86: new Function Runtime, PHP 8.6.0 with 1 extensions',
116+ ], $new->changes($old));
117+ }
118+
119+ public function testNewMeasurementDatesAloneAreNoChange(): void
120+ {
121+ $catalogue = FunctionRuntimeCatalogue::load();
122+ $remeasured = new FunctionRuntimeCatalogue(array_map(static fn (array $functionRuntime): array => ['measuredAt' => '2099-01-01T00:00:00Z'] + $functionRuntime, $catalogue->functionRuntimes));
123+
124+ self::assertSame([], $remeasured->changes($catalogue));
125+ }
126+
127+ /**
128+ * @param array<string, mixed> $measurement
129+ */
130+ private static function generated(array $measurement): FunctionRuntimeCatalogue
131+ {
132+ $file = tempnam(sys_get_temp_dir(), 'catalogue');
133+ self::assertNotFalse($file);
134+ try {
135+ file_put_contents($file, FunctionRuntimeCatalogue::generate([json_encode($measurement, \JSON_THROW_ON_ERROR)]));
136+ /** @var array<string, array{measuredAt: string, php: string, extensions: array<string, string>}> $functionRuntimes */
137+ $functionRuntimes = require $file;
138+
139+ return new FunctionRuntimeCatalogue($functionRuntimes);
140+ } finally {
141+ unlink($file);
142+ }
143+ }
144+}
new file mode 100644
@@ -0,0 +1,144 @@
1+<?php
2+
3+declare(strict_types=1);
4+
5+namespace JDecool\ScalewayRuntime\Tests;
6+
7+use JDecool\ScalewayRuntime\FunctionRuntimeCatalogue;
8+use PHPUnit\Framework\TestCase;
9+
10+final class FunctionRuntimeCatalogueTest extends TestCase
11+{
12+ public function testCommittedCatalogueIsGeneratedFromTheProbeOutputs(): void
13+ {
14+ $files = glob(__DIR__.'/Fixtures/FunctionRuntimes/*.json') ?: [];
15+ self::assertNotEmpty($files);
16+
17+ self::assertSame(
18+ FunctionRuntimeCatalogue::generate(array_map(static fn (string $file): string => (string) file_get_contents($file), $files)),
19+ file_get_contents(FunctionRuntimeCatalogue::FILE),
20+ 'resources/function-runtimes.php is out of date: run "php probe/catalogue.php".',
21+ );
22+ }
23+
24+ public function testMeasuredFunctionRuntimesAreSupported(): void
25+ {
26+ $catalogue = FunctionRuntimeCatalogue::load();
27+
28+ self::assertSame(['php84', 'php85'], array_keys($catalogue->functionRuntimes));
29+ self::assertMatchesRegularExpression('/^8\.4\.\d+$/', $catalogue->get('php84')['php']);
30+ }
31+
32+ public function testNamesAndVersionsAreComposers(): void
33+ {
34+ $catalogue = self::generated([
35+ 'measuredAt' => '2026-11-22T11:47:13Z',
36+ 'phpVersion' => '8.4.28-1+deb12',
37+ 'extensions' => [
38+ 'Core' => '8.4.28',
39+ 'standard' => '8.4.28',
40+ 'Zend OPcache' => '8.4.28',
41+ 'PDO_OCI' => '1.2.0',
42+ 'mysqlnd' => 'mysqlnd 8.4.28',
43+ 'oddity' => '1.2.3 build 4',
44+ 'unversioned' => false,
45+ 'igbinary' => '3.2.17RC1',
46+ ],
47+ ]);
48+
49+ self::assertSame([
50+ 'php84' => [
51+ 'measuredAt' => '2026-11-22T11:47:13Z',
52+ 'php' => '8.4.28',
53+ 'extensions' => [
54+ 'ext-igbinary' => '3.2.17RC1',
55+ 'ext-mysqlnd' => '0',
56+ 'ext-oddity' => '1.2.3',
57+ 'ext-pdo_oci' => '1.2.0',
58+ 'ext-unversioned' => '0',
59+ 'ext-zend-opcache' => '8.4.28',
60+ ],
61+ ],
62+ ], $catalogue->functionRuntimes);
63+ }
64+
65+ public function testParseablePhpVersionIsKeptWhole(): void
66+ {
67+ $catalogue = self::generated(['measuredAt' => '2026-11-22T11:47:13Z', 'phpVersion' => '8.5.0-RC1', 'extensions' => []]);
68+
69+ self::assertSame('8.5.0-RC1', $catalogue->get('php85')['php']);
70+ }
71+
72+ public function testTwoMeasurementsOfTheSameFunctionRuntimeAreRefused(): void
73+ {
74+ $measurement = json_encode(['measuredAt' => '2026-11-22T11:47:13Z', 'phpVersion' => '8.4.28', 'extensions' => []], \JSON_THROW_ON_ERROR);
75+
76+ $this->expectExceptionMessage('Two probe outputs measure php84: keep one.');
77+
78+ FunctionRuntimeCatalogue::generate([$measurement, str_replace('8.4.28', '8.4.29', $measurement)]);
79+ }
80+
81+ public function testIncompleteMeasurementIsRefused(): void
82+ {
83+ $this->expectExceptionMessage('A probe output must hold "measuredAt", "phpVersion" and "extensions".');
84+
85+ FunctionRuntimeCatalogue::generate(['{"phpVersion": "8.4.28"}']);
86+ }
87+
88+ public function testUnmeasuredFunctionRuntimeIsRefused(): void
89+ {
90+ $this->expectExceptionMessage('"php83" is not a measured Function Runtime: use php84 or php85.');
91+
92+ FunctionRuntimeCatalogue::load()->get('php83');
93+ }
94+
95+ public function testChangesListWhatANewMeasurementChanged(): void
96+ {
97+ $old = new FunctionRuntimeCatalogue([
98+ 'php83' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.3.30', 'extensions' => []],
99+ 'php84' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.4.27', 'extensions' => ['ext-amqp' => '2.2.0', 'ext-ctype' => '8.4.27', 'ext-redis' => '6.3.0']],
100+ 'php85' => ['measuredAt' => '2026-11-14T10:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-redis' => '6.3.0']],
101+ ]);
102+ $new = new FunctionRuntimeCatalogue([
103+ 'php84' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.4.29', 'extensions' => ['ext-ctype' => '8.4.29', 'ext-foo' => '1.2.0', 'ext-redis' => '6.3.0']],
104+ 'php85' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.5.13', 'extensions' => ['ext-redis' => '6.3.0']],
105+ 'php86' => ['measuredAt' => '2026-11-29T10:00:00Z', 'php' => '8.6.0', 'extensions' => ['ext-redis' => '6.3.0']],
106+ ]);
107+
108+ self::assertSame([
109+ 'php83: no longer measured',
110+ 'php84: PHP 8.4.27 -> 8.4.29',
111+ 'php84: ext-ctype 8.4.27 -> 8.4.29',
112+ 'php84: + ext-foo 1.2.0',
113+ 'php84: - ext-amqp',
114+ 'php84: measured 2026-11-14T10:00:00Z -> 2026-11-29T10:00:00Z',
115+ 'php86: new Function Runtime, PHP 8.6.0 with 1 extensions',
116+ ], $new->changes($old));
117+ }
118+
119+ public function testNewMeasurementDatesAloneAreNoChange(): void
120+ {
121+ $catalogue = FunctionRuntimeCatalogue::load();
122+ $remeasured = new FunctionRuntimeCatalogue(array_map(static fn (array $functionRuntime): array => ['measuredAt' => '2099-01-01T00:00:00Z'] + $functionRuntime, $catalogue->functionRuntimes));
123+
124+ self::assertSame([], $remeasured->changes($catalogue));
125+ }
126+
127+ /**
128+ * @param array<string, mixed> $measurement
129+ */
130+ private static function generated(array $measurement): FunctionRuntimeCatalogue
131+ {
132+ $file = tempnam(sys_get_temp_dir(), 'catalogue');
133+ self::assertNotFalse($file);
134+ try {
135+ file_put_contents($file, FunctionRuntimeCatalogue::generate([json_encode($measurement, \JSON_THROW_ON_ERROR)]));
136+ /** @var array<string, array{measuredAt: string, php: string, extensions: array<string, string>}> $functionRuntimes */
137+ $functionRuntimes = require $file;
138+
139+ return new FunctionRuntimeCatalogue($functionRuntimes);
140+ } finally {
141+ unlink($file);
142+ }
143+ }
144+}
modified tests/PackagerTest.php +56 -2
@@ -171,9 +171,63 @@ final class PackagerTest extends TestCase
171171 self::assertFileDoesNotExist($this->dir.'/function.zip');
172172 }
173173
174- private function package(): void
174+ public function testPlatformRequirementsAreCheckedAgainstTheFunctionRuntimeBeforeZipping(): void
175175 {
176- new Packager($this->appDir, $this->log)->package($this->dir.'/function.zip');
176+ $this->requireInTheLock(['php' => '>=8.4']);
177+
178+ $this->package('php84');
179+
180+ self::assertFileExists($this->dir.'/function.zip');
181+ self::assertStringContainsString('1 satisfied, 0 unknown, 0 incompatible on php84', $this->log());
182+ }
183+
184+ public function testIncompatiblePlatformRequirementLeavesNoZip(): void
185+ {
186+ $this->requireInTheLock(['ext-not-on-scaleway' => '*']);
187+
188+ try {
189+ $this->package('php84');
190+ self::fail('The application must be refused.');
191+ } catch (\RuntimeException $e) {
192+ self::assertStringStartsWith('php84 does not meet the Platform Requirements above', $e->getMessage());
193+ }
194+ self::assertStringContainsString('INCOMPATIBLE ext-not-on-scaleway * required by acme/lib 1.0.0', $this->log());
195+ self::assertFileDoesNotExist($this->dir.'/function.zip');
196+ }
197+
198+ public function testPlatformRequirementsAreNotCheckedWithoutAFunctionRuntime(): void
199+ {
200+ $this->requireInTheLock(['ext-not-on-scaleway' => '*']);
201+
202+ $this->package();
203+
204+ self::assertFileExists($this->dir.'/function.zip');
205+ self::assertStringNotContainsString('ext-not-on-scaleway', $this->log());
206+ }
207+
208+ private function package(?string $functionRuntime = null): void
209+ {
210+ new Packager($this->appDir, $this->log)->package($this->dir.'/function.zip', $functionRuntime);
211+ }
212+
213+ /**
214+ * @param array<string, string> $require of the locked acme/lib, which leaves the lock in sync with composer.json
215+ */
216+ private function requireInTheLock(array $require): void
217+ {
218+ $lock = json_decode((string) file_get_contents($this->appDir.'/composer.lock'), true);
219+ self::assertIsArray($lock);
220+ self::assertIsArray($lock['packages']);
221+ self::assertIsArray($lock['packages'][0]);
222+ $lock['packages'][0]['require'] = $require;
223+ $this->filesystem->dumpFile($this->appDir.'/composer.lock', (string) json_encode($lock));
224+ }
225+
226+ private function log(): string
227+ {
228+ rewind($this->log);
229+
230+ return (string) stream_get_contents($this->log);
177231 }
178232
179233 /**
@@ -171,9 +171,63 @@ final class PackagerTest extends TestCase
171 self::assertFileDoesNotExist($this->dir.'/function.zip');171 self::assertFileDoesNotExist($this->dir.'/function.zip');
172 }172 }
173 173
174- private function package(): void174+ public function testPlatformRequirementsAreCheckedAgainstTheFunctionRuntimeBeforeZipping(): void
175 {175 {
176- new Packager($this->appDir, $this->log)->package($this->dir.'/function.zip');176+ $this->requireInTheLock(['php' => '>=8.4']);
177+
178+ $this->package('php84');
179+
180+ self::assertFileExists($this->dir.'/function.zip');
181+ self::assertStringContainsString('1 satisfied, 0 unknown, 0 incompatible on php84', $this->log());
182+ }
183+
184+ public function testIncompatiblePlatformRequirementLeavesNoZip(): void
185+ {
186+ $this->requireInTheLock(['ext-not-on-scaleway' => '*']);
187+
188+ try {
189+ $this->package('php84');
190+ self::fail('The application must be refused.');
191+ } catch (\RuntimeException $e) {
192+ self::assertStringStartsWith('php84 does not meet the Platform Requirements above', $e->getMessage());
193+ }
194+ self::assertStringContainsString('INCOMPATIBLE ext-not-on-scaleway * required by acme/lib 1.0.0', $this->log());
195+ self::assertFileDoesNotExist($this->dir.'/function.zip');
196+ }
197+
198+ public function testPlatformRequirementsAreNotCheckedWithoutAFunctionRuntime(): void
199+ {
200+ $this->requireInTheLock(['ext-not-on-scaleway' => '*']);
201+
202+ $this->package();
203+
204+ self::assertFileExists($this->dir.'/function.zip');
205+ self::assertStringNotContainsString('ext-not-on-scaleway', $this->log());
206+ }
207+
208+ private function package(?string $functionRuntime = null): void
209+ {
210+ new Packager($this->appDir, $this->log)->package($this->dir.'/function.zip', $functionRuntime);
211+ }
212+
213+ /**
214+ * @param array<string, string> $require of the locked acme/lib, which leaves the lock in sync with composer.json
215+ */
216+ private function requireInTheLock(array $require): void
217+ {
218+ $lock = json_decode((string) file_get_contents($this->appDir.'/composer.lock'), true);
219+ self::assertIsArray($lock);
220+ self::assertIsArray($lock['packages']);
221+ self::assertIsArray($lock['packages'][0]);
222+ $lock['packages'][0]['require'] = $require;
223+ $this->filesystem->dumpFile($this->appDir.'/composer.lock', (string) json_encode($lock));
224+ }
225+
226+ private function log(): string
227+ {
228+ rewind($this->log);
229+
230+ return (string) stream_get_contents($this->log);
177 }231 }
178 232
179 /**233 /**