Extract a 3-method SettingsStore port (worked example for ISP)

Open Beginner friendly
#7 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with application/cache.py to follow the existing port pattern, then read src/aitts/settings.py and tests/test_settings_service.py. Define the three-method protocol and update the service type, replace the test store fixture with a dict-backed fake, and run the settings service tests to confirm the validation rules still pass without SQLite.

Written by the indexing model from the issue text.

Description

enhancement good first issue

The problem

SettingsService is constructed with the whole Store. It uses three of its
41 public methods:

get_setting, has_setting, set_setting

That is an Interface Segregation failure: a client depending on 38 methods it
never calls. It also keeps aitts.settings out of the core, because importing
Store drags SQLite in behind it.

The fix, and the precedent

application/cache.py already does this correctly:

class CacheMetadataPort(Protocol):
    def protected_audio_paths(self) -> frozenset[str]: ...
    def forget_terminal_audio(self, path: Path) -> int: ...

CacheController takes that two-method port, lives in the core, and Store
satisfies it structurally — it is a Protocol, so there is no inheritance,
no registration, and Store needed no changes at all.

Do the same here:

class SettingsStorePort(Protocol):
    def get_setting(self, key: str, default: str) -> str: ...
    def has_setting(self, key: str) -> bool: ...
    def set_setting(self, key: str, value: str) -> None: ...

SettingsService.__init__(self, store: SettingsStorePort, environment: SettingsEnvironment).
Store continues to satisfy it with no edit.

Why this one first

It is the smallest of the five and the shape is identical for the others, so it
is the worked example. It also means tests/test_settings_service.py can drop
its real SQLite store for a dict-backed fake, which is the point of the port —
the tests already prove the validation rules and would then prove them without
a database.

Scope

  • src/aitts/settings.py — the Protocol and the constructor type
  • src/aitts/daemon.py — no change needed; it passes self._store already
  • tests/test_settings_service.py — swap the store fixture for a fake

Part of #12.

Dominant language
Python
Stars
0
Forks
1
Avg merge
2h 13m
Merged PRs (30d)
51

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flyingrobots/AI-TTS

All issues in flyingrobots/AI-TTS

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.