Repository navigation
test: kill the surviving mutants in the Livestatus backend, commands and host import - #83
Merged
Merged
Conversation
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ection Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Replace the per-file api_device_save() stand-ins by one stub with the signature of lib/api_device.php, recorded by parameter name, and move the page frame and CSRF stubs into the same file so the result no longer depends on which test file runs first. Reset the denied realms before each layout test. Widen the silent-server bound, take the process status time from a range captured around the call, and require the delayed server to delay. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
SonarCloud reports 8.4% duplicated lines on new code. This removes the repetition it found without changing what any test asserts. BackendMappingTest: the host, service and servicegroup row expectations listed the same run of status keys three times. The keys now live in one ordered list (npcm_status_keys) and npcm_status_row() pairs them with the values, so key order is unchanged and a missing or extra value is an error. The service and servicegroup tests share one expected set of service values. The two tests that built the same two-group backend now call npcm_two_group_backend(). All rows are still compared whole with toBe(). ImportControllerTest and ImportMutationTest: the identical Cacti stub setup, per-test reset and host fixture move to tests/Unit/support/import-controller.php, loaded by both files. The Unit suite runs the same 958 tests and 5649 assertions before and after. Refs #83 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
xmacan
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Adds unit tests for code merged in #75. Tests only: no production file is
changed.
Fixes #82
What the tests pin
NpcLqlvalue conversion and the 4096 byte bound, theLimit:line, and theLivestatus client's header strictness, size and time clamps, multi-chunk
reads, error message trimming, connection failure handling and the
command wire line (a
rawmode was added to the fake server for this)NagiosCmdinteger normalisation and its 2147483647 bound, the 255 and 1024character limits, and the downtime time and duration checks
NpcLivestatusBackend, the object idlookups (type, chunking at 500, 128 character names), sorting, paging, the
state and search filters, and the group listings
and template limits, the import key handling, and the row shading
and the JSON answers of the small controllers
Results
Infection 0.35.15, changed lines against the pre-merge base, 1743 mutants in
the production files plus 7 in
controllers/servicegroups.php.Unit suite alone. These figures were measured before the final two commits,
which only add tests, so they can only rise; the mutants those commits target
were re-run one by one and are killed (see below):
The 74 uncovered mutants are mostly method visibility changes on declaration
lines. Every escaped and uncovered mutant was then run against the whole suite
(Security, Unit, Integration and E2E, with MariaDB and Naemon 1.6.0; a control
run of the unmutated tree after every 25 mutants stayed green). That killed
the 74 uncovered mutants and some of the escapes, leaving 72 escaped.
The last commit kills 6 more (verified one by one), so 66 remain:
servicegroups.php)Remaining 66 survivors
None can be killed by a test that is deterministic and does not change
production code.
Equivalent (the output cannot differ):
(backend 345, 453, 1006, 1012, 1073, 1105, 1109, 1116; import 82, 216, 218,
259, 279, 323; nagioscmd 1783, 1788, 1813, 1818; livestatus 295, 419)
array_fillstart index (852, 1067)array_map('intval')andarray_valuesremoval where array keys convertanyway (backend 528, 969; import 244)
datetime(-1)(646)entry_time(backend 504); numeric-stringcomparison (1089)
$i--alternates row shading the same way (import 83, 158)
limitdefault 0 or -1 both omit theLimit:line (livestatus 210, 326)tcp://prefix, becausestream_socket_client()defaults to TCP (377);fread()chunk sizes (434), which the reassembled answer hidesPHP 8's stable sort, and no proof of equivalence was made.
finallyunwrapping that only closes a handle (livestatus 286, 356, 385,409), whose effect is a leaked descriptor a test cannot see
Socket timing (depends on peer reset and buffer timing, so any assertion would
be flaky): livestatus 353, 382, 403, 405, 406 (two), 412, 415, 416,
441, 442 and the stream timeout arithmetic at 458. Targeted timing tests added
here (delayed answer within the limit, silent peer giving up after about one
second) kill the deadline mutants at 283.
Not observable from tests: import 363, the removal of Cacti's
general_header()call, which the tests replace with a stub.The lists are by source line; several mutants can share a line.
Files that produced no mutants
npc.phpis top-level front-controller code; Infection only mutates codeinside functions and methods, so it yields none in any configuration. The
RealServerTest E2E suite exercises it.
controllers/servicegroups.phpis not loaded by any unit test, so it has nounit coverage entry and is skipped unless
--with-uncoveredis used. Withthat flag it yields 7 mutants; the full suite kills all 7.
Suite
Full suite on this branch with the merged code (Security, Unit, Integration and
E2E; MariaDB 11.8 and Naemon 1.6.0 in Docker): 1206 passed and 1 skipped on PHP
8.2 and on PHP 8.3, 0 failed. The skip is the
js/npc.jstest, which needsnode; the test image has none. Withnodeinstalled it runs, giving 1207passed and 0 skipped. Unit and Security alone pass on PHP 8.2, 8.3 and 8.5
(1018 passed, 1 skipped for the same reason), also in random order with 20
seeds on 8.3 and one seed on 8.2 and 8.5.
Notes
recognised by its PHPUnit output parser and its include interceptor breaks
the file and socket tests. Infection generated the mutants and a separate
runner ran them against real files with the covering tests.
api_device_save()(tests/Unit/support/cacti-stubs.php), with theparameter names, order and defaults of Cacti's function, together with the
page frame and CSRF stubs. This also removes an order dependence between
ImportControllerTestand the layout tests that made the former fail underrandom ordering (
--order-by=random, for example seeds 0, 5 and 6).