Skip to content

config.ts: dedupe platform-default-path computation (getDefaultUserConfigPath / resolveUserConfigPath) #1746

Description

@carlos-alm

Context

Found during titan-forge phase 14 gauntlet audit of src/infrastructure/config.ts (rule 11, pillar III — same violation entry that also flagged the consent appliesTo-glob duplication, which phase 14 fixes).

Problem

The XDG_CONFIG_HOME / APPDATA / unix platform-default-path computation is copy-pasted between two functions:

  • getDefaultUserConfigPath() (around line 254-268 as of this writing)
  • resolveUserConfigPath() (around line 282-313)

Both implement the same three-way branch (XDG_CONFIG_HOME env → Windows %APPDATA%~/.config), with resolveUserConfigPath layering an extra existsSync check on top. This is a maintenance hazard: a future change to the priority order or path shape (e.g. adding a new env var) has to be applied in two places, and it's easy to miss one.

Suggested fix

Extract the three-way branch into a single shared helper (e.g. computePlatformDefaultConfigPath(): string) that both functions call, with resolveUserConfigPath doing its own existsSync checks on top of the shared computation.

Scope note

Not fixed in phase 14 (titan-forge) because that phase's commit message/label scoped the "glob-match dedupe" work specifically to the consent appliesTo-glob duplication (the other half of the same gauntlet rule-11 violation), and no later phase in sync.json revisits src/infrastructure/config.ts. Filing this so the finding isn't lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions