liveProfiles.test.mjs
2.98 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath, pathToFileURL } from 'node:url'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const profilesPath = path.join(projectRoot, 'tests/order-lifecycle/liveProfiles.mjs')
async function loadProfiles() {
assert.equal(fs.existsSync(profilesPath), true, 'live profile resolver must exist')
return import(pathToFileURL(profilesPath))
}
test('resolves approved profiles using environment-only credentials', async () => {
const { resolveLiveProfile } = await loadProfiles()
const mingming = resolveLiveProfile('mingming-dev', {
LIVE_MINGMING_MOBILE: 'runtime-mobile-a',
LIVE_MINGMING_CODE: 'runtime-code-a',
LIVE_MINGMING_YQ_NAME: 'runtime-park-a',
})
const bobo = resolveLiveProfile('bobo-test', {
LIVE_BOBO_MOBILE: 'runtime-mobile-b',
LIVE_BOBO_CODE: 'runtime-code-b',
})
assert.equal(mingming.environment, 'development')
assert.equal(mingming.storeName, '明明崇文4S店')
assert.equal(mingming.yqName, 'runtime-park-a')
assert.equal(mingming.mobile, 'runtime-mobile-a')
assert.equal(bobo.environment, 'test')
assert.equal(bobo.storeName, '波波的单店门店')
assert.equal(bobo.sceneName, '精品升级')
})
test('requires explicit selection, secrets, and an independent write gate', async () => {
const { resolveLiveProfile, assertLiveWriteAllowed } = await loadProfiles()
assert.throws(() => resolveLiveProfile('', {}), /profile.*required/i)
assert.throws(() => resolveLiveProfile('unknown', {}), /unknown live profile/i)
assert.throws(
() => resolveLiveProfile('bobo-test', {}),
/LIVE_BOBO_MOBILE.*LIVE_BOBO_CODE/,
)
const profile = resolveLiveProfile('bobo-test', {
LIVE_BOBO_MOBILE: 'runtime-mobile',
LIVE_BOBO_CODE: 'runtime-code',
})
assert.throws(() => assertLiveWriteAllowed(profile, {}), /LIVE_ALLOW_WRITES=1/)
assert.equal(
assertLiveWriteAllowed(profile, { LIVE_ALLOW_WRITES: '1' }),
true,
)
})
test('profile metadata never contains credential literals', async () => {
const { LIVE_PROFILE_DEFINITIONS } = await loadProfiles()
const serialized = JSON.stringify(LIVE_PROFILE_DEFINITIONS)
assert.doesNotMatch(serialized, /\b1\d{10}\b/)
assert.doesNotMatch(serialized, /(?:mobile|code)Value/i)
})
test('existing order lifecycle harness accepts an explicitly write-enabled profile', async () => {
const { loadE2EConfig } = await import('./e2e/testConfig.mjs')
const config = loadE2EConfig({
ORDER_E2E_PROFILE: 'mingming-dev',
LIVE_MINGMING_MOBILE: 'runtime-mobile',
LIVE_MINGMING_CODE: 'runtime-code',
LIVE_MINGMING_YQ_NAME: 'runtime-park',
LIVE_ALLOW_WRITES: '1',
RUN_ORDER_E2E: '1',
})
assert.equal(config.profile, 'mingming-dev')
assert.equal(config.baseUrl, 'http://dj.dev.glsx.com.cn/rop-dj-car-boutique')
assert.equal(config.storeName, '明明崇文4S店')
assert.equal(config.mobile, 'runtime-mobile')
})