Foundry.Context.ScenarioCache (Foundry v0.4.0)

Copy Markdown View Source

Caches the latest scenario extraction report and tells subscribers when it changes.

Why this owns its own subscriber set

It used to call Phoenix.PubSub.broadcast/3 against Foundry.PubSub, which put phoenix_pubsub in the library's dependency list and, worse, put a supervision tree there: the pubsub process had to already be running before a mix task could ask this module anything. ADR-035 moved everything with a supervision tree to the Studio, so the cache monitors its own subscribers instead. One process, no dependency, and the message a subscriber receives is unchanged -- {:scenarios_updated, report}.

get/0 answers nil rather than raising

ADR-036 runs the library inside a target project as a mix task, where nothing starts this GenServer. Foundry.Context.ProjectContext already treats nil as "no cache, extract now", so the absent process is a cache miss and not a failure. A GenServer.call to an unregistered name exits, which would have killed the mix task with a message about :noproc rather than about scenarios.

Boot does not extract

⚠️ It used to send(self(), :extract_static) here, and that extraction ran against File.cwd!() -- the Studio's directory, never the target's. Every subscriber was then handed a report describing Foundry's own repository, which is how the coverage panel came to say "105 nodes still have no scenario coverage" (Foundry's node count) about a project with 344 nodes. Coverage for a target is computed in that target's subprocess under ADR-036; this cache now only holds what mix foundry.scenarios.extract explicitly hands it.

Summary

Functions

Returns a specification to start this module under a supervisor.

The cached report, or nil when there is no cache to read.

Registers the caller for {:scenarios_updated, report} messages.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get()

@spec get() :: struct() | nil

The cached report, or nil when there is no cache to read.

start_link(opts \\ [])

subscribe()

@spec subscribe() :: :ok

Registers the caller for {:scenarios_updated, report} messages.

Answers :ok even when the cache is not running -- a Studio page that subscribes before the cache boots gets no messages, which is what it got from pubsub too.

update(report)