🐞 fix: Update config file handling
This commit is contained in:
+10
-1
@@ -111,12 +111,21 @@ function camelize(value: unknown): unknown {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectFromNull(value: unknown): unknown {
|
||||||
|
return value === null ? {} : value;
|
||||||
|
}
|
||||||
|
|
||||||
export function expandHome(path: string): string {
|
export function expandHome(path: string): string {
|
||||||
return path.startsWith('~/') ? resolve(homedir(), path.slice(2)) : path;
|
return path.startsWith('~/') ? resolve(homedir(), path.slice(2)) : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadConfigFromString(source: string): AppConfig {
|
export function loadConfigFromString(source: string): AppConfig {
|
||||||
const parsed = camelize(YAML.parse(source) ?? {});
|
const parsed = camelize(YAML.parse(source) ?? {}) as Record<string, any>;
|
||||||
|
parsed.newsletters = objectFromNull(parsed.newsletters);
|
||||||
|
parsed.categories = objectFromNull(parsed.categories) as Record<string, any>;
|
||||||
|
if (parsed.categories && typeof parsed.categories === 'object') {
|
||||||
|
parsed.categories.llm = objectFromNull(parsed.categories.llm);
|
||||||
|
}
|
||||||
return configSchema.parse(parsed);
|
return configSchema.parse(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,28 @@ output:
|
|||||||
expect(config.enrichment.concurrency).toBe(3);
|
expect(config.enrichment.concurrency).toBe(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats comment-only YAML maps as empty objects', () => {
|
||||||
|
const config = loadConfigFromString(`
|
||||||
|
gmail:
|
||||||
|
folder: Newsletters
|
||||||
|
output:
|
||||||
|
name: Newsletter Link Catalog
|
||||||
|
excel:
|
||||||
|
enabled: true
|
||||||
|
path: ./output/catalog.xlsx
|
||||||
|
newsletters:
|
||||||
|
# sender@example.com:
|
||||||
|
categories:
|
||||||
|
custom:
|
||||||
|
- Rust
|
||||||
|
llm:
|
||||||
|
# provider: anthropic
|
||||||
|
`);
|
||||||
|
|
||||||
|
expect(config.newsletters).toEqual({});
|
||||||
|
expect(config.categories.llm.provider).toBe('anthropic');
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects conflicting relative and absolute date filters', () => {
|
it('rejects conflicting relative and absolute date filters', () => {
|
||||||
expect(() => validateDateFilters({ last: '30d', from: '2026-01-01' })).toThrow(
|
expect(() => validateDateFilters({ last: '30d', from: '2026-01-01' })).toThrow(
|
||||||
/cannot be combined/i
|
/cannot be combined/i
|
||||||
|
|||||||
Reference in New Issue
Block a user