|
| 1 | +/** |
| 2 | + * @file E2E tests for `socket login`, `socket logout`, and `socket whoami`. |
| 3 | + * Ported from `packages/cli/test/smoke.sh`'s login/logout sections, plus |
| 4 | + * the `whoami` check that lived in `critical-commands.e2e.test.mts`. |
| 5 | + * |
| 6 | + * login is interactive in normal use; the smoke.sh check only ran the |
| 7 | + * no-arg form (which exits 0 after printing a prompt note). logout |
| 8 | + * mutates the developer's stored Socket session, so the destructive |
| 9 | + * forms route through executeCliInScratch (isolated HOME → |
| 10 | + * isolated keychain). The non-destructive `--help` / `--dry-run` |
| 11 | + * checks use the normal helpers. |
| 12 | + * |
| 13 | + * Gated on `RUN_E2E_TESTS=1`. The destructive logout run additionally |
| 14 | + * gates on RUN_E2E_DESTRUCTIVE=1 even though scratch-isolation means it's |
| 15 | + * safe — operator opt-in stays consistent with the repos.e2e file. |
| 16 | + */ |
| 17 | + |
| 18 | +import { beforeAll, describe, expect, it } from 'vitest' |
| 19 | + |
| 20 | +import { ENV } from '../../src/constants/env.mts' |
| 21 | +import { getDefaultApiToken } from '../../src/util/socket/sdk.mts' |
| 22 | +import { |
| 23 | + executeCliCommand, |
| 24 | + executeCliInScratch, |
| 25 | +} from '../helpers/cli-execution.mts' |
| 26 | + |
| 27 | +const RUN = ENV.RUN_E2E_TESTS |
| 28 | +const RUN_DESTRUCTIVE = process.env['RUN_E2E_DESTRUCTIVE'] === '1' |
| 29 | + |
| 30 | +describe('socket login (e2e)', () => { |
| 31 | + it.skipIf(!RUN)('login --help exits 0', async () => { |
| 32 | + const result = await executeCliCommand(['login', '--help']) |
| 33 | + expect(result.code).toBe(0) |
| 34 | + }) |
| 35 | + |
| 36 | + it.skipIf(!RUN)('login --dry-run exits 0', async () => { |
| 37 | + const result = await executeCliCommand(['login', '--dry-run']) |
| 38 | + expect(result.code).toBe(0) |
| 39 | + }) |
| 40 | + |
| 41 | + // smoke.sh's `run_socket 0 login` ran the real login flow. In an e2e |
| 42 | + // suite that can't accept TTY input, the equivalent is to confirm the |
| 43 | + // command starts cleanly when there's no token to bind to — easiest in |
| 44 | + // a scratch HOME with --no-interactive. |
| 45 | + it.skipIf(!RUN)('login --no-interactive (no token) exits non-zero cleanly', async () => { |
| 46 | + const result = await executeCliInScratch(['login', '--no-interactive']) |
| 47 | + expect(result.code).toBeGreaterThan(0) |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
| 51 | +describe('socket logout (e2e)', () => { |
| 52 | + it.skipIf(!RUN)('logout --help exits 0', async () => { |
| 53 | + const result = await executeCliCommand(['logout', '--help']) |
| 54 | + expect(result.code).toBe(0) |
| 55 | + }) |
| 56 | + |
| 57 | + it.skipIf(!RUN)('logout --dry-run exits 0', async () => { |
| 58 | + const result = await executeCliCommand(['logout', '--dry-run']) |
| 59 | + expect(result.code).toBe(0) |
| 60 | + }) |
| 61 | + |
| 62 | + it.skipIf(!RUN || !RUN_DESTRUCTIVE)( |
| 63 | + 'logout (scratch-isolated) exits 0', |
| 64 | + async () => { |
| 65 | + // Even though scratch isolation means we're never touching the real |
| 66 | + // session, gate on RUN_E2E_DESTRUCTIVE so destructive ops stay |
| 67 | + // explicitly opt-in across the e2e suite. |
| 68 | + const result = await executeCliInScratch(['logout']) |
| 69 | + expect(result.code).toBe(0) |
| 70 | + }, |
| 71 | + ) |
| 72 | +}) |
| 73 | + |
| 74 | +describe('socket whoami (e2e, auth required)', () => { |
| 75 | + let hasAuth = false |
| 76 | + beforeAll(async () => { |
| 77 | + if (RUN) { |
| 78 | + hasAuth = !!(await getDefaultApiToken()) |
| 79 | + } |
| 80 | + }) |
| 81 | + |
| 82 | + it.skipIf(!RUN || !hasAuth)('whoami exits 0 with auth present', async () => { |
| 83 | + const result = await executeCliCommand(['whoami']) |
| 84 | + expect(result.code).toBe(0) |
| 85 | + }) |
| 86 | +}) |
0 commit comments