9.0 KiB
issue, issue_title
| issue | issue_title |
|---|---|
| 113 | refactor: remove legacy path defaults from logging and extension-config |
Remove legacy path defaults from logging and extension-config
Problem Statement
src/extension-config.ts exports module-scope constants (CONFIG_PATH, LOGS_DIR, DEBUG_LOG_PATH, PERMISSION_REVIEW_LOG_PATH) derived from import.meta.url that point to the legacy extension-root paths.
The current architecture uses agentDir-derived paths via computeExtensionPaths() and runtime.ts always provides explicit paths to the logger.
The legacy constants only serve as defaults in createPermissionSystemLogger() and in the legacy loadPermissionSystemConfig() / savePermissionSystemConfig() / getPermissionSystemConfigPath() / ensurePermissionSystemConfig() functions — none of which are imported by any production code in src/.
This creates confusing fallback behavior: if a caller omitted a path argument, it would silently use the wrong directory.
Goals
- Make
debugLogPath,reviewLogPath, andensureLogsDirectoryrequired inPermissionSystemLoggerOptions. - Remove the legacy path constants (
CONFIG_PATH,LOGS_DIR,DEBUG_LOG_PATH,PERMISSION_REVIEW_LOG_PATH) fromextension-config.ts. - Remove the legacy config functions (
loadPermissionSystemConfig,savePermissionSystemConfig,getPermissionSystemConfigPath,ensurePermissionSystemConfig) that are dead production code. - Update tests that import removed symbols.
Non-Goals
- Changing
EXTENSION_ROOTorresolveExtensionRoot()— still used byruntime.ts. - Changing
ensurePermissionSystemLogsDirectory()— still used byruntime.ts(called with an explicitlogsDirargument). - Refactoring
runtime.tsor the config-loader pipeline.
Background
Permission surface
None — this is a pure internal cleanup. No permission surface is involved.
Relevant modules
src/extension-config.ts— defines the legacy constants and functions. Also definesEXTENSION_ID,DEFAULT_EXTENSION_CONFIG,normalizePermissionSystemConfig,detectMisplacedPermissionKeys,ensurePermissionSystemLogsDirectory, andEXTENSION_ROOTwhich remain in use.src/logging.ts—createPermissionSystemLogger()imports legacy constants as defaults for its optional parameters.src/runtime.ts— the sole production consumer of both modules; already provides explicit paths and never relies on legacy defaults.
Test consumers of legacy symbols
tests/extension-config.test.ts— importsloadPermissionSystemConfigfor integration tests.tests/permission-system.test.ts— importsloadPermissionSystemConfig,savePermissionSystemConfig; also creates a logger with all options explicit.tests/config-modal.test.ts— importsloadPermissionSystemConfig,savePermissionSystemConfigfor config-modal round-trip tests.tests/config-reporter.test.ts— creates a logger with explicit paths (omitsdebugLogPathbut this is benign since it never writes debug logs); needsensureLogsDirectorybut not the legacy default.
Design Overview
logging.ts changes
Make all three optional fields required in PermissionSystemLoggerOptions:
interface PermissionSystemLoggerOptions {
getConfig: () => PermissionSystemExtensionConfig;
debugLogPath: string;
reviewLogPath: string;
ensureLogsDirectory: () => string | undefined;
}
Remove the ?? fallback expressions and the imports of DEBUG_LOG_PATH, LOGS_DIR, PERMISSION_REVIEW_LOG_PATH, and ensurePermissionSystemLogsDirectory from extension-config.
extension-config.ts changes
Remove:
CONFIG_PATHLOGS_DIRDEBUG_LOG_PATHPERMISSION_REVIEW_LOG_PATHensurePermissionSystemConfig()loadPermissionSystemConfig()savePermissionSystemConfig()getPermissionSystemConfigPath()cloneDefaultConfig()(private, only used byloadPermissionSystemConfig)createDefaultConfigContent()(private, only used byensurePermissionSystemConfig)ensureConfigDirectory()(private, only used byensurePermissionSystemConfigandsavePermissionSystemConfig)- The
PermissionSystemConfigLoadResultandPermissionSystemConfigSaveResultinterfaces (only used by the removed functions)
Remove the now-unused import of renameSync, unlinkSync, and writeFileSync from node:fs.
Keep existsSync and mkdirSync (used by ensurePermissionSystemLogsDirectory).
Make the logsDir parameter of ensurePermissionSystemLogsDirectory required (remove the = LOGS_DIR default).
Test changes
tests/extension-config.test.ts— remove theloadPermissionSystemConfigdescribe block and its import. ThedetectMisplacedPermissionKeysandnormalizePermissionSystemConfigtests remain.tests/permission-system.test.ts— remove or replace theloadPermissionSystemConfig/savePermissionSystemConfigtests. These test config round-tripping which is now covered byconfig-loader.test.tsor can be deleted as dead-code tests.tests/config-modal.test.ts— replaceloadPermissionSystemConfig/savePermissionSystemConfigusage with directreadFileSync+JSON.parse+normalizePermissionSystemConfigandwriteFileSync, or with theloadUnifiedConfigfunction thatruntime.tsalready uses.tests/config-reporter.test.ts— add the missingdebugLogPathto the logger construction call.
Test Impact Analysis
- New tests enabled — none; this is a removal, not an extraction.
- Redundant tests — the
loadPermissionSystemConfig/savePermissionSystemConfigtests inpermission-system.test.tsandextension-config.test.tstest functions that no production code calls. They should be removed. - Tests that must stay —
detectMisplacedPermissionKeysandnormalizePermissionSystemConfigtests inextension-config.test.ts; logger tests inpermission-system.test.tsthat construct the logger with explicit options; config-modal tests (adapted to use direct file I/O orloadUnifiedConfig).
TDD Order
-
Make logger options required and fix test call-sites. Update
PermissionSystemLoggerOptionsto makedebugLogPath,reviewLogPath, andensureLogsDirectoryrequired. Remove legacy-constant imports fromlogging.ts. Updatetests/config-reporter.test.tsto providedebugLogPath. Runpnpm vitest run tests/config-reporter.test.ts tests/permission-system.test.ts tests/runtime.test.tsto confirm. Commit:refactor: make logger path options required (#113) -
Remove legacy config functions and constants from
extension-config.ts. DeleteCONFIG_PATH,LOGS_DIR,DEBUG_LOG_PATH,PERMISSION_REVIEW_LOG_PATH, the four legacy config functions, their helper functions, and the two result interfaces. MakeensurePermissionSystemLogsDirectory'slogsDirparameter required. Remove unusednode:fsimports. Commit:refactor: remove legacy path constants and config functions (#113) -
Update
tests/extension-config.test.ts. Remove theloadPermissionSystemConfigdescribe block and its import. Commit:test: remove dead loadPermissionSystemConfig tests (#113) -
Update
tests/permission-system.test.ts. Remove theloadPermissionSystemConfig/savePermissionSystemConfigimport and tests. Commit:test: remove dead legacy config round-trip tests (#113) -
Update
tests/config-modal.test.ts. ReplaceloadPermissionSystemConfig/savePermissionSystemConfigwith direct file I/O orloadUnifiedConfig+normalizePermissionSystemConfig. Runpnpm vitest run tests/config-modal.test.tsto confirm. Commit:test: migrate config-modal tests off legacy config functions (#113) -
Run full suite and type-check. Run
pnpm run buildandpnpm vitest run. Commit (if any fixes needed):fix: address build/test issues from legacy removal (#113)
Risks and Mitigations
| Risk | Mitigation |
|---|---|
| Could this silently weaken a permission? | No — this change only affects logging paths and config I/O helpers; no permission evaluation logic is touched. |
| An external consumer imports a removed symbol | These are internal modules; the package is not published as a library. Tests are the only consumers. |
config-reporter.test.ts silently used the legacy debugLogPath default |
Step 1 makes it required, forcing the test to provide an explicit value and exposing any latent bug. |
config-modal.test.ts refactoring introduces a subtle behavior change |
The replacement uses the same underlying normalizePermissionSystemConfig function, preserving semantics. |
Open Questions
- None — the issue is fully scoped and all affected call-sites are identified.