Repository navigation
Expand file tree
/
Copy pathresolve-cli-options.test.ts
More file actions
142 lines (122 loc) · 4.79 KB
/
Copy pathresolve-cli-options.test.ts
File metadata and controls
142 lines (122 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { test } from 'vitest';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { mkdtempForTestSync } from '@agent-device/test-kit';
import { resolveCliOptions } from './resolve-cli-options.ts';
/**
* Points `~` at an empty directory so a developer's own ~/.agent-device/config.json cannot add
* defaults to what a test asserts, and keeps PATH so the rest of resolution behaves.
*/
function isolatedEnv(env: Record<string, string>): Record<string, string> {
const home = mkdtempForTestSync('agent-device-cli-env-');
return { HOME: home, USERPROFILE: home, PATH: process.env.PATH ?? '', ...env };
}
test('a frame rate from the environment is not a flag the caller typed', () => {
// `record stop` reads no recording option. A default it ignores must not become a refusal, or
// AGENT_DEVICE_FPS in a CI shell would break every `record stop`.
const parsed = resolveCliOptions(['record', 'stop'], {
cwd: process.cwd(),
env: isolatedEnv({ AGENT_DEVICE_FPS: '30' }),
});
assert.equal(parsed.flags.fps, 30);
assert.deepEqual(
parsed.providedFlags.map((entry) => entry.key),
[],
);
});
test('a frame rate the caller typed stays a typed flag', () => {
const parsed = resolveCliOptions(['record', 'start', './capture.mp4', '--fps', '30'], {
cwd: process.cwd(),
env: isolatedEnv({}),
});
assert.deepEqual(
parsed.providedFlags.map((entry) => entry.key),
['fps'],
);
});
// #3179: settings consumes --app only when this invocation typed it. A mutation that silently
// landed on AGENT_DEVICE_TARGET_APP would change permissions for an app the caller never named,
// while `doctor --app` (and its env default) still reads a configured default app by design.
test('an app from the environment never reaches a settings mutation', () => {
const parsed = resolveCliOptions(['settings', 'permission', 'grant', 'camera'], {
cwd: process.cwd(),
env: isolatedEnv({ AGENT_DEVICE_TARGET_APP: 'com.example.configured' }),
});
assert.equal(parsed.flags.targetApp, undefined);
assert.deepEqual(
parsed.providedFlags.map((entry) => entry.key),
[],
);
});
test('a typed --app still reaches a settings mutation', () => {
const parsed = resolveCliOptions(
['settings', 'permission', 'grant', 'camera', '--app', 'com.example.typed'],
{
cwd: process.cwd(),
env: isolatedEnv({ AGENT_DEVICE_TARGET_APP: 'com.example.configured' }),
},
);
assert.equal(parsed.flags.targetApp, 'com.example.typed');
});
test('the same env default keeps filling doctor, which reads a configured app without a mutation', () => {
const parsed = resolveCliOptions(['doctor'], {
cwd: process.cwd(),
env: isolatedEnv({ AGENT_DEVICE_TARGET_APP: 'com.example.configured' }),
});
assert.equal(parsed.flags.targetApp, 'com.example.configured');
});
// #3260: --text-stdin makes fill block on stdin, so only a typed flag may turn it on.
test('fill --text-stdin has no environment default', () => {
const parsed = resolveCliOptions(['fill', '@e3', 'typed text'], {
cwd: process.cwd(),
env: isolatedEnv({ AGENT_DEVICE_TEXT_STDIN: '1' }),
});
assert.equal(parsed.flags.textStdin, undefined);
});
test('a config file cannot set fill --text-stdin', () => {
const configPath = `${mkdtempForTestSync('agent-device-cli-config-')}/config.json`;
fs.writeFileSync(configPath, JSON.stringify({ textStdin: true }));
assert.throws(
() =>
resolveCliOptions(['fill', '@e3', 'typed text', '--config', configPath], {
cwd: process.cwd(),
env: isolatedEnv({}),
}),
/Config key "textStdin" is not allowed/,
);
});
test('a typed --text-stdin reaches fill', () => {
const parsed = resolveCliOptions(['fill', '@e3', '--text-stdin'], {
cwd: process.cwd(),
env: isolatedEnv({}),
});
assert.equal(parsed.flags.textStdin, true);
});
// #4298: `device status|release` narrow claims by the selectors the caller typed. A config default
// udid would otherwise win over a typed --serial in the claim filter and hide the requested claim.
test('config selectors never narrow device status or release', () => {
const dir = mkdtempForTestSync('agent-device-cli-config-');
const configPath = `${dir}/agent-device.json`;
fs.writeFileSync(
configPath,
JSON.stringify({
platform: 'ios',
device: 'Configured',
udid: 'cfg-udid',
serial: 'cfg-serial',
}),
);
for (const action of ['status', 'release']) {
const parsed = resolveCliOptions(
['device', action, '--serial', 'typed-serial', '--config', configPath],
{
cwd: process.cwd(),
env: isolatedEnv({}),
},
);
assert.equal(parsed.flags.serial, 'typed-serial');
assert.equal(parsed.flags.udid, undefined);
assert.equal(parsed.flags.device, undefined);
assert.equal(parsed.flags.platform, undefined);
}
});