Repository navigation
Expand file tree
/
Copy pathprepare-runtime.test.ts
More file actions
80 lines (72 loc) · 3.22 KB
/
Copy pathprepare-runtime.test.ts
File metadata and controls
80 lines (72 loc) · 3.22 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { resolvePreparedRuntimePath } from "../scripts/prepare-runtime";
describe("prepare-runtime", () => {
it("selects explicit same-checkout runtime artifacts without published acquisition", async () => {
const root = await mkdtemp(join(tmpdir(), "copilot-prepare-runtime-"));
try {
const cliPath = join(root, "copilot-runtime");
const legacyCliPath = join(root, "app.js");
await Promise.all([writeFile(cliPath, ""), writeFile(legacyCliPath, "")]);
const acquirePackage = vi.fn(async () => {
throw new Error("published acquisition must not run");
});
await expect(
resolvePreparedRuntimePath({
acquirePackage,
environment: {
COPILOT_CLI_PATH: cliPath,
COPILOT_LEGACY_CLI_PATH: legacyCliPath,
COPILOT_RUNTIME_SOURCE: "checkout",
},
})
).resolves.toBe(cliPath);
await expect(
resolvePreparedRuntimePath({
acquirePackage,
environment: {
COPILOT_CLI_PATH: cliPath,
COPILOT_LEGACY_CLI_PATH: legacyCliPath,
COPILOT_RUNTIME_SOURCE: "checkout",
},
option: "--print-legacy-path",
})
).resolves.toBe(legacyCliPath);
expect(acquirePackage).not.toHaveBeenCalled();
} finally {
await rm(root, { force: true, recursive: true });
}
});
it("fails missing checkout artifacts before published acquisition", async () => {
const acquirePackage = vi.fn(async () => {
throw new Error("published acquisition must not run");
});
await expect(
resolvePreparedRuntimePath({
acquirePackage,
environment: { COPILOT_RUNTIME_SOURCE: "checkout" },
root: join(import.meta.dirname, "copied-sdk"),
})
).rejects.toThrow(
/COPILOT_CLI_PATH must select an existing same-checkout runtime artifact/
);
expect(acquirePackage).not.toHaveBeenCalled();
});
it("retains pinned package acquisition outside the runtime checkout", async () => {
const packageRoot = join(import.meta.dirname, "published-package");
const acquirePackage = vi.fn(async () => packageRoot);
await expect(
resolvePreparedRuntimePath({
acquirePackage,
environment: {},
option: "--print-legacy-path",
root: join(import.meta.dirname, "copied-sdk"),
})
).resolves.toBe(join(packageRoot, "app.js"));
expect(acquirePackage).toHaveBeenCalledOnce();
});
});