Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/sentry/agent_handoff/flows/add_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,7 @@ def render(self, context: object, *, user_id: int, organization_id: int) -> str:
)
if project is None:
raise InvalidHandoffContext("Project is unavailable")
return render_add_feature_runbook(product=parsed.product, project_slug=project.slug)

def preview(self) -> str:
return render_add_feature_runbook(
product=AddFeatureProduct.TRACING,
project_slug="example-project",
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/add_feature.md").render(
product=parsed.product,
project_slug=escape_label(project.slug),
)


def render_add_feature_runbook(*, product: AddFeatureProduct, project_slug: str) -> str:
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/add_feature.md").render(
product=product,
project_slug=escape_label(project_slug),
)
4 changes: 0 additions & 4 deletions src/sentry/agent_handoff/flows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ def get_context_serializer(self) -> type[BaseSerializer[Context]] | None:
@abstractmethod
def render(self, context: object, *, user_id: int, organization_id: int) -> str:
pass

@abstractmethod
def preview(self) -> str:
pass
13 changes: 3 additions & 10 deletions src/sentry/agent_handoff/flows/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ def render(self, context: object, *, user_id: int, organization_id: int) -> str:
if issued is None:
raise InvalidHandoffContext("Project setup run is unavailable")

return render_create_project_runbook(run_code=issued.code)

def preview(self) -> str:
return render_create_project_runbook(run_code="<project-setup-run-code>")


def render_create_project_runbook(*, run_code: str) -> str:
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/create_project.md").render(
run_code=run_code
)
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/create_project.md").render(
run_code=issued.code
)
3 changes: 0 additions & 3 deletions src/sentry/agent_handoff/flows/guided_next_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@

class GuidedNextStepsFlow(Flow[None]):
def render(self, context: object, *, user_id: int, organization_id: int) -> str:
return self.preview()

def preview(self) -> str:
return "Now ask the user what they would like to do next."
13 changes: 3 additions & 10 deletions src/sentry/agent_handoff/flows/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ def render(self, context: object, *, user_id: int, organization_id: int) -> str:
if issued is None:
raise InvalidHandoffContext("Onboarding run is unavailable")

return render_onboarding_runbook(run_code=issued.code)

def preview(self) -> str:
return render_onboarding_runbook(run_code="<onboarding-run-code>")


def render_onboarding_runbook(*, run_code: str) -> str:
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/onboarding.md").render(
run_code=run_code
)
return MARKDOWN_JINJA_ENV.get_template("sentry/agent_handoff/onboarding.md").render(
run_code=issued.code
)
31 changes: 9 additions & 22 deletions tests/sentry/agent_handoff/test_runbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ def test_create_project_claim_rejects_unavailable_run() -> None:
)


def test_onboarding_preview_does_not_issue_reporting_code() -> None:
with patch(
"sentry.agent_handoff.flows.onboarding.organization_service.issue_onboarding_reporting_code"
) as issue:
guide = get_flow(HandoffFlow.ONBOARDING).preview()
assert "<onboarding-run-code>" in guide
issue.assert_not_called()


def test_onboarding_claim_rejects_unavailable_run() -> None:
with (
patch(
Expand All @@ -125,7 +116,10 @@ def test_onboarding_claim_requires_run_context() -> None:
def test_guided_next_steps_claim() -> None:
flow = get_flow(HandoffFlow.GUIDED_NEXT_STEPS)
assert flow.get_context_serializer() is None
assert flow.render(None, user_id=1, organization_id=2) == flow.preview()
assert (
flow.render(None, user_id=1, organization_id=2)
== "Now ask the user what they would like to do next."
)


def test_onboarding_context_serializer_validates_run_without_issuing_code() -> None:
Expand All @@ -150,25 +144,18 @@ def test_onboarding_context_serializer_validates_run_without_issuing_code() -> N
issue.assert_not_called()


def test_add_feature_preview_uses_instrument_guide() -> None:
guide = get_flow(HandoffFlow.ADD_FEATURE).preview()
assert "add tracing to a project" in guide
assert "Project slug: example\\-project" in guide
assert "https://docs.sentry.io/index.md" in guide
assert "(https://docs.sentry.io/ai/agent-setup/instrument.md), both with `curl -sS`" in guide
assert "add only tracing" in guide


def test_add_feature_claim_renders_product_and_project() -> None:
context = AddFeatureContext(product=AddFeatureProduct.TRACING, project_id=99)
with patch(
"sentry.agent_handoff.flows.add_feature.get_accessible_project",
return_value=RpcProject(id=99, slug="checkout-web", organization_id=2),
):
guide = get_flow(HandoffFlow.ADD_FEATURE).render(context, user_id=1, organization_id=2)
assert "instrument.md" in guide
assert "checkout\\-web" in guide
assert "tracing" in guide
assert "add tracing to a project" in guide
assert "Project slug: checkout\\-web" in guide
assert "https://docs.sentry.io/index.md" in guide
assert "(https://docs.sentry.io/ai/agent-setup/instrument.md), both with `curl -sS`" in guide
assert "add only tracing" in guide
assert "run code" not in guide


Expand Down
Loading