Skip to content

Cookie Consent: Record consent log versions#49996

Draft
chihsuan wants to merge 3 commits into
trunkfrom
auto/WOOA7S-1606
Draft

Cookie Consent: Record consent log versions#49996
chihsuan wants to merge 3 commits into
trunkfrom
auto/WOOA7S-1606

Conversation

@chihsuan

@chihsuan chihsuan commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fixes WOOA7S-1606

Proposed changes

  • Add policy_version and banner_version columns to the cookie consent log table and bump the consent-log DB version so existing tables are migrated by dbDelta.
  • Store the configured log.policy_version and log.banner_version values on each consent log record, defaulting each value to 1.
  • Add a narrow Cookie_Consent::get_log_versions() accessor while keeping the full cookie-consent config private.
  • Normalize Cookie_Consent::get_log_versions() values to non-empty strings and add PHPUnit coverage for default, filtered, scalar, empty, and invalid values.
  • Add a cookie-consent package changelog entry.
  • Resolve the static-analysis cleanup reported on the reviewer-fix commit by making REST route numeric keys explicit and removing stale suppressions.

Related product discussion/links

Does this pull request change what data or activity we track or use?

Yes. Cookie consent log records now include the policy and banner version strings in effect when consent was captured. These values come from cookie-consent configuration and are intended as proof-of-consent metadata.

Testing instructions

  • Confirm the branch scope: git diff --name-only origin/trunk...HEAD lists only:
    • projects/packages/cookie-consent/changelog/add-consent-log-versions
    • projects/packages/cookie-consent/src/class-consent-log-controller.php
    • projects/packages/cookie-consent/src/class-cookie-consent.php
    • projects/packages/cookie-consent/tests/php/Cookie_Consent_Log_Versions_Test.php
  • Run syntax checks:
    • php -l projects/packages/cookie-consent/src/class-consent-log-controller.php
    • php -l projects/packages/cookie-consent/src/class-cookie-consent.php
    • php -l projects/packages/cookie-consent/tests/php/Cookie_Consent_Log_Versions_Test.php
  • Run focused log-version tests: projects/packages/cookie-consent/vendor/bin/phpunit-select-config projects/packages/cookie-consent/phpunit.#.xml.dist --colors=always --filter Cookie_Consent_Log_Versions_Test
  • Run cookie-consent tests: PATH="$HOME/.nvm/versions/node/v24.15.0/bin:$PATH" /Users/chihsuan/Library/pnpm/pnpm jetpack test php packages/cookie-consent
  • Run PHPCS: composer phpcs:lint -- projects/packages/cookie-consent/src/class-consent-log-controller.php projects/packages/cookie-consent/src/class-cookie-consent.php projects/packages/cookie-consent/tests/php/Cookie_Consent_Log_Versions_Test.php
  • Verify a consent log insert stores default 1 versions when no log config is supplied and configured versions when jetpack_cookie_consent_config supplies log.policy_version / log.banner_version.

Validation note: local phan packages/cookie-consent --allow-polyfill-parser still exits nonzero on the existing current-trunk PHPUnit scaffold diagnostics under projects/packages/cookie-consent/tests/php/*. The CI-reported PhanPluginMixedKeyNoKey and unused-suppression diagnostics from f23774f4fb are addressed in 5a8bbb6284.

Summary:
- Add policy and banner version columns to the consent log table.
- Store configured log versions when writing consent log records.
- Expose only a narrow log-version accessor and keep full config private.
- Add the package changelog entry.

Rationale:
- Consent records need to preserve the policy and banner versions that
  were in effect when consent was captured so later copy or category
  changes do not weaken proof-of-consent records.
- The table version bump lets dbDelta migrate existing installations.
- A narrow accessor avoids widening the full cookie-consent config into
  the package public API.

Tests:
- php -l projects/packages/cookie-consent/src/class-consent-log-controller.php
- php -l projects/packages/cookie-consent/src/class-cookie-consent.php
- isolated PHP harness for default, configured, and invalid log version inserts
- PATH="$HOME/.nvm/versions/node/v24.15.0/bin:$PATH" /Users/chihsuan/Library/pnpm/pnpm --dir projects/packages/cookie-consent test
- PATH="$HOME/.nvm/versions/node/v24.15.0/bin:$PATH" /Users/chihsuan/Library/pnpm/pnpm jetpack test php packages/cookie-consent
- composer phpcs:lint -- projects/packages/cookie-consent/src/class-consent-log-controller.php projects/packages/cookie-consent/src/class-cookie-consent.php
- PATH="$HOME/.nvm/versions/node/v24.15.0/bin:$PATH" /Users/chihsuan/Library/pnpm/pnpm jetpack phan packages/cookie-consent --allow-polyfill-parser (fails on existing trunk tests/php PHPUnit scaffold issues)
@chihsuan chihsuan self-assigned this Jun 26, 2026
@chihsuan chihsuan requested a review from Copilot June 26, 2026 08:55
@chihsuan chihsuan marked this pull request as draft June 26, 2026 08:55
@jp-launch-control

jp-launch-control Bot commented Jun 26, 2026

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

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.

Pull request overview

This PR enhances the cookie-consent “proof of consent” logging by persisting the policy and banner version values that were in effect at the time a consent event was recorded, and exposes a small accessor for retrieving those configured version values.

Changes:

  • Add policy_version and banner_version columns to the consent log DB table and bump the table schema version for dbDelta migration.
  • Persist configured log versions on each consent-log insert, defaulting to '1' when unset/invalid.
  • Add a public Cookie_Consent::get_log_versions() accessor and add a cookie-consent changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
projects/packages/cookie-consent/src/class-cookie-consent.php Adds a public accessor for log versions and introduces default log.*_version config keys.
projects/packages/cookie-consent/src/class-consent-log-controller.php Updates schema version, adds DB columns, writes versions on insert, and exposes versions in the REST schema.
projects/packages/cookie-consent/changelog/add-consent-log-versions Records the user-facing change in the package changelog.

Comment thread projects/packages/cookie-consent/src/class-cookie-consent.php
Comment thread projects/packages/cookie-consent/src/class-cookie-consent.php
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 26, 2026
Normalize Cookie_Consent::get_log_versions() so callers receive non-empty strings, then add PHPUnit coverage for defaults, filtered overrides, scalar normalization, and invalid config values.

Addresses review comment 3480280243.

Addresses review comment 3480280267.
@chihsuan chihsuan marked this pull request as ready for review June 26, 2026 09:08
@chihsuan chihsuan marked this pull request as draft June 26, 2026 09:19
Make REST route endpoint indexes explicit so Phan no longer reports mixed keyed and unkeyed entries, and remove file-level suppressions that CI reports as unused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Cookie Consent [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants