recovered from aaronjaworski710
CI / offline-tests (push) Has been cancelled
CI / web-unit-tests (push) Has been cancelled
CI / package-console10 (push) Has been cancelled

This commit is contained in:
reform
2026-10-23 20:02:14 +03:00
commit 8044e88be4
409 changed files with 104886 additions and 0 deletions
@@ -0,0 +1,139 @@
"""Control-plane to pipeline reachability for Outlook (Task #206).
Pins the full in-process chain WITHOUT touching the network or a real
browser/mailbox:
get_provider("outlook") → real OutlookProvider
→ Pipeline.run(count=N, fail_fast=...) (proxy preflight mocked)
→ OutlookProvider.register_one() short-circuits at the live gate
→ RegisterResult(ok=False, error_kind="provider")
→ pipeline classifies as terminal provider, stats.fail++,
and (under fail_fast=True) stops after the first attempt.
This closes the gap left by ``test_outlook_pipeline_gated`` (Task 11), which
fakes the provider entirely with ``FakeOutlookProvider``: it never reaches
the REAL registry-resolved OutlookProvider nor the REAL live gate, so a
regression that breaks the gate short-circuit (e.g. moving network work above
the gate) would slip past it. Here the provider is real; only the shared
node/egress proxy preflight is mocked — it would otherwise hit the network
per dead node (~12s libcurl timeouts), which is environment-dependent and
not part of the reachability contract.
Live-browser behaviour is NOT exercised; this is mock-environment only and is
explicitly skipped when ``GROK_REGISTER_OUTLOOK_LIVE=1``.
"""
from __future__ import annotations
import os
import pytest
from register_core.pipeline import Pipeline
from register_core.providers.outlook_adapter import OutlookProvider
from register_core.providers.registry import get_provider
pytestmark = pytest.mark.skipif(
os.environ.get("GROK_REGISTER_OUTLOOK_LIVE") == "1",
reason="acceptance test is mock-only; live browser tests are separately gated",
)
def _mock_proxy_prefs(monkeypatch):
"""Mock the shared node/egress probe so the test never touches the network."""
monkeypatch.setattr(
"register_core.util.proxy.preflight_nodes_for_register",
lambda extra=None, *, log_fn=None: dict(extra or {}),
)
monkeypatch.setattr(
"register_core.util.proxy.inject_attempt_proxy",
lambda extra=None, *, log_fn=None: {**(extra or {}), "proxy": None},
)
monkeypatch.setattr(
"register_core.util.proxy.report_attempt_proxy_result",
lambda *a, **k: None,
)
def test_registry_returns_real_outlook_provider(monkeypatch):
"""The control-plane argv `--provider outlook` resolves, through the same
registry the CLI / Pipeline.from_job uses, to a real OutlookProvider (not a
fake, not None). This is the first hop of reachability."""
monkeypatch.delenv("GROK_REGISTER_OUTLOOK_LIVE", raising=False)
provider = get_provider("outlook")
assert isinstance(provider, OutlookProvider)
assert provider.name == "outlook"
def test_outlook_gate_off_pipeline_classifies_provider_and_stops_fast(
monkeypatch, tmp_path
):
"""Gate OFF + fail_fast=True → the pipeline does exactly ONE attempt, the
real OutlookProvider short-circuits at the gate (no browser/mailbox), and
the result is classified as a terminal ``provider`` failure (not mail_miss,
not fatal). This is the safe control-flow reachability contract: a non-live
harness never opens a browser/mailbox/proxy and surfaces a provider-kind
failure to the control plane."""
monkeypatch.delenv("GROK_REGISTER_OUTLOOK_LIVE", raising=False)
monkeypatch.setenv("OUTLOOK_AUTHS_DIR", str(tmp_path / "outlook_auths"))
_mock_proxy_prefs(monkeypatch)
provider = get_provider("outlook")
emitted: list = []
stats = Pipeline(
provider,
fail_fast=True,
on_result=emitted.append,
).run(count=3, extra={})
# Exactly one attempt before fail-fast stop (gate is terminal provider, not
# a soft mail_miss retry).
assert len(stats.results) == 1, stats.results
result = stats.results[0]
assert result.ok is False
assert result.error_kind == "provider"
assert result.provider == "outlook"
assert result.error is not None
assert "live gate" in result.error.lower() or "GROK_REGISTER_OUTLOOK_LIVE" in result.error, (
result.error
)
assert stats.fail == 1
assert stats.ok == 0
assert stats.stopped_reason, "fail_fast=True must record why it stopped"
# No artifact written (gate is OFF).
auths = tmp_path / "outlook_auths"
assert not auths.exists() or not list(auths.glob("outlook-*.json"))
# Public view carries no real credential even on a gated failure: the
# password/secret fields are present (key names are public schema, not
# secrets) but MUST be empty for a gate-off short-circuit — no account
# was created, so there is no value to leak.
public = result.to_public_dict()
assert public.get("password") in (None, "")
assert public.get("secret") in (None, "")
assert public.get("secret_kind") in (None, "none")
def test_outlook_gate_off_is_deterministic_across_attempts(monkeypatch, tmp_path):
"""Gate OFF + fail_fast=False → every attempt across count=3 short-circuits
identically and deterministically (stateless gate). Proves the live gate is
not stateful and does not degrade into a network call on repeat attempts."""
monkeypatch.delenv("GROK_REGISTER_OUTLOOK_LIVE", raising=False)
monkeypatch.setenv("OUTLOOK_AUTHS_DIR", str(tmp_path / "outlook_auths"))
_mock_proxy_prefs(monkeypatch)
provider = get_provider("outlook")
stats = Pipeline(provider, fail_fast=False).run(count=3, extra={})
assert len(stats.results) == 3, stats.results
assert stats.fail == 3
assert stats.ok == 0
assert all(r.ok is False for r in stats.results)
assert all(r.error_kind == "provider" for r in stats.results)
assert all(
r.error is not None
and ("live gate" in r.error.lower() or "GROK_REGISTER_OUTLOOK_LIVE" in r.error)
for r in stats.results
)
# Gate OFF across all three attempts → never opens a browser, never writes.
auths = tmp_path / "outlook_auths"
assert not auths.exists() or not list(auths.glob("outlook-*.json"))
@@ -0,0 +1,103 @@
"""End-to-end mocked acceptance for the Outlook pipeline (Task 11).
Live-browser behaviour is NOT exercised here — this test is mock-only and is
explicitly skipped when ``GROK_REGISTER_OUTLOOK_LIVE=1`` (the live browser
tests live in their own separately-gated module). The contract pinned here:
1. The pipeline's ``inject_attempt_proxy`` shallow-copies ``extra`` and sets
``extra["proxy"]``; the value reaches the provider's ``register_one``.
2. A provider that writes a 0600 Outlook auth artifact and returns a
``RegisterResult`` with ``secret_kind="refresh_token"`` is carried
through unchanged.
3. The public result view (``to_public_dict``) redacts the password, the
refresh-token secret, and the proxy value — none leak into public dicts,
even though the on-disk private artifact retains the secret.
"""
from __future__ import annotations
import json
import os
import stat
import pytest
from register_core.contracts import RegisterResult
from register_core.pipeline import Pipeline
pytestmark = pytest.mark.skipif(
os.environ.get("GROK_REGISTER_OUTLOOK_LIVE") == "1",
reason="this acceptance test is mock-only; live browser tests are separately gated",
)
def test_mock_outlook_pipeline_carries_proxy_and_redacts_public_result(
monkeypatch, tmp_path
):
seen: dict[str, object] = {}
monkeypatch.setattr(
"register_core.util.proxy.preflight_nodes_for_register",
lambda extra=None, *, log_fn=None: dict(extra or {}),
)
monkeypatch.setattr(
"register_core.util.proxy.inject_attempt_proxy",
lambda extra=None, *, log_fn=None: {**(extra or {}), "proxy": "synthetic-proxy"},
)
class FakeOutlookProvider:
name = "outlook"
def register_one(self, *, email_source, extra):
seen["proxy"] = extra["proxy"]
path = tmp_path / "outlook_auths" / "outlook-user.json"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(
json.dumps(
{
"email": "user@outlook.com",
"password": "synthetic-password",
"client_id": "synthetic-client-id",
"refresh_token": "synthetic-refresh-token",
"bound": True,
}
),
encoding="utf-8",
)
path.chmod(stat.S_IRUSR | stat.S_IWUSR)
return RegisterResult(
ok=True,
provider=self.name,
email="user@outlook.com",
password="synthetic-password",
secret="synthetic-refresh-token",
secret_kind="refresh_token",
artifacts={
"outlook_auth_path": str(path),
"bound": True,
"recovery_email": "r@invalid",
},
)
emitted: list[RegisterResult] = []
stats = Pipeline(
FakeOutlookProvider(),
fail_fast=False,
on_result=emitted.append,
).run(count=1, extra={})
assert stats.results and stats.results[0].ok is True
assert seen == {"proxy": "synthetic-proxy"}
path = tmp_path / "outlook_auths" / "outlook-user.json"
assert stat.S_IMODE(path.stat().st_mode) == 0o600
private = json.loads(path.read_text(encoding="utf-8"))
assert private["refresh_token"] == "synthetic-refresh-token"
public = emitted[0].to_public_dict()
public_json = json.dumps(public)
assert public["artifacts"]["outlook_auth_path"] == str(path)
assert public["artifacts"]["bound"] is True
assert public["artifacts"]["recovery_email"] == "r@invalid"
assert "synthetic-password" not in public_json
assert "synthetic-refresh-token" not in public_json
assert "synthetic-proxy" not in public_json