Skip to content
2 changes: 2 additions & 0 deletions .buildkite/commands/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

trap 'echo "Termination signal received — failing the job."; exit 1' TERM INT

PLATFORM=${1:?Expected platform to be provided as first parameter}
ARCH=${2:?Expected architecture to be provided as second parameter}

Expand Down
14 changes: 5 additions & 9 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
IMAGE_ID: $IMAGE_ID

e2e_config: &e2e_config
timeout_in_minutes: 100
command: bash .buildkite/commands/run-e2e-tests.sh "{{matrix.platform}}" "{{matrix.arch}}"
artifact_paths:
- test-results/**/*.zip
Expand All @@ -23,12 +24,7 @@ e2e_config: &e2e_config
setup: { platform: [], arch: [] }
adjustments:
- with: { platform: mac, arch: arm64 }
# Windows E2E temporarily disabled while AINFRA-2588 investigates Windows E2E hangs in Buildkite.
# See https://linear.app/a8c/issue/AINFRA-2588/investigate-studio-windows-e2e-hangs-in-buildkite
# - with: { platform: windows, arch: x64 }
notify:
- github_commit_status:
context: E2E Tests
- with: { platform: windows, arch: x64 }

steps:
- label: Lint
Expand Down Expand Up @@ -87,6 +83,9 @@ steps:

- group: E2E Tests
key: e2e-tests
notify:
- github_commit_status:
context: E2E Tests
steps:
# E2E tests run on supported platform/architecture combinations.
# - mac-arm64: Native on Apple Silicon agents
Expand Down Expand Up @@ -118,9 +117,6 @@ steps:
env:
DEBUG: "pw:browser"
# TEMP(rsm-2593): if: removed to force E2E on every push while iterating on Linux E2E setup. Revert before merge.
notify:
- github_commit_status:
context: E2E Tests

- label: ":chart_with_upwards_trend: Performance Metrics"
key: metrics
Expand Down
11 changes: 3 additions & 8 deletions apps/cli/lib/native-php/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NativePhpSupportedVersion } from '@studio/common/lib/php-binary-metadat
import { writeFile } from 'atomically';
import semver from 'semver';
import { getPhpBinaryPath } from '../dependency-management/paths';
import { getFullyResolvedTmpDirPath } from './tmp-dir';

// Disabled to shrink the attack surface available to PHP code running inside a
// Studio site. Each entry falls into one of:
Expand Down Expand Up @@ -215,13 +216,7 @@ function getOpcacheRootDir(): string {
return opcacheRootDir;
}

// Resolve to the long-form path on Windows. `os.tmpdir()` can return an 8.3
// short name (e.g. C:\Users\BUILDK~1\AppData\…) when the user has a long
// username, and PHP's INI scanner treats `~` as a special token, breaking
// `-d opcache.file_cache=<path>` parsing.
const tmpRoot =
process.platform === 'win32' ? fs.realpathSync.native( os.tmpdir() ) : os.tmpdir();
opcacheRootDir = fs.mkdtempSync( path.join( tmpRoot, 'studio-opcache-' ) );
opcacheRootDir = fs.mkdtempSync( path.join( getFullyResolvedTmpDirPath(), 'studio-opcache-' ) );
const dirToClean = opcacheRootDir;
process.once( 'exit', () => {
try {
Expand Down Expand Up @@ -292,7 +287,7 @@ export function getDefaultPhpArgs(
// runtime.php (constants, SQLite loader, upload proxy) into imported sites
// without modifying their wp-config.php.
if ( autoPrependFile ) {
args.push( '-d', `auto_prepend_file=${ autoPrependFile }` );
args.push( '-d', `auto_prepend_file="${ toPhpIniPath( autoPrependFile ) }"` );
Comment thread
gavande1 marked this conversation as resolved.
}

return args;
Expand Down
11 changes: 8 additions & 3 deletions apps/cli/lib/native-php/phpmyadmin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { getFullyResolvedTmpDirPath } from './tmp-dir';
import type { ServerConfig } from 'cli/lib/types/wordpress-server-ipc';

function phpStringLiteral( value: string ): string {
Expand All @@ -9,12 +9,17 @@ function phpStringLiteral( value: string ): string {

export function getNativePhpMyAdminWpEnvPath( config: Pick< ServerConfig, 'siteId' > ): string {
const safeSiteId = config.siteId.replace( /[^a-zA-Z0-9._-]/g, '-' );
return path.join( os.tmpdir(), 'studio-phpmyadmin-wp-env', safeSiteId, 'wp-env.php' );
return path.join(
getFullyResolvedTmpDirPath(),
'studio-phpmyadmin-wp-env',
safeSiteId,
'wp-env.php'
);
}

export function getPhpMyAdminSessionPath( config: Pick< ServerConfig, 'siteId' > ): string {
const safeSiteId = config.siteId.replace( /[^a-zA-Z0-9._-]/g, '-' );
return path.join( os.tmpdir(), 'studio-phpmyadmin-sessions', safeSiteId );
return path.join( getFullyResolvedTmpDirPath(), 'studio-phpmyadmin-sessions', safeSiteId );
}

export async function writeNativePhpMyAdminWpEnv( config: ServerConfig ): Promise< string > {
Expand Down
6 changes: 4 additions & 2 deletions apps/cli/lib/native-php/site-setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { DEFAULT_LOCALE } from '@studio/common/lib/locale';
import { escapePhpSingleQuotedString } from '@studio/common/lib/mu-plugins';
import { decodePassword } from '@studio/common/lib/passwords';
import { getWpCliPharPath } from 'cli/lib/dependency-management/paths';
import { runPhpCommand } from './php-process';
import { getFullyResolvedTmpDirPath } from './tmp-dir';
import type { NativePhpSupportedVersion } from '@studio/common/lib/php-binary-metadata';
import type { ServerConfig } from 'cli/lib/types/wordpress-server-ipc';

Expand Down Expand Up @@ -99,7 +99,9 @@ export function writeSiteUrlPrependFile(
siteUrl: string,
originalAutoPrependFile?: string
): string {
const dir = fs.mkdtempSync( path.join( os.tmpdir(), 'studio-siteurl-prepend-' ) );
const dir = fs.mkdtempSync(
path.join( getFullyResolvedTmpDirPath(), 'studio-siteurl-prepend-' )
);
const prependPath = path.join( dir, 'prepend.php' );
fs.writeFileSync( prependPath, getSiteUrlPrependContent( siteUrl, originalAutoPrependFile ) );
return prependPath;
Expand Down
14 changes: 14 additions & 0 deletions apps/cli/lib/native-php/tmp-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'node:fs';
import os from 'node:os';

// Returns `os.tmpdir()` resolved to its long-form path on Windows.
//
// When the OS account name is longer than 8 characters (e.g. CI's `buildkite-agent`),
// Windows exposes an 8.3 short name and `os.tmpdir()` can return something like
// `C:\Users\BUILDK~1\AppData\Local\Temp`. PHP's INI/argument scanner treats the `~` as a
// special token, so any temp path we hand to PHP — auto_prepend_file, opcache.file_cache,
// the phpMyAdmin config, … — breaks with `syntax error, unexpected '~'`. Resolving to the
// long form removes the tilde. No-op on macOS/Linux, which don't have 8.3 short names.
export function getFullyResolvedTmpDirPath(): string {
return process.platform === 'win32' ? fs.realpathSync.native( os.tmpdir() ) : os.tmpdir();
}
Loading
Loading