fix: harden configuration dynamic patterns and writes

This commit is contained in:
Tom Boucher
2026-05-15 09:18:15 -04:00
parent 24a992a05c
commit 12a9f4f038
3 changed files with 51 additions and 10 deletions

View File

@@ -41,7 +41,16 @@ export interface DynamicKeyPattern {
}
export const DYNAMIC_KEY_PATTERNS: readonly DynamicKeyPattern[] = _schemaManifest.dynamicKeyPatterns.map(
(p) => ({ ...p, test: (key: string) => new RegExp(p.source).test(key) }),
(p) => {
const pattern = new RegExp(p.source);
return {
...p,
test: (key: string) => {
pattern.lastIndex = 0;
return pattern.test(key);
},
};
},
);
// ─── Types ───────────────────────────────────────────────────────────────────
@@ -305,6 +314,11 @@ export async function migrateOnDisk(cwd: string, workstream?: string): Promise<M
}
}
writeFileSync(configPath, JSON.stringify(result, null, 2));
try {
writeFileSync(configPath, JSON.stringify(result, null, 2));
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
throw new Error(`Failed to write migrated config at ${configPath}: ${msg}`);
}
return { migrated: true, normalizations, wrote: configPath };
}