Skip to content

refactor(vdef): extract resolver with full coverage and browser tests - #8483

Draft
somethingwithproof wants to merge 6 commits into
developfrom
refactor/vdef-resolver-objects
Draft

somethingwithproof wants to merge 6 commits into
developfrom
refactor/vdef-resolver-objects

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Extract VDEF expression assembly into an injectable resolver and repository while retaining the public functions, display spacing, item ordering, nested definitions, and live function dictionary. Keep legacy item lookup at the adapter boundary to preserve its existing result and error contracts. No persistent cache or new dependency is introduced.

Real-browser testing also found that the VDEF editor renders the hidden id twice, causing creation to submit an array that validation rejects. Remove the redundant field and cover creating a definition and item through the public form.

Validation:

  • PHP 8.3.36 and 8.4.25: all 7 contract tests pass with SQLite fixtures and native MariaDB 11.4.13.
  • 100% PHP line coverage across lib/vdef.php and the new classes; enforced in the dedicated CI job.
  • Four Chromium E2E scenarios pass against authenticated Cacti and a disposable MariaDB, covering creation, persistence, ordered/nested previews, edits, empty definitions, and unknown items. CI retains browser traces and native PHP request coverage.
  • 1,500 generated comparisons on each runtime match the original results, exception types, and SQL queries.
  • PHPStan, formatting, syntax, workflow validation, and security guards pass.

Targets develop (Cacti 1.3). Existing callers continue to use the same public functions.

Fixes #8879.

@somethingwithproof
somethingwithproof requested a review from a team as a code owner October 26, 2026 02:26
@somethingwithproof
somethingwithproof requested review from TheWitness and removed request for a team October 26, 2026 02:26
@somethingwithproof
somethingwithproof marked this pull request as draft October 26, 2026 06:49
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch 5 times, most recently from 8b8b831 to 79ae508 Compare November 1, 2026 20:46
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch 6 times, most recently from 694f8ac to cf7dfc4 Compare November 6, 2026 08:46
@somethingwithproof
somethingwithproof force-pushed the refactor/vdef-resolver-objects branch from 03cecde to cb269cf Compare November 9, 2026 05:24
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch 4 times, most recently from 28a3946 to 9215e52 Compare November 11, 2026 21:09
@somethingwithproof somethingwithproof added this to the v1.3.0 milestone Nov 13, 2026
@somethingwithproof somethingwithproof added the data collection Issues related to data collection label Nov 13, 2026
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch 4 times, most recently from d4a0fd3 to 5f0afa1 Compare November 17, 2026 08:48
@somethingwithproof somethingwithproof added the release:1.3 Namespaced Cacti workflow label label Nov 17, 2026

@TheWitness TheWitness left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I want to review with the team. Can these be defined using use and namespaces as opposed to requiring? Not sure it makes much of a difference here anyway. The other question is did we go far enough here?

@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch from 5f0afa1 to 77668e2 Compare November 17, 2026 20:48
@somethingwithproof

Copy link
Copy Markdown
Member Author

Can these be defined using use and namespaces as opposed to requiring?

Done in e214316. Cacti\Vdef is now in the Composer PSR-4 map alongside Cacti\Auth and Cacti\Console, lib/vdef.php imports the classes with use, and the require_once lines are gone. The generated strings and the query sequence are unchanged. I'm making the same change to the CDEF resolver in #8479 so the two match.

The other question is did we go far enough here?

Each VDEF item is still looked up through get_vdef_item_name(), one query per item, the same as before. That keeps its existing warnings and error behaviour for plugins. The next step would be building item names from the rows the resolver already reads. That removes the per-item query, but changes how missing or unknown items fail. I'd rather do that as a follow-up if you want it.

@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch 2 times, most recently from 8992f2d to f8e13d7 Compare November 20, 2026 08:51
@somethingwithproof somethingwithproof added the type:task Namespaced Cacti workflow label label Nov 23, 2026
@somethingwithproof
somethingwithproof force-pushed the refactor/vdef-resolver-objects branch from f8e13d7 to 55f67ad Compare November 25, 2026 07:58
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch from 55f67ad to c41313a Compare November 25, 2026 20:50
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Imported vdef_items rows are stored as given, so a type 5 item can name
its own VDEF or form a cycle. VdefResolver followed such references
until the stack was exhausted. Track the reference chain, cap nesting
depth and total expansions like the CDEF resolver, log the reason and
resolve the definition to ''.

Also drop the unneeded PSR-4 entry from composer.json (every entry
point loads lib/Vdef with require_once), add PHPDoc to the new classes
and record the duplicate id field fix in a changelog fragment.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The changed-coverage job only reads probes from run_pr_change_tests.sh,
so lib/Vdef and lib/vdef.php reported "instrumented: false" even though
the dedicated VDEF job covers every line. Run the VDEF suite there too,
with FixtureCoverage prepended to write the Xdebug report.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Register Cacti\Vdef in the PSR-4 map, as Cacti\Auth and Cacti\Console
already are, and import the classes with use statements instead of
require_once. lib/vdef.php still loads without Composer; the classes
are resolved only when get_vdef() runs, which every caller reaches
after include/global.php has registered the autoloader.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…the CDEF ones

between them lets both PRs merge in either order.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@github-actions
github-actions Bot force-pushed the refactor/vdef-resolver-objects branch from c41313a to 219d05a Compare November 26, 2026 08:51
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

data collection Issues related to data collection release:1.3 Namespaced Cacti workflow label type:task Namespaced Cacti workflow label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor VDEF expression assembly into a testable resolver; the VDEF editor renders its id field twice

2 participants