MCPcopy Index your code
hub / github.com/coder/coder / TestPlanTurnPromptContract

Function TestPlanTurnPromptContract

coderd/x/chatd/chatd_test.go:2002–2073  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2000}
2001
2002func TestPlanTurnPromptContract(t *testing.T) {
2003 t.Parallel()
2004
2005 ctx := testutil.Context(t, testutil.WaitLong)
2006 db, ps := dbtestutil.NewDB(t)
2007
2008 var (
2009 requests []recordedOpenAIRequest
2010 requestsMu sync.Mutex
2011 )
2012 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
2013 if !req.Stream {
2014 return chattest.OpenAINonStreamingResponse("title")
2015 }
2016
2017 requestsMu.Lock()
2018 requests = append(requests, recordOpenAIRequest(req))
2019 requestsMu.Unlock()
2020
2021 return chattest.OpenAIStreamingResponse(
2022 chattest.OpenAITextChunks("plan acknowledged")...,
2023 )
2024 })
2025
2026 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
2027 planModeInstructions := "Ask about deployment sequencing before finalizing the plan."
2028 err := db.UpsertChatPlanModeInstructions(dbauthz.AsSystemRestricted(ctx), planModeInstructions)
2029 require.NoError(t, err)
2030 ws, dbAgent := seedWorkspaceWithAgent(t, db, user.ID)
2031 server := newWorkspaceToolTestServer(t, db, ps, dbAgent.ID, "# Plan\n")
2032
2033 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
2034 OwnerID: user.ID,
2035 OrganizationID: org.ID,
2036 Title: "plan-turn-prompt-contract",
2037 ModelConfigID: model.ID,
2038 PlanMode: database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true},
2039 WorkspaceID: uuid.NullUUID{UUID: ws.ID, Valid: true},
2040 InitialUserContent: []codersdk.ChatMessagePart{
2041 codersdk.ChatMessageText("Plan the rollout."),
2042 },
2043 })
2044 require.NoError(t, err)
2045
2046 waitForChatProcessed(ctx, t, db, chat.ID, server)
2047
2048 requestsMu.Lock()
2049 recorded := append([]recordedOpenAIRequest(nil), requests...)
2050 requestsMu.Unlock()
2051
2052 require.Len(t, recorded, 1, "expected exactly 1 streamed model call")
2053 require.True(t, requestHasSystemSubstring(recorded[0], "You are in Plan Mode."))
2054 require.True(t, requestHasSystemSubstring(recorded[0], "The only intentional authored workspace artifact is the plan file"))
2055 require.True(t, requestHasSystemSubstring(recorded[0], "You may use execute and process_output for exploration"))
2056 require.True(t, requestHasSystemSubstring(recorded[0], "approved external MCP tools when available"))
2057 require.True(t, requestHasSystemSubstring(recorded[0], "Workspace MCP tools are not available in root plan mode"))
2058 require.True(t, requestHasSystemSubstring(recorded[0], "After a successful propose_plan call, stop immediately"))
2059 require.True(t, requestHasSystemSubstring(recorded[0], planModeInstructions))

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewDBFunction · 0.92
NewOpenAIFunction · 0.92
OpenAIStreamingResponseFunction · 0.92
OpenAITextChunksFunction · 0.92
AsSystemRestrictedFunction · 0.92
ChatMessageTextFunction · 0.92
PlanningOverlayPromptFunction · 0.92
recordOpenAIRequestFunction · 0.85
seedWorkspaceWithAgentFunction · 0.85

Tested by

no test coverage detected