-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathsetup.mts
More file actions
57 lines (49 loc) · 2.16 KB
/
Copy pathsetup.mts
File metadata and controls
57 lines (49 loc) · 2.16 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
/**
* @file Vitest setup file for test utilities.
*/
import { existsSync, readFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { scrubAmbientSocketEnv } from './repo/_shared/lib/scrub-socket-env.mts'
// Disable debug output during tests
process.env['DEBUG'] = ''
delete process.env['NODE_DEBUG']
// Drop ambient Socket credentials, developer shell tokens, so spawned CLI
// children resolve tokens from each test's --config override, matching the
// credential-free CI runners.
scrubAmbientSocketEnv()
// Load inlined environment variables from bundle-tools.json.
// These are normally inlined at build time by esbuild, but tests run from source.
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const externalToolsPath = path.join(__dirname, '..', 'bundle-tools.json')
if (existsSync(externalToolsPath)) {
try {
const externalTools = JSON.parse(
readFileSync(externalToolsPath, 'utf8'),
).tools
// Set inlined environment variables if not already set.
// All tools now use 'version' field. GitHub-released tools also have optional 'tag'.
const toolVersions: Record<string, string | undefined> = {
INLINED_COANA_VERSION: externalTools['@coana-tech/cli']?.version,
INLINED_HOMEPAGE: 'https://github.com/SocketDev/socket-cli',
INLINED_NAME: '@socketsecurity/cli',
INLINED_OPENGREP_VERSION: externalTools['opengrep']?.version,
INLINED_PUBLISHED_BUILD: '',
INLINED_PYCLI_VERSION: externalTools['socketsecurity']?.version,
INLINED_PYTHON_BUILD_TAG: externalTools['python']?.tag,
INLINED_PYTHON_VERSION: externalTools['python']?.version,
INLINED_SOCKET_PATCH_VERSION: externalTools['socket-patch']?.version,
INLINED_TRIVY_VERSION: externalTools['trivy']?.version,
INLINED_TRUFFLEHOG_VERSION: externalTools['trufflehog']?.version,
INLINED_VERSION: '0.0.0-test',
INLINED_VERSION_HASH: '0.0.0-test:abc1234:test',
}
for (const [key, value] of Object.entries(toolVersions)) {
if (!process.env[key] && value) {
process.env[key] = value
}
}
} catch {
// Ignore errors loading bundle-tools.json.
}
}