Skip to content

Commit 7dfeb33

Browse files
refactor(remote): keep the remote temp artifact path shape inside daemon-artifacts
1 parent 332c35f commit 7dfeb33

4 files changed

Lines changed: 33 additions & 39 deletions

File tree

‎src/daemon/__tests__/macos-app-lease.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
parseMacOsAppLeaseKey,
99
} from '../macos-app-lease.ts';
1010
import type { DaemonRequest } from '../daemon-request.ts';
11-
import { buildRemoteTempArtifactPath } from '../../remote/remote-temp-artifact-path.ts';
1211

1312
const lease: Pick<DeviceLease, 'backend' | 'deviceKey'> = {
1413
backend: 'macos-app',
@@ -114,7 +113,7 @@ test('open accepts only the leased bundle and nothing it could launch beside it'
114113
});
115114

116115
test('nothing under the lease names a host path or launches beside the app', () => {
117-
const temp = buildRemoteTempArtifactPath('screenshot', '.png');
116+
const temp = '/tmp/agent-device-screenshot-1791219384278-ab12cd.png';
118117
assertMacOsAppLeaseAdmitsRequest(lease, request('screenshot', [temp]), leasedSession);
119118
assertMacOsAppLeaseAdmitsRequest(lease, request('screenshot', [], { out: temp }), leasedSession);
120119
for (const target of [['/Users/me/.zshrc'], ['/tmp/agent-device-screenshot-1-a.png/../x']]) {

‎src/daemon/macos-app-lease.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isProcessAlive, readHostEnvironmentVariable } from '@agent-device/host-
66
import { isMacOs } from '@agent-device/kernel/device';
77
import { AppError } from '@agent-device/kernel/errors';
88
import { isAppLeaseAllowed } from './daemon-command-registry.ts';
9-
import { isRemoteTempArtifactPath } from '../remote/remote-temp-artifact-path.ts';
9+
import { isRemoteTempArtifactPath } from '../remote/daemon-artifacts.ts';
1010
import type { DaemonRequest } from './daemon-request.ts';
1111
import type { SessionState } from './session-state.ts';
1212

‎src/remote/daemon-artifacts.ts‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import {
66
appendRecordingExtensionWhenMissing,
77
recordingExtensionForPlatform,
88
} from '@agent-device/capture-kit/recording-output-path';
9-
import {
10-
buildRemoteTempArtifactDirPath,
11-
buildRemoteTempArtifactPath,
12-
} from './remote-temp-artifact-path.ts';
139
import { uploadArtifact } from './upload-client.ts';
1410
import { createStderrUploadProgressReporter, type UploadProgressSink } from './upload-progress.ts';
1511

@@ -345,6 +341,37 @@ function hasNonEmptyString(value: unknown): value is string {
345341
return typeof value === 'string' && value.trim().length > 0;
346342
}
347343

344+
const REMOTE_TEMP_DIR = '/tmp';
345+
346+
/** The daemon-host temp path a remote client names for an artifact it downloads afterwards. */
347+
function buildRemoteTempArtifactPath(prefix: string, extension: string): string {
348+
const safeExtension = extension.startsWith('.') ? extension : `.${extension}`;
349+
return path.posix.join(REMOTE_TEMP_DIR, `${remoteTempArtifactStem(prefix)}${safeExtension}`);
350+
}
351+
352+
/** A directory temp path — unlike `buildRemoteTempArtifactPath`, no extension is ever appended. */
353+
function buildRemoteTempArtifactDirPath(prefix: string): string {
354+
return path.posix.join(REMOTE_TEMP_DIR, remoteTempArtifactStem(prefix));
355+
}
356+
357+
/** Whether `value` has the shape `buildRemoteTempArtifactPath(prefix, extension)` returns. */
358+
export function isRemoteTempArtifactPath(
359+
value: string,
360+
prefix: string,
361+
extension: string,
362+
): boolean {
363+
const stem = path.posix.basename(value, extension);
364+
return (
365+
value === path.posix.join(REMOTE_TEMP_DIR, `${stem}${extension}`) &&
366+
stem.startsWith(`agent-device-${prefix}-`) &&
367+
/^\d+-[a-z0-9]+$/.test(stem.slice(`agent-device-${prefix}-`.length))
368+
);
369+
}
370+
371+
function remoteTempArtifactStem(prefix: string): string {
372+
return `agent-device-${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
373+
}
374+
348375
export async function materializeRemoteArtifacts(
349376
info: DaemonArtifactEndpoint,
350377
req: DaemonRequest,

‎src/remote/remote-temp-artifact-path.ts‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)