Skip to content

Commit c1c5f6a

Browse files
tianzhouclaude
andcommitted
test: make the TOML/DSN conflict tests match a reachable state
The tests mocked loadTomlConfig() into returning a config while argv had no --config. Since --config is the only way TOML loads, that state cannot occur at runtime — and it specifically skipped the .env-before-TOML load, which is gated on the flag, so those tests exercised a path production never takes. They now pass --config, and run from an empty temp directory so an ambient .env cannot reach the load the flag now triggers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6d69d4b commit c1c5f6a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/config/__tests__/env.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,22 +621,34 @@ describe('Environment Configuration Tests', () => {
621621

622622
describe('resolveSourceConfigs TOML/DSN conflict', () => {
623623
const originalArgv = process.argv;
624+
const originalCwd = process.cwd();
625+
let tempDir: string;
626+
let configPath: string;
624627

625628
beforeEach(() => {
626-
process.argv = ['node', 'script.js'];
629+
// Run from an empty directory so an ambient .env cannot reach the
630+
// .env-before-TOML load that --config now triggers.
631+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'toml-dsn-conflict-'));
632+
configPath = path.join(tempDir, 'dbhub.toml');
633+
process.chdir(tempDir);
634+
// --config is the only way TOML gets loaded, so it has to be present for
635+
// the mocked loadTomlConfig() to stand for a state reachable at runtime.
636+
process.argv = ['node', 'script.js', '--config', configPath];
627637
vi.mocked(loadTomlConfig).mockReturnValue({
628638
sources: [{ id: 'db1', type: 'sqlite', dsn: 'sqlite://a.db' }],
629639
source: 'dbhub.toml',
630640
} as any);
631641
});
632642

633643
afterEach(() => {
644+
process.chdir(originalCwd);
645+
fs.rmSync(tempDir, { recursive: true, force: true });
634646
process.argv = originalArgv;
635647
vi.mocked(loadTomlConfig).mockReturnValue(null);
636648
});
637649

638650
it('rejects a --dsn flag supplied alongside TOML config', async () => {
639-
process.argv = ['node', 'script.js', '--dsn=sqlite://:memory:'];
651+
process.argv = ['node', 'script.js', '--config', configPath, '--dsn=sqlite://:memory:'];
640652
const { resolveSourceConfigs } = await import('../env.js');
641653

642654
await expect(resolveSourceConfigs()).rejects.toThrow(

0 commit comments

Comments
 (0)