|
19 | 19 | * - the channel is owned by the parent: set when named, deleted otherwise. |
20 | 20 | */ |
21 | 21 |
|
| 22 | +import { readFileSync } from 'node:fs'; |
22 | 23 | import { describe, expect, it } from 'vitest'; |
23 | 24 | import { |
| 25 | + INTERNAL_CEREMONY_AUTH_TOKEN_FROM_FLAG_ENV, |
| 26 | + INTERNAL_CEREMONY_DATABASE_DRIVER_ENV, |
24 | 27 | INTERNAL_CEREMONY_DATABASE_URL_ENV, |
25 | 28 | ceremonyDatabaseUrl, |
| 29 | + readCeremonyConnectionChannel, |
26 | 30 | readCeremonyDatabaseChannel, |
| 31 | + writeCeremonyConnectionChannel, |
27 | 32 | writeCeremonyDatabaseChannel, |
28 | 33 | } from './internal-ceremony-database-channel.js'; |
29 | 34 |
|
@@ -63,3 +68,38 @@ describe('the ceremony-database channel to the serve child', () => { |
63 | 68 | expect(readCeremonyDatabaseChannel({ [INTERNAL_CEREMONY_DATABASE_URL_ENV]: '' })).toBeUndefined(); |
64 | 69 | }); |
65 | 70 | }); |
| 71 | + |
| 72 | +describe('#31547 — the driver and the token flag, carried beside the URL', () => { |
| 73 | + it('⭐ --database-driver is carried by value, --database-auth-token only as "the flag gave it": its value is never written', () => { |
| 74 | + const env: NodeJS.ProcessEnv = {}; |
| 75 | + writeCeremonyConnectionChannel(env, { databaseDriver: 'turso', databaseAuthToken: 'tok-s3cret-31547' }); |
| 76 | + expect(env[INTERNAL_CEREMONY_DATABASE_DRIVER_ENV]).toBe('turso'); |
| 77 | + expect(env[INTERNAL_CEREMONY_AUTH_TOKEN_FROM_FLAG_ENV]).toBe('1'); |
| 78 | + expect(JSON.stringify(env)).not.toContain('s3cret'); |
| 79 | + // Shaped as the guard's options, so `serve` spreads it as it is. |
| 80 | + expect(readCeremonyConnectionChannel(env)).toEqual({ databaseDriver: 'turso', databaseAuthTokenFromFlag: true }); |
| 81 | + }); |
| 82 | + |
| 83 | + it('is owned by the parent: no flag, no variable — an inherited copy never speaks', () => { |
| 84 | + const env: NodeJS.ProcessEnv = { |
| 85 | + [INTERNAL_CEREMONY_DATABASE_DRIVER_ENV]: 'pg', |
| 86 | + [INTERNAL_CEREMONY_AUTH_TOKEN_FROM_FLAG_ENV]: '1', |
| 87 | + }; |
| 88 | + writeCeremonyConnectionChannel(env, { databaseDriver: undefined, databaseAuthToken: undefined }); |
| 89 | + expect(INTERNAL_CEREMONY_DATABASE_DRIVER_ENV in env).toBe(false); |
| 90 | + expect(INTERNAL_CEREMONY_AUTH_TOKEN_FROM_FLAG_ENV in env).toBe(false); |
| 91 | + expect(readCeremonyConnectionChannel(env)).toEqual({}); |
| 92 | + // An empty flag value put nothing in the child's environment either (`start` / `dev` test truthiness). |
| 93 | + writeCeremonyConnectionChannel(env, { databaseDriver: '', databaseAuthToken: '' }); |
| 94 | + expect(readCeremonyConnectionChannel(env)).toEqual({}); |
| 95 | + }); |
| 96 | + |
| 97 | + it('⭐ `os dev` writes both channels from its own resolution, as `os start` does: one hand-off, no second resolver', () => { |
| 98 | + for (const command of ['start', 'dev']) { |
| 99 | + const source = readFileSync(new URL(`../commands/${command}.ts`, import.meta.url), 'utf8'); |
| 100 | + expect(source, command).toMatch(/writeCeremonyDatabaseChannel\(localEnv, ceremonyDatabaseUrl\(resolvedDb, \{ homeFlag: /); |
| 101 | + expect(source, command).toMatch(/writeCeremonyConnectionChannel\(localEnv, \{\s*databaseDriver: flags\['database-driver'\],\s*databaseAuthToken: flags\['database-auth-token'\],/); |
| 102 | + } |
| 103 | + }); |
| 104 | +}); |
| 105 | + |
0 commit comments