State Management¶
Requirements¶
Requirement: Immutable Global State¶
The system SHALL provide an immutable Globals dataclass that contains all
framework state and cannot be modified after creation.
Scenario: State creation during initialization¶
WHEN
prepare()completes successfullyTHEN a
Globalsinstance is returned with all fields populatedAND all fields are immutable (frozen dataclass with accretive containers)
Scenario: State access by application code¶
WHEN application code accesses
GlobalsfieldsTHEN field values are consistent with the state at initialization time
AND no field can be modified through the
Globalsreference
Scenario: State serialization¶
WHEN
Globals.as_dictionary()is calledTHEN a shallow copy of all state fields is returned as a dictionary
AND the returned dictionary is independent of the
Globalsinstance
Requirement: Location Provision¶
The system SHALL provide methods on Globals for resolving platform-specific
locations with configuration overrides.
Scenario: Default cache location¶
WHEN
Globals.provide_cache_location()is called without argumentsTHEN the platform-default cache directory is returned
AND the directory path is derived from
platformdirs
Scenario: Location with configuration override¶
WHEN configuration contains a
locations.cacheentryTHEN
Globals.provide_cache_location()uses the configured pathAND template variables (
{user_cache},{user_home},{application_name}) are expanded
Scenario: Location with subpath appendages¶
WHEN
Globals.provide_data_location('subdir', 'file.txt')is calledTHEN the subpath is appended to the resolved base location
AND the full path is returned
Requirement: State Field Composition¶
The Globals dataclass SHALL contain fields for application metadata,
configuration, platform directories, distribution information, and the exit stack.
Scenario: Complete state assembly¶
WHEN
prepare()assembles theGlobalsinstanceTHEN the following fields are populated:
application:Informationinstance with name, publisher, versionconfiguration: accretive dictionary with merged configurationdirectories:PlatformDirsinstance for the applicationdistribution:Informationinstance with deployment modeexits: theAsyncExitStackpassed toprepare()