(t *testing.T)
| 2000 | } |
| 2001 | |
| 2002 | func 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)) |
nothing calls this directly
no test coverage detected