Skip to content

fix(activity:list): handle null result on in-progress activities#59

Merged
miguelsanchez-upsun merged 2 commits intomainfrom
fix/activity-result-null
Apr 29, 2026
Merged

fix(activity:list): handle null result on in-progress activities#59
miguelsanchez-upsun merged 2 commits intomainfrom
fix/activity-result-null

Conversation

@pjcdawkins
Copy link
Copy Markdown
Contributor

Summary

Fixes #57. ActivityMonitor::formatResult() threw a TypeError when invoked on an activity whose result was null (i.e. still in progress). The bug surfaced after upstream legacy-cli #1572 changed the signature to take an Activity object instead of the string result and started reading $activity->result internally.

The fix coerces a missing result to an empty string before the result-name lookup so the function always returns a string. An empty result column in activity:list for in-progress activities matches the column's prior behavior.

Changes

  • legacy/src/Service/ActivityMonitor.php - guard against null $activity->result.
  • legacy/tests/Service/ActivityMonitorTest.php - new unit tests covering success, failure, null/in-progress, and failed-command-override paths.
  • legacy/phpstan-stubs/Activity.stub + legacy/phpstan.neon - local PHPStan stub that marks result, completed_at and started_at as ?string. The upstream client docblock has them as non-null string, which is why PHPStan did not catch this. With the stub in place, running PHPStan at level 8 flags the original bug (and the equivalent fix passes); the project still runs at level 7 by default.

ActivityMonitor::formatResult() crashed with a TypeError when invoked on
an activity whose result property was null (i.e. not yet finished).
Coerce a missing result to an empty string before looking it up in the
result-name map, so the function can always return a string.

The bug surfaced after the change in formatResult's signature to take an
Activity object rather than a string result, in legacy-cli #1572.

Add a unit test for ActivityMonitor::formatResult covering success,
failure, null/in-progress, and the failed-command override path.

Add a PHPStan stub for Platformsh\Client\Model\Activity that marks
result, completed_at and started_at as nullable. The upstream docblock
declares them as non-null strings, which is why static analysis did not
catch this. Running PHPStan at level 8 with the stub in place would have
flagged the original bug.

Closes #57

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 29, 2026 12:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a runtime TypeError in ActivityMonitor::formatResult() when formatting in-progress activities whose result is null, aligning activity:list output with prior behavior (empty result column) and improving static analysis coverage via a local PHPStan stub.

Changes:

  • Coerce a null activity result to '' before doing the result-name lookup.
  • Add PHPUnit coverage for success, failure, in-progress/null-result, and failed-command override paths.
  • Configure PHPStan to load a local stub for Platformsh\Client\Model\Activity with nullable timestamp/result properties.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
legacy/src/Service/ActivityMonitor.php Prevents formatResult() from returning null by normalizing a null result to an empty string.
legacy/tests/Service/ActivityMonitorTest.php Adds unit tests covering the fixed null-result/in-progress behavior and command failure overrides.
legacy/phpstan.neon Registers the local Activity stub file for PHPStan analysis.
legacy/phpstan-stubs/Activity.stub Documents nullable Activity model properties for more accurate static analysis.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread legacy/tests/Service/ActivityMonitorTest.php
Comment thread legacy/tests/Service/ActivityMonitorTest.php
Comment thread legacy/phpstan-stubs/Activity.stub
Address PR review feedback:

- Set 'result' => null explicitly in the null-result test fixtures so
  the intent is unambiguous and not reliant on Activity model defaults.
- Bring the PHPStan stub in line with Upsun's OpenAPI spec: mark
  created_at, updated_at, description and text as nullable; add
  cancelled_at, expires_at, integration and timings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@miguelsanchez-upsun miguelsanchez-upsun merged commit 510b2a8 into main Apr 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal error in ActivityMonitor with version 5.10.*

3 participants