Repository navigation
Expand file tree
/
Copy pathchildUserPrompts.test.ts
More file actions
123 lines (115 loc) · 4.48 KB
/
Copy pathchildUserPrompts.test.ts
File metadata and controls
123 lines (115 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { describe, expect, it } from "vitest";
import { childUserPrompts } from "./e2e/harness/childUserPrompts.js";
const context = "start hook context\n\nRead the requested file.";
describe("subagent request observation", () => {
it.each([
["/chat/completions", { messages: [{ role: "user", content: context }] }],
["/messages", { messages: [{ role: "user", content: [{ type: "text", text: context }] }] }],
["/responses", { input: context }],
[
"/responses",
{
input: [
{
type: "message",
role: "user",
content: [{ type: "input_text", text: context }],
},
],
},
],
])("observes the child's user input on %s", (endpoint, body) => {
expect(
childUserPrompts(`http://localhost${endpoint}`, JSON.stringify(body), {
parentAgentId: "parent",
})
).toEqual([context]);
});
it.each(["/chat/completions", "/messages", "/responses"])(
"does not mistake a parent request for child context on %s",
(endpoint) => {
expect(
childUserPrompts(
`http://localhost${endpoint}`,
JSON.stringify({
messages: [{ role: "user", content: context }],
input: [{ type: "message", role: "user", content: context }],
}),
{}
)
).toEqual([]);
}
);
it.each(["/chat/completions", "/messages", "/responses"])(
"does not find hook context in system, developer, assistant, or tool content on %s",
(endpoint) => {
const messages = ["system", "developer", "assistant", "tool"].map((role) => ({
role,
content: context,
}));
expect(
childUserPrompts(
`http://localhost${endpoint}`,
JSON.stringify({
instructions: context,
system: context,
messages,
input: [
...messages
.filter((message) => message.role !== "tool")
.map((message) => ({ type: "message", ...message })),
{ type: "function_call_output", call_id: "tool", output: context },
],
}),
{ parentAgentId: "parent" }
)
).toEqual([]);
}
);
it.each([
{ kind: "string", content: context },
{ kind: "blocks", content: [{ type: "input_text", text: context }] },
])("ignores Responses developer-only $kind input", ({ content }) => {
expect(
childUserPrompts(
"http://localhost/responses",
JSON.stringify({
input: [{ type: "message", role: "developer", content }],
}),
{ parentAgentId: "parent" }
)
).toEqual([]);
});
it("extracts only the original user input from mixed Responses roles", () => {
const userPrompt = "Read the requested file.";
expect(
childUserPrompts(
"http://localhost/responses",
JSON.stringify({
input: [
{ type: "message", role: "developer", content: context },
{
type: "message",
role: "user",
content: [{ type: "input_text", text: userPrompt }],
},
],
}),
{ parentAgentId: "parent" }
)
).toEqual([userPrompt]);
});
it.each(["/chat/completions", "/messages", "/responses"])(
"keeps missing child context missing on %s",
(endpoint) => {
expect(
childUserPrompts(`http://localhost${endpoint}`, "{}", {
parentAgentId: "parent",
})
).toEqual([]);
}
);
});