Skip to content

test: kill escaped mutants in certificate FileService - #8079

Merged
vitormattos merged 1 commit into
LibreSign:mainfrom
maia-andre:test/8053-certificate-file-service
Aug 27, 2026
Merged

test: kill escaped mutants in certificate FileService#8079
vitormattos merged 1 commit into
LibreSign:mainfrom
maia-andre:test/8053-certificate-file-service

Conversation

@maia-andre

Copy link
Copy Markdown
Contributor

Ref: #8053

📝 Summary

One focused source/test pair from #8053:

  • lib/Service/Certificate/FileService.php
  • tests/php/Unit/Service/Certificate/FileServiceTest.php

Infection reported 8 escaped mutants for this file (Covered Code MSI 57.89%): the path concatenation in loadCertificateFileByGeneration() (5 Concat/ConcatOperandRemoval mutants) and the guards in readCertificateFile() (3 LogicalNot/LogicalOr mutants). All existing scenarios asserted only the empty-string fallback and never read an existing certificate file, so mutants that broke the path building or the guards kept every test green.

This PR only adds tests — no production code changes:

  • testReturnsContentOfExistingCertificateFile (data provider): creates real ca.pem/ca-key.pem files in the vfsStream virtual filesystem, with different contents, and asserts each public method returns the content of its own file. Kills the 5 path-concatenation mutants and 2 of the guard mutants.
  • testReturnsEmptyStringWhenCertificateFileIsNotReadable: existing file with chmod 0o000 in the virtual filesystem; asserts the guard rejects it silently (empty string, no debug log). Kills the remaining ||&& guard mutant.

After the change, Infection reports 20/20 mutants killed — Covered Code MSI 100% for this scope, with no errors and no timeouts.

Note on the ||&& guard mutant: original and mutated code both return '' for an existing-but-unreadable file. What kills the mutant is that the mutated code reaches file_get_contents() and triggers a PHP warning, which fails the run because the project sets failOnWarning="true" in tests/php/phpunit.xml. The observable behavior protected here is "an unreadable file is rejected by the guard without attempting to read it".

🧪 How to test

composer test:unit -- --filter FileServiceTest

XDEBUG_MODE=coverage vendor/bin/infection --configuration=infection.json5 \
  --test-framework-options="--testsuite=unit" --show-mutations \
  lib/Service/Certificate/FileService.php

Expected: 12 tests green; 20 mutants generated, 20 killed, Covered Code MSI 100%.

⚙️ API / Back‑end changes

  • Unit and/or integration tests added – required for backend changes

Test-only change; no production code, capabilities, or API documentation affected.

✅ Checklist

  • I have read and followed the contribution guide.
  • Focused PHPUnit, focused Infection and php-cs-fixer pass for the changed file.

🤖 AI (if applicable)

  • The content of this PR was partially or fully generated using AI

Infection reported 8 escaped mutants in lib/Service/Certificate/FileService.php
(Covered Code MSI 57.89%): the path concatenation in
loadCertificateFileByGeneration() and the file_exists/is_readable guards in
readCertificateFile() were never exercised with an existing certificate file.

Add scenarios reading real ca.pem/ca-key.pem files from the virtual filesystem
and an existing-but-unreadable file case. Covered Code MSI is now 100% for this
scope (20/20 mutants killed).

Ref LibreSign#8053

Assisted-by: Claude Code:claude-fable-5
Signed-off-by: André Maia <andrefnkmm@gmail.com>
@github-project-automation github-project-automation Bot moved this from 0. Backlog to 1. to do in Roadmap Aug 27, 2026
@vitormattos

Copy link
Copy Markdown
Member

/backport to stable35

@vitormattos

Copy link
Copy Markdown
Member

/backport to stable34

@vitormattos

Copy link
Copy Markdown
Member

/backport to stable33

@vitormattos

Copy link
Copy Markdown
Member

/backport to stable32

@vitormattos
vitormattos merged commit 3e739aa into LibreSign:main Aug 27, 2026
72 checks passed
@github-project-automation github-project-automation Bot moved this from 1. to do to 4. to release in Roadmap Aug 27, 2026
@backportbot-libresign

Copy link
Copy Markdown

The backport to stable32 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable32
git pull origin stable32

# Create the new backport branch
git checkout -b backport/8079/stable32

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick c015a47a

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/8079/stable32

Error: Failed to push branch backport/8079/stable32: remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/LibreSign/libresign.git/'


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 4. to release

Development

Successfully merging this pull request may close these issues.

2 participants