Skip to content

🐛 fix(mymemory): hydrate source and target language codes on TM matches - #4710

Open
mauretto78 wants to merge 3 commits into
developfrom
fix-mymemory-missing-languages
Open

🐛 fix(mymemory): hydrate source and target language codes on TM matches#4710
mauretto78 wants to merge 3 commits into
developfrom
fix-mymemory-missing-languages

Conversation

@mauretto78

@mauretto78 mauretto78 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

MyMemory TM matches were losing their source/target language codes, and segment/
translation could end up null when the API response omitted those keys. This fixes
MyMemory::_decode() and GetMemoryResponse::buildMyMemoryMatch() to hydrate source/
target from the engine config and to always default segment/translation to an empty
string.

Type

  • feat — new user-facing feature
  • fix — bug fix
  • refactor — restructure without behavior change
  • chore — build, deps, config, docs
  • perf — performance improvement
  • test — test coverage

Changes

File Change
lib/Utils/Engines/MyMemory.php inject source/target from $this->_config into decoded matches; default segment/translation to '' when absent
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php hydrate source/target (and null-safe tm_properties) onto Matches in buildMyMemoryMatch()
tests/unit/Core/Engines/Results/MyMemory/GetMemoryResponseTest.php new regression tests for missing segment/translation, missing tm_properties, and source/target hydration

Testing

  • vendor/bin/phpunit --exclude-group=ExternalServices --no-coverage passes
  • ./vendor/bin/phpstan passes (0 errors, with baseline)
  • Manual testing performed (describe below)
  • New tests added for changed behavior
  • Regression tests added for bug fixes

Ran the full suite in Docker: 9222 tests, 30003 assertions. 4 pre-existing failures in
CommentControllerTest (broker-unavailable scenarios) are environment-dependent and
unrelated to this change — they also fail on develop in this environment since the
ActiveMQ broker container is reachable rather than down.

phpstan run clean (0 errors) on all three changed files.

AI Disclosure

  • No AI tools were used in this PR
  • AI tools were used — name the agent/tool below

Claude Code (claude-sonnet-5)

Notes

None.


- inject source/target language codes from engine config into decoded MyMemory
  matches in MyMemory::_decode() so they survive to the response layer
- default segment/translation to empty string instead of relying on undefined
  array keys when the API omits them
- hydrate source/target and tm_properties fields on
  GetMemoryResponse::buildMyMemoryMatch() so they reach the Matches object
- add unit tests covering missing segment/translation, missing tm_properties,
  and source/target hydration
@github-actions

Copy link
Copy Markdown

🧪 Test-Guard Report

✅ PASS — All changed source files have adequate test coverage.

Coverage Analysis: ✅ PASS

Changed lines: 100.0% covered (threshold: 80%)

📋 2 files: 2 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ✅ pass 100% diff coverage ≥ 80% threshold
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass 100% diff coverage ≥ 80% threshold

Result: ✅ PASS

@github-actions

Copy link
Copy Markdown

🧪 Test-Guard Report

⚠️ WARNING — Test coverage has minor gaps — review recommended.

Coverage Analysis: ❌ FAIL

Changed lines: 100.0% covered (threshold: 80%)

📋 5 files: 3 ❌ fail, 2 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ✅ pass 100% diff coverage ≥ 80% threshold
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass 100% diff coverage ≥ 80% threshold
public/js/components/segments/SegmentFooterMultiMatches.js ❌ fail not in coverage report
public/js/components/segments/SegmentFooterTabMatches.js ❌ fail not in coverage report
public/js/components/segments/TabConcordanceResults.js ❌ fail not in coverage report

Test File Matching: ❌ FAIL

File matching: 1 pass, 4 fail

📋 5 files: 4 ❌ fail, 1 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ❌ fail No matching test file found
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass Test file modified in PR: tests/unit/Core/Engines/Results/MyMemory/GetMemoryResponseTest.php
public/js/components/segments/SegmentFooterMultiMatches.js ❌ fail No matching test file found
public/js/components/segments/SegmentFooterTabMatches.js ❌ fail No matching test file found
public/js/components/segments/TabConcordanceResults.js ❌ fail No matching test file found

Per-File Evaluation: ⚠️ WARNING

Evaluated 5 files: 3 via AI (1 batch), 2 via shortcuts.

📋 5 files: 3 ⚠️ warning, 2 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ✅ pass shortcut → coverage 100% ≥ 80%
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass shortcut → coverage 100% ≥ 80%
public/js/components/segments/SegmentFooterMultiMatches.js ⚠️ warning No coverage data; new branches for source/target penalty display untested.
public/js/components/segments/SegmentFooterTabMatches.js ⚠️ warning No coverage data; added penalty tooltip and conditional rendering not verified by tests.
public/js/components/segments/TabConcordanceResults.js ⚠️ warning No coverage data; added conditional styling and refs without test verification.

Result: ⚠️ WARNING


Why this FAIL?

  • Coverage Analysis: The JavaScript files under public/js/components/segments (SegmentFooterMultiMatches.js, SegmentFooterTabMatches.js, TabConcordanceResults.js) are missing from the coverage report, indicating a coverage configuration issue that prevents coverage data collection → update coverage instrumentation/configuration to include these files.
  • Test File Matching: No matching test files were found for lib/Utils/Engines/MyMemory.php and the three JavaScript segment components, meaning these source files lack associated tests → consider adding or linking appropriate tests for these files.
  • Per-File Evaluation: The three JavaScript segment files have new or changed UI logic (penalty display, tooltips, conditional rendering, styling, refs) that are untested due to missing coverage data → add tests to verify these UI behaviors.
  • Test File Matching: The PHP file lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php has a matching test file modified in this PR and full coverage → no action needed.

To resolve: configure coverage to include the JavaScript segment files and add or link tests that cover their new or changed UI logic.

Comment thread lib/Utils/Engines/MyMemory.php Outdated
$decoded['matches'][$pos]['segment'] = $match['segment'] ?? '';
$decoded['matches'][$pos]['translation'] = $match['translation'] ?? '';
$decoded['matches'][$pos]['target_note'] = $match['target_note'] ?? '';
$decoded['matches'][$pos]['source'] = $this->_config['source'] ?? $match['source'] ?? '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, we are using the match language returned by MyMemory as a fallback—prioritizing it over the language defined in the class configuration, which might eventually be populated with Matecat's source/target values. Currently, this fallback has no effect because $this->_config['source'/'target'] are always null, but if we start using those values ​​later, the feature will break. The two parameters need to be swapped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed — swapped the precedence in MyMemory::_decode() so $match['source']/$match['target'] now win over $this->_config, with config only used as a fallback when the match omits them. Added two regression tests in DecodeMyMemoryTest covering both directions (match wins when present, config used when absent). Pushed as 539447f.

Ostico noted the fallback precedence was backwards: _decode() prioritized
$this->_config['source'/'target'] over the value MyMemory returns on the
match itself. That currently has no visible effect since _config is never
populated with those keys, but would silently break real match language
codes the moment it is. Swap the precedence so the match's own value wins,
falling back to config only when the match omits it, and add regression
tests for both directions.
@mauretto78

Copy link
Copy Markdown
Contributor Author

@Ostico Addressed your review comment — fixed the precedence swap in MyMemory::_decode() and added regression tests. Ready for another look.

@github-actions

Copy link
Copy Markdown

🧪 Test-Guard Report

⚠️ WARNING — Test coverage has minor gaps — review recommended.

Coverage Analysis: ❌ FAIL

Changed lines: 100.0% covered (threshold: 80%)

📋 5 files: 3 ❌ fail, 2 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ✅ pass 100% diff coverage ≥ 80% threshold
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass 100% diff coverage ≥ 80% threshold
public/js/components/segments/SegmentFooterMultiMatches.js ❌ fail not in coverage report
public/js/components/segments/SegmentFooterTabMatches.js ❌ fail not in coverage report
public/js/components/segments/TabConcordanceResults.js ❌ fail not in coverage report

Test File Matching: ❌ FAIL

File matching: 1 pass, 4 fail

📋 5 files: 4 ❌ fail, 1 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ❌ fail No matching test file found
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass Test file modified in PR: tests/unit/Core/Engines/Results/MyMemory/GetMemoryResponseTest.php
public/js/components/segments/SegmentFooterMultiMatches.js ❌ fail No matching test file found
public/js/components/segments/SegmentFooterTabMatches.js ❌ fail No matching test file found
public/js/components/segments/TabConcordanceResults.js ❌ fail No matching test file found

Per-File Evaluation: ⚠️ WARNING

Evaluated 5 files: 3 via AI (1 batch), 2 via shortcuts.

📋 5 files: 3 ⚠️ warning, 2 ✅ pass
File Verdict Reason
lib/Utils/Engines/MyMemory.php ✅ pass shortcut → coverage 100% ≥ 80%
lib/Utils/Engines/Results/MyMemory/GetMemoryResponse.php ✅ pass shortcut → coverage 100% ≥ 80%
public/js/components/segments/SegmentFooterMultiMatches.js ⚠️ warning No coverage data; changes add UI elements and conditional classes without test evidence.
public/js/components/segments/SegmentFooterTabMatches.js ⚠️ warning No coverage data; adds conditional UI elements and tooltips, no test evidence.
public/js/components/segments/TabConcordanceResults.js ⚠️ warning No coverage data; adds UI elements with conditional classes, no test evidence.

Result: ⚠️ WARNING


Why this FAIL?

  • Coverage Analysis: The JavaScript files under public/js/components/segments (SegmentFooterMultiMatches.js, SegmentFooterTabMatches.js, TabConcordanceResults.js) are missing from the coverage report entirely → likely a coverage configuration issue (source filter or instrumentation) that prevents coverage data collection for these files.
  • Test File Matching: No matching test files found for the changed JavaScript segment files and for lib/Utils/Engines/MyMemory.php → tests are missing or not named to match these source files, so test presence is unconfirmed.
  • Per-File Evaluation: AI flagged the three segment JS files for adding UI elements and conditional logic without any test evidence → indicates missing tests for new UI behavior.
  • Per-File Evaluation: lib/Utils/Engines/MyMemory.php and its related GetMemoryResponse.php have full coverage and matching tests → no action needed for these files.

To resolve: Add or configure test coverage and matching tests for the changed JavaScript segment files and add tests for lib/Utils/Engines/MyMemory.php, and fix coverage instrumentation to include these JS files.

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.

3 participants