Skip to content

Commit ee45492

Browse files
committed
AuthStep.kind, vet explain_auth op, un-stale the builtin tool test
- AuthStep gains a structured language-neutral kind (api_keys, env:<VAR>, placeholder, oauth-file); the conformance test compares kinds instead of parsing display strings. - lm15.vet implements the new explain_auth protocol op: harness-supplied env/api_keys/credentials_path only, never the real environment; returns configured, the kind/state chain, and the full human rendering for the harness-side AUTH-5 sentinel gate. - test_builtin_without_signature_rejected: map gained an introspectable signature in newer CPython; iter now carries the non-introspectable path, and a new test pins that map stays rejected on every supported version (either message). Full suite: 678 passed.
1 parent eb39f3e commit ee45492

5 files changed

Lines changed: 68 additions & 19 deletions

File tree

‎lm15/doctor.py‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ class AuthStep:
5555
- ``"shadowed"`` — usable, but an earlier rung wins;
5656
- ``"absent"`` — nothing here.
5757
58+
``kind`` is the language-neutral source identifier from the contract
59+
fixtures (lm15-contract/auth/resolution.json): ``"api_keys"``,
60+
``"env:<VAR>"``, ``"placeholder"``, or ``"oauth-file"``. Conformance
61+
compares kinds, never display strings.
62+
5863
``detail`` is human text and carries no secret material by construction.
5964
"""
6065

66+
kind: str
6167
source: str
6268
detail: str
6369
state: str
@@ -115,10 +121,10 @@ def _oauth_step(provider: str, path_override: str | None) -> AuthStep:
115121
source = f"local OAuth credential {path}"
116122
credential = reader(path)
117123
if credential is None:
118-
return AuthStep(source=source, detail="missing or unreadable", state="absent")
124+
return AuthStep(kind="oauth-file", source=source, detail="missing or unreadable", state="absent")
119125
detail = _expiry_detail(credential)
120126
state = "selected" if ("expired" not in detail or credential.refresh_token) else "absent"
121-
return AuthStep(source=source, detail=detail, state=state)
127+
return AuthStep(kind="oauth-file", source=source, detail=detail, state=state)
122128

123129

124130
def explain_auth(
@@ -157,28 +163,41 @@ def explain_auth(
157163
if has_entry:
158164
steps.append(
159165
AuthStep(
166+
kind="api_keys",
160167
source="explicit api_keys entry",
161168
detail="provided (value never shown)",
162169
state="selected",
163170
)
164171
)
165172
selected = True
166173
else:
167-
steps.append(AuthStep(source="explicit api_keys entry", detail="not provided", state="absent"))
174+
steps.append(
175+
AuthStep(
176+
kind="api_keys",
177+
source="explicit api_keys entry",
178+
detail="not provided",
179+
state="absent",
180+
)
181+
)
168182

169183
for key in _declared_env_keys(canonical, ADAPTERS):
170184
if environment.get(key):
171185
state = "shadowed" if selected else "selected"
172-
steps.append(AuthStep(source=f"env ${key}", detail="set (value never shown)", state=state))
186+
steps.append(
187+
AuthStep(kind=f"env:{key}", source=f"env ${key}", detail="set (value never shown)", state=state)
188+
)
173189
selected = True
174190
else:
175-
steps.append(AuthStep(source=f"env ${key}", detail="not set", state="absent"))
191+
steps.append(
192+
AuthStep(kind=f"env:{key}", source=f"env ${key}", detail="not set", state="absent")
193+
)
176194

177195
route = CHAT_PRESET_ROUTES.get(canonical)
178196
if route is not None and route.default_key is not None:
179197
state = "shadowed" if selected else "selected"
180198
steps.append(
181199
AuthStep(
200+
kind="placeholder",
182201
source="local-server placeholder key",
183202
detail=f"preset default for keyless {canonical} servers",
184203
state=state,

‎lm15/vet.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,38 @@ def op_validate(msg: JsonObject) -> JsonObject:
228228
return {"ok": True, "normalized": to_dict(obj)}
229229

230230

231+
def op_explain_auth(msg: JsonObject) -> JsonObject:
232+
"""AUTH-7 resolution chain over harness-supplied inputs only.
233+
234+
The harness owns every input: ``env`` (always passed, even empty, so the
235+
real process environment never leaks in), ``api_keys_providers`` planted
236+
with the fixture sentinel, and ``credentials_path`` pointing at a
237+
harness-materialized borrowed file. ``report_text`` carries every human
238+
rendering so the harness can enforce AUTH-5 (sentinel absence) itself.
239+
"""
240+
from .doctor import explain_auth
241+
242+
provider = str(msg["provider"])
243+
sentinel = str(msg["sentinel"])
244+
kwargs: dict[str, Any] = {"env": {str(k): str(v) for k, v in (msg.get("env") or {}).items()}}
245+
providers = msg.get("api_keys_providers") or []
246+
if providers:
247+
kwargs["api_keys"] = {str(p): sentinel for p in providers}
248+
credentials_path = msg.get("credentials_path")
249+
if credentials_path is not None:
250+
if provider == "claude-code":
251+
kwargs["claude_credentials_path"] = str(credentials_path)
252+
else:
253+
kwargs["codex_auth_path"] = str(credentials_path)
254+
255+
report = explain_auth(provider, **kwargs)
256+
return {
257+
"configured": report.configured,
258+
"steps": [{"kind": step.kind, "state": step.state} for step in report.steps],
259+
"report_text": "\n".join((report.describe(), repr(report), str(report))),
260+
}
261+
262+
231263
def op_surface_dump(msg: JsonObject) -> JsonObject:
232264
return {
233265
"types": _reflect_types(),
@@ -298,6 +330,7 @@ def _string_vocabulary(obj: Any) -> list[str] | None:
298330
"serde_roundtrip": op_serde_roundtrip,
299331
"validate": op_validate,
300332
"surface_dump": op_surface_dump,
333+
"explain_auth": op_explain_auth,
301334
}
302335

303336

‎tests/test_auth_resolution_contract.py‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ def _materialize_borrowed_file(tmp_path: Path, state: str) -> str | None:
4242
return str(path)
4343

4444

45-
def _step_kind(source: str) -> str:
46-
"""Map the human display source to the fixture's language-neutral kind."""
47-
if source == "explicit api_keys entry":
48-
return "api_keys"
49-
if source.startswith("env $"):
50-
return f"env:{source.removeprefix('env $')}"
51-
if source == "local-server placeholder key":
52-
return "placeholder"
53-
if source.startswith("local OAuth credential"):
54-
return "oauth-file"
55-
raise AssertionError(f"unmapped auth step source: {source!r}")
56-
57-
5845
@pytest.mark.parametrize("case", CASES, ids=[case["id"] for case in CASES])
5946
def test_auth_resolution_contract_case(case: dict, tmp_path: Path) -> None:
6047
kwargs: dict = {"env": case.get("env", {})}
@@ -69,7 +56,7 @@ def test_auth_resolution_contract_case(case: dict, tmp_path: Path) -> None:
6956

7057
expect = case["expect"]
7158
assert report.configured is expect["configured"], case["id"]
72-
actual_steps = [{"kind": _step_kind(step.source), "state": step.state} for step in report.steps]
59+
actual_steps = [{"kind": step.kind, "state": step.state} for step in report.steps]
7360
assert actual_steps == expect["steps"], case["id"]
7461

7562
# AUTH-5: the planted sentinel must never surface in any rendering.

‎tests/test_tools.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,16 @@ def f(d: dict[int, str]) -> None: ...
366366

367367

368368
def test_builtin_without_signature_rejected() -> None:
369+
# ``iter`` has no introspectable signature on every supported CPython.
369370
with pytest.raises(ToolDerivationError, match=r"not introspectable"):
371+
tool(iter)
372+
373+
374+
def test_builtin_map_rejected_on_every_python() -> None:
375+
# ``map`` gained an introspectable signature in newer CPython. Old
376+
# versions reject it as non-introspectable; new versions reject its
377+
# positional-only parameter. Both paths must stay ToolDerivationError.
378+
with pytest.raises(ToolDerivationError, match=r"not introspectable|positional-only"):
370379
tool(map)
371380

372381

‎tests/test_vet_shim.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ALL_OPS = [
2626
"build_request",
2727
"capabilities",
28+
"explain_auth",
2829
"normalize_error",
2930
"parse_response",
3031
"replay_stream",

0 commit comments

Comments
 (0)