Skip to content

Commit 8bd1663

Browse files
committed
feat(e2e): add interactive prompts and cache support for smol/sea binaries
Add intelligent binary handling for e2e tests: - Local: Interactive prompts (using @socketsecurity/lib/prompts) to build missing binaries with Y/n confirmation - CI: Skip building if binaries not in cache (rely on cache restoration) - Cache restoration: Restore smol/sea binaries from publish-socketbin workflow - Enable smol/sea testing in CI when binaries are cached Changes: - Use confirm() from @socketsecurity/lib/prompts for Y/n prompts - Use logger from @socketsecurity/lib/logger instead of console - Add cache restoration steps in ci.yml e2e job - Enable TEST_SEA_BINARY and TEST_SMOL_BINARY in CI - Update publish-socketbin dry-run description to clarify cache priming Workflow: 1. Run publish-socketbin with dry-run=true to prime cache 2. CI e2e tests restore cached binaries and test all three binary types 3. Locally, users get prompted to build missing binaries
1 parent 985ab53 commit 8bd1663

File tree

3 files changed

+74
-29
lines changed

3 files changed

+74
-29
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,35 @@ jobs:
6363
with:
6464
node-version: ${{ matrix.node-version }}
6565

66+
- name: Generate build cache key
67+
id: build-cache-key
68+
shell: bash
69+
run: |
70+
HASH=$(find build/patches scripts -type f \( -name "*.patch" -o -name "*.mjs" \) | sort | xargs shasum -a 256 | shasum -a 256 | cut -d' ' -f1)
71+
echo "hash=$HASH" >> $GITHUB_OUTPUT
72+
73+
- name: Restore smol binary cache
74+
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
75+
with:
76+
path: packages/node-smol-builder/dist/socket-smol
77+
key: node-binary-linux-x64-${{ steps.build-cache-key.outputs.hash }}
78+
restore-keys: node-binary-linux-x64-
79+
80+
- name: Restore SEA binary cache
81+
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
82+
with:
83+
path: packages/node-sea-builder/dist/socket-sea
84+
key: sea-binary-linux-x64-${{ steps.build-cache-key.outputs.hash }}
85+
restore-keys: sea-binary-linux-x64-
86+
6687
- name: Build CLI
6788
working-directory: packages/cli
6889
run: pnpm run build
6990

7091
- name: Run e2e tests
7192
working-directory: packages/cli
7293
env:
94+
TEST_SEA_BINARY: '1'
95+
TEST_SMOL_BINARY: '1'
7396
SOCKET_CLI_API_TOKEN: ${{ secrets.SOCKET_CLI_API_TOKEN }}
7497
run: pnpm run e2e-tests

.github/workflows/publish-socketbin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- smol-sea
1818
default: smol
1919
dry-run:
20-
description: 'Dry run (build but do not publish)'
20+
description: 'Dry run (build but do not publish) - primes cache for CI e2e tests'
2121
required: false
2222
type: boolean
2323
default: false

packages/cli/test/e2e/binary-test-suite.e2e.test.mts

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { existsSync } from 'node:fs'
44
import path from 'node:path'
55
import { fileURLToPath } from 'node:url'
66

7+
import { logger } from '@socketsecurity/lib/logger'
8+
import { confirm } from '@socketsecurity/lib/prompts'
79
import { spawn } from '@socketsecurity/lib/spawn'
810
import { beforeAll, describe, expect, it } from 'vitest'
911

@@ -50,14 +52,14 @@ async function buildBinary(binaryType: keyof typeof BINARIES): Promise<boolean>
5052
return false
5153
}
5254

53-
console.log(`Building ${binary.name}...`)
54-
console.log(`Running: ${binary.buildCommand.join(' ')}`)
55+
logger.log(`Building ${binary.name}...`)
56+
logger.log(`Running: ${binary.buildCommand.join(' ')}`)
5557

5658
if (binaryType === 'smol') {
57-
console.log('Note: smol build may take 30-60 minutes on first build')
58-
console.log(' (subsequent builds are faster with caching)')
59+
logger.log('Note: smol build may take 30-60 minutes on first build')
60+
logger.log(' (subsequent builds are faster with caching)')
5961
}
60-
console.log()
62+
logger.log('')
6163

6264
try {
6365
const result = await spawn(binary.buildCommand[0], binary.buildCommand.slice(1), {
@@ -66,14 +68,14 @@ async function buildBinary(binaryType: keyof typeof BINARIES): Promise<boolean>
6668
})
6769

6870
if (result.code !== 0) {
69-
console.error(`Failed to build ${binary.name}`)
71+
logger.error(`Failed to build ${binary.name}`)
7072
return false
7173
}
7274

73-
console.log(`Successfully built ${binary.name}`)
75+
logger.log(`Successfully built ${binary.name}`)
7476
return true
7577
} catch (e) {
76-
console.error(`Error building ${binary.name}:`, e)
78+
logger.error(`Error building ${binary.name}:`, e)
7779
return false
7880
}
7981
}
@@ -97,44 +99,64 @@ function runBinaryTestSuite(binaryType: keyof typeof BINARIES) {
9799
binaryExists = existsSync(binary.path)
98100

99101
if (!binaryExists) {
100-
console.log()
101-
console.warn(
102-
`Binary not found: ${binary.path}. Attempting to build...`,
103-
)
102+
logger.log('')
103+
logger.warn(`Binary not found: ${binary.path}`)
104+
105+
// In CI: Skip building (rely on cache).
106+
if (process.env.CI) {
107+
logger.log('Running in CI - skipping build (binary not in cache)')
108+
logger.log('To prime cache, run: gh workflow run publish-socketbin.yml --field dry-run=true')
109+
logger.log('')
110+
return
111+
}
112+
113+
// Locally: Prompt user to build.
114+
const shouldBuild = await confirm({
115+
default: true,
116+
message: `Build ${binary.name}? (may take 30-60 min for smol)`,
117+
})
118+
119+
if (!shouldBuild) {
120+
logger.log('Skipping build. Tests will be skipped.')
121+
logger.log(`To build manually, run: ${binary.buildCommand.join(' ')}`)
122+
logger.log('')
123+
return
124+
}
104125

126+
logger.log('Building binary...')
105127
const buildSuccess = await buildBinary(binaryType)
106128

107129
if (buildSuccess) {
108130
binaryExists = existsSync(binary.path)
109131
}
110132

111133
if (!binaryExists) {
112-
console.log()
113-
console.error(`Failed to build ${binary.name}. Tests will be skipped.`)
114-
console.log(`To build this binary manually, run:`)
115-
console.log(` ${binary.buildCommand.join(' ')}`)
116-
console.log()
134+
logger.log('')
135+
logger.error(`Failed to build ${binary.name}. Tests will be skipped.`)
136+
logger.log('To build this binary manually, run:')
137+
logger.log(` ${binary.buildCommand.join(' ')}`)
138+
logger.log('')
117139
return
118140
}
119141

120-
console.log(`Binary built successfully: ${binary.path}`)
121-
console.log()
142+
logger.log(`Binary built successfully: ${binary.path}`)
143+
logger.log('')
122144
}
123145

124146
// Check authentication.
125147
if (ENV.RUN_E2E_TESTS) {
126148
const apiToken = await getDefaultApiToken()
127149
hasAuth = !!apiToken
128150
if (!apiToken) {
129-
console.log()
130-
console.warn('E2E tests require Socket authentication.')
131-
console.log('Please run one of the following:')
132-
console.log(' 1. socket login (to authenticate with Socket)')
133-
console.log(' 2. Set SOCKET_SECURITY_API_KEY environment variable')
134-
console.log(' 3. Skip E2E tests by not setting RUN_E2E_TESTS\n')
135-
console.log(
136-
'E2E tests will be skipped due to missing authentication.\n',
137-
)
151+
logger.log('')
152+
logger.warn('E2E tests require Socket authentication.')
153+
logger.log('Please run one of the following:')
154+
logger.log(' 1. socket login (to authenticate with Socket)')
155+
logger.log(' 2. Set SOCKET_SECURITY_API_KEY environment variable')
156+
logger.log(' 3. Skip E2E tests by not setting RUN_E2E_TESTS')
157+
logger.log('')
158+
logger.log('E2E tests will be skipped due to missing authentication.')
159+
logger.log('')
138160
}
139161
}
140162
})

0 commit comments

Comments
 (0)