@nexical/cli 0.1.7 → 0.10.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.
Files changed (236) hide show
  1. package/.github/workflows/deploy.yml +3 -3
  2. package/README.md +317 -104
  3. package/dist/chunk-JYASTIIW.js +42 -0
  4. package/dist/chunk-JYASTIIW.js.map +1 -0
  5. package/dist/chunk-LZ3YQWAR.js +2204 -0
  6. package/dist/chunk-LZ3YQWAR.js.map +1 -0
  7. package/dist/chunk-OKXOCNXP.js +105 -0
  8. package/dist/chunk-OKXOCNXP.js.map +1 -0
  9. package/dist/chunk-OYFWMYPG.js +52 -0
  10. package/dist/chunk-OYFWMYPG.js.map +1 -0
  11. package/dist/chunk-WKERTCM6.js +74 -0
  12. package/dist/chunk-WKERTCM6.js.map +1 -0
  13. package/dist/index.js +32 -5
  14. package/dist/index.js.map +1 -1
  15. package/dist/src/commands/init.d.ts +11 -0
  16. package/dist/src/commands/init.js +88 -0
  17. package/dist/src/commands/init.js.map +1 -0
  18. package/dist/src/commands/module/add.d.ts +14 -0
  19. package/dist/src/commands/module/add.js +136 -0
  20. package/dist/src/commands/module/add.js.map +1 -0
  21. package/dist/src/commands/module/list.d.ts +10 -0
  22. package/dist/src/commands/module/list.js +73 -0
  23. package/dist/src/commands/module/list.js.map +1 -0
  24. package/dist/src/commands/module/remove.d.ts +12 -0
  25. package/dist/src/commands/module/remove.js +71 -0
  26. package/dist/src/commands/module/remove.js.map +1 -0
  27. package/dist/src/commands/module/update.d.ts +11 -0
  28. package/dist/src/commands/module/update.js +52 -0
  29. package/dist/src/commands/module/update.js.map +1 -0
  30. package/dist/src/commands/run.d.ts +11 -0
  31. package/dist/src/commands/run.js +93 -0
  32. package/dist/src/commands/run.js.map +1 -0
  33. package/dist/src/utils/discovery.d.ts +13 -0
  34. package/dist/src/utils/discovery.js +9 -0
  35. package/dist/src/utils/git.d.ts +16 -0
  36. package/dist/src/utils/git.js +29 -0
  37. package/dist/src/utils/git.js.map +1 -0
  38. package/dist/src/utils/url-resolver.d.ts +15 -0
  39. package/dist/src/utils/url-resolver.js +9 -0
  40. package/dist/src/utils/url-resolver.js.map +1 -0
  41. package/index.ts +29 -5
  42. package/package.json +33 -31
  43. package/src/commands/init.ts +85 -0
  44. package/src/commands/module/add.ts +169 -0
  45. package/src/commands/module/list.ts +69 -0
  46. package/src/commands/module/remove.ts +74 -0
  47. package/src/commands/module/update.ts +50 -0
  48. package/src/commands/run.ts +98 -0
  49. package/src/utils/discovery.ts +134 -0
  50. package/src/utils/git.ts +65 -0
  51. package/src/utils/url-resolver.ts +57 -0
  52. package/test/e2e/lifecycle.e2e.test.ts +152 -0
  53. package/test/integration/commands/init.integration.test.ts +82 -0
  54. package/test/integration/commands/module.integration.test.ts +144 -0
  55. package/test/integration/commands/run.integration.test.ts +90 -0
  56. package/test/integration/utils/command-loading.integration.test.ts +80 -0
  57. package/test/unit/commands/init.test.ts +153 -0
  58. package/test/unit/commands/module/add.test.ts +262 -0
  59. package/test/unit/commands/module/list.test.ts +115 -0
  60. package/test/unit/commands/module/remove.test.ts +89 -0
  61. package/test/unit/commands/module/update.test.ts +91 -0
  62. package/test/unit/commands/run.test.ts +252 -0
  63. package/test/unit/utils/command-discovery.test.ts +176 -0
  64. package/test/unit/utils/git.test.ts +152 -0
  65. package/test/unit/utils/integration-helpers.test.ts +72 -0
  66. package/test/unit/utils/url-resolver.test.ts +39 -0
  67. package/test/utils/integration-helpers.ts +66 -0
  68. package/vitest.e2e.config.ts +0 -1
  69. package/dist/chunk-JDRAVUKK.js +0 -48
  70. package/dist/chunk-JDRAVUKK.js.map +0 -1
  71. package/dist/src/commands/admin/create-user.d.ts +0 -15
  72. package/dist/src/commands/admin/create-user.js +0 -49
  73. package/dist/src/commands/admin/create-user.js.map +0 -1
  74. package/dist/src/commands/branch/create.d.ts +0 -19
  75. package/dist/src/commands/branch/create.js +0 -59
  76. package/dist/src/commands/branch/create.js.map +0 -1
  77. package/dist/src/commands/branch/delete.d.ts +0 -15
  78. package/dist/src/commands/branch/delete.js +0 -50
  79. package/dist/src/commands/branch/delete.js.map +0 -1
  80. package/dist/src/commands/branch/get.d.ts +0 -15
  81. package/dist/src/commands/branch/get.js +0 -53
  82. package/dist/src/commands/branch/get.js.map +0 -1
  83. package/dist/src/commands/branch/list.d.ts +0 -15
  84. package/dist/src/commands/branch/list.js +0 -51
  85. package/dist/src/commands/branch/list.js.map +0 -1
  86. package/dist/src/commands/job/get.d.ts +0 -15
  87. package/dist/src/commands/job/get.js +0 -62
  88. package/dist/src/commands/job/get.js.map +0 -1
  89. package/dist/src/commands/job/list.d.ts +0 -15
  90. package/dist/src/commands/job/list.js +0 -57
  91. package/dist/src/commands/job/list.js.map +0 -1
  92. package/dist/src/commands/job/logs.d.ts +0 -15
  93. package/dist/src/commands/job/logs.js +0 -67
  94. package/dist/src/commands/job/logs.js.map +0 -1
  95. package/dist/src/commands/job/trigger.d.ts +0 -19
  96. package/dist/src/commands/job/trigger.js +0 -74
  97. package/dist/src/commands/job/trigger.js.map +0 -1
  98. package/dist/src/commands/login.d.ts +0 -8
  99. package/dist/src/commands/login.js +0 -31
  100. package/dist/src/commands/login.js.map +0 -1
  101. package/dist/src/commands/project/create.d.ts +0 -24
  102. package/dist/src/commands/project/create.js +0 -63
  103. package/dist/src/commands/project/create.js.map +0 -1
  104. package/dist/src/commands/project/delete.d.ts +0 -20
  105. package/dist/src/commands/project/delete.js +0 -58
  106. package/dist/src/commands/project/delete.js.map +0 -1
  107. package/dist/src/commands/project/get.d.ts +0 -15
  108. package/dist/src/commands/project/get.js +0 -49
  109. package/dist/src/commands/project/get.js.map +0 -1
  110. package/dist/src/commands/project/list.d.ts +0 -15
  111. package/dist/src/commands/project/list.js +0 -45
  112. package/dist/src/commands/project/list.js.map +0 -1
  113. package/dist/src/commands/project/update.d.ts +0 -19
  114. package/dist/src/commands/project/update.js +0 -66
  115. package/dist/src/commands/project/update.js.map +0 -1
  116. package/dist/src/commands/team/create.d.ts +0 -19
  117. package/dist/src/commands/team/create.js +0 -45
  118. package/dist/src/commands/team/create.js.map +0 -1
  119. package/dist/src/commands/team/delete.d.ts +0 -20
  120. package/dist/src/commands/team/delete.js +0 -52
  121. package/dist/src/commands/team/delete.js.map +0 -1
  122. package/dist/src/commands/team/get.d.ts +0 -15
  123. package/dist/src/commands/team/get.js +0 -42
  124. package/dist/src/commands/team/get.js.map +0 -1
  125. package/dist/src/commands/team/list.d.ts +0 -8
  126. package/dist/src/commands/team/list.js +0 -30
  127. package/dist/src/commands/team/list.js.map +0 -1
  128. package/dist/src/commands/team/member/invite.d.ts +0 -20
  129. package/dist/src/commands/team/member/invite.js +0 -54
  130. package/dist/src/commands/team/member/invite.js.map +0 -1
  131. package/dist/src/commands/team/member/remove.d.ts +0 -15
  132. package/dist/src/commands/team/member/remove.js +0 -43
  133. package/dist/src/commands/team/member/remove.js.map +0 -1
  134. package/dist/src/commands/team/update.d.ts +0 -19
  135. package/dist/src/commands/team/update.js +0 -55
  136. package/dist/src/commands/team/update.js.map +0 -1
  137. package/dist/src/commands/token/generate.d.ts +0 -19
  138. package/dist/src/commands/token/generate.js +0 -48
  139. package/dist/src/commands/token/generate.js.map +0 -1
  140. package/dist/src/commands/token/list.d.ts +0 -8
  141. package/dist/src/commands/token/list.js +0 -31
  142. package/dist/src/commands/token/list.js.map +0 -1
  143. package/dist/src/commands/token/revoke.d.ts +0 -15
  144. package/dist/src/commands/token/revoke.js +0 -38
  145. package/dist/src/commands/token/revoke.js.map +0 -1
  146. package/dist/src/commands/whoami.d.ts +0 -8
  147. package/dist/src/commands/whoami.js +0 -26
  148. package/dist/src/commands/whoami.js.map +0 -1
  149. package/dist/src/utils/nexical-client.d.ts +0 -10
  150. package/dist/src/utils/nexical-client.js +0 -12
  151. package/src/commands/admin/create-user.ts +0 -46
  152. package/src/commands/branch/create.ts +0 -57
  153. package/src/commands/branch/delete.ts +0 -47
  154. package/src/commands/branch/get.ts +0 -50
  155. package/src/commands/branch/list.ts +0 -50
  156. package/src/commands/job/get.ts +0 -59
  157. package/src/commands/job/list.ts +0 -56
  158. package/src/commands/job/logs.ts +0 -67
  159. package/src/commands/job/trigger.ts +0 -73
  160. package/src/commands/login.ts +0 -31
  161. package/src/commands/project/create.ts +0 -61
  162. package/src/commands/project/delete.ts +0 -56
  163. package/src/commands/project/get.ts +0 -46
  164. package/src/commands/project/list.ts +0 -44
  165. package/src/commands/project/update.ts +0 -63
  166. package/src/commands/team/create.ts +0 -43
  167. package/src/commands/team/delete.ts +0 -50
  168. package/src/commands/team/get.ts +0 -39
  169. package/src/commands/team/list.ts +0 -26
  170. package/src/commands/team/member/invite.ts +0 -56
  171. package/src/commands/team/member/remove.ts +0 -40
  172. package/src/commands/team/update.ts +0 -53
  173. package/src/commands/token/generate.ts +0 -45
  174. package/src/commands/token/list.ts +0 -27
  175. package/src/commands/token/revoke.ts +0 -35
  176. package/src/commands/whoami.ts +0 -21
  177. package/src/utils/nexical-client.ts +0 -47
  178. package/test/e2e/auth.e2e.test.ts +0 -46
  179. package/test/e2e/job-workflow.e2e.test.ts +0 -33
  180. package/test/e2e/project-lifecycle.e2e.test.ts +0 -48
  181. package/test/e2e/setup.ts +0 -237
  182. package/test/e2e/utils.ts +0 -33
  183. package/test/integration/commands/admin/create-user.test.ts +0 -51
  184. package/test/integration/commands/branch/create.test.ts +0 -51
  185. package/test/integration/commands/branch/delete.test.ts +0 -43
  186. package/test/integration/commands/branch/get.test.ts +0 -49
  187. package/test/integration/commands/branch/list.test.ts +0 -47
  188. package/test/integration/commands/job/get.test.ts +0 -54
  189. package/test/integration/commands/job/list.test.ts +0 -47
  190. package/test/integration/commands/job/logs.test.ts +0 -47
  191. package/test/integration/commands/job/trigger.test.ts +0 -57
  192. package/test/integration/commands/login.test.ts +0 -62
  193. package/test/integration/commands/project/create.test.ts +0 -53
  194. package/test/integration/commands/project/delete.test.ts +0 -43
  195. package/test/integration/commands/project/get.test.ts +0 -51
  196. package/test/integration/commands/project/list.test.ts +0 -47
  197. package/test/integration/commands/project/update.test.ts +0 -53
  198. package/test/integration/commands/team/create.test.ts +0 -53
  199. package/test/integration/commands/team/delete.test.ts +0 -43
  200. package/test/integration/commands/team/get.test.ts +0 -50
  201. package/test/integration/commands/team/list.test.ts +0 -47
  202. package/test/integration/commands/team/member/invite.test.ts +0 -46
  203. package/test/integration/commands/team/member/remove.test.ts +0 -43
  204. package/test/integration/commands/team/update.test.ts +0 -50
  205. package/test/integration/commands/token/generate.test.ts +0 -51
  206. package/test/integration/commands/token/list.test.ts +0 -47
  207. package/test/integration/commands/token/revoke.test.ts +0 -43
  208. package/test/integration/commands/whoami.test.ts +0 -49
  209. package/test/unit/commands/admin/create-user.test.ts +0 -51
  210. package/test/unit/commands/branch/create.test.ts +0 -57
  211. package/test/unit/commands/branch/delete.test.ts +0 -49
  212. package/test/unit/commands/branch/get.test.ts +0 -67
  213. package/test/unit/commands/branch/list.test.ts +0 -62
  214. package/test/unit/commands/job/get.test.ts +0 -76
  215. package/test/unit/commands/job/list.test.ts +0 -62
  216. package/test/unit/commands/job/logs.test.ts +0 -60
  217. package/test/unit/commands/job/trigger.test.ts +0 -75
  218. package/test/unit/commands/login.test.ts +0 -64
  219. package/test/unit/commands/project/create.test.ts +0 -64
  220. package/test/unit/commands/project/delete.test.ts +0 -72
  221. package/test/unit/commands/project/get.test.ts +0 -73
  222. package/test/unit/commands/project/list.test.ts +0 -62
  223. package/test/unit/commands/project/update.test.ts +0 -58
  224. package/test/unit/commands/team/create.test.ts +0 -68
  225. package/test/unit/commands/team/delete.test.ts +0 -71
  226. package/test/unit/commands/team/get.test.ts +0 -70
  227. package/test/unit/commands/team/list.test.ts +0 -56
  228. package/test/unit/commands/team/member/invite.test.ts +0 -52
  229. package/test/unit/commands/team/member/remove.test.ts +0 -49
  230. package/test/unit/commands/team/update.test.ts +0 -63
  231. package/test/unit/commands/token/generate.test.ts +0 -65
  232. package/test/unit/commands/token/list.test.ts +0 -58
  233. package/test/unit/commands/token/revoke.test.ts +0 -49
  234. package/test/unit/commands/whoami.test.ts +0 -49
  235. package/test/unit/utils/nexical-client.test.ts +0 -113
  236. /package/dist/src/utils/{nexical-client.js.map → discovery.js.map} +0 -0
@@ -1,35 +0,0 @@
1
-
2
- import { BaseCommand } from '@nexical/cli-core';
3
- import { getClient } from '../../utils/nexical-client.js';
4
-
5
- export default class AuthTokensRevokeCommand extends BaseCommand {
6
- static description = 'Revoke an API token';
7
-
8
- static args = {
9
- args: [
10
- {
11
- name: 'id',
12
- required: true,
13
- description: 'ID of the token to revoke',
14
- },
15
- ],
16
- };
17
-
18
- async run(options: any) {
19
- const client = getClient();
20
- const { id } = options;
21
- const tid = parseInt(id, 10);
22
-
23
- if (isNaN(tid)) {
24
- this.error('Token ID must be a number.');
25
- return;
26
- }
27
-
28
- try {
29
- await client.auth.revokeToken(tid);
30
- this.success(`Token ${tid} revoked.`);
31
- } catch (error: any) {
32
- this.error(`Failed to revoke token: ${error.message}`);
33
- }
34
- }
35
- }
@@ -1,21 +0,0 @@
1
-
2
- import { BaseCommand } from '@nexical/cli-core';
3
- import { getClient } from '../utils/nexical-client.js';
4
-
5
- export default class WhoamiCommand extends BaseCommand {
6
- static description = 'Show current logged in user';
7
-
8
- async run() {
9
- const client = getClient();
10
-
11
- try {
12
- const user = await client.users.me();
13
- this.info(`Logged in as:`);
14
- this.info(` Name: ${user.fullName}`);
15
- this.info(` Email: ${user.email}`);
16
- this.info(` ID: ${user.id}`);
17
- } catch (error: any) {
18
- this.error('Not logged in or token expired. Run `astrical login`.');
19
- }
20
- }
21
- }
@@ -1,47 +0,0 @@
1
-
2
- import { NexicalClient } from '@nexical/sdk';
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import os from 'node:os';
6
-
7
- const getConfigPaths = () => {
8
- const HOME = process.env.HOME || os.homedir();
9
- const CONFIG_DIR = path.join(HOME, '.nexical');
10
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
11
- return { CONFIG_DIR, CONFIG_FILE };
12
- };
13
-
14
- interface Config {
15
- token?: string;
16
- }
17
-
18
- export function getConfig(): Config {
19
- const { CONFIG_FILE } = getConfigPaths();
20
- if (!fs.existsSync(CONFIG_FILE)) {
21
- return {};
22
- }
23
- try {
24
- const content = fs.readFileSync(CONFIG_FILE, 'utf-8');
25
- return JSON.parse(content);
26
- } catch (error) {
27
- return {};
28
- }
29
- }
30
-
31
- export function saveToken(token: string) {
32
- const { CONFIG_DIR, CONFIG_FILE } = getConfigPaths();
33
- if (!fs.existsSync(CONFIG_DIR)) {
34
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
35
- }
36
- const config = getConfig();
37
- config.token = token;
38
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
39
- }
40
-
41
- export function getClient(): NexicalClient {
42
- const config = getConfig();
43
- return new NexicalClient({
44
- token: config.token,
45
- baseURL: process.env.NEXICAL_API_URL,
46
- });
47
- }
@@ -1,46 +0,0 @@
1
- import { describe, it, expect, beforeAll } from 'vitest';
2
- import { runCLI, TEST_HOME } from './utils.js';
3
- import { resetMockStore } from './setup.js';
4
- import fs from 'fs-extra';
5
- import path from 'path';
6
-
7
- describe('Authentication E2E', () => {
8
- // Isolate config for tests
9
- const TEST_CONFIG_DIR = path.join(TEST_HOME, '.nexical');
10
- const TEST_CONFIG_FILE = path.join(TEST_CONFIG_DIR, 'config.json');
11
-
12
- beforeAll(async () => {
13
- resetMockStore();
14
- // Clean up any existing config
15
- if (await fs.pathExists(TEST_CONFIG_FILE)) {
16
- await fs.remove(TEST_CONFIG_FILE);
17
- }
18
- });
19
-
20
- it('should show not logged in initially', async () => {
21
- const { stdout } = await runCLI(['whoami']);
22
- expect(stdout).toContain('Not logged in or token expired');
23
- });
24
-
25
- it('should login successfully', async () => {
26
- // Simulate login
27
- // Since login is interactive (browser open), we might mock the open module or
28
- // just trust runCLI can handle the non-interactive part until the prompt.
29
- // However, key to this test is that we can MANUALLY set the token via CLI
30
- // OR we just simulate the token save if the CLI doesn't support non-interactive login easily.
31
-
32
- // For E2E of the CLI 'login' command specifically, it's hard without a browser.
33
- // But we can verify "whoami" works IF we have a token.
34
-
35
- // Let's manually inject a token to simulate a successful login state for now
36
- // as true E2E of OAuth device flow requires browser automation which is out of scope.
37
-
38
- await fs.mkdirp(TEST_CONFIG_DIR);
39
- await fs.writeJSON(TEST_CONFIG_FILE, { token: 'mock-access-token' });
40
-
41
- const { stdout } = await runCLI(['whoami']);
42
- expect(stdout).toContain('Logged in as:');
43
- expect(stdout).toContain('Name: Test User');
44
- expect(stdout).toContain('Email: test@example.com');
45
- });
46
- });
@@ -1,33 +0,0 @@
1
- import { describe, it, expect, beforeAll } from 'vitest';
2
- import { runCLI } from './utils.js';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import os from 'os';
6
- import { resetMockStore } from './setup.js';
7
-
8
- describe('Job Workflow E2E', () => {
9
- const TEST_CONFIG_DIR = path.join(os.homedir(), '.nexical');
10
- const TEST_CONFIG_FILE = path.join(TEST_CONFIG_DIR, 'config.json');
11
-
12
- beforeAll(async () => {
13
- resetMockStore();
14
- resetMockStore();
15
- // Ensure logged in
16
- await fs.mkdirp(TEST_CONFIG_DIR);
17
- await fs.writeJSON(TEST_CONFIG_FILE, { token: 'mock-access-token' });
18
- });
19
-
20
- it('should trigger a job', async () => {
21
- // We use "3" as branchId (must be numeric for CLI validation)
22
- const { stdout } = await runCLI(['job', 'trigger', '1', '101', '3', 'deploy']);
23
- expect(stdout).toContain('Job 123 triggered successfully!');
24
- expect(stdout).toContain('Status: pending');
25
- });
26
-
27
- it('should get job logs', async () => {
28
- const { stdout } = await runCLI(['job', 'logs', '1', '101', '3', '123']);
29
- expect(stdout).toContain('Logs for Job 123:');
30
- expect(stdout).toContain('Build initialized');
31
- expect(stdout).toContain('Build successful');
32
- });
33
- });
@@ -1,48 +0,0 @@
1
- import { describe, it, expect, beforeAll } from 'vitest';
2
- import { runCLI } from './utils.js';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import os from 'os';
6
- import { resetMockStore } from './setup.js';
7
-
8
- describe('Project Lifecycle E2E', () => {
9
- const TEST_CONFIG_DIR = path.join(os.homedir(), '.nexical');
10
- const TEST_CONFIG_FILE = path.join(TEST_CONFIG_DIR, 'config.json');
11
-
12
- beforeAll(async () => {
13
- resetMockStore();
14
- // Ensure logged intMockStore();
15
- // Ensure logged in
16
- await fs.mkdirp(TEST_CONFIG_DIR);
17
- await fs.writeJSON(TEST_CONFIG_FILE, { token: 'mock-access-token' });
18
- });
19
-
20
- it('should create a new project', async () => {
21
- const { stdout } = await runCLI(['project', 'create', '1', 'My Project', '--repo', 'https://github.com/test/repo']);
22
- expect(stdout).toContain('Project "My Project" set up successfully!');
23
- expect(stdout).toContain('ID: 101');
24
- });
25
-
26
- it('should list projects', async () => {
27
- const { stdout } = await runCLI(['project', 'list', '1']);
28
- expect(stdout).toContain('Projects in Team 1:');
29
- expect(stdout).toContain('My Project (ID: 101)');
30
- });
31
-
32
- it('should update project', async () => {
33
- const { stdout } = await runCLI(['project', 'update', '1', '101', '--name', 'Updated Project']);
34
- // Note: The CLI success message format depends on command impl.
35
- expect(stdout).toContain('Project 101 updated!');
36
- // expect(stdout).toContain('Name: Updated Project'); // CLI might not print details
37
- });
38
-
39
- it('should delete project', async () => {
40
- const { stdout } = await runCLI(['project', 'delete', '1', '101', '--confirm']);
41
- expect(stdout).toContain('Project 101 deleted.');
42
- });
43
-
44
- it('should verify deletion', async () => {
45
- const { stdout } = await runCLI(['project', 'list', '1']);
46
- expect(stdout).not.toContain('ID: 101');
47
- });
48
- });
package/test/e2e/setup.ts DELETED
@@ -1,237 +0,0 @@
1
- import { beforeAll, afterAll } from 'vitest';
2
- import http from 'http';
3
-
4
- const MOCK_PORT = 3333;
5
- export const TEST_API_URL = `http://localhost:${MOCK_PORT}`;
6
-
7
- // Simple in-memory mock store
8
- export const mockStore = {
9
- users: [] as any[],
10
- tokens: [] as any[],
11
- teams: [] as any[],
12
- projects: [] as any[],
13
- jobs: [] as any[],
14
- };
15
-
16
- export const resetMockStore = () => {
17
- mockStore.users = [];
18
- mockStore.tokens = [];
19
- mockStore.teams = [
20
- { id: 1, name: 'My Team', slug: 'my-team' }
21
- ];
22
- mockStore.projects = [];
23
- mockStore.jobs = [];
24
- };
25
-
26
- const server = http.createServer((req, res) => {
27
- const { method, url } = req;
28
- let body = '';
29
-
30
- req.on('data', chunk => {
31
- body += chunk.toString();
32
- });
33
-
34
- req.on('end', () => {
35
- let parsedBody: any = {};
36
- try {
37
- if (body) parsedBody = JSON.parse(body);
38
- } catch (e) {
39
- // ignore
40
- }
41
-
42
- console.log(`[MOCK API] ${method} ${url}`, parsedBody);
43
-
44
- res.setHeader('Content-Type', 'application/json');
45
-
46
- // --- Mock Routes ---
47
-
48
- // AUTH
49
- if (method === 'POST' && url === '/auth/device') {
50
- res.writeHead(200);
51
- res.end(JSON.stringify({ deviceCode: '1234', userCode: 'ABCD-1234', verificationUrl: 'http://localhost:3000/verify' }));
52
- return;
53
- }
54
-
55
- if (method === 'POST' && url === '/auth/token') {
56
- res.writeHead(200);
57
- res.end(JSON.stringify({ accessToken: 'mock-access-token', refreshToken: 'mock-refresh-token' }));
58
- return;
59
- }
60
-
61
- if (method === 'POST' && url === '/auth/logout') {
62
- res.writeHead(200);
63
- res.end(JSON.stringify({ success: true }));
64
- return;
65
- }
66
-
67
- // Auth
68
- if (method === 'GET' && url === '/users/me') {
69
- const authHeader = req.headers['authorization'];
70
- const token = authHeader?.split(' ')[1];
71
-
72
- if (!token || token === 'expired') {
73
- res.writeHead(401);
74
- res.end(JSON.stringify({ error: 'Unauthorized' }));
75
- return;
76
- }
77
-
78
- const user = mockStore.users[0] || {
79
- id: '123e4567-e89b-12d3-a456-426614174000', // Valid UUID
80
- email: 'test@example.com',
81
- fullName: 'Test User',
82
- avatarUrl: null,
83
- role: 'user',
84
- createdAt: new Date().toISOString(),
85
- updatedAt: new Date().toISOString()
86
- };
87
-
88
- // Wrap in { user: ... }
89
- res.writeHead(200);
90
- res.end(JSON.stringify({ user }));
91
- return;
92
- }
93
-
94
- // PROJECTS
95
- if (method === 'POST' && url === '/teams/1/projects') {
96
- const newProject = {
97
- id: 101, // SDK expects number
98
- teamId: 1,
99
- name: parsedBody.name,
100
- repoUrl: parsedBody.repoUrl || null,
101
- productionUrl: null,
102
- contextHash: null,
103
- mode: 'managed',
104
- createdAt: new Date().toISOString(),
105
- updatedAt: new Date().toISOString(),
106
- };
107
- mockStore.projects.push(newProject);
108
-
109
- // Wrap in { project: ... }
110
- res.writeHead(201);
111
- res.end(JSON.stringify({ project: newProject }));
112
- return;
113
- }
114
-
115
- if (method === 'GET' && url === '/teams/1/projects') {
116
- // Wrap in { projects: ... }
117
- res.writeHead(200);
118
- res.end(JSON.stringify({ projects: mockStore.projects }));
119
- return;
120
- }
121
-
122
- if (method === 'PUT' && url?.match(/\/teams\/1\/projects\/\d+$/)) {
123
- const id = parseInt(url.split('/').pop() || '0');
124
- const project = mockStore.projects.find((p: any) => p.id === id);
125
- if (project) {
126
- // Update logic mimicking body parse (simplification)
127
- // content-length usually small in tests
128
- // For now, return existing or updated stub
129
- project.name = 'Updated Project'; // Hardcode for test expectation
130
- res.writeHead(200);
131
- res.end(JSON.stringify({ project }));
132
- return;
133
- }
134
- res.writeHead(404);
135
- res.end('Not Found');
136
- return;
137
- }
138
-
139
- if (method === 'DELETE' && url?.match(/\/teams\/1\/projects\/\d+$/)) {
140
- const id = parseInt(url.split('/').pop() || '0');
141
- const index = mockStore.projects.findIndex((p: any) => p.id === id);
142
- if (index !== -1) {
143
- mockStore.projects.splice(index, 1);
144
- res.writeHead(200);
145
- res.end(JSON.stringify({ message: 'Project deleted' }));
146
- } else {
147
- res.writeHead(404);
148
- res.end(JSON.stringify({ message: "Not Found" }));
149
- }
150
- return;
151
- }
152
-
153
- // TEAMS
154
- if (method === 'GET' && url === '/teams/1') {
155
- // Return team 1 mock
156
- res.writeHead(200);
157
- res.end(JSON.stringify({
158
- id: 1,
159
- name: 'My Team',
160
- slug: 'my-team',
161
- billingPlan: 'free',
162
- creditsBalance: 100,
163
- createdAt: new Date().toISOString(),
164
- updatedAt: new Date().toISOString(),
165
- role: 'owner'
166
- }));
167
- return;
168
- }
169
-
170
- // Jobs
171
- if (method === 'POST' && url?.includes('/jobs') && !url.includes('/logs')) {
172
- const newJob = {
173
- id: 123,
174
- branchId: 3,
175
- type: 'deploy',
176
- status: 'pending',
177
- queue: 'public',
178
- inputs: null,
179
- outputs: null,
180
- assignedFactoryId: null,
181
- startedAt: null,
182
- completedAt: null,
183
- createdAt: new Date().toISOString(),
184
- };
185
- mockStore.jobs.push(newJob);
186
- // Wrap in { job: ... }
187
- res.writeHead(201);
188
- res.end(JSON.stringify({ job: newJob }));
189
- return;
190
- }
191
-
192
- // Logs
193
- if (method === 'GET' && url?.includes('/logs')) {
194
- const stubLogs = [
195
- {
196
- id: 1,
197
- jobId: 123,
198
- level: 'info',
199
- message: 'Build initialized',
200
- metadata: null,
201
- timestamp: new Date().toISOString()
202
- },
203
- {
204
- id: 2,
205
- jobId: 123,
206
- level: 'info',
207
- message: 'Build successful',
208
- metadata: null,
209
- timestamp: new Date().toISOString()
210
- }
211
- ];
212
- // Wrap in { logs: ... }
213
- res.writeHead(200);
214
- res.end(JSON.stringify({ logs: stubLogs }));
215
- return;
216
- }
217
-
218
- // Default 404
219
- res.writeHead(404);
220
- res.end(JSON.stringify({ message: 'Not Found' }));
221
- });
222
- });
223
-
224
- beforeAll(async () => {
225
- return new Promise<void>((resolve) => {
226
- server.listen(MOCK_PORT, () => {
227
- console.log(`Mock API running on port ${MOCK_PORT}`);
228
- resolve();
229
- });
230
- });
231
- });
232
-
233
- afterAll(async () => {
234
- return new Promise<void>((resolve) => {
235
- server.close(() => resolve());
236
- });
237
- });
package/test/e2e/utils.ts DELETED
@@ -1,33 +0,0 @@
1
- import path from "path";
2
- import { execa } from "execa";
3
- import { fileURLToPath } from "node:url";
4
- import os from 'os';
5
- import fs from 'fs-extra';
6
-
7
- // Constants
8
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
- const CLI_BIN = path.resolve(__dirname, '../../dist/index.js');
10
- const TEST_API_URL = 'http://localhost:3333';
11
- export const TEST_HOME = path.resolve(__dirname, '../../test-home');
12
-
13
- // Ensure test home exists
14
- if (!fs.existsSync(TEST_HOME)) {
15
- fs.mkdirpSync(TEST_HOME);
16
- }
17
-
18
- /**
19
- * Runs the CLI command against the compiled binary (E2E style)
20
- */
21
- export async function runCLI(args: string[], options: any = {}) {
22
- return execa("node", [CLI_BIN, ...args], {
23
- cwd: options.cwd || process.cwd(),
24
- ...options,
25
- env: {
26
- ...process.env,
27
- NEXICAL_API_URL: TEST_API_URL, // Point to Mock API
28
- HOME: TEST_HOME, // Isolate config
29
- ...options.env,
30
- },
31
- reject: false, // Allow checking exit code in tests
32
- });
33
- }
@@ -1,51 +0,0 @@
1
-
2
- import { describe, it, expect, vi, beforeEach } from 'vitest';
3
- import AdminUsersCreateSystemCommand from '../../../../src/commands/admin/create-user.js';
4
- import { getClient } from '../../../../src/utils/nexical-client.js';
5
-
6
- vi.mock('../../../../src/utils/nexical-client.js');
7
-
8
- describe('AdminUsersCreateSystemCommand Integration', () => {
9
- let command: AdminUsersCreateSystemCommand;
10
- let mockClient: any;
11
-
12
- beforeEach(() => {
13
- vi.resetAllMocks();
14
-
15
- mockClient = {
16
- auth: {
17
- createSystemUser: vi.fn(),
18
- },
19
- };
20
- vi.mocked(getClient).mockReturnValue(mockClient);
21
-
22
- command = new AdminUsersCreateSystemCommand([], {} as any);
23
- vi.spyOn(command, 'info').mockImplementation(() => { });
24
- vi.spyOn(command, 'success').mockImplementation(() => { });
25
- vi.spyOn(command, 'error').mockImplementation(() => { });
26
- });
27
-
28
- it('should create system user successfully', async () => {
29
- mockClient.auth.createSystemUser.mockResolvedValue({
30
- user: { fullName: 'Integration User', id: 'sys-int' }
31
- });
32
-
33
- await command.run({ name: 'Integration User', email: 'sys-int@example.com', password: 'password123' });
34
-
35
- expect(mockClient.auth.createSystemUser).toHaveBeenCalledWith({
36
- fullName: 'Integration User',
37
- email: 'sys-int@example.com',
38
- password: 'password123'
39
- });
40
- expect(command.success).toHaveBeenCalledWith('System user "Integration User" created!');
41
- expect(command.info).toHaveBeenCalledWith('ID: sys-int');
42
- });
43
-
44
- it('should handle creation failure', async () => {
45
- mockClient.auth.createSystemUser.mockRejectedValue(new Error('Email already exists'));
46
-
47
- await command.run({ name: 'Integration User', email: 'sys-int@example.com', password: 'password123' });
48
-
49
- expect(command.error).toHaveBeenCalledWith('Failed to create system user: Email already exists');
50
- });
51
- });
@@ -1,51 +0,0 @@
1
-
2
- import { describe, it, expect, vi, beforeEach } from 'vitest';
3
- import BranchesCreateCommand from '../../../../src/commands/branch/create.js';
4
- import { getClient } from '../../../../src/utils/nexical-client.js';
5
-
6
- vi.mock('../../../../src/utils/nexical-client.js');
7
-
8
- describe('BranchesCreateCommand Integration', () => {
9
- let command: BranchesCreateCommand;
10
- let mockClient: any;
11
-
12
- beforeEach(() => {
13
- vi.resetAllMocks();
14
-
15
- mockClient = {
16
- branches: {
17
- create: vi.fn(),
18
- },
19
- };
20
- vi.mocked(getClient).mockReturnValue(mockClient);
21
-
22
- command = new BranchesCreateCommand([], {} as any);
23
- vi.spyOn(command, 'info').mockImplementation(() => { });
24
- vi.spyOn(command, 'success').mockImplementation(() => { });
25
- vi.spyOn(command, 'error').mockImplementation(() => { });
26
- });
27
-
28
- it('should create branch successfully', async () => {
29
- mockClient.branches.create.mockResolvedValue({
30
- name: 'integration-branch',
31
- id: 'br-int'
32
- });
33
-
34
- await command.run({ teamId: '1', projectId: '2', name: 'integration-branch', preview: 'http://int.com' });
35
-
36
- expect(mockClient.branches.create).toHaveBeenCalledWith(1, 2, {
37
- name: 'integration-branch',
38
- previewUrl: 'http://int.com',
39
- });
40
- expect(command.success).toHaveBeenCalledWith('Branch "integration-branch" created!');
41
- expect(command.info).toHaveBeenCalledWith('ID: br-int');
42
- });
43
-
44
- it('should handle creation failure', async () => {
45
- mockClient.branches.create.mockRejectedValue(new Error('Branch exists'));
46
-
47
- await command.run({ teamId: '1', projectId: '2', name: 'main' });
48
-
49
- expect(command.error).toHaveBeenCalledWith('Failed to create branch: Branch exists');
50
- });
51
- });
@@ -1,43 +0,0 @@
1
-
2
- import { describe, it, expect, vi, beforeEach } from 'vitest';
3
- import BranchesDeleteCommand from '../../../../src/commands/branch/delete.js';
4
- import { getClient } from '../../../../src/utils/nexical-client.js';
5
-
6
- vi.mock('../../../../src/utils/nexical-client.js');
7
-
8
- describe('BranchesDeleteCommand Integration', () => {
9
- let command: BranchesDeleteCommand;
10
- let mockClient: any;
11
-
12
- beforeEach(() => {
13
- vi.resetAllMocks();
14
-
15
- mockClient = {
16
- branches: {
17
- delete: vi.fn(),
18
- },
19
- };
20
- vi.mocked(getClient).mockReturnValue(mockClient);
21
-
22
- command = new BranchesDeleteCommand([], {} as any);
23
- vi.spyOn(command, 'success').mockImplementation(() => { });
24
- vi.spyOn(command, 'error').mockImplementation(() => { });
25
- });
26
-
27
- it('should delete branch successfully', async () => {
28
- mockClient.branches.delete.mockResolvedValue({});
29
-
30
- await command.run({ teamId: '1', projectId: '2', branchId: '3' });
31
-
32
- expect(mockClient.branches.delete).toHaveBeenCalledWith(1, 2, 3);
33
- expect(command.success).toHaveBeenCalledWith('Branch 3 deleted.');
34
- });
35
-
36
- it('should handle deletion failure', async () => {
37
- mockClient.branches.delete.mockRejectedValue(new Error('Not found'));
38
-
39
- await command.run({ teamId: '1', projectId: '2', branchId: '3' });
40
-
41
- expect(command.error).toHaveBeenCalledWith('Failed to delete branch: Not found');
42
- });
43
- });