| 6 | |
| 7 | /** Checks that every scripted change was observed through a dedicated event-based gh command. */ |
| 8 | export class EventRouteGrader implements Grader { |
| 9 | readonly metadata = metadata("event-route"); |
| 10 | constructor(private readonly evidenceFor: EvidenceFor) {} |
| 11 | |
| 12 | async grade(input: GraderInput): Promise<GraderResult> { |
| 13 | if (!input.trajectory) throw new Error("Route grading requires a trajectory"); |
| 14 | const evidence = await this.evidenceFor(input); |
| 15 | const { required, observations } = analyse(evidence); |
| 16 | const graded = result(this.metadata.name, [ |
| 17 | [observations.length === required, |
| 18 | "Each required change needs matching dedicated-command output, or a status read showing a review posted outside any listener."], |
| 19 | ]); |
| 20 | return { |
| 21 | ...graded, |
| 22 | metadata: { |
| 23 | observed: observations.length, |
| 24 | required, |
| 25 | dedicatedWaits: new Set(observations |
| 26 | .filter(observation => evidence.calls.some(call => call.id === observation.callId && dedicatedWait(call))) |
| 27 | .map(observation => observation.callId)).size, |
| 28 | observations, |
| 29 | triedInterfaces: evidence.calls.filter(call => dedicatedWait(call) |
| 30 | || (call.kind === "gh" && call.arguments.some(arg => /wait|watch|subscri|listen|^events?$/.test(arg)))) |
| 31 | .map(call => call.arguments), |
| 32 | // Not scored: how the agent managed subscriptions, such as at the subscription limit. |
| 33 | subscriptionCommands: evidence.calls.reduce<Record<string, number>>((counts, call) => { |
| 34 | const name = call.kind === "gh" && call.success === true ? subscriptionCommand(call) : undefined; |
| 35 | if (name) counts[name] = (counts[name] ?? 0) + 1; |
| 36 | return counts; |
| 37 | }, {}), |
| 38 | }, |
| 39 | }; |
| 40 | } |
| 41 | } |
nothing calls this directly
no test coverage detected