Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/__tests__/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ test('web supports only the initial browser interaction slice', () => {
'network',
'open',
'press',
'record',
'screenshot',
'scroll',
'snapshot',
Expand Down Expand Up @@ -428,7 +429,6 @@ test('web supports only the initial browser interaction slice', () => {
'perf',
'pinch',
'push',
'record',
'reinstall',
'rotate',
'settings',
Expand Down
2 changes: 2 additions & 0 deletions src/core/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const LINUX_DEVICE: KindMatrix = { device: true };
const LINUX_NONE: KindMatrix = {};
const WEB_DEVICE: KindMatrix = { device: true };
const WEB_RUNTIME_COMMANDS = ['open', 'close'] as const;
const WEB_RECORDING_COMMANDS = ['record'] as const;
const WEB_QUERY_COMMANDS = [
'find',
'get',
Expand All @@ -55,6 +56,7 @@ const WEB_INTERACTION_COMMANDS = ['click', 'fill', 'focus', 'press', 'scroll', '
const WEB_SETTING_COMMANDS = ['viewport'] as const;
const WEB_SUPPORTED_COMMANDS = new Set<string>([
...WEB_RUNTIME_COMMANDS,
...WEB_RECORDING_COMMANDS,
...WEB_QUERY_COMMANDS,
...WEB_INTERACTION_COMMANDS,
...WEB_SETTING_COMMANDS,
Expand Down
40 changes: 37 additions & 3 deletions src/daemon-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { pipeline } from 'node:stream/promises';
import { AppError } from './utils/errors.ts';
import type { DaemonArtifact, DaemonRequest, DaemonResponse } from './daemon/types.ts';
import { buildDaemonHttpAuthHeaders } from './daemon/http-contract.ts';
import {
appendRecordingExtensionWhenMissing,
recordingExtensionForPlatform,
} from './recording/output-path.ts';
import { uploadArtifact } from './upload-client.ts';

// Mirrors the current daemon RPC timeout, but artifact download timeouts may diverge.
Expand Down Expand Up @@ -214,17 +218,43 @@ function prepareRemoteArtifactCommand(
};
}
if (req.command === 'record' && (positionals[0] ?? '').toLowerCase() === 'start') {
const localPath = resolveClientArtifactOutputPath(req, 'outPath', '.mp4', 1);
if (!recordingHasRequestedClientPath(req) && req.flags?.platform === undefined) {
return null;
}
const fallbackExtension = recordingFallbackExtension(req);
const localPath = normalizeRecordingClientArtifactPath(
resolveClientArtifactOutputPath(req, 'outPath', fallbackExtension, 1),
req,
);
return {
field: 'outPath',
localPath,
positionalIndex: 1,
positionalPath: buildRemoteTempArtifactPath('recording', path.extname(localPath) || '.mp4'),
positionalPath: buildRemoteTempArtifactPath(
'recording',
path.extname(localPath) || fallbackExtension,
),
};
}
return null;
}

function recordingFallbackExtension(req: Omit<DaemonRequest, 'token'>): string {
return recordingExtensionForPlatform(req.flags?.platform);
}

function recordingHasRequestedClientPath(req: Omit<DaemonRequest, 'token'>): boolean {
return hasNonEmptyString(req.positionals?.[1]) || hasNonEmptyString(req.flags?.out);
}

function normalizeRecordingClientArtifactPath(
localPath: string,
req: Omit<DaemonRequest, 'token'>,
): string {
if (req.flags?.platform !== 'web') return localPath;
return appendRecordingExtensionWhenMissing(localPath, recordingFallbackExtension(req));
}

function resolveClientArtifactOutputPath(
req: Omit<DaemonRequest, 'token'>,
field: 'path' | 'outPath',
Expand All @@ -233,10 +263,14 @@ function resolveClientArtifactOutputPath(
): string {
const requested = req.positionals?.[positionalIndex] ?? req.flags?.out;
const fallbackName = `${field === 'path' ? 'screenshot' : 'recording'}-${Date.now()}${fallbackExtension}`;
const rawPath = requested && requested.trim().length > 0 ? requested : fallbackName;
const rawPath = hasNonEmptyString(requested) ? requested : fallbackName;
return path.isAbsolute(rawPath) ? rawPath : path.resolve(req.meta?.cwd ?? process.cwd(), rawPath);
}

function hasNonEmptyString(value: unknown): value is string {
return typeof value === 'string' && value.trim().length > 0;
}

function buildRemoteTempArtifactPath(prefix: string, extension: string): string {
const safeExtension = extension.startsWith('.') ? extension : `.${extension}`;
return path.posix.join(
Expand Down
Loading
Loading