Repository navigation
Expand file tree
/
Copy pathlimrun-host-scope.test.ts
More file actions
84 lines (81 loc) · 3.06 KB
/
Copy pathlimrun-host-scope.test.ts
File metadata and controls
84 lines (81 loc) · 3.06 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
import assert from 'node:assert/strict';
import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { beforeAll, test } from 'vitest';
import { mkdtempForTestSync } from '@agent-device/test-kit';
import { withCommandHost } from '@agent-device/host-kit/command';
import { createLimrunRuntimeDependencies } from './limrun-runtime-dependencies.ts';
beforeAll(async () => {
if (process.platform !== 'win32') await import('@agent-device/platform-apple/install-artifact');
});
test.skipIf(process.platform === 'win32')(
'Limrun ADB callbacks retain their owning host outside and across concurrent foreign scopes',
async () => {
const root = mkdtempForTestSync('agent-device-limrun-host-');
const bin = path.join(root, 'bin');
mkdirSync(bin);
const adb = path.join(bin, 'adb');
writeFileSync(
adb,
`#!${process.execPath}\n` +
`process.stdout.write(JSON.stringify({args:process.argv.slice(2),host:process.env.LIMRUN_OWNER}));\n`,
);
chmodSync(adb, 0o755);
const owner = (name: string) =>
createLimrunRuntimeDependencies({
env: { ...process.env, PATH: bin, LIMRUN_OWNER: name },
cwd: root,
});
const first = owner('first');
const second = owner('second');
const invocation = {
target: { selector: { kind: 'unspecified' as const }, server: { kind: 'ambient' as const } },
command: ['devices'],
};
const previous = { PATH: process.env.PATH, LIMRUN_OWNER: process.env.LIMRUN_OWNER };
process.env.PATH = bin;
process.env.LIMRUN_OWNER = 'ambient';
try {
const standalone = await first.host.runAdb(invocation);
const [left, right] = await withCommandHost(
{
host: { env: { ...process.env, PATH: bin, LIMRUN_OWNER: 'foreign' }, cwd: root },
requestEnv: { LIMRUN_OWNER: 'foreign-request' },
},
() => Promise.all([first.host.runAdb(invocation), second.host.runAdb(invocation)]),
);
for (const [result, host] of [
[standalone, 'first'],
[left, 'first'],
[right, 'second'],
] as const) {
assert.deepEqual(JSON.parse(result.stdout), { args: ['devices'], host });
}
} finally {
for (const [key, value] of Object.entries(previous)) {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
}
},
);
test.skipIf(process.platform === 'win32')(
'Limrun bundle inference resolves plist tooling from its supplied host without an outer scope',
async () => {
const root = mkdtempForTestSync('agent-device-limrun-plist-');
const plutil = path.join(root, 'plutil');
writeFileSync(
plutil,
`#!${process.execPath}\nprocess.stdout.write(JSON.stringify({CFBundleDisplayName:'Scoped App'}));\n`,
);
chmodSync(plutil, 0o755);
const dependencies = createLimrunRuntimeDependencies({
env: { ...process.env, PATH: root },
cwd: root,
});
assert.equal(
await dependencies.ios.readBundleAppName(path.join(root, 'Example.app')),
'Scoped App',
);
},
);