Skip to content

Commit acca16f

Browse files
committed
fix(sim-setup): give a placeholder shared secret the same fix as a missing one
1 parent 6243955 commit acca16f

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎packages/sim-setup/src/checks.test.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vi.mock('./context', async (importOriginal) => {
1515
})
1616

1717
import { type CheckContext, loadCheckContext, runChecks } from './checks'
18-
import type { EnvFile, EnvTarget } from './env-files'
18+
import { type EnvFile, type EnvTarget, parseEnv } from './env-files'
1919

2020
function envFile(target: EnvTarget, values: Record<string, string> = {}): EnvFile {
2121
return {
@@ -126,18 +126,22 @@ describe('doctor --fix on env files', () => {
126126
expect(readFileSync(files.db, 'utf8')).toBe(dbFile)
127127
})
128128

129-
it('leaves a shared secret it cannot copy unset rather than generating a different one', async () => {
130-
const secret = `BETTER_AUTH_SECRET=\${AUTH_SECRET_BASE}0123456789abcdef0123456789abcdef`
131-
writeFiles({
132-
sim: `${secret}\n`,
133-
realtime: 'DATABASE_URL=postgresql://localhost/sim\n',
134-
db: '',
135-
})
136-
137-
for (const finding of await runChecks(loadCheckContext(false), ['schema'])) finding.autofix?.()
138-
139-
expect(readFileSync(files.realtime, 'utf8')).not.toContain('BETTER_AUTH_SECRET')
140-
})
129+
it.each([
130+
['missing', 'DATABASE_URL=postgresql://localhost/sim\n'],
131+
['a placeholder', 'BETTER_AUTH_SECRET=your_auth_secret_here\n'],
132+
])(
133+
'never generates a shared secret it cannot copy when realtime has it %s',
134+
async (_, realtime) => {
135+
const secret = `BETTER_AUTH_SECRET=\${AUTH_SECRET_BASE}0123456789abcdef0123456789abcdef`
136+
writeFiles({ sim: `${secret}\n`, realtime, db: '' })
137+
138+
for (const finding of await runChecks(loadCheckContext(false), ['schema']))
139+
finding.autofix?.()
140+
141+
const after = parseEnv(readFileSync(files.realtime, 'utf8')).get('BETTER_AUTH_SECRET')
142+
expect(after).toBe(parseEnv(realtime).get('BETTER_AUTH_SECRET'))
143+
}
144+
)
141145

142146
it('reports a value it cannot write instead of aborting the other fixes', async () => {
143147
const unwritable = 'DATABASE_URL="postgresql://u:p\\$x\\y@localhost/sim"\n'

‎packages/sim-setup/src/checks.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ function checkSchema(ctx: CheckContext): Finding[] {
229229
continue
230230
}
231231
if (isPlaceholder(value)) {
232+
// Same fix as a missing key: a shared secret is mirrored from the app, never regenerated.
233+
const autofix = MIN_32_KEYS.has(key) ? autofixForMissing(ctx, target, key) : undefined
232234
findings.push({
233235
group: 'schema',
234236
status: production ? 'fail' : 'warn',
235237
message: `${rel(file)}: ${key} still has the .env.example placeholder`,
236-
fix: MIN_32_KEYS.has(key)
237-
? 'doctor --fix generates a real value'
238+
fix: autofix
239+
? 'doctor --fix sets a real value'
238240
: `replace the placeholder in ${rel(file)}`,
239-
autofix: MIN_32_KEYS.has(key)
240-
? () => writeEnvValues(target, { [key]: generateSecret() })
241-
: undefined,
241+
autofix,
242242
})
243243
continue
244244
}

0 commit comments

Comments
 (0)