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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export function seedAndroidRecordingResource(
scope: manifest.scope,
showTouches: manifest.showTouches,
recordOnlySession: manifest.recordOnlySession,
exportQuality: manifest.exportQuality,
...(manifest.exportQuality === undefined
? {}
: { exportQuality: manifest.exportQuality }),
transportMode: manifest.transportMode,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type AndroidRecordingManifestFixture = {
scope: 'device';
showTouches: boolean;
recordOnlySession: boolean;
exportQuality: 'medium' | 'high';
exportQuality?: 'medium' | 'high';
transportMode: 'transport-composed';
chunks: NativeChunk[];
pendingRemotePath?: string;
Expand Down Expand Up @@ -126,7 +126,7 @@ function hasCaptureSettings(value: JsonObject): boolean {
value.scope === 'device' &&
isBooleanProperty(value, 'showTouches') &&
isBooleanProperty(value, 'recordOnlySession') &&
isExportQuality(value.exportQuality) &&
isOptionalExportQuality(value.exportQuality) &&
value.transportMode === 'transport-composed' &&
hasChunkList(value.chunks) &&
hasOptionalString(value, 'pendingRemotePath') &&
Expand Down Expand Up @@ -174,6 +174,10 @@ function isExportQuality(value: JsonValue | undefined): boolean {
return value === 'medium' || value === 'high';
}

function isOptionalExportQuality(value: JsonValue | undefined): boolean {
return value === undefined || isExportQuality(value);
}

function isJsonObject(value: unknown): value is JsonObject {
return (
typeof value === 'object' && value !== null && !Array.isArray(value) && isJsonRecord(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';
import { createAndroidRecordingProvider } from './android-recording-provider-fixtures.ts';

test('Android recording provider fixtures reject unmodeled executable commands', async () => {
const provider = createAndroidRecordingProvider({ calls: [] });

await assert.rejects(
provider.exec(['shell', 'echo unmodeled-provider-command']),
/Unhandled Android recording provider command: shell echo unmodeled-provider-command/,
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function respondToCommand(
const pull = respondToPull(args, params, state);
if (pull) return pull;
if (args.join(' ') === 'shell getprop sys.boot_completed') return ok('1\n');
return respondToShellCommand(args[1] ?? '', state);
const response = args[0] === 'shell' ? respondToShellCommand(args[1] ?? '', state) : undefined;
if (response) return response;
throw new Error(`Unhandled Android recording provider command: ${args.join(' ')}`);
}

function respondToPull(
Expand Down Expand Up @@ -108,12 +110,21 @@ function respondToManifestTarget(

function respondToProcessCommand(command: string, processes: Map<string, NativeProcess>) {
return (
respondToProcessList(command, processes) ??
respondToProcessDirectory(command, processes) ??
respondToProcessMetadata(command, processes) ??
respondToProcessSignal(command, processes)
);
}

function respondToProcessList(command: string, processes: Map<string, NativeProcess>) {
if (command !== 'ps -A -o pid=') return undefined;
const alivePids = [...processes.entries()]
.filter(([, nativeProcess]) => nativeProcess.alive)
.map(([pid]) => pid);
return ok(alivePids.length > 0 ? `${alivePids.join('\n')}\n` : '');
}

function respondToProcessDirectory(command: string, processes: Map<string, NativeProcess>) {
const directory = /^test -d \/proc\/(\d+)$/.exec(command);
const [, directoryPid] = directory ?? [];
Expand Down Expand Up @@ -148,8 +159,16 @@ function respondToScreenrecordCommand(command: string, processes: Map<string, Na
}

function respondToArtifactCommand(command: string) {
if (command.startsWith('test -e ')) return ok();
return command.startsWith('stat -c %s ') ? ok('2048\n') : ok();
for (const prefix of ['test -e ', 'rm -f ']) {
const target = shellPath(command, prefix);
if (target && isRecordingArtifactPath(target)) return ok();
}
const target = shellPath(command, 'stat -c %s ');
return target && isRecordingArtifactPath(target) ? ok('2048\n') : undefined;
}

function isRecordingArtifactPath(path: string): boolean {
return /^\/(?:sdcard|data\/local\/tmp)\/agent-device-recording-\d+\.mp4$/.test(path);
}

function addManifestProcesses(
Expand Down
Loading