|
| 1 | +import { describeEval, toolCalls } from "vitest-evals"; |
| 2 | +import { expect } from "vitest"; |
| 3 | +import { mention, rubric, slackEvals } from "../../src/helpers"; |
| 4 | +import { |
| 5 | + eventTaskCreateCalls, |
| 6 | + eventTaskManagementCalls, |
| 7 | + seedEventTask, |
| 8 | +} from "./helpers"; |
| 9 | + |
| 10 | +describeEval("Event Task Credentials", slackEvals, (it) => { |
| 11 | + it("when event work may need user-bound authorization, use the creator default", async ({ |
| 12 | + run, |
| 13 | + }) => { |
| 14 | + const result = await run({ |
| 15 | + overrides: { |
| 16 | + github_resource_events: true, |
| 17 | + plugin_dirs: ["fixtures/resource-event-plugins"], |
| 18 | + plugin_packages: ["@sentry/junior-github"], |
| 19 | + }, |
| 20 | + initialEvents: [ |
| 21 | + mention( |
| 22 | + "$eval-resource-events Create a pull request titled 'Credentialed review handling'. When review changes are requested, create an event task that inspects the feedback and posts a fix plan in this channel.", |
| 23 | + ), |
| 24 | + ], |
| 25 | + criteria: rubric({ |
| 26 | + pass: [ |
| 27 | + "The event task is created without asking for separate confirmation to use credentials needed for the requested work.", |
| 28 | + "The reply may accurately say the event task can use the creator's connected GitHub access; credential access alone does not mean the task executes as the user.", |
| 29 | + ], |
| 30 | + fail: [ |
| 31 | + "Do not require the user to separately authorize routine connected credential use.", |
| 32 | + "Do not explicitly claim the event task's actor is the user instead of Junior.", |
| 33 | + ], |
| 34 | + }), |
| 35 | + }); |
| 36 | + |
| 37 | + const createCalls = eventTaskCreateCalls(result.session); |
| 38 | + expect(createCalls).toHaveLength(1); |
| 39 | + expect(createCalls[0]!.arguments).toMatchObject({ |
| 40 | + trigger: { |
| 41 | + events: ["pull_request.review.changes_requested"], |
| 42 | + namespace: "github", |
| 43 | + identifier: "getsentry/junior#208", |
| 44 | + }, |
| 45 | + }); |
| 46 | + expect([undefined, "creator"]).toContain( |
| 47 | + createCalls[0]!.arguments?.credentialMode, |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("when another channel member requests creator credentials, explain who can enable them", async ({ |
| 52 | + run, |
| 53 | + }) => { |
| 54 | + const thread = { |
| 55 | + channel_type: "channel" as const, |
| 56 | + channel_id: "CEVENTAUTH", |
| 57 | + id: "thread-event-task-credential-other-user", |
| 58 | + thread_ts: "1700000000.921000", |
| 59 | + }; |
| 60 | + await seedEventTask({ |
| 61 | + createdBy: { |
| 62 | + slackUserId: "UALICE", |
| 63 | + userName: "alice", |
| 64 | + fullName: "Alice Example", |
| 65 | + }, |
| 66 | + credentialMode: "system", |
| 67 | + id: "evt_alice_system_credentials", |
| 68 | + taskText: "Post a GitHub issue digest in this channel.", |
| 69 | + thread, |
| 70 | + }); |
| 71 | + |
| 72 | + const result = await run({ |
| 73 | + overrides: { |
| 74 | + github_resource_events: true, |
| 75 | + plugin_packages: ["@sentry/junior-github"], |
| 76 | + }, |
| 77 | + initialEvents: [ |
| 78 | + mention( |
| 79 | + "Update that event task to use my connected credentials instead.", |
| 80 | + { |
| 81 | + thread, |
| 82 | + author: { |
| 83 | + user_id: "UBOBBB", |
| 84 | + user_name: "bob", |
| 85 | + full_name: "Bob Example", |
| 86 | + }, |
| 87 | + }, |
| 88 | + ), |
| 89 | + ], |
| 90 | + criteria: rubric({ |
| 91 | + pass: [ |
| 92 | + "The reply does not enable credentials and explains that Alice, the task creator, is the person who can enable creator credential use.", |
| 93 | + ], |
| 94 | + fail: [ |
| 95 | + "Do not attempt to enable creator credentials for Bob.", |
| 96 | + "Do not replace Alice's task with a new event task.", |
| 97 | + ], |
| 98 | + }), |
| 99 | + }); |
| 100 | + |
| 101 | + expect(eventTaskCreateCalls(result.session)).toEqual([]); |
| 102 | + expect( |
| 103 | + toolCalls(result.session).filter( |
| 104 | + (call) => |
| 105 | + call.name === "updateEventTask" && |
| 106 | + call.arguments?.credentialMode === "creator", |
| 107 | + ), |
| 108 | + ).toEqual([]); |
| 109 | + expect(eventTaskManagementCalls(result.session, "listEventTasks")).toEqual([ |
| 110 | + expect.objectContaining({ |
| 111 | + result: expect.objectContaining({ |
| 112 | + tasks: [ |
| 113 | + expect.objectContaining({ |
| 114 | + createdBy: expect.objectContaining({ |
| 115 | + slackUserId: "UALICE", |
| 116 | + }), |
| 117 | + id: "evt_alice_system_credentials", |
| 118 | + }), |
| 119 | + ], |
| 120 | + }), |
| 121 | + }), |
| 122 | + ]); |
| 123 | + }); |
| 124 | + |
| 125 | + it("when the creator requests credential use, enable creator mode", async ({ |
| 126 | + run, |
| 127 | + }) => { |
| 128 | + const author = { |
| 129 | + user_id: "UALICE", |
| 130 | + user_name: "alice", |
| 131 | + full_name: "Alice Example", |
| 132 | + }; |
| 133 | + const thread = { |
| 134 | + channel_type: "channel" as const, |
| 135 | + channel_id: "CEVENTAUTH", |
| 136 | + id: "thread-event-task-credential-creator", |
| 137 | + thread_ts: "1700000000.922000", |
| 138 | + }; |
| 139 | + await seedEventTask({ |
| 140 | + createdBy: { |
| 141 | + slackUserId: author.user_id, |
| 142 | + userName: author.user_name, |
| 143 | + fullName: author.full_name, |
| 144 | + }, |
| 145 | + credentialMode: "system", |
| 146 | + id: "evt_creator_system_credentials", |
| 147 | + taskText: "Post a GitHub issue digest in this channel.", |
| 148 | + thread, |
| 149 | + }); |
| 150 | + |
| 151 | + const result = await run({ |
| 152 | + overrides: { |
| 153 | + github_resource_events: true, |
| 154 | + plugin_packages: ["@sentry/junior-github"], |
| 155 | + }, |
| 156 | + initialEvents: [ |
| 157 | + mention("Enable my connected credentials for that event task now.", { |
| 158 | + thread, |
| 159 | + author, |
| 160 | + }), |
| 161 | + ], |
| 162 | + criteria: rubric({ |
| 163 | + pass: [ |
| 164 | + "The reply confirms that the creator's connected credentials are now available to the event task when needed.", |
| 165 | + ], |
| 166 | + fail: ["Do not create a replacement event task."], |
| 167 | + }), |
| 168 | + }); |
| 169 | + |
| 170 | + expect(eventTaskCreateCalls(result.session)).toEqual([]); |
| 171 | + expect(eventTaskManagementCalls(result.session, "listEventTasks")).toEqual([ |
| 172 | + expect.objectContaining({ |
| 173 | + result: expect.objectContaining({ |
| 174 | + tasks: [ |
| 175 | + expect.objectContaining({ |
| 176 | + createdBy: expect.objectContaining({ |
| 177 | + slackUserId: "UALICE", |
| 178 | + }), |
| 179 | + id: "evt_creator_system_credentials", |
| 180 | + }), |
| 181 | + ], |
| 182 | + }), |
| 183 | + }), |
| 184 | + ]); |
| 185 | + expect( |
| 186 | + eventTaskManagementCalls(result.session, "updateEventTask").filter( |
| 187 | + (call) => call.arguments?.credentialMode === "creator", |
| 188 | + ), |
| 189 | + ).toHaveLength(1); |
| 190 | + }); |
| 191 | +}); |
0 commit comments