Skip to content

Rename include/ to includes/, use require, and re-register hooks on upgrade - #53

Merged
cigamit merged 12 commits into
mainfrom
refactor/schema-includes-database
Oct 1, 2026
Merged

cigamit merged 12 commits into
mainfrom
refactor/schema-includes-database

Conversation

@TheWitness

@TheWitness TheWitness commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Rename include/ → includes/, re-register hooks on upgrade, and add the fleet file manifest

Adopts the fleet includes/ convention (with the upgrade migration that makes the rename safe) and adds the fleet-wide manifest.json + upgrade-time file-pruning mechanism.

Rename + hook re-registration

  • git mv include/ → includes/ (arrays.php, database.php, functions.php, settings.php) and repoint every caller.
  • Upgrade hook re-registration — plugin_evidence_upgrade_database() repoints plugin_hooks.file from include/* to includes/* for this plugin on a version change, so existing installs load their hooks from the new path after upgrade.

File manifest + upgrade pruning

  • manifest.json (root) with tombstones (include/), expected (top-level files/directories shipping today, directories with a trailing /), and whitelist (empty — evidence's data/ holds shipped reference SQL, not user data).
  • evidence_prune_files() (in setup.php, called from the version-change block of plugin_evidence_upgrade_database()) deletes the tombstoned include/ tree and the dev-only tests/ tree, refuses any path that resolves outside the plugin directory (a tampered manifest.json), warns on any file/directory it cannot remove, leaves whitelist/.git* alone, and logs — without removing — any top-level entry the manifest does not account for.
  • tests/bin/validate-manifest.php (wired into plugin-ci-workflow.yml) fails on drift between expected and the real top-level tree.
  • Unit tests cover tombstone/file/dir removal, path-escape refusal, permission warnings, whitelist/.git protection, and the missing/malformed-manifest no-ops; the upgrade test sandboxes base_path so the prune runs against a temp tree.

Validation

Full Pest suite green (31 passed) and the patch-coverage gate passes for all changed measured lines; manifest drift-check passes and the translation template is up to date.

Revision: hardening & fleet cleanup

Since the initial description, this PR also:

  • Prunes phpunit.xml on upgrade (alongside the dev-only tests/ tree) and leaves .md* lint configs in place — the drift check now ignores tests/, phpunit.xml, .git*, .md*, and whitelisted paths.
  • Hardens the prune against tampered manifests: refuses any tombstone whose normalized path contains a ./.. traversal segment or resolves outside the plugin directory (including via a symlinked directory), and protects a directory when a whitelisted entry lives beneath it — each with added unit coverage.
  • Renames the prune helpers to the documented naming convention: evidence_prune_files() / evidence_rmtree() (the plugin_evidence_ prefix is reserved for lifecycle/hook-registration functions).
  • Gives tests/Unit/PruneFilesTest.php the full standard GPL v2 header and aligns the Project Structure block in .github/copilot-instructions.md.

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Existing installations may retain broken hook paths, and the coverage configuration does not reliably measure the relocated code.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

This PR moves Evidence’s plugin files to includes/ and makes PHP loading fail fast, aligning the plugin layout with the stated fleet convention.

Changes:

  • Relocates plugin files and updates their references, including hook registrations.
  • Changes include calls to require and represents two schema primary keys as arrays.
  • Updates tests and translation source references for the new paths.
File Description
tests/​Unit/​EvidenceLifecycleTest.php Updates a path in a test comment.
tests/​Unit/​EvidenceDatabaseTest.php Updates a path in a test comment.
tests/​Security/​PhpCompatibilityTest.php Updates the vendor-directory exclusion.
tests/​bin/​patch-coverage.php Allow­lists three entry points for coverage.
setup.php Updates hook paths and database loading.
poller_evidence.php Updates required files and loading behavior.
locales/​po/​cacti.pot Updates translation source references.
includes/​settings.php Relocates settings definitions.
includes/​functions.php Relocates functions and updates required paths.
includes/​database.php Relocates schema code and changes two primary-key definitions.
includes/​arrays.php Relocates configuration arrays.
evidence.php Updates required files and loading behavior.
evidence_tab.php Updates required files and loading behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread setup.php
Existing installs persist api_plugin_register_hook() file paths as include/functions.php and include/settings.php, and plugin_evidence_check_config() does not refresh those registrations on upgrade. Renaming the directory to includes/ would leave those hooks pointing at missing files. Keep the directory as include/ and retain only the require/require_once fail-fast conversion, the array-form primaries in include/database.php, and the patch-coverage allowlist. Reverts the cacti.pot regeneration and test-comment path churn that the rename introduced.
@TheWitness TheWitness changed the title Relocate schema/library to includes/ and use require/require_once Use require/require_once and array primaries (keep include/ directory) Sep 30, 2026
Copilot added 2 commits September 30, 2026 08:50
The include_once->require_once conversions in plugin_evidence_poller_bottom(), plugin_evidence_host_edit_bottom(), evidence_show_host_info() and evidence_show_actual_data() are the only changes in the measured include/functions.php, and those live hook/render paths are not unit-loadable. A measured file cannot be allowlisted in patch-coverage, so restore the base include_once forms to drop the file from the changed set and clear the 100% patch-coverage gate.
Per author approval, complete the fleet directory convention.

- git mv include/ -> includes/ and repoint every plugin reference (entry
  points, setup.php hook file args, poller, internal library includes).
- Re-register the affected hooks on upgrade: plugin_evidence_upgrade_database()
  now repoints plugin_hooks.file from include/* to includes/* for the plugin,
  so existing installations load their UI/settings/poller hooks from the new
  path instead of the removed directory.
- Regenerate the translation template for the moved files.
@TheWitness TheWitness changed the title Use require/require_once and array primaries (keep include/ directory) Rename include/ to includes/, use require, and re-register hooks on upgrade Sep 30, 2026
Copilot added 6 commits September 30, 2026 13:36
phpunit.xml ships in the repo for CI but is a dev-only test artifact, so it
is removed from manifest.json 'expected', pruned from installs on upgrade
(like tests/), and excluded from the manifest drift check.

The retired markdown-lint configs (.mdlrc, .md_style.rb) are deleted, and
.md* is now ignored like .git*: protected from pruning and excluded from
drift if it reappears.
The upgrade-time prune now rejects any tombstone containing '.'/'..' segments
(which could escape the plugin directory or resolve to its root) and treats
ancestors of whitelist entries as protected, so a tombstone on a parent
directory can no longer delete a whitelisted file beneath it.
The trailing '# ...' comments in the Project Structure block drifted further
right down the tree; align them all to a single column.
- Use the full license header (from the plugin's own setup.php) in
  tests/Unit/PruneFilesTest.php instead of the abbreviated copyright banner.
- Document that the manifest drift check and the upgrade-time prune also
  handle phpunit.xml and .md* files, matching the implemented behavior.
The repository naming contract reserves the plugin_<name>_ prefix for plugin
lifecycle / hook-registration functions; all other functions use the plain
<name>_ prefix. Rename the internal upgrade helpers accordingly:

  plugin_<name>_prune_files() -> <name>_prune_files()
  plugin_<name>_rmtree()      -> <name>_rmtree()

The call site, unit tests, and the copilot-instructions.md references are
updated to match. No behavioral change.
@cigamit
cigamit merged commit a8b5ecd into main Oct 1, 2026
3 checks passed
@cigamit
cigamit deleted the refactor/schema-includes-database branch October 1, 2026 06:50
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