Skip to content

Commit 0baaaa0

Browse files
author
Ark
committed
fix(script): avoid eager contracts import and relocate Harmony test
Signed-off-by: Ark <[email protected]>
1 parent fa0b33c commit 0baaaa0

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

‎packages/ad-script/src/internal/script-utils.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import type { SessionAction } from '@agent-device/contracts/session';
2-
import { isSessionRuntimePlatform, type SessionRuntimeHints } from '@agent-device/kernel/contracts';
2+
import type { SessionRuntimeHints } from '@agent-device/kernel/contracts';
33
import { appendScreenshotScriptFlags } from '@agent-device/contracts/capture';
44
import { splitRefGenerationSuffix } from '@agent-device/kernel/snapshot';
55

6+
const SCRIPT_RUNTIME_PLATFORMS = {
7+
ios: true,
8+
android: true,
9+
harmonyos: true,
10+
} satisfies Record<NonNullable<SessionRuntimeHints['platform']>, true>;
11+
12+
function isScriptRuntimePlatform(
13+
value: unknown,
14+
): value is NonNullable<SessionRuntimeHints['platform']> {
15+
return typeof value === 'string' && Object.hasOwn(SCRIPT_RUNTIME_PLATFORMS, value);
16+
}
17+
618
/**
719
* #1076 versioned refs: a recorded ref positional may carry a `~s<generation>`
820
* pin from the client that issued it (`@e12~s3`). Generations are meaningless
@@ -168,7 +180,7 @@ export function appendRuntimeHintFlags(
168180
flags: Pick<SessionAction, 'flags'>['flags'] | SessionRuntimeHints | undefined,
169181
): void {
170182
if (!flags) return;
171-
if (isSessionRuntimePlatform(flags.platform)) {
183+
if (isScriptRuntimePlatform(flags.platform)) {
172184
parts.push('--platform', flags.platform);
173185
}
174186
if (typeof flags.metroHost === 'string' && flags.metroHost.length > 0) {
@@ -325,7 +337,7 @@ export function parseReplayRuntimeFlags(args: string[]): {
325337
const nextArg = args[index + 1];
326338
if (token === '--platform' && nextArg !== undefined) {
327339
const platform = nextArg;
328-
if (isSessionRuntimePlatform(platform)) {
340+
if (isScriptRuntimePlatform(platform)) {
329341
flags.platform = platform;
330342
}
331343
index += 1;

‎src/__tests__/remote-connection-harmonyos.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@ import fs from 'node:fs';
33
import {
44
connectionWorkspace,
55
createTestClient,
6+
forceConnectFlags,
67
seedConnectionState,
78
} from './remote-connection.fixtures.ts';
8-
import { materializeRemoteConnectionForCommand } from '../cli/commands/connection-runtime.ts';
9+
import {
10+
materializeRemoteConnectionForCommand,
11+
resolveRequestedLeaseBackend,
12+
} from '../cli/commands/connection-runtime.ts';
913
import { disconnectCommand } from '../cli/commands/connection.ts';
1014
import { readRemoteConnectionState } from '../remote/remote-connection-state.ts';
1115
import { LeaseRegistry } from '../daemon/lease-registry.ts';
1216

17+
test('HarmonyOS platform resolves to its proxy lease backend', () => {
18+
expect(
19+
resolveRequestedLeaseBackend(
20+
forceConnectFlags({
21+
stateDir: '/tmp/agent-device',
22+
remoteConfig: '/tmp/remote.json',
23+
platform: 'harmonyos',
24+
}),
25+
),
26+
).toBe('harmonyos-instance');
27+
});
28+
1329
test.each(['apple', 'harmonyos', 'ios', 'android'] as const)(
1430
'stored Harmony runtime compatibility respects %s selection',
1531
async (platform) => {

‎src/__tests__/remote-connection.test.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ import {
3434
materializeRemoteConnectionForCommand,
3535
CLOUD_WEBDRIVER_REMOTE_LEASE_TTL_MS,
3636
PROXY_REMOTE_LEASE_TTL_MS,
37-
resolveRequestedLeaseBackend,
3837
} from '../cli/commands/connection-runtime.ts';
39-
4038
import { stopMetroCompanion } from '../metro/client-metro-companion.ts';
4139
import { AppError } from '@agent-device/kernel/errors';
4240
import {
@@ -47,19 +45,6 @@ import {
4745
} from '../remote/remote-connection-state.ts';
4846
import type { AgentDeviceClient } from '../agent-device-client.ts';
4947

50-
test('HarmonyOS platform resolves to its proxy lease backend', () => {
51-
assert.equal(
52-
resolveRequestedLeaseBackend(
53-
forceConnectFlags({
54-
stateDir: '/tmp/agent-device',
55-
remoteConfig: '/tmp/remote.json',
56-
platform: 'harmonyos',
57-
}),
58-
),
59-
'harmonyos-instance',
60-
);
61-
});
62-
6348
afterEach(() => {
6449
vi.clearAllMocks();
6550
vi.restoreAllMocks();

0 commit comments

Comments
 (0)