fix(adapters): no hardcoded installed module references -- use mod_modules.resolve() #123

Open
opened 2026-06-04 09:13:22 +02:00 by michael · 1 comment
Owner

Problem

fragjan adapters must not hardcode references to installed modules.
Installed modules are managed by the module manager and may change,
be upgraded, or be replaced by alternative implementations.

Hardcoded requires bypass the module manager contract and break
the capability abstraction.

Current violations

adapters/log/init.lua hardcodes module names:

local ok, mod = pcall(require, "daw.log.file")
local ok, mod = pcall(require, "daw.log.syslog")

This violates the DAW adapter pattern: adapters must discover
modules via mod_modules.resolve(), not via direct require().

Rule

Adapters that load installed modules MUST use mod_modules.resolve()
with the capability name, not pcall(require, "module.name").

Only the following direct requires are permitted in adapters:

  • daw.common.* (standard library, not installed via module manager)
  • core.* (fragjan core modules, part of the program itself)
  • other adapters (adapters.ui, adapters.log, adapters.primitive)

Fix for adapters/log

Replace hardcoded requires with capability-based resolution:

-- wrong
local ok, mod = pcall(require, "daw.log.file")

-- correct
local resolved, err = mod_modules.resolve(ctx.modules_dir, "log-file", cfg)

adapters/log maps config section names to capability names:

  • [logging "file"] -> resolve "log-file"
  • [logging "debug"] -> resolve "log-file" (second instance via M.new())
  • [logging "syslog"] -> resolve "log-syslog"

Acceptance criteria

  • adapters/log uses mod_modules.resolve() for all backend modules
  • no pcall(require, "daw.log.*") in adapters/
  • fragjan rule added: no installed module hardcoded in adapters/
  • adapters/primitive verified (already uses resolve -- confirm)

References

## Problem fragjan adapters must not hardcode references to installed modules. Installed modules are managed by the module manager and may change, be upgraded, or be replaced by alternative implementations. Hardcoded requires bypass the module manager contract and break the capability abstraction. ## Current violations adapters/log/init.lua hardcodes module names: ```lua local ok, mod = pcall(require, "daw.log.file") local ok, mod = pcall(require, "daw.log.syslog") ``` This violates the DAW adapter pattern: adapters must discover modules via mod_modules.resolve(), not via direct require(). ## Rule Adapters that load installed modules MUST use mod_modules.resolve() with the capability name, not pcall(require, "module.name"). Only the following direct requires are permitted in adapters: - daw.common.* (standard library, not installed via module manager) - core.* (fragjan core modules, part of the program itself) - other adapters (adapters.ui, adapters.log, adapters.primitive) ## Fix for adapters/log Replace hardcoded requires with capability-based resolution: ```lua -- wrong local ok, mod = pcall(require, "daw.log.file") -- correct local resolved, err = mod_modules.resolve(ctx.modules_dir, "log-file", cfg) ``` adapters/log maps config section names to capability names: - [logging "file"] -> resolve "log-file" - [logging "debug"] -> resolve "log-file" (second instance via M.new()) - [logging "syslog"] -> resolve "log-syslog" ## Acceptance criteria - [ ] adapters/log uses mod_modules.resolve() for all backend modules - [ ] no pcall(require, "daw.log.*") in adapters/ - [ ] fragjan rule added: no installed module hardcoded in adapters/ - [ ] adapters/primitive verified (already uses resolve -- confirm) ## References - DAW/fragjan#118 -- adapters/log implementation - DAW/fragjan#97 -- adapters/log contract
michael added this to the Basic Version milestone 2026-06-04 11:29:28 +02:00
Author
Owner

Review 2026-11-21 (fragjan develop, 6e1c56e)

Acceptance criteria:

  • adapters/log uses mod_modules.resolve() for all backend modules
  • no pcall(require, "daw.log.*") in adapters/
  • fragjan rule added: no installed module hardcoded in adapters/ -- no such rule exists in the rule packs. The existing rule no-require-except-mainjan is disabled and checks something else.
  • adapters/primitive verified -- adapters/primitive/init.lua does not call mod_modules.resolve() itself; still to be checked whether that is intended.

The code part is done. The issue stays open until the rule exists or the criterion is dropped (decision pending).

## Review 2026-11-21 (fragjan develop, 6e1c56e) Acceptance criteria: - [x] adapters/log uses mod_modules.resolve() for all backend modules - [x] no pcall(require, "daw.log.*") in adapters/ - [ ] fragjan rule added: no installed module hardcoded in adapters/ -- no such rule exists in the rule packs. The existing rule no-require-except-mainjan is disabled and checks something else. - [ ] adapters/primitive verified -- adapters/primitive/init.lua does not call mod_modules.resolve() itself; still to be checked whether that is intended. The code part is done. The issue stays open until the rule exists or the criterion is dropped (decision pending).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#123
No description provided.