Skip to content

Commit 08f9f38

Browse files
authored
Reapply "Make oz runs publicly viewable (#276)" (#293) (#307)
This reverts commit f2caf2e.
1 parent 8e4bc4a commit 08f9f38

2 files changed

Lines changed: 144 additions & 1 deletion

File tree

.github/scripts/oz_workflows/oz_client.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import time
44
from pathlib import Path
5-
from typing import Callable, cast
5+
from typing import Any, Callable, cast
66

77
from oz_agent_sdk import OzAPI
88
from oz_agent_sdk.types import AgentRunParams, AmbientAgentConfigParam, McpServerConfigParam
@@ -14,6 +14,19 @@
1414

1515
TERMINAL_STATES = {"SUCCEEDED", "FAILED", "ERROR", "CANCELLED"}
1616

17+
# Default public-access level for the run's shared session.
18+
#
19+
# The oz-for-oss workflows are intended for OSS repositories where community
20+
# members should be able to view agent activity through the session link
21+
# without being invited to the run's team. We therefore opt every run into
22+
# anyone-with-link viewer access by default. Callers that want to opt out or
23+
# pick a different level can override this via the
24+
# WARP_SESSION_SHARING_PUBLIC_ACCESS environment variable; set it to "NONE" or
25+
# "OFF" to disable public sharing for a run.
26+
DEFAULT_SESSION_SHARING_PUBLIC_ACCESS = "VIEWER"
27+
_SESSION_SHARING_DISABLED_VALUES = {"NONE", "OFF", "DISABLED", "FALSE", "0"}
28+
_SESSION_SHARING_SUPPORTED_LEVELS = {"VIEWER", "EDITOR"}
29+
1730

1831
def oz_api_base_url() -> str:
1932
"""Return the configured Oz API base URL.
@@ -37,6 +50,31 @@ def build_oz_client() -> OzAPI:
3750
)
3851

3952

53+
def _resolve_session_sharing_public_access() -> str | None:
54+
"""Resolve the configured public-access level for session sharing.
55+
56+
Returns the level string (``"VIEWER"`` or ``"EDITOR"``) when public session
57+
sharing should be enabled for the run, or ``None`` when the caller has
58+
explicitly disabled public sharing.
59+
"""
60+
raw = optional_env("WARP_SESSION_SHARING_PUBLIC_ACCESS")
61+
if raw == "":
62+
return DEFAULT_SESSION_SHARING_PUBLIC_ACCESS
63+
normalized = raw.upper()
64+
if normalized in _SESSION_SHARING_DISABLED_VALUES:
65+
return None
66+
if normalized not in _SESSION_SHARING_SUPPORTED_LEVELS:
67+
warning(
68+
"WARP_SESSION_SHARING_PUBLIC_ACCESS="
69+
f"{raw!r} is not a supported value; expected one of "
70+
f"{sorted(_SESSION_SHARING_SUPPORTED_LEVELS)} or a disable value "
71+
f"({sorted(_SESSION_SHARING_DISABLED_VALUES - {''})}). "
72+
"Disabling public session sharing for this run."
73+
)
74+
return None
75+
return normalized
76+
77+
4078
def build_agent_config(
4179
*,
4280
config_name: str,
@@ -66,6 +104,19 @@ def build_agent_config(
66104
warning(
67105
"WARP_AGENT_PROFILE is set, but the Oz Python SDK does not expose CLI profile support. Ignoring it."
68106
)
107+
108+
# Opt runs into anyone-with-link viewer access so community members can
109+
# follow along via the session link. This relies on the server-side
110+
# `session_sharing.public_access` field added in APP-3762; the field is
111+
# typed once the Oz SDK is regenerated from the updated OpenAPI spec. In
112+
# the meantime the request body is serialized from this TypedDict
113+
# (total=False) so the extra key passes through at runtime.
114+
public_access = _resolve_session_sharing_public_access()
115+
if public_access is not None:
116+
cast(dict[str, Any], config)["session_sharing"] = {
117+
"public_access": public_access,
118+
}
119+
69120
return config
70121

71122

.github/scripts/tests/test_oz_client.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,98 @@ def test_requires_warp_environment_id(self) -> None:
228228
workspace=Path("/tmp"),
229229
)
230230

231+
@patch.dict(os.environ, {"WARP_ENVIRONMENT_ID": "default-env"}, clear=True)
232+
def test_defaults_session_sharing_to_viewer(self) -> None:
233+
config = build_agent_config(
234+
config_name="review-pull-request",
235+
workspace=Path("/tmp"),
236+
)
237+
self.assertEqual(
238+
dict(config).get("session_sharing"),
239+
{"public_access": "VIEWER"},
240+
)
241+
242+
@patch.dict(
243+
os.environ,
244+
{
245+
"WARP_ENVIRONMENT_ID": "default-env",
246+
"WARP_SESSION_SHARING_PUBLIC_ACCESS": "EDITOR",
247+
},
248+
clear=True,
249+
)
250+
def test_session_sharing_can_be_set_to_editor(self) -> None:
251+
config = build_agent_config(
252+
config_name="review-pull-request",
253+
workspace=Path("/tmp"),
254+
)
255+
self.assertEqual(
256+
dict(config).get("session_sharing"),
257+
{"public_access": "EDITOR"},
258+
)
259+
260+
@patch.dict(
261+
os.environ,
262+
{
263+
"WARP_ENVIRONMENT_ID": "default-env",
264+
"WARP_SESSION_SHARING_PUBLIC_ACCESS": "viewer",
265+
},
266+
clear=True,
267+
)
268+
def test_session_sharing_is_case_insensitive(self) -> None:
269+
config = build_agent_config(
270+
config_name="review-pull-request",
271+
workspace=Path("/tmp"),
272+
)
273+
self.assertEqual(
274+
dict(config).get("session_sharing"),
275+
{"public_access": "VIEWER"},
276+
)
277+
278+
@patch.dict(
279+
os.environ,
280+
{
281+
"WARP_ENVIRONMENT_ID": "default-env",
282+
"WARP_SESSION_SHARING_PUBLIC_ACCESS": "none",
283+
},
284+
clear=True,
285+
)
286+
def test_session_sharing_can_be_disabled(self) -> None:
287+
config = build_agent_config(
288+
config_name="review-pull-request",
289+
workspace=Path("/tmp"),
290+
)
291+
self.assertNotIn("session_sharing", dict(config))
292+
293+
@patch.dict(
294+
os.environ,
295+
{
296+
"WARP_ENVIRONMENT_ID": "default-env",
297+
"WARP_SESSION_SHARING_PUBLIC_ACCESS": "off",
298+
},
299+
clear=True,
300+
)
301+
def test_session_sharing_off_also_disables(self) -> None:
302+
config = build_agent_config(
303+
config_name="review-pull-request",
304+
workspace=Path("/tmp"),
305+
)
306+
self.assertNotIn("session_sharing", dict(config))
307+
308+
@patch.dict(
309+
os.environ,
310+
{
311+
"WARP_ENVIRONMENT_ID": "default-env",
312+
"WARP_SESSION_SHARING_PUBLIC_ACCESS": "bogus",
313+
},
314+
clear=True,
315+
)
316+
def test_unknown_session_sharing_value_disables_sharing(self) -> None:
317+
config = build_agent_config(
318+
config_name="review-pull-request",
319+
workspace=Path("/tmp"),
320+
)
321+
self.assertNotIn("session_sharing", dict(config))
322+
231323

232324
if __name__ == "__main__":
233325
unittest.main()

0 commit comments

Comments
 (0)