@autifyhq/autify-cli-integration-test 0.66.0 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const globals_1 = require("@jest/globals");
5
+ const node_child_process_1 = require("node:child_process");
6
+ const node_fs_1 = require("node:fs");
7
+ const promises_1 = require("node:fs/promises");
8
+ const node_http_1 = require("node:http");
9
+ const node_net_1 = require("node:net");
10
+ const node_os_1 = require("node:os");
11
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
+ const node_process_1 = require("node:process");
13
+ const get_autify_cli_path_1 = require("../../test/helpers/get-autify-cli-path");
14
+ /**
15
+ * Start a simple HTTP proxy server that supports CONNECT tunneling and tracks URLs
16
+ */
17
+ const startTrackingProxy = () => {
18
+ const proxiedUrls = [];
19
+ const server = (0, node_http_1.createServer)((req, res) => {
20
+ // Handle regular HTTP requests (not used by undici ProxyAgent for HTTPS)
21
+ const fullUrl = req.url ?? "/";
22
+ proxiedUrls.push(fullUrl);
23
+ res.writeHead(200);
24
+ res.end();
25
+ });
26
+ // Handle CONNECT method for HTTPS tunneling (used by undici ProxyAgent)
27
+ server.on("connect", (req, clientSocket, head) => {
28
+ const { port: targetPort, hostname: targetHostname } = new URL(`https://${req.url}`);
29
+ proxiedUrls.push(`https://${req.url}`);
30
+ // Connect to the target server
31
+ const serverSocket = new node_net_1.Socket();
32
+ serverSocket.connect(Number(targetPort) || 443, targetHostname, () => {
33
+ clientSocket.write("HTTP/1.1 200 Connection Established\r\n" +
34
+ "Proxy-agent: Node.js-Proxy\r\n" +
35
+ "\r\n");
36
+ serverSocket.write(head);
37
+ serverSocket.pipe(clientSocket);
38
+ clientSocket.pipe(serverSocket);
39
+ });
40
+ serverSocket.on("error", () => {
41
+ clientSocket.end();
42
+ });
43
+ });
44
+ server.listen();
45
+ const { port } = server.address();
46
+ return {
47
+ server,
48
+ port,
49
+ getProxiedUrls: () => proxiedUrls,
50
+ };
51
+ };
52
+ /**
53
+ * Run autify CLI command with proxy configuration
54
+ */
55
+ const runAutifyWithProxy = async (command, proxyPort, cacheDir, useFakeMode = false) => {
56
+ return new Promise((resolve, reject) => {
57
+ const autifyPath = (0, get_autify_cli_path_1.getAutifyCliPath)();
58
+ const testEnv = {
59
+ ...node_process_1.env,
60
+ HTTP_PROXY: `http://127.0.0.1:${proxyPort}`,
61
+ HTTPS_PROXY: `http://127.0.0.1:${proxyPort}`,
62
+ // Don't use proxy for these hosts
63
+ NO_PROXY: "localhost,127.0.0.1",
64
+ // Use test cache directory
65
+ XDG_CACHE_HOME: cacheDir,
66
+ };
67
+ // Use fake mode for autifyconnect to avoid interactive prompts
68
+ if (useFakeMode) {
69
+ testEnv.AUTIFY_CONNECT_CLIENT_MODE = "fake";
70
+ }
71
+ const proc = (0, node_child_process_1.spawn)(autifyPath, command, {
72
+ env: testEnv,
73
+ shell: process.platform === "win32",
74
+ });
75
+ let stdout = "";
76
+ let stderr = "";
77
+ proc.stdout?.on("data", (data) => {
78
+ stdout += data.toString();
79
+ });
80
+ proc.stderr?.on("data", (data) => {
81
+ stderr += data.toString();
82
+ });
83
+ proc.on("close", (exitCode) => {
84
+ resolve({ exitCode, stdout, stderr });
85
+ });
86
+ proc.on("error", (error) => {
87
+ reject(error);
88
+ });
89
+ });
90
+ };
91
+ /**
92
+ * Clean up default cache directory (not the test cache)
93
+ * This ensures a fresh download for testing proxy behavior
94
+ */
95
+ const cleanupDefaultCache = async () => {
96
+ const cachePaths = [
97
+ // macOS
98
+ node_path_1.default.join(node_process_1.env.HOME ?? "", "Library", "Caches", "autify"),
99
+ // Linux/XDG
100
+ node_path_1.default.join(node_process_1.env.HOME ?? "", ".cache", "autify"),
101
+ // Windows (LOCALAPPDATA)
102
+ node_process_1.env.LOCALAPPDATA ? node_path_1.default.join(node_process_1.env.LOCALAPPDATA, "autify") : null,
103
+ // Windows fallback (APPDATA)
104
+ node_process_1.env.APPDATA ? node_path_1.default.join(node_process_1.env.APPDATA, "autify") : null,
105
+ ].filter((p) => p !== null && (0, node_fs_1.existsSync)(p));
106
+ await Promise.all(cachePaths.map((cachePath) => (0, promises_1.rm)(cachePath, { recursive: true, force: true })));
107
+ };
108
+ (0, globals_1.describe)("Proxy Integration Tests", () => {
109
+ let proxyServer;
110
+ let testCacheDir;
111
+ beforeEach(async () => {
112
+ // Clean up any existing cached binaries
113
+ await cleanupDefaultCache();
114
+ // Create temporary cache directory for this test
115
+ testCacheDir = await (0, promises_1.mkdtemp)(node_path_1.default.join((0, node_os_1.tmpdir)(), "autify-test-"));
116
+ // Start tracking proxy
117
+ proxyServer = startTrackingProxy();
118
+ });
119
+ afterEach(async () => {
120
+ if (proxyServer) {
121
+ proxyServer.server.close();
122
+ }
123
+ // Clean up test cache directory
124
+ if (testCacheDir && (0, node_fs_1.existsSync)(testCacheDir)) {
125
+ await (0, promises_1.rm)(testCacheDir, { recursive: true, force: true });
126
+ }
127
+ });
128
+ (0, globals_1.test)("autify connect client install should use proxy when HTTP_PROXY is set", async () => {
129
+ const { exitCode } = await runAutifyWithProxy(["connect", "client", "install"], proxyServer.port, testCacheDir);
130
+ (0, globals_1.expect)(exitCode).toBe(0);
131
+ // Verify that the autifyconnect binary download went through the proxy
132
+ const proxiedUrls = proxyServer.getProxiedUrls();
133
+ const autifyconnectDownload = proxiedUrls.find((url) => url.includes("autifyconnect.s3"));
134
+ (0, globals_1.expect)(autifyconnectDownload).toBeDefined();
135
+ (0, globals_1.expect)(autifyconnectDownload).toContain("autifyconnect.s3.ap-northeast-1.amazonaws.com");
136
+ }, 60_000);
137
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get the Autify CLI path for testing.
3
+ *
4
+ * Uses AUTIFY_CLI_PATH env var if set, otherwise falls back to "autify" (globally installed).
5
+ *
6
+ * To test with dev CLI, set: AUTIFY_CLI_PATH=../bin/dev
7
+ *
8
+ * Same pattern as:
9
+ * - e2e-test/mobile/get-autify-cli-path.ts
10
+ * - integration-test/src/bin/autify-with-proxy.ts getAutifyCli()
11
+ */
12
+ export declare const getAutifyCliPath: () => string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAutifyCliPath = void 0;
4
+ const node_process_1 = require("node:process");
5
+ /**
6
+ * Get the Autify CLI path for testing.
7
+ *
8
+ * Uses AUTIFY_CLI_PATH env var if set, otherwise falls back to "autify" (globally installed).
9
+ *
10
+ * To test with dev CLI, set: AUTIFY_CLI_PATH=../bin/dev
11
+ *
12
+ * Same pattern as:
13
+ * - e2e-test/mobile/get-autify-cli-path.ts
14
+ * - integration-test/src/bin/autify-with-proxy.ts getAutifyCli()
15
+ */
16
+ const getAutifyCliPath = () => {
17
+ return node_process_1.env.AUTIFY_CLI_PATH ?? "autify";
18
+ };
19
+ exports.getAutifyCliPath = getAutifyCliPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autifyhq/autify-cli-integration-test",
3
- "version": "0.66.0",
3
+ "version": "0.67.0",
4
4
  "description": "Autify Command Line Interface (CLI) Integration Test",
5
5
  "author": "Autify",
6
6
  "bin": {
@@ -48,7 +48,8 @@
48
48
  "build": "shx rm -rf dist && tsc -b",
49
49
  "prepack": "npm run build",
50
50
  "test": "autify-mobile-generate-fake-app && cross-env AUTIFY_TEST_WAIT_INTERVAL_SECOND=0 jest --testMatch **/dist/test/**/*.test.js",
51
- "test:record": "AUTIFY_POLLY_RECORD=1 jest --testMatch **/dist/test/**/*.test.js --updateSnapshot"
51
+ "test:record": "AUTIFY_POLLY_RECORD=1 jest --testMatch **/dist/test/**/*.test.js --updateSnapshot",
52
+ "test:proxy": "jest --testMatch **/dist/proxy-tests/**/*.test.js"
52
53
  },
53
54
  "engines": {
54
55
  "node": ">=22.16.0"