mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
* feat(self-host): add capability-aware setup * fix(self-host): preserve capability compatibility * fix(copilot): honor preview availability server-side * improvement(self-host): centralize capability resolution * fix(self-host): preserve integration availability paths * fix(testing): align capability-aware config mocks * improvement(self-host): simplify capability setup configuration * fix(setup): preserve unowned storage overrides * fix(self-host): reconcile storage and allowlists * fix(integrations): preserve connect deep links
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import {
|
|
isPlaceholder,
|
|
isUsableSecret,
|
|
parseEnv,
|
|
reconcileEnvContent,
|
|
upsertEnv,
|
|
} from './env-files.ts'
|
|
|
|
describe('placeholder detection', () => {
|
|
it('recognizes underscore and hyphen template prefixes', () => {
|
|
expect(isPlaceholder('your_secret_key')).toBe(true)
|
|
expect(isPlaceholder('your-secure-production-auth-secret-here')).toBe(true)
|
|
expect(isUsableSecret('BETTER_AUTH_SECRET', 'your-secure-production-auth-secret-here')).toBe(
|
|
false
|
|
)
|
|
expect(isPlaceholder('yourActualSecret')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('upsertEnv', () => {
|
|
it('writes the value that parseEnv will use', () => {
|
|
const updated = upsertEnv('RESEND_API_KEY=old\nOTHER=value\n', 'RESEND_API_KEY', 'current')
|
|
|
|
expect(parseEnv(updated).get('RESEND_API_KEY')).toBe('current')
|
|
})
|
|
|
|
it('fails fast when duplicate active entries make the effective write ambiguous', () => {
|
|
expect(() =>
|
|
upsertEnv(
|
|
'RESEND_API_KEY=old\nexport RESEND_API_KEY=current\n',
|
|
'RESEND_API_KEY',
|
|
'replacement'
|
|
)
|
|
).toThrow('Duplicate active RESEND_API_KEY entries')
|
|
})
|
|
})
|
|
|
|
describe('reconcileEnvContent', () => {
|
|
it('applies provider removals and replacements to one snapshot', () => {
|
|
const reconciled = reconcileEnvContent(
|
|
'SMTP_HOST=old-host\nSMTP_PORT=587\nRESEND_API_KEY=old-key\n',
|
|
['SMTP_HOST', 'SMTP_PORT'],
|
|
{ RESEND_API_KEY: 'new-key' }
|
|
)
|
|
|
|
expect(parseEnv(reconciled)).toEqual(new Map([['RESEND_API_KEY', 'new-key']]))
|
|
})
|
|
|
|
it('fails before returning content when a replacement key is duplicated', () => {
|
|
const content = 'SMTP_HOST=old-host\nRESEND_API_KEY=old-key\nRESEND_API_KEY=newer-key\n'
|
|
|
|
expect(() =>
|
|
reconcileEnvContent(content, ['SMTP_HOST'], { RESEND_API_KEY: 'replacement' })
|
|
).toThrow('Duplicate active RESEND_API_KEY entries')
|
|
expect(parseEnv(content).get('SMTP_HOST')).toBe('old-host')
|
|
})
|
|
})
|