Class: Browserctl::Workflow::RecoveryManager

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/workflow/recovery_manager.rb

Overview

Owns the AUTH_REQUIRED recovery state machine for ‘load_state`.

When the daemon reports AUTH_REQUIRED on a ‘state_load` (e.g. expired cookies in the bundle), the manager either runs the bound flow or the caller-provided override, re-saves the bundle, and reloads it with `skip_auth_check: true`.

Decoupled from ContextualPersistence so the multi-step recovery logic has a dedicated home and a dedicated spec. The host context only needs to expose ‘client` (for daemon RPCs) and `invoke` (for running the bound flow); see ContextualPersistence#load_state.

Constant Summary collapse

AUTH_REQUIRED_CODE =
"AUTH_REQUIRED"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ RecoveryManager

Returns a new instance of RecoveryManager.

Parameters:

  • context (#client, #invoke)

    a workflow context exposing the daemon client and an ‘invoke(flow_name, page:)` entry point.



21
22
23
# File 'lib/browserctl/workflow/recovery_manager.rb', line 21

def initialize(context)
  @context = context
end

Class Method Details

.auth_required?(res) ⇒ Boolean

True when ‘res` is the daemon’s AUTH_REQUIRED preflight signal.

Returns:

  • (Boolean)


26
27
28
# File 'lib/browserctl/workflow/recovery_manager.rb', line 26

def self.auth_required?(res)
  (res[:code] || res["code"]) == AUTH_REQUIRED_CODE
end

Instance Method Details

#recover(state_name, initial_res, on_auth_required: nil) ⇒ Object

Run recovery for ‘state_name` given the daemon’s initial AUTH_REQUIRED response. Returns the merged retry result (with ‘rotated: true`) or raises Browserctl::WorkflowError when no flow is bound and no override is supplied, or when the post-rotation reload still fails.

Parameters:

  • state_name (String)

    the bundle name being loaded

  • initial_res (Hash)

    the original AUTH_REQUIRED response

  • on_auth_required (Proc, nil) (defaults to: nil)

    optional override; when given, it runs in lieu of invoking the suggested flow.



39
40
41
42
43
44
45
46
47
# File 'lib/browserctl/workflow/recovery_manager.rb', line 39

def recover(state_name, initial_res, on_auth_required: nil)
  if on_auth_required
    on_auth_required.call
  else
    invoke_bound_flow(state_name, initial_res)
  end

  rotate_and_reload(state_name)
end