)
+ // contains no dot, so Status::is_local_site() treats it as a local site and Jetpack
+ // enters offline mode. Offline mode blocks My Jetpack from initializing at all
+ // (Initializer::should_initialize()), yet this fixture explicitly simulates a
+ // production, connected site. This is install-wide: flipping it shifts what EVERY
+ // scenario measures (Jetpack runs more code paths when not offline) — see the
+ // offline-mode attribution note in README.md.
+ //
+ // Two filters are needed because Status::is_offline_mode() falls back to the stored
+ // option when the filtered value is false: `$offline = (bool) apply_filters( ... );
+ // if ( ! $offline ) { $offline = (bool) get_option( 'jetpack_offline_mode' ); }`. The
+ // first filter overrides the is_local_site() result; pre_option_* forces the option
+ // read to 0 so a dirty/reused fixture DB with jetpack_offline_mode=1 can't silently
+ // turn offline mode back on and break every scenario's boot.
+ add_filter( 'jetpack_offline_mode', '__return_false' );
+ add_filter( 'pre_option_jetpack_offline_mode', '__return_zero' );
+
// Set up fake connection on init (after Jetpack loads).
add_action( 'plugins_loaded', array( $this, 'setup_fake_connection' ), 1 );
diff --git a/tools/performance/scripts/post-to-codevitals.test.js b/tools/performance/scripts/post-to-codevitals.test.js
index a0f70c885206..ef0b90e5bab5 100644
--- a/tools/performance/scripts/post-to-codevitals.test.js
+++ b/tools/performance/scripts/post-to-codevitals.test.js
@@ -51,6 +51,10 @@ const FORMS_LCP_KEY = 'forms-responses-connection-sim-largestContentfulPaint';
const FORMS_TTFB_KEY = 'forms-responses-connection-sim-timeToFirstByte';
const FORMS_FCP_KEY = 'forms-responses-connection-sim-firstContentfulPaint';
const FORMS_DECODED_KEY = 'forms-responses-connection-sim-decodedBytesKB';
+const MJ_LCP_KEY = 'my-jetpack-connection-sim-largestContentfulPaint';
+const MJ_TTFB_KEY = 'my-jetpack-connection-sim-timeToFirstByte';
+const MJ_FCP_KEY = 'my-jetpack-connection-sim-firstContentfulPaint';
+const MJ_DECODED_KEY = 'my-jetpack-connection-sim-decodedBytesKB';
/**
* Build the nested per-field summary the multi-metric jetpackConnected scenario reads.
@@ -81,16 +85,39 @@ function formsSummary( { lcp = 300, ttfb = 200, fcp = 500, decodedBytesKB = 8229
};
}
+/**
+ * Build the nested per-field summary the myJetpack scenario reads: the same shape as
+ * formsSummary (three timing fields + the bundle-size field). LCP (~640) and decodedBytesKB
+ * (~5860) track the observed local medians; ttfb/fcp are plausible in-range fillers. All four
+ * sit inside SANITY_RANGES so they post cleanly unless a test overrides one.
+ */
+function myJetpackSummary( { lcp = 640, ttfb = 220, fcp = 560, decodedBytesKB = 5860 } = {} ) {
+ return {
+ median: lcp,
+ lcp: { median: lcp },
+ ttfb: { median: ttfb },
+ fcp: { median: fcp },
+ decodedBytesKB: { median: decodedBytesKB },
+ };
+}
+
/**
* Write a results fixture and return its path. `median` is the LCP median (kept as the
* first positional arg so existing single-arg call sites read the same); TTFB and FCP
* default to in-range values so the two new metrics post cleanly unless overridden. Pass
- * `forms` (an object of field overrides) to also include a `formsResponses` measurement; omit
- * it and only `jetpackConnected` is written, exactly as before.
+ * `forms` and/or `myJetpack` (objects of field overrides) to also include those measurements;
+ * omit both and only `jetpackConnected` is written, exactly as before.
*/
function writeResults(
median,
- { ttfb = 150, fcp = 400, hash = 'testhash', branch = 'trunk', forms = null } = {}
+ {
+ ttfb = 150,
+ fcp = 400,
+ hash = 'testhash',
+ branch = 'trunk',
+ forms = null,
+ myJetpack = null,
+ } = {}
) {
const dir = fs.mkdtempSync( path.join( os.tmpdir(), 'cv-results-' ) );
const file = path.join( dir, 'results.json' );
@@ -100,6 +127,9 @@ function writeResults(
if ( forms ) {
measurements.formsResponses = { summary: formsSummary( forms ) };
}
+ if ( myJetpack ) {
+ measurements.myJetpack = { summary: myJetpackSummary( myJetpack ) };
+ }
fs.writeFileSync( file, JSON.stringify( { git: { hash, branch }, measurements } ) );
return file;
}
@@ -486,6 +516,50 @@ test( 'the formsResponses scenario posts LCP, TTFB, FCP and decodedBytes to prod
);
} );
+test( 'the myJetpack scenario posts LCP, TTFB, FCP and decodedBytes to production keys', () => {
+ // Pins the FORMS-717 config: the My Jetpack admin page (the heaviest Jetpack admin bundle)
+ // carries the bundle-size metric (summary.decodedBytesKB.median) alongside the timing metrics,
+ // each on its own production key. A dropped/renamed key, or a decoded metric with no type
+ // (which would post unchecked), fails here rather than silently in the append-only store.
+ const scenario = SCENARIOS.find( s => s.key === 'myJetpack' );
+ assert.ok( scenario, 'myJetpack scenario must exist' );
+ assert.ok( Array.isArray( scenario.metrics ), 'myJetpack must use the metrics array' );
+ assert.deepEqual(
+ scenario.metrics.map( m => ( {
+ field: m.field,
+ codevitalsKey: m.codevitalsKey,
+ type: m.type,
+ } ) ),
+ [
+ { field: 'lcp', codevitalsKey: MJ_LCP_KEY, type: 'lcp' },
+ { field: 'ttfb', codevitalsKey: MJ_TTFB_KEY, type: 'ttfb' },
+ { field: 'fcp', codevitalsKey: MJ_FCP_KEY, type: 'fcp' },
+ { field: 'decodedBytesKB', codevitalsKey: MJ_DECODED_KEY, type: 'decodedBytesKB' },
+ ]
+ );
+ // The page-navigation contract measure-lcp.js reads: a target path + a hydration selector.
+ // The selector is the AdminPage frame that appears only after React renders MyJetpackScreen
+ // into the (initially empty) container, so a run measures the rendered app, not the shell.
+ assert.equal( scenario.path, '/wp-admin/admin.php?page=my-jetpack' );
+ assert.equal( scenario.waitForSelector, '#my-jetpack-container .jp-admin-page' );
+ // A weak guard on its own: My Jetpack is a single-slug SPA, so every view keeps
+ // `page=my-jetpack` — even the not-connected redirect to `&step=onboarding`. What actually
+ // stops a wrong-view post is the `.jp-admin-page` selector above (OnboardingScreen renders
+ // without AdminPage, so it never matches). expectUrlIncludes only catches a redirect that
+ // leaves My Jetpack entirely.
+ assert.equal( scenario.expectUrlIncludes, 'page=my-jetpack' );
+ // A resource-count floor so a partial capture can't post an undercounted decodedBytesKB.
+ // Pin the exact value (siblings pin every field by equality) so a later edit toward the
+ // ~90-resource load can't erode the margin silently, and exercise the real guard at the
+ // boundary: one below the floor must throw, the floor itself must not.
+ assert.equal( scenario.minResourceCount, 64 );
+ assert.throws(
+ () => assertCaptureComplete( { totalRequests: 63 }, scenario ),
+ /Incomplete capture: 63 resources < expected minimum 64/
+ );
+ assert.doesNotThrow( () => assertCaptureComplete( { totalRequests: 64 }, scenario ) );
+} );
+
// --- redactToken (keeps the token out of logs and errors) ---
test( 'redactToken strips the exact token and any token query param', () => {
@@ -529,6 +603,25 @@ test( 'dry-run with both scenarios present posts all 7 keys, including the Forms
assert.equal( Object.keys( result.payload.metrics ).length, 7 );
} );
+test( 'dry-run with all three scenarios present posts all 11 keys, including the My Jetpack decoded-bytes key', async () => {
+ // The full automated run measures all three scenarios, so the payload carries jetpackConnected's
+ // 3 timing keys, formsResponses' 4, AND myJetpack's 4 (timing + decodedBytesKB). The config test
+ // pins the myJetpack keys statically; this proves they reach the payload with the right values
+ // under the exact production key names, so a wiring regression in the scenario-agnostic loop
+ // (a dropped/renamed myJetpack metric) fails here rather than silently in the append-only store.
+ const file = writeResults( 120, {
+ forms: { decodedBytesKB: 8229 },
+ myJetpack: { lcp: 640, ttfb: 220, fcp: 560, decodedBytesKB: 5860 },
+ } );
+ const result = await silenced( () => postToCodeVitals( file, { dryRun: true } ) );
+ assert.equal( result.validationFailed, false );
+ assert.equal( result.payload.metrics[ MJ_LCP_KEY ], 640 );
+ assert.equal( result.payload.metrics[ MJ_TTFB_KEY ], 220 );
+ assert.equal( result.payload.metrics[ MJ_FCP_KEY ], 560 );
+ assert.equal( result.payload.metrics[ MJ_DECODED_KEY ], 5860 );
+ assert.equal( Object.keys( result.payload.metrics ).length, 11 );
+} );
+
test( 'a live run with an out-of-range Forms decodedBytesKB posts nothing and never calls fetch', async () => {
// The append-only guarantee end to end: one out-of-range decoded value (52000 > max 51200)
// fails its sanity check, the per-run atomic gate commits to posting nothing, and fetch is
diff --git a/tools/performance/scripts/scenarios.js b/tools/performance/scripts/scenarios.js
index c77706b4cf9f..9ef612537f1c 100644
--- a/tools/performance/scripts/scenarios.js
+++ b/tools/performance/scripts/scenarios.js
@@ -117,6 +117,71 @@ export const SCENARIOS = [
postToCodeVitals: true,
isBaseline: false,
},
+ {
+ key: 'myJetpack',
+ name: 'My Jetpack (connection sim)',
+ cliName: 'my-jetpack',
+ // Same WordPress instance as the Dashboard and Forms scenarios — just a different page —
+ // so no new Docker service is needed; only `path`/`waitForSelector` below differ.
+ dockerService: 'wordpress-jetpack-connected',
+ wpPath: '/var/www/html/jetpack-connected',
+ envVar: 'WP_JETPACK_CONNECTED_URL',
+ defaultUrl: 'http://localhost:8083',
+ header: 'My Jetpack (simulated WP.com connection)',
+ // The My Jetpack admin page - the heaviest Jetpack admin bundle. PHP emits an empty
+ // `` and React (createRoot) renders MyJetpackScreen into
+ // it, so measure-lcp.js waits for the AdminPage frame (`.jp-admin-page`, a non-hashed
+ // class from @automattic/jetpack-components) to appear so a run measures the rendered app,
+ // not the empty shell. Capture completeness then rests on the networkidle wait plus the
+ // stable resource count, not the frame selector (`.jp-admin-page` renders with its children
+ // in one commit, so its presence is not a load-finished proxy) and not networkidle alone
+ // (the async product cards can settle after a quiet gap). The minResourceCount floor below
+ // is the backstop against gross truncation.
+ //
+ // Requires offline mode OFF (Status::is_offline_mode() gates
+ // Initializer::should_initialize(); localhost has no dot so the fixture is "local" =
+ // offline by default): the simulate-wpcom-connection mu-plugin flips it. See the README
+ // offline-mode attribution note.
+ path: '/wp-admin/admin.php?page=my-jetpack',
+ waitForSelector: '#my-jetpack-container .jp-admin-page',
+ expectUrlIncludes: 'page=my-jetpack',
+ // A healthy load of this page fetches ~92 resources (stable across iterations locally);
+ // measure-lcp.js fails the run if it captures fewer than this floor, so a truncated/partial
+ // capture can't post an in-range but undercounted decodedBytesKB. Set to ~70% of the observed
+ // count (count-based, not asset-based) so it only catches gross capture truncation.
+ minResourceCount: 64,
+ // These four post straight to PRODUCTION keys — the `-staging` window in the README
+ // Safeguards is deliberately waived here (owner decision, Liam 2026-07-08), same rationale
+ // and substitute guardrails (SANITY_RANGES + all-or-nothing gate + manual sign-off) as the
+ // wp-admin-dashboard and forms-responses keys.
+ metrics: [
+ {
+ field: 'lcp',
+ codevitalsKey: 'my-jetpack-connection-sim-largestContentfulPaint',
+ type: 'lcp',
+ },
+ {
+ field: 'ttfb',
+ codevitalsKey: 'my-jetpack-connection-sim-timeToFirstByte',
+ type: 'ttfb',
+ },
+ {
+ field: 'fcp',
+ codevitalsKey: 'my-jetpack-connection-sim-firstContentfulPaint',
+ type: 'fcp',
+ },
+ {
+ // The bundle-size metric: summed per-resource decodedBodySize in KB (see
+ // measure-lcp.js). My Jetpack is the heaviest Jetpack admin bundle, so this is
+ // the surface a bundle regression is most damaging on.
+ field: 'decodedBytesKB',
+ codevitalsKey: 'my-jetpack-connection-sim-decodedBytesKB',
+ type: 'decodedBytesKB',
+ },
+ ],
+ postToCodeVitals: true,
+ isBaseline: false,
+ },
];
/**
@@ -135,12 +200,12 @@ export const SANITY_RANGES = {
fcp: { min: 50, max: 30000 },
tbt: { min: 0, max: 10000 }, // Can legitimately be 0; >10s is catastrophic.
cls: { min: 0, max: 5 }, // >5 would mean the page is unusable.
- // Summed per-resource decodedBodySize, in KB. The Forms responses wp-build dashboard
- // measures ~8200 KB (deterministic across iterations). These are guardrails against a
- // broken measurement, NOT a trend clip: min 1000 catches a page that failed to load its
- // wp-build shell (a real dashboard is always well over 1MB decoded); max 51200 (50MB)
- // catches a bytes-vs-KB scale error while staying clear of any legitimate regression, which
- // the trend should record rather than reject.
+ // Summed per-resource decodedBodySize, in KB. This row now guards two scenarios: the Forms
+ // responses wp-build dashboard (~8200 KB) and My Jetpack (~5860 KB), so do not tighten it to
+ // either page's profile. These are guardrails against a broken measurement, NOT a trend clip:
+ // min 1000 catches a page that failed to load its wp-build shell (a real dashboard is always
+ // well over 1MB decoded); max 51200 (50MB) catches a bytes-vs-KB scale error while staying
+ // clear of any legitimate regression, which the trend should record rather than reject.
decodedBytesKB: { min: 1000, max: 51200 },
};