Fix system instruction loading failing on repeated calls#358
Fix system instruction loading failing on repeated calls#358
Conversation
…_file Calling get_system_instruction() twice with the same explicit filename silently returns an empty string on the second call because require_once returns true instead of the file's return value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> EOF )
Change require_once to require so the file's return value is always returned, not just on the first inclusion. This matches the behavior already used on line 175 for the automatic detection path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move shared ability construction and feature dir resolution into setUp. Add a helper for temp file lifecycle with automatic cleanup in tearDown. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @copilot. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #358 +/- ##
==========================================
Coverage 57.70% 57.70%
Complexity 617 617
==========================================
Files 46 46
Lines 3173 3173
==========================================
Hits 1831 1831
Misses 1342 1342
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…tyTest Expose experiment as instance property so delegate tests can assert against it, and add native PHP types to all test class properties. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a0cc159 to
d2e658b
Compare
There was a problem hiding this comment.
Pull request overview
Fixes repeated system-instruction loads returning an empty string by ensuring the instruction file’s return value is retrieved on every call, and adds/updates integration tests to prevent regressions.
Changes:
- Switch explicit system-instruction loading from
require_oncetorequireto preserve the file’s returned string across consecutive calls. - Refactor
Abstract_AbilityTestsetup/cleanup to reduce duplication and add a regression test for consecutive calls. - Add a temp file helper and centralized cleanup in
tearDown().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| includes/Abstracts/Abstract_Ability.php | Fixes repeated loads by using require so the returned instruction string is available on every call. |
| tests/Integration/Includes/Abstracts/Abstract_AbilityTest.php | Refactors common setup and adds coverage for the consecutive-call regression scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ire_once references Agent-Logs-Url: https://github.com/WordPress/ai/sessions/d1d20095-084d-4a31-9bb9-3a41869f6494 Co-authored-by: gziolo <699132+gziolo@users.noreply.github.com>
What?
Fix
load_system_instruction_from_file()silently returning an empty string whenget_system_instruction()is called more than once with the same explicit filename in a single request.Why?
The method used
require_onceto load instruction files. On the first call, PHP returns the file's return value (the instruction string). On subsequent calls,require_oncereturnstrueinstead, causingis_string($content)to fail and the method to silently return''.How?
require_oncetorequire, consistent with the automatic detection path which already usesrequireget_system_instruction()twice with the same file and asserts both calls return the instructionAbstract_AbilityTestby extracting shared setup intosetUp()and a temp file helperTesting Instructions
composer installnpm run test:php -- --filter='Abstract_AbilityTest'— all 10 tests should passnpm run test:php— all tests should pass