fix(#2152): accept a homedir option in readGsd(Effective|Global)ModelOverrides

readGsdEffectiveModelOverrides resolved ~/.gsd/defaults.json via os.homedir()
with no seam, so a test asserting project-only overrides could not isolate the
global file. Add an optional { homedir } option (defaults to os.homedir()) to
readGsdGlobalModelOverrides and readGsdEffectiveModelOverrides — the same
dependency-injection shape the sibling warnIfStaleBake already uses. Backward-
compatible: existing callers pass no option and behave identically.

Closes #2152
This commit is contained in:
Tom Boucher
2026-07-12 15:49:16 -04:00
parent 5bce5c46a6
commit c4f17a8d6e

View File

@@ -1139,9 +1139,10 @@ function writeSettings(settingsPath, settings) {
* Used by Codex TOML and OpenCode agent file generators to embed per-agent
* model assignments so that model_overrides is respected on non-Claude runtimes (#2256).
*/
function readGsdGlobalModelOverrides() {
function readGsdGlobalModelOverrides(options = {}) {
try {
const defaultsPath = path.join(os.homedir(), '.gsd', 'defaults.json');
const home = options.homedir ? options.homedir() : os.homedir();
const defaultsPath = path.join(home, '.gsd', 'defaults.json');
if (!fs.existsSync(defaultsPath)) return null;
const raw = fs.readFileSync(defaultsPath, 'utf-8');
const parsed = JSON.parse(raw);
@@ -1178,8 +1179,8 @@ function readGsdGlobalModelOverrides() {
* Returns a plain `{ agentName: modelId }` object, or `null` when neither
* source defines `model_overrides`.
*/
function readGsdEffectiveModelOverrides(targetDir = null) {
const global = readGsdGlobalModelOverrides();
function readGsdEffectiveModelOverrides(targetDir = null, options = {}) {
const global = readGsdGlobalModelOverrides(options);
let projectOverrides = null;
if (targetDir) {