@ai-devkit/agent-manager 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgentManager.d.ts +12 -0
- package/dist/AgentManager.d.ts.map +1 -1
- package/dist/AgentManager.js +20 -1
- package/dist/AgentManager.js.map +1 -1
- package/dist/__tests__/AgentManager.test.js +111 -0
- package/dist/__tests__/AgentManager.test.js.map +1 -1
- package/dist/__tests__/capacity/devin.test.js +239 -0
- package/dist/__tests__/capacity/devin.test.js.map +1 -0
- package/dist/__tests__/fixtures.test.js +218 -0
- package/dist/__tests__/fixtures.test.js.map +1 -0
- package/dist/__tests__/readiness-fixtures.test.js +54 -0
- package/dist/__tests__/readiness-fixtures.test.js.map +1 -0
- package/dist/capacity/index.d.ts +3 -0
- package/dist/capacity/index.d.ts.map +1 -1
- package/dist/capacity/index.js +8 -0
- package/dist/capacity/index.js.map +1 -1
- package/dist/capacity/providers/devin.d.ts +13 -0
- package/dist/capacity/providers/devin.d.ts.map +1 -0
- package/dist/capacity/providers/devin.js +92 -0
- package/dist/capacity/providers/devin.js.map +1 -0
- package/dist/capacity/sources/devin.d.ts +12 -0
- package/dist/capacity/sources/devin.d.ts.map +1 -0
- package/dist/capacity/sources/devin.js +29 -0
- package/dist/capacity/sources/devin.js.map +1 -0
- package/dist/fixtures/bundle.d.ts +67 -0
- package/dist/fixtures/bundle.d.ts.map +1 -0
- package/dist/fixtures/bundle.js +86 -0
- package/dist/fixtures/bundle.js.map +1 -0
- package/dist/fixtures/capture.d.ts +11 -0
- package/dist/fixtures/capture.d.ts.map +1 -0
- package/dist/fixtures/capture.js +317 -0
- package/dist/fixtures/capture.js.map +1 -0
- package/dist/harnesses/devin/credentials.d.ts +10 -0
- package/dist/harnesses/devin/credentials.d.ts.map +1 -0
- package/dist/harnesses/devin/credentials.js +66 -0
- package/dist/harnesses/devin/credentials.js.map +1 -0
- package/dist/harnesses/shared.d.ts.map +1 -1
- package/dist/harnesses/shared.js +1 -1
- package/dist/harnesses/shared.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentManager.ts +37 -1
- package/src/__tests__/AgentManager.test.ts +84 -0
- package/src/__tests__/capacity/devin.test.ts +210 -0
- package/src/__tests__/capacity/fixtures/devin-config.json +6 -0
- package/src/__tests__/capacity/fixtures/devin-credentials.toml +4 -0
- package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +5 -0
- package/src/__tests__/capacity/fixtures/devin-quota.json +10 -0
- package/src/__tests__/fixtures.test.ts +247 -0
- package/src/__tests__/readiness-fixtures.test.ts +79 -0
- package/src/capacity/index.ts +12 -0
- package/src/capacity/providers/devin.ts +121 -0
- package/src/capacity/sources/devin.ts +49 -0
- package/src/fixtures/bundle.ts +130 -0
- package/src/fixtures/capture.ts +349 -0
- package/src/harnesses/devin/credentials.ts +88 -0
- package/src/harnesses/shared.ts +1 -1
- package/src/index.ts +1 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { parseDevinCapacity } from "../../capacity/providers/devin.js";
|
|
5
|
+
import { probeDevinCapacity } from "../../capacity/sources/devin.js";
|
|
6
|
+
import { resolveDevinCredential } from "../../harnesses/devin/credentials.js";
|
|
7
|
+
const checkedAt = "2026-10-05T10:00:00.000Z";
|
|
8
|
+
const fixture = (name)=>readFile(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), "utf8");
|
|
9
|
+
const credentialFiles = async (path)=>{
|
|
10
|
+
if (path === "/users/test/.local/share/devin/credentials.toml") {
|
|
11
|
+
return fixture("devin-credentials.toml");
|
|
12
|
+
}
|
|
13
|
+
if (path === "/users/test/.config/devin/config.json") {
|
|
14
|
+
return fixture("devin-config.json");
|
|
15
|
+
}
|
|
16
|
+
throw Object.assign(new Error("missing"), {
|
|
17
|
+
code: "ENOENT"
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
describe("devin credential resolution", ()=>{
|
|
21
|
+
it("prefers DEVIN_API_KEY and DEVIN_ORG_ID without reading files", async ()=>{
|
|
22
|
+
const reader = vi.fn(credentialFiles);
|
|
23
|
+
await expect(resolveDevinCredential({
|
|
24
|
+
env: {
|
|
25
|
+
DEVIN_API_KEY: "env-key",
|
|
26
|
+
DEVIN_ORG_ID: "org-env"
|
|
27
|
+
},
|
|
28
|
+
readFile: reader
|
|
29
|
+
})).resolves.toEqual({
|
|
30
|
+
key: "env-key",
|
|
31
|
+
orgId: "org-env"
|
|
32
|
+
});
|
|
33
|
+
expect(reader).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
it("reads the key from credentials.toml and org from config.json", async ()=>{
|
|
36
|
+
const reader = vi.fn(credentialFiles);
|
|
37
|
+
await expect(resolveDevinCredential({
|
|
38
|
+
env: {
|
|
39
|
+
HOME: "/users/test"
|
|
40
|
+
},
|
|
41
|
+
readFile: reader
|
|
42
|
+
})).resolves.toEqual({
|
|
43
|
+
key: "devin-test-key",
|
|
44
|
+
orgId: "org-test1234"
|
|
45
|
+
});
|
|
46
|
+
expect(reader).toHaveBeenCalledWith("/users/test/.local/share/devin/credentials.toml", "utf8");
|
|
47
|
+
expect(reader).toHaveBeenCalledWith("/users/test/.config/devin/config.json", "utf8");
|
|
48
|
+
});
|
|
49
|
+
it.each([
|
|
50
|
+
[
|
|
51
|
+
"missing credentials file",
|
|
52
|
+
async (path)=>{
|
|
53
|
+
if (path.endsWith("config.json")) return fixture("devin-config.json");
|
|
54
|
+
throw Object.assign(new Error("missing"), {
|
|
55
|
+
code: "ENOENT"
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
/Devin API key not found/
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
"malformed credentials file",
|
|
62
|
+
async (path)=>{
|
|
63
|
+
if (path.endsWith("credentials.toml")) return "not = [valid";
|
|
64
|
+
return fixture("devin-config.json");
|
|
65
|
+
},
|
|
66
|
+
/credentials file is malformed/
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
"credentials without key",
|
|
70
|
+
async (path)=>{
|
|
71
|
+
if (path.endsWith("credentials.toml")) return 'api_server_url = "https://x"';
|
|
72
|
+
return fixture("devin-config.json");
|
|
73
|
+
},
|
|
74
|
+
/Devin API key not found/
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
"missing config file",
|
|
78
|
+
async (path)=>{
|
|
79
|
+
if (path.endsWith("credentials.toml")) return fixture("devin-credentials.toml");
|
|
80
|
+
throw Object.assign(new Error("missing"), {
|
|
81
|
+
code: "ENOENT"
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
/Devin organization id not found/
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
"config without org_id",
|
|
88
|
+
async (path)=>{
|
|
89
|
+
if (path.endsWith("credentials.toml")) return fixture("devin-credentials.toml");
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
devin: {}
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
/Devin organization id not found/
|
|
95
|
+
]
|
|
96
|
+
])("fails clearly for %s without exposing file content", async (_name, readFileImpl, pattern)=>{
|
|
97
|
+
await expect(resolveDevinCredential({
|
|
98
|
+
env: {
|
|
99
|
+
HOME: "/users/test"
|
|
100
|
+
},
|
|
101
|
+
readFile: readFileImpl
|
|
102
|
+
})).rejects.toThrow(pattern);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("devin quota mapping", ()=>{
|
|
106
|
+
it("maps daily and weekly windows with credits", async ()=>{
|
|
107
|
+
const report = parseDevinCapacity(JSON.parse(await fixture("devin-quota.json")));
|
|
108
|
+
expect(report).toMatchObject({
|
|
109
|
+
authenticated: true,
|
|
110
|
+
available: "yes",
|
|
111
|
+
creditsRemaining: 12.5
|
|
112
|
+
});
|
|
113
|
+
expect(report.windows).toEqual([
|
|
114
|
+
{
|
|
115
|
+
id: "devin:daily",
|
|
116
|
+
label: "Daily",
|
|
117
|
+
durationMinutes: 1440,
|
|
118
|
+
usedPercent: 25,
|
|
119
|
+
resetsAt: "2026-10-06T08:00:00.000Z"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "devin:weekly",
|
|
123
|
+
label: "Weekly",
|
|
124
|
+
durationMinutes: 10080,
|
|
125
|
+
usedPercent: 60,
|
|
126
|
+
resetsAt: "2026-10-11T08:00:00.000Z"
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
});
|
|
130
|
+
it("omits the daily window when hide_daily_quota is true", ()=>{
|
|
131
|
+
const report = parseDevinCapacity({
|
|
132
|
+
is_quota_plan: true,
|
|
133
|
+
has_quota_allocation: true,
|
|
134
|
+
daily_percentage: 90,
|
|
135
|
+
weekly_percentage: 10,
|
|
136
|
+
hide_daily_quota: true
|
|
137
|
+
});
|
|
138
|
+
expect(report.windows.map((window)=>window.id)).toEqual([
|
|
139
|
+
"devin:weekly"
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
it("reports authenticated unknown availability for non-quota plans", async ()=>{
|
|
143
|
+
const report = parseDevinCapacity(JSON.parse(await fixture("devin-quota-nonplan.json")));
|
|
144
|
+
expect(report).toEqual({
|
|
145
|
+
authenticated: true,
|
|
146
|
+
available: "unknown",
|
|
147
|
+
windows: [],
|
|
148
|
+
creditsRemaining: null
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it("clamps percentages and degrades missing fields honestly", ()=>{
|
|
152
|
+
const report = parseDevinCapacity({
|
|
153
|
+
is_quota_plan: true,
|
|
154
|
+
has_quota_allocation: true,
|
|
155
|
+
daily_percentage: 140,
|
|
156
|
+
weekly_reset_at: "not-a-date",
|
|
157
|
+
overage_balance: "unknown"
|
|
158
|
+
});
|
|
159
|
+
const [daily, weekly] = report.windows;
|
|
160
|
+
expect(daily.usedPercent).toBe(100);
|
|
161
|
+
expect(weekly.usedPercent).toBeNull();
|
|
162
|
+
expect(weekly.resetsAt).toBeNull();
|
|
163
|
+
expect(report.creditsRemaining).toBeNull();
|
|
164
|
+
expect(report.available).toBe("no");
|
|
165
|
+
});
|
|
166
|
+
it("rejects non-object responses", ()=>{
|
|
167
|
+
expect(()=>parseDevinCapacity("nope")).toThrow(/Devin quota/);
|
|
168
|
+
expect(()=>parseDevinCapacity(null)).toThrow(/Devin quota/);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe("devin request", ()=>{
|
|
172
|
+
it("GETs the org quota endpoint with only Bearer authentication", async ()=>{
|
|
173
|
+
const body = await fixture("devin-quota.json");
|
|
174
|
+
const fetch = vi.fn(async ()=>new Response(body, {
|
|
175
|
+
status: 200
|
|
176
|
+
}));
|
|
177
|
+
const report = await probeDevinCapacity({
|
|
178
|
+
checkedAt,
|
|
179
|
+
env: {
|
|
180
|
+
DEVIN_API_KEY: "request-test-key",
|
|
181
|
+
DEVIN_ORG_ID: "org-abc"
|
|
182
|
+
},
|
|
183
|
+
fetch
|
|
184
|
+
});
|
|
185
|
+
expect(fetch).toHaveBeenCalledWith("https://app.devin.ai/api/org-abc/billing/quota/usage", expect.objectContaining({
|
|
186
|
+
method: "GET",
|
|
187
|
+
headers: {
|
|
188
|
+
Authorization: "Bearer request-test-key"
|
|
189
|
+
}
|
|
190
|
+
}));
|
|
191
|
+
expect(report.harness).toBe("devin");
|
|
192
|
+
expect(report.provider).toBe("devin");
|
|
193
|
+
expect(JSON.stringify(report)).not.toContain("request-test-key");
|
|
194
|
+
});
|
|
195
|
+
it.each([
|
|
196
|
+
401,
|
|
197
|
+
403
|
|
198
|
+
])("reports HTTP %i as unauthenticated", async (status)=>{
|
|
199
|
+
const report = await probeDevinCapacity({
|
|
200
|
+
checkedAt,
|
|
201
|
+
env: {
|
|
202
|
+
DEVIN_API_KEY: "request-test-key",
|
|
203
|
+
DEVIN_ORG_ID: "org-abc"
|
|
204
|
+
},
|
|
205
|
+
fetch: vi.fn(async ()=>new Response("denied", {
|
|
206
|
+
status
|
|
207
|
+
}))
|
|
208
|
+
});
|
|
209
|
+
expect(report).toMatchObject({
|
|
210
|
+
authenticated: false,
|
|
211
|
+
available: "unknown",
|
|
212
|
+
windows: []
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
it("rejects other non-200 and malformed JSON responses with sanitized errors", async ()=>{
|
|
216
|
+
await expect(probeDevinCapacity({
|
|
217
|
+
checkedAt,
|
|
218
|
+
env: {
|
|
219
|
+
DEVIN_API_KEY: "never-expose-this-key",
|
|
220
|
+
DEVIN_ORG_ID: "org-abc"
|
|
221
|
+
},
|
|
222
|
+
fetch: vi.fn(async ()=>new Response("private body", {
|
|
223
|
+
status: 503
|
|
224
|
+
}))
|
|
225
|
+
})).rejects.toThrow("Devin quota request failed: HTTP 503");
|
|
226
|
+
await expect(probeDevinCapacity({
|
|
227
|
+
checkedAt,
|
|
228
|
+
env: {
|
|
229
|
+
DEVIN_API_KEY: "never-expose-this-key",
|
|
230
|
+
DEVIN_ORG_ID: "org-abc"
|
|
231
|
+
},
|
|
232
|
+
fetch: vi.fn(async ()=>new Response("not-json", {
|
|
233
|
+
status: 200
|
|
234
|
+
}))
|
|
235
|
+
})).rejects.toThrow("Devin quota response is not valid JSON");
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=devin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/capacity/devin.test.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport { parseDevinCapacity } from \"../../capacity/providers/devin.js\";\nimport { probeDevinCapacity } from \"../../capacity/sources/devin.js\";\nimport { resolveDevinCredential } from \"../../harnesses/devin/credentials.js\";\n\nconst checkedAt = \"2026-10-05T10:00:00.000Z\";\nconst fixture = (name: string) =>\n readFile(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), \"utf8\");\n\nconst credentialFiles = async (path: string): Promise<string> => {\n if (path === \"/users/test/.local/share/devin/credentials.toml\") {\n return fixture(\"devin-credentials.toml\");\n }\n if (path === \"/users/test/.config/devin/config.json\") {\n return fixture(\"devin-config.json\");\n }\n throw Object.assign(new Error(\"missing\"), { code: \"ENOENT\" });\n};\n\ndescribe(\"devin credential resolution\", () => {\n it(\"prefers DEVIN_API_KEY and DEVIN_ORG_ID without reading files\", async () => {\n const reader = vi.fn(credentialFiles);\n await expect(\n resolveDevinCredential({\n env: { DEVIN_API_KEY: \"env-key\", DEVIN_ORG_ID: \"org-env\" },\n readFile: reader,\n }),\n ).resolves.toEqual({ key: \"env-key\", orgId: \"org-env\" });\n expect(reader).not.toHaveBeenCalled();\n });\n\n it(\"reads the key from credentials.toml and org from config.json\", async () => {\n const reader = vi.fn(credentialFiles);\n await expect(\n resolveDevinCredential({ env: { HOME: \"/users/test\" }, readFile: reader }),\n ).resolves.toEqual({ key: \"devin-test-key\", orgId: \"org-test1234\" });\n expect(reader).toHaveBeenCalledWith(\"/users/test/.local/share/devin/credentials.toml\", \"utf8\");\n expect(reader).toHaveBeenCalledWith(\"/users/test/.config/devin/config.json\", \"utf8\");\n });\n\n it.each([\n [\n \"missing credentials file\",\n async (path: string) => {\n if (path.endsWith(\"config.json\")) return fixture(\"devin-config.json\");\n throw Object.assign(new Error(\"missing\"), { code: \"ENOENT\" });\n },\n /Devin API key not found/,\n ],\n [\n \"malformed credentials file\",\n async (path: string) => {\n if (path.endsWith(\"credentials.toml\")) return \"not = [valid\";\n return fixture(\"devin-config.json\");\n },\n /credentials file is malformed/,\n ],\n [\n \"credentials without key\",\n async (path: string) => {\n if (path.endsWith(\"credentials.toml\")) return 'api_server_url = \"https://x\"';\n return fixture(\"devin-config.json\");\n },\n /Devin API key not found/,\n ],\n [\n \"missing config file\",\n async (path: string) => {\n if (path.endsWith(\"credentials.toml\")) return fixture(\"devin-credentials.toml\");\n throw Object.assign(new Error(\"missing\"), { code: \"ENOENT\" });\n },\n /Devin organization id not found/,\n ],\n [\n \"config without org_id\",\n async (path: string) => {\n if (path.endsWith(\"credentials.toml\")) return fixture(\"devin-credentials.toml\");\n return JSON.stringify({ devin: {} });\n },\n /Devin organization id not found/,\n ],\n ])(\"fails clearly for %s without exposing file content\", async (_name, readFileImpl, pattern) => {\n await expect(\n resolveDevinCredential({ env: { HOME: \"/users/test\" }, readFile: readFileImpl }),\n ).rejects.toThrow(pattern);\n });\n});\n\ndescribe(\"devin quota mapping\", () => {\n it(\"maps daily and weekly windows with credits\", async () => {\n const report = parseDevinCapacity(JSON.parse(await fixture(\"devin-quota.json\")));\n expect(report).toMatchObject({\n authenticated: true,\n available: \"yes\",\n creditsRemaining: 12.5,\n });\n expect(report.windows).toEqual([\n {\n id: \"devin:daily\",\n label: \"Daily\",\n durationMinutes: 1440,\n usedPercent: 25,\n resetsAt: \"2026-10-06T08:00:00.000Z\",\n },\n {\n id: \"devin:weekly\",\n label: \"Weekly\",\n durationMinutes: 10080,\n usedPercent: 60,\n resetsAt: \"2026-10-11T08:00:00.000Z\",\n },\n ]);\n });\n\n it(\"omits the daily window when hide_daily_quota is true\", () => {\n const report = parseDevinCapacity({\n is_quota_plan: true,\n has_quota_allocation: true,\n daily_percentage: 90,\n weekly_percentage: 10,\n hide_daily_quota: true,\n });\n expect(report.windows.map((window) => window.id)).toEqual([\"devin:weekly\"]);\n });\n\n it(\"reports authenticated unknown availability for non-quota plans\", async () => {\n const report = parseDevinCapacity(JSON.parse(await fixture(\"devin-quota-nonplan.json\")));\n expect(report).toEqual({\n authenticated: true,\n available: \"unknown\",\n windows: [],\n creditsRemaining: null,\n });\n });\n\n it(\"clamps percentages and degrades missing fields honestly\", () => {\n const report = parseDevinCapacity({\n is_quota_plan: true,\n has_quota_allocation: true,\n daily_percentage: 140,\n weekly_reset_at: \"not-a-date\",\n overage_balance: \"unknown\",\n });\n const [daily, weekly] = report.windows;\n expect(daily.usedPercent).toBe(100);\n expect(weekly.usedPercent).toBeNull();\n expect(weekly.resetsAt).toBeNull();\n expect(report.creditsRemaining).toBeNull();\n expect(report.available).toBe(\"no\");\n });\n\n it(\"rejects non-object responses\", () => {\n expect(() => parseDevinCapacity(\"nope\")).toThrow(/Devin quota/);\n expect(() => parseDevinCapacity(null)).toThrow(/Devin quota/);\n });\n});\n\ndescribe(\"devin request\", () => {\n it(\"GETs the org quota endpoint with only Bearer authentication\", async () => {\n const body = await fixture(\"devin-quota.json\");\n const fetch = vi.fn(async () => new Response(body, { status: 200 }));\n const report = await probeDevinCapacity({\n checkedAt,\n env: { DEVIN_API_KEY: \"request-test-key\", DEVIN_ORG_ID: \"org-abc\" },\n fetch,\n });\n expect(fetch).toHaveBeenCalledWith(\n \"https://app.devin.ai/api/org-abc/billing/quota/usage\",\n expect.objectContaining({\n method: \"GET\",\n headers: { Authorization: \"Bearer request-test-key\" },\n }),\n );\n expect(report.harness).toBe(\"devin\");\n expect(report.provider).toBe(\"devin\");\n expect(JSON.stringify(report)).not.toContain(\"request-test-key\");\n });\n\n it.each([401, 403])(\"reports HTTP %i as unauthenticated\", async (status) => {\n const report = await probeDevinCapacity({\n checkedAt,\n env: { DEVIN_API_KEY: \"request-test-key\", DEVIN_ORG_ID: \"org-abc\" },\n fetch: vi.fn(async () => new Response(\"denied\", { status })),\n });\n expect(report).toMatchObject({\n authenticated: false,\n available: \"unknown\",\n windows: [],\n });\n });\n\n it(\"rejects other non-200 and malformed JSON responses with sanitized errors\", async () => {\n await expect(\n probeDevinCapacity({\n checkedAt,\n env: { DEVIN_API_KEY: \"never-expose-this-key\", DEVIN_ORG_ID: \"org-abc\" },\n fetch: vi.fn(async () => new Response(\"private body\", { status: 503 })),\n }),\n ).rejects.toThrow(\"Devin quota request failed: HTTP 503\");\n await expect(\n probeDevinCapacity({\n checkedAt,\n env: { DEVIN_API_KEY: \"never-expose-this-key\", DEVIN_ORG_ID: \"org-abc\" },\n fetch: vi.fn(async () => new Response(\"not-json\", { status: 200 })),\n }),\n ).rejects.toThrow(\"Devin quota response is not valid JSON\");\n });\n});\n"],"names":["readFile","fileURLToPath","describe","expect","it","vi","parseDevinCapacity","probeDevinCapacity","resolveDevinCredential","checkedAt","fixture","name","URL","url","credentialFiles","path","Object","assign","Error","code","reader","fn","env","DEVIN_API_KEY","DEVIN_ORG_ID","resolves","toEqual","key","orgId","not","toHaveBeenCalled","HOME","toHaveBeenCalledWith","each","endsWith","JSON","stringify","devin","_name","readFileImpl","pattern","rejects","toThrow","report","parse","toMatchObject","authenticated","available","creditsRemaining","windows","id","label","durationMinutes","usedPercent","resetsAt","is_quota_plan","has_quota_allocation","daily_percentage","weekly_percentage","hide_daily_quota","map","window","weekly_reset_at","overage_balance","daily","weekly","toBe","toBeNull","body","fetch","Response","status","objectContaining","method","headers","Authorization","harness","provider","toContain"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,aAAa,QAAQ,WAAW;AACzC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAS;AAClD,SAASC,kBAAkB,QAAQ,oCAAoC;AACvE,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,sBAAsB,QAAQ,uCAAuC;AAE9E,MAAMC,YAAY;AAClB,MAAMC,UAAU,CAACC,OACfX,SAASC,cAAc,IAAIW,IAAI,CAAC,WAAW,EAAED,MAAM,EAAE,YAAYE,GAAG,IAAI;AAE1E,MAAMC,kBAAkB,OAAOC;IAC7B,IAAIA,SAAS,mDAAmD;QAC9D,OAAOL,QAAQ;IACjB;IACA,IAAIK,SAAS,yCAAyC;QACpD,OAAOL,QAAQ;IACjB;IACA,MAAMM,OAAOC,MAAM,CAAC,IAAIC,MAAM,YAAY;QAAEC,MAAM;IAAS;AAC7D;AAEAjB,SAAS,+BAA+B;IACtCE,GAAG,gEAAgE;QACjE,MA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C,UAAY,IAAIiD,SAAS,UAAU;oBAAEC;gBAAO;QAC3D;QACApE,OAAOwC,QAAQE,aAAa,CAAC;YAC3BC,eAAe;YACfC,WAAW;YACXE,SAAS,EAAE;QACb;IACF;IAEA7C,GAAG,4EAA4E;QAC7E,MAAMD,OACJI,mBAAmB;YACjBE;YACAa,KAAK;gBAAEC,eAAe;gBAAyBC,cAAc;YAAU;YACvE6C,OAAOhE,GAAGgB,EAAE,CAAC,UAAY,IAAIiD,SAAS,gBAAgB;oBAAEC,QAAQ;gBAAI;QACtE,IACA9B,OAAO,CAACC,OAAO,CAAC;QAClB,MAAMvC,OACJI,mBAAmB;YACjBE;YACAa,KAAK;gBAAEC,eAAe;gBAAyBC,cAAc;YAAU;YACvE6C,OAAOhE,GAAGgB,EAAE,CAAC,UAAY,IAAIiD,SAAS,YAAY;oBAAEC,QAAQ;gBAAI;QAClE,IACA9B,OAAO,CAACC,OAAO,CAAC;IACpB;AACF"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixture replay: materialize each committed bundle into a fake HOME,
|
|
3
|
+
* run the adapter's detectAgents with the recorded processes + frozen
|
|
4
|
+
* clock, and require byte-identical output to `expected`.
|
|
5
|
+
*
|
|
6
|
+
* The same bundles are consumed by devkit-harness Rust tests — this file is
|
|
7
|
+
* the TS↔TS side of the parity oracle.
|
|
8
|
+
*/ import { describe, it, expect, afterEach } from "vitest";
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import Database from "better-sqlite3";
|
|
13
|
+
import { createBuiltinAdapters } from "../harnesses/index.js";
|
|
14
|
+
import { CodexAdapter } from "../harnesses/codex/CodexAdapter.js";
|
|
15
|
+
import { PiAdapter } from "../harnesses/pi/PiAdapter.js";
|
|
16
|
+
import { GeminiCliAdapter } from "../harnesses/gemini/GeminiCliAdapter.js";
|
|
17
|
+
import { CopilotAdapter } from "../harnesses/copilot/CopilotAdapter.js";
|
|
18
|
+
import { AgentRegistry } from "../utils/AgentRegistry.js";
|
|
19
|
+
import { expand, expandNow, normalizeAgents, withFrozenClock } from "../fixtures/bundle.js";
|
|
20
|
+
import { captureLive, FIXTURES_ROOT } from "../fixtures/capture.js";
|
|
21
|
+
const bundlePaths = fs.existsSync(FIXTURES_ROOT) ? fs.readdirSync(FIXTURES_ROOT, {
|
|
22
|
+
withFileTypes: true
|
|
23
|
+
}).flatMap((d)=>d.isDirectory() ? fs.readdirSync(path.join(FIXTURES_ROOT, d.name)).filter((f)=>f.endsWith(".json")).map((f)=>path.join(FIXTURES_ROOT, d.name, f)) : []) : [];
|
|
24
|
+
/** Adapters whose detect path consults AgentRegistry. */ const REGISTRY_AWARE = new Set([
|
|
25
|
+
"codex",
|
|
26
|
+
"pi",
|
|
27
|
+
"gemini_cli",
|
|
28
|
+
"copilot"
|
|
29
|
+
]);
|
|
30
|
+
function adapterFor(type, registry) {
|
|
31
|
+
// Adapters that consult the registry during detection get the seeded
|
|
32
|
+
// isolated instance so replay never reads real ~/.ai-devkit state.
|
|
33
|
+
if (type === "codex" && registry) return new CodexAdapter(registry);
|
|
34
|
+
if (type === "pi" && registry) return new PiAdapter(registry);
|
|
35
|
+
if (type === "gemini_cli" && registry) return new GeminiCliAdapter(registry);
|
|
36
|
+
if (type === "copilot" && registry) return new CopilotAdapter(registry);
|
|
37
|
+
const adapter = createBuiltinAdapters().find((a)=>a.type === type);
|
|
38
|
+
if (!adapter) throw new Error(`no builtin adapter for "${type}"`);
|
|
39
|
+
return adapter;
|
|
40
|
+
}
|
|
41
|
+
/** Seed an isolated registry at `<home>/.ai-devkit/agents.json`. */ function seedRegistry(bundle, home, nowIso) {
|
|
42
|
+
if (!REGISTRY_AWARE.has(bundle.adapter)) return undefined;
|
|
43
|
+
const registry = new AgentRegistry(path.join(home, ".ai-devkit", "agents.json"));
|
|
44
|
+
const entries = (bundle.registry ?? []).map((e)=>({
|
|
45
|
+
name: "",
|
|
46
|
+
type: bundle.adapter,
|
|
47
|
+
runtime: "tmux",
|
|
48
|
+
runtimeRef: null,
|
|
49
|
+
cwd: "",
|
|
50
|
+
startedAt: nowIso,
|
|
51
|
+
sessionId: "",
|
|
52
|
+
sessionFilePath: "",
|
|
53
|
+
pinned: false,
|
|
54
|
+
...expand(expandNow(e, nowIso), home)
|
|
55
|
+
}));
|
|
56
|
+
registry.registerBatch(entries);
|
|
57
|
+
return registry;
|
|
58
|
+
}
|
|
59
|
+
/** Materialize a bundle into a temp HOME; returns cleanup + replay inputs. */ function materialize(bundle) {
|
|
60
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "fixture-home-"));
|
|
61
|
+
// "$TODAY" resolves to the local `YYYY/MM/DD` day key at write time — Codex
|
|
62
|
+
// date-dir discovery derives day keys from process start times in local
|
|
63
|
+
// time, so static dirs would drift across replay days/timezones.
|
|
64
|
+
const now = new Date();
|
|
65
|
+
const todayKey = [
|
|
66
|
+
String(now.getFullYear()).padStart(4, "0"),
|
|
67
|
+
String(now.getMonth() + 1).padStart(2, "0"),
|
|
68
|
+
String(now.getDate()).padStart(2, "0")
|
|
69
|
+
].join("/");
|
|
70
|
+
for (const [rel, content] of Object.entries(bundle.home)){
|
|
71
|
+
const p = path.join(home, expand(rel.split("$TODAY").join(todayKey), home));
|
|
72
|
+
fs.mkdirSync(path.dirname(p), {
|
|
73
|
+
recursive: true
|
|
74
|
+
});
|
|
75
|
+
fs.writeFileSync(p, expand(content.split("$TODAY").join(todayKey), home));
|
|
76
|
+
}
|
|
77
|
+
// SQLite stores (OpenCode's opencode.db) materialize from ordered SQL
|
|
78
|
+
// statements — binary dbs can't travel in the JSON `home` map.
|
|
79
|
+
for (const [rel, stmts] of Object.entries(bundle.sqlite ?? {})){
|
|
80
|
+
const p = path.join(home, expand(rel.split("$TODAY").join(todayKey), home));
|
|
81
|
+
fs.mkdirSync(path.dirname(p), {
|
|
82
|
+
recursive: true
|
|
83
|
+
});
|
|
84
|
+
const db = new Database(p);
|
|
85
|
+
try {
|
|
86
|
+
for (const stmt of stmts){
|
|
87
|
+
db.exec(expand(stmt.split("$TODAY").join(todayKey), home));
|
|
88
|
+
}
|
|
89
|
+
} finally{
|
|
90
|
+
db.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// "$NOW" resolves to the instant home files were written — legacy
|
|
94
|
+
// cwd+birthtime matching compares process start times against real file
|
|
95
|
+
// creation times, so a static timestamp would drift out of tolerance.
|
|
96
|
+
const nowIso = new Date().toISOString();
|
|
97
|
+
// Deterministic mtimes for adapters that read them (Grok lastActive /
|
|
98
|
+
// latest-session pick) — "$NOW" resolves like the process sentinel.
|
|
99
|
+
for (const [rel, mt] of Object.entries(bundle.mtimes ?? {})){
|
|
100
|
+
const p = path.join(home, expand(rel.split("$TODAY").join(todayKey), home));
|
|
101
|
+
const ms = mt === "$NOW" ? Date.parse(nowIso) : mt;
|
|
102
|
+
fs.utimesSync(p, ms / 1000, ms / 1000);
|
|
103
|
+
}
|
|
104
|
+
// JSON round-tripped Date fields (e.g. ProcessInfo.startTime) come back as
|
|
105
|
+
// ISO strings — adapters expect real Date instances.
|
|
106
|
+
const processes = expandNow(expand(bundle.processes, home), nowIso).map((p)=>({
|
|
107
|
+
...p,
|
|
108
|
+
startTime: p.startTime ? new Date(p.startTime) : undefined
|
|
109
|
+
}));
|
|
110
|
+
const frozenNow = bundle.frozenNow === "$NOW" ? Date.parse(nowIso) : bundle.frozenNow;
|
|
111
|
+
// Pids whose startTime resolves to the materialization instant — Codex
|
|
112
|
+
// derives session day-dirs from start times, so only these paths contain
|
|
113
|
+
// the replay-day key and normalize to $TODAY.
|
|
114
|
+
const nowPids = new Set(bundle.processes.filter((p)=>p.startTime === "$NOW").map((p)=>p.pid));
|
|
115
|
+
return {
|
|
116
|
+
home,
|
|
117
|
+
processes,
|
|
118
|
+
frozenNow,
|
|
119
|
+
todayKey,
|
|
120
|
+
// Only $NOW resolves — $FIXTURE_HOME and $TODAY stay literal to match
|
|
121
|
+
// the normalized actual form.
|
|
122
|
+
expected: expandNow(bundle.expected, nowIso),
|
|
123
|
+
cleanup: ()=>fs.rmSync(home, {
|
|
124
|
+
recursive: true,
|
|
125
|
+
force: true
|
|
126
|
+
}),
|
|
127
|
+
nowIso,
|
|
128
|
+
nowPids
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
describe("fixture replay (TS parity oracle)", ()=>{
|
|
132
|
+
const saved = process.env.HOME;
|
|
133
|
+
afterEach(()=>{
|
|
134
|
+
if (saved === undefined) delete process.env.HOME;
|
|
135
|
+
else process.env.HOME = saved;
|
|
136
|
+
});
|
|
137
|
+
if (bundlePaths.length === 0) {
|
|
138
|
+
it.todo("no fixture bundles committed yet — run AI_DEVKIT_FIXTURE_CAPTURE=1");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
for (const bundlePath of bundlePaths){
|
|
142
|
+
it(`replays ${path.relative(FIXTURES_ROOT, bundlePath)}`, async ()=>{
|
|
143
|
+
const bundle = JSON.parse(fs.readFileSync(bundlePath, "utf8"));
|
|
144
|
+
const { home, processes, frozenNow, expected, cleanup, todayKey, nowIso, nowPids } = materialize(bundle);
|
|
145
|
+
// Pin XDG to the fixture's canonical share dir — an ambient
|
|
146
|
+
// XDG_DATA_HOME would resolve the real opencode.db into replay.
|
|
147
|
+
const savedXdg = process.env.XDG_DATA_HOME;
|
|
148
|
+
// Same for ANTIGRAVITY_CLI_HOME — clearing it falls the adapter
|
|
149
|
+
// back to the pinned HOME's canonical base dir.
|
|
150
|
+
const savedAgy = process.env.ANTIGRAVITY_CLI_HOME;
|
|
151
|
+
try {
|
|
152
|
+
process.env.HOME = home;
|
|
153
|
+
process.env.XDG_DATA_HOME = path.join(home, ".local", "share");
|
|
154
|
+
delete process.env.ANTIGRAVITY_CLI_HOME;
|
|
155
|
+
const registry = seedRegistry(bundle, home, nowIso);
|
|
156
|
+
const agents = await withFrozenClock(frozenNow, ()=>adapterFor(bundle.adapter, registry).detectAgents({
|
|
157
|
+
processes
|
|
158
|
+
}));
|
|
159
|
+
// Day-key dirs normalize back to $TODAY only for agents whose
|
|
160
|
+
// process startTime was $NOW — static-start agents keep concrete
|
|
161
|
+
// dates so live bundles stay replayable on any day.
|
|
162
|
+
const actual = JSON.parse(JSON.stringify(normalizeAgents(agents, home))).map((a)=>nowPids.has(a.pid) ? JSON.parse(JSON.stringify(a).split(todayKey).join("$TODAY")) : a);
|
|
163
|
+
expect(actual).toEqual(expected);
|
|
164
|
+
} finally{
|
|
165
|
+
if (savedXdg === undefined) delete process.env.XDG_DATA_HOME;
|
|
166
|
+
else process.env.XDG_DATA_HOME = savedXdg;
|
|
167
|
+
if (savedAgy === undefined) delete process.env.ANTIGRAVITY_CLI_HOME;
|
|
168
|
+
else process.env.ANTIGRAVITY_CLI_HOME = savedAgy;
|
|
169
|
+
cleanup();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
// Opt-in live capture: AI_DEVKIT_FIXTURE_CAPTURE=1 npx vitest run fixtures
|
|
175
|
+
describe.runIf(process.env.AI_DEVKIT_FIXTURE_CAPTURE === "1")("fixture capture (live)", ()=>{
|
|
176
|
+
it("captures claude bundle from the live machine", async ()=>{
|
|
177
|
+
const out = await captureLive(adapterFor("claude"), "live");
|
|
178
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
179
|
+
}, 30000);
|
|
180
|
+
it("captures codex bundle from the live machine", async ()=>{
|
|
181
|
+
const out = await captureLive(adapterFor("codex"), "live");
|
|
182
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
183
|
+
}, 30000);
|
|
184
|
+
it("captures pi bundle from the live machine", async ()=>{
|
|
185
|
+
const out = await captureLive(adapterFor("pi"), "live");
|
|
186
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
187
|
+
}, 30000);
|
|
188
|
+
it("captures gemini_cli bundle from the live machine", async ()=>{
|
|
189
|
+
const out = await captureLive(adapterFor("gemini_cli"), "live");
|
|
190
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
191
|
+
}, 30000);
|
|
192
|
+
it("captures copilot bundle from the live machine", async ()=>{
|
|
193
|
+
const out = await captureLive(adapterFor("copilot"), "live");
|
|
194
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
195
|
+
}, 30000);
|
|
196
|
+
it("captures grok_cli bundle from the live machine", async ()=>{
|
|
197
|
+
const out = await captureLive(adapterFor("grok_cli"), "live");
|
|
198
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
199
|
+
}, 30000);
|
|
200
|
+
it("captures opencode bundle from the live machine", async ()=>{
|
|
201
|
+
const out = await captureLive(adapterFor("opencode"), "live");
|
|
202
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
203
|
+
}, 30000);
|
|
204
|
+
it("captures devin bundle from the live machine", async ()=>{
|
|
205
|
+
const out = await captureLive(adapterFor("devin"), "live");
|
|
206
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
207
|
+
}, 30000);
|
|
208
|
+
it("captures kiro bundle from the live machine", async ()=>{
|
|
209
|
+
const out = await captureLive(adapterFor("kiro"), "live");
|
|
210
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
211
|
+
}, 30000);
|
|
212
|
+
it("captures antigravity_cli bundle from the live machine", async ()=>{
|
|
213
|
+
const out = await captureLive(adapterFor("antigravity_cli"), "live");
|
|
214
|
+
expect(fs.existsSync(out)).toBe(true);
|
|
215
|
+
}, 30000);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=fixtures.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/__tests__/fixtures.test.ts"],"sourcesContent":["/**\n * Fixture replay: materialize each committed bundle into a fake HOME,\n * run the adapter's detectAgents with the recorded processes + frozen\n * clock, and require byte-identical output to `expected`.\n *\n * The same bundles are consumed by devkit-harness Rust tests — this file is\n * the TS↔TS side of the parity oracle.\n */\n\nimport { describe, it, expect, afterEach } from \"vitest\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport Database from \"better-sqlite3\";\nimport { createBuiltinAdapters } from \"../harnesses/index.js\";\nimport { CodexAdapter } from \"../harnesses/codex/CodexAdapter.js\";\nimport { PiAdapter } from \"../harnesses/pi/PiAdapter.js\";\nimport { GeminiCliAdapter } from \"../harnesses/gemini/GeminiCliAdapter.js\";\nimport { CopilotAdapter } from \"../harnesses/copilot/CopilotAdapter.js\";\nimport { AgentRegistry, type RegistryEntry } from \"../utils/AgentRegistry.js\";\nimport { expand, expandNow, normalizeAgents, withFrozenClock } from \"../fixtures/bundle.js\";\nimport type { FixtureBundle } from \"../fixtures/bundle.js\";\nimport { captureLive, FIXTURES_ROOT } from \"../fixtures/capture.js\";\n\nconst bundlePaths = fs.existsSync(FIXTURES_ROOT)\n ? fs\n .readdirSync(FIXTURES_ROOT, { withFileTypes: true })\n .flatMap((d) =>\n d.isDirectory()\n ? fs\n .readdirSync(path.join(FIXTURES_ROOT, d.name))\n .filter((f) => f.endsWith(\".json\"))\n .map((f) => path.join(FIXTURES_ROOT, d.name, f))\n : [],\n )\n : [];\n\n/** Adapters whose detect path consults AgentRegistry. */\nconst REGISTRY_AWARE = new Set([\"codex\", \"pi\", \"gemini_cli\", \"copilot\"]);\n\nfunction adapterFor(type: string, registry?: AgentRegistry) {\n // Adapters that consult the registry during detection get the seeded\n // isolated instance so replay never reads real ~/.ai-devkit state.\n if (type === \"codex\" && registry) return new CodexAdapter(registry);\n if (type === \"pi\" && registry) return new PiAdapter(registry);\n if (type === \"gemini_cli\" && registry) return new GeminiCliAdapter(registry);\n if (type === \"copilot\" && registry) return new CopilotAdapter(registry);\n const adapter = createBuiltinAdapters().find((a) => a.type === type);\n if (!adapter) throw new Error(`no builtin adapter for \"${type}\"`);\n return adapter;\n}\n\n/** Seed an isolated registry at `<home>/.ai-devkit/agents.json`. */\nfunction seedRegistry(bundle: FixtureBundle, home: string, nowIso: string): AgentRegistry | undefined {\n if (!REGISTRY_AWARE.has(bundle.adapter)) return undefined;\n const registry = new AgentRegistry(path.join(home, \".ai-devkit\", \"agents.json\"));\n const entries = (bundle.registry ?? []).map(\n (e) =>\n ({\n name: \"\",\n type: bundle.adapter,\n runtime: \"tmux\",\n runtimeRef: null,\n cwd: \"\",\n startedAt: nowIso,\n sessionId: \"\",\n sessionFilePath: \"\",\n pinned: false,\n ...expand(expandNow(e as Record<string, unknown>, nowIso), home),\n }) as RegistryEntry,\n );\n registry.registerBatch(entries);\n return registry;\n}\n\n/** Materialize a bundle into a temp HOME; returns cleanup + replay inputs. */\nfunction materialize(bundle: FixtureBundle) {\n const home = fs.mkdtempSync(path.join(os.tmpdir(), \"fixture-home-\"));\n // \"$TODAY\" resolves to the local `YYYY/MM/DD` day key at write time — Codex\n // date-dir discovery derives day keys from process start times in local\n // time, so static dirs would drift across replay days/timezones.\n const now = new Date();\n const todayKey = [\n String(now.getFullYear()).padStart(4, \"0\"),\n String(now.getMonth() + 1).padStart(2, \"0\"),\n String(now.getDate()).padStart(2, \"0\"),\n ].join(\"/\");\n for (const [rel, content] of Object.entries(bundle.home)) {\n const p = path.join(home, expand(rel.split(\"$TODAY\").join(todayKey), home));\n fs.mkdirSync(path.dirname(p), { recursive: true });\n fs.writeFileSync(p, expand(content.split(\"$TODAY\").join(todayKey), home));\n }\n // SQLite stores (OpenCode's opencode.db) materialize from ordered SQL\n // statements — binary dbs can't travel in the JSON `home` map.\n for (const [rel, stmts] of Object.entries(bundle.sqlite ?? {})) {\n const p = path.join(home, expand(rel.split(\"$TODAY\").join(todayKey), home));\n fs.mkdirSync(path.dirname(p), { recursive: true });\n const db = new Database(p);\n try {\n for (const stmt of stmts) {\n db.exec(expand(stmt.split(\"$TODAY\").join(todayKey), home));\n }\n } finally {\n db.close();\n }\n }\n // \"$NOW\" resolves to the instant home files were written — legacy\n // cwd+birthtime matching compares process start times against real file\n // creation times, so a static timestamp would drift out of tolerance.\n const nowIso = new Date().toISOString();\n // Deterministic mtimes for adapters that read them (Grok lastActive /\n // latest-session pick) — \"$NOW\" resolves like the process sentinel.\n for (const [rel, mt] of Object.entries(bundle.mtimes ?? {})) {\n const p = path.join(home, expand(rel.split(\"$TODAY\").join(todayKey), home));\n const ms = mt === \"$NOW\" ? Date.parse(nowIso) : mt;\n fs.utimesSync(p, ms / 1000, ms / 1000);\n }\n // JSON round-tripped Date fields (e.g. ProcessInfo.startTime) come back as\n // ISO strings — adapters expect real Date instances.\n const processes = expandNow(expand(bundle.processes, home), nowIso).map((p) => ({\n ...p,\n startTime: p.startTime ? new Date(p.startTime) : undefined,\n }));\n const frozenNow = bundle.frozenNow === \"$NOW\" ? Date.parse(nowIso) : bundle.frozenNow;\n // Pids whose startTime resolves to the materialization instant — Codex\n // derives session day-dirs from start times, so only these paths contain\n // the replay-day key and normalize to $TODAY.\n const nowPids = new Set(\n bundle.processes.filter((p) => p.startTime === \"$NOW\").map((p) => p.pid),\n );\n return {\n home,\n processes,\n frozenNow,\n todayKey,\n // Only $NOW resolves — $FIXTURE_HOME and $TODAY stay literal to match\n // the normalized actual form.\n expected: expandNow(bundle.expected, nowIso),\n cleanup: () => fs.rmSync(home, { recursive: true, force: true }),\n nowIso,\n nowPids,\n };\n}\n\ndescribe(\"fixture replay (TS parity oracle)\", () => {\n const saved = process.env.HOME;\n afterEach(() => {\n if (saved === undefined) delete process.env.HOME;\n else process.env.HOME = saved;\n });\n\n if (bundlePaths.length === 0) {\n it.todo(\"no fixture bundles committed yet — run AI_DEVKIT_FIXTURE_CAPTURE=1\");\n return;\n }\n\n for (const bundlePath of bundlePaths) {\n it(`replays ${path.relative(FIXTURES_ROOT, bundlePath)}`, async () => {\n const bundle: FixtureBundle = JSON.parse(fs.readFileSync(bundlePath, \"utf8\"));\n const { home, processes, frozenNow, expected, cleanup, todayKey, nowIso, nowPids } =\n materialize(bundle);\n // Pin XDG to the fixture's canonical share dir — an ambient\n // XDG_DATA_HOME would resolve the real opencode.db into replay.\n const savedXdg = process.env.XDG_DATA_HOME;\n // Same for ANTIGRAVITY_CLI_HOME — clearing it falls the adapter\n // back to the pinned HOME's canonical base dir.\n const savedAgy = process.env.ANTIGRAVITY_CLI_HOME;\n try {\n process.env.HOME = home;\n process.env.XDG_DATA_HOME = path.join(home, \".local\", \"share\");\n delete process.env.ANTIGRAVITY_CLI_HOME;\n const registry = seedRegistry(bundle, home, nowIso);\n const agents = await withFrozenClock(frozenNow, () =>\n adapterFor(bundle.adapter, registry).detectAgents({ processes }),\n );\n // Day-key dirs normalize back to $TODAY only for agents whose\n // process startTime was $NOW — static-start agents keep concrete\n // dates so live bundles stay replayable on any day.\n const actual = JSON.parse(JSON.stringify(normalizeAgents(agents, home))).map((a) =>\n nowPids.has(a.pid)\n ? JSON.parse(JSON.stringify(a).split(todayKey).join(\"$TODAY\"))\n : a,\n );\n expect(actual).toEqual(expected);\n } finally {\n if (savedXdg === undefined) delete process.env.XDG_DATA_HOME;\n else process.env.XDG_DATA_HOME = savedXdg;\n if (savedAgy === undefined) delete process.env.ANTIGRAVITY_CLI_HOME;\n else process.env.ANTIGRAVITY_CLI_HOME = savedAgy;\n cleanup();\n }\n });\n }\n});\n\n// Opt-in live capture: AI_DEVKIT_FIXTURE_CAPTURE=1 npx vitest run fixtures\ndescribe.runIf(process.env.AI_DEVKIT_FIXTURE_CAPTURE === \"1\")(\"fixture capture (live)\", () => {\n it(\"captures claude bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"claude\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures codex bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"codex\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures pi bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"pi\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures gemini_cli bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"gemini_cli\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures copilot bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"copilot\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures grok_cli bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"grok_cli\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures opencode bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"opencode\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures devin bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"devin\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures kiro bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"kiro\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n\n it(\"captures antigravity_cli bundle from the live machine\", async () => {\n const out = await captureLive(adapterFor(\"antigravity_cli\"), \"live\");\n expect(fs.existsSync(out)).toBe(true);\n }, 30000);\n});\n"],"names":["describe","it","expect","afterEach","fs","os","path","Database","createBuiltinAdapters","CodexAdapter","PiAdapter","GeminiCliAdapter","CopilotAdapter","AgentRegistry","expand","expandNow","normalizeAgents","withFrozenClock","captureLive","FIXTURES_ROOT","bundlePaths","existsSync","readdirSync","withFileTypes","flatMap","d","isDirectory","join","name","filter","f","endsWith","map","REGISTRY_AWARE","Set","adapterFor","type","registry","adapter","find","a","Error","seedRegistry","bundle","home","nowIso","has","undefined","entries","e","runtime","runtimeRef","cwd","startedAt","sessionId","sessionFilePath","pinned","registerBatch","materialize","mkdtempSync","tmpdir","now","Date","todayKey","String","getFullYear","padStart","getMonth","getDate","rel","content","Object","p","split","mkdirSync","dirname","recursive","writeFileSync","stmts","sqlite","db","stmt","exec","close","toISOString","mt","mtimes","ms","parse","utimesSync","processes","startTime","frozenNow","nowPids","pid","expected","cleanup","rmSync","force","saved","process","env","HOME","length","todo","bundlePath","relative","JSON","readFileSync","savedXdg","XDG_DATA_HOME","savedAgy","ANTIGRAVITY_CLI_HOME","agents","detectAgents","actual","stringify","toEqual","runIf","AI_DEVKIT_FIXTURE_CAPTURE","out","toBe"],"mappings":"AAAA;;;;;;;CAOC,GAED,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,SAAS,QAAQ,SAAS;AACzD,YAAYC,QAAQ,UAAU;AAC9B,YAAYC,QAAQ,UAAU;AAC9B,YAAYC,UAAU,YAAY;AAClC,OAAOC,cAAc,iBAAiB;AACtC,SAASC,qBAAqB,QAAQ,wBAAwB;AAC9D,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SAASC,SAAS,QAAQ,+BAA+B;AACzD,SAASC,gBAAgB,QAAQ,0CAA0C;AAC3E,SAASC,cAAc,QAAQ,yCAAyC;AACxE,SAASC,aAAa,QAA4B,4BAA4B;AAC9E,SAASC,MAAM,EAAEC,SAAS,EAAEC,eAAe,EAAEC,eAAe,QAAQ,wBAAwB;AAE5F,SAASC,WAAW,EAAEC,aAAa,QAAQ,yBAAyB;AAEpE,MAAMC,cAAchB,GAAGiB,UAAU,CAACF,iBAC9Bf,GACGkB,WAAW,CAACH,eAAe;IAAEI,eAAe;AAAK,GACjDC,OAAO,CAAC,CAACC,IACRA,EAAEC,WAAW,KACTtB,GACGkB,WAAW,CAAChB,KAAKqB,IAAI,CAACR,eAAeM,EAAEG,IAAI,GAC3CC,MAAM,CAAC,CAACC,IAAMA,EAAEC,QAAQ,CAAC,UACzBC,GAAG,CAAC,CAACF,IAAMxB,KAAKqB,IAAI,CAACR,eAAeM,EAAEG,IAAI,EAAEE,MAC/C,EAAE,IAEV,EAAE;AAEN,uDAAuD,GACvD,MAAMG,iBAAiB,IAAIC,IAAI;IAAC;IAAS;IAAM;IAAc;CAAU;AAEvE,SAASC,WAAWC,IAAY,EAAEC,QAAwB;IACxD,qEAAqE;IACrE,mEAAmE;IACnE,IAAID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AAa;QACtDjC,OAAOE,GAAGiB,UAAU,CAACmG,MAAMC,IAAI,CAAC;IAClC,GAAG;IAEHxH,GAAG,+CAA+C;QAChD,MAAMuH,MAAM,MAAMtG,YAAYiB,WAAW,UAAU;QACnDjC,OAAOE,GAAGiB,UAAU,CAACmG,MAAMC,IAAI,CAAC;IAClC,GAAG;IAEHxH,GAAG,8CAA8C;QAC/C,MAAMuH,MAAM,MAAMtG,YAAYiB,WAAW,SAAS;QAClDjC,OAAOE,GAAGiB,UAAU,CAACmG,MAAMC,IAAI,CAAC;IAClC,GAAG;IAEHxH,GAAG,yDAAyD;QAC1D,MAAMuH,MAAM,MAAMtG,YAAYiB,WAAW,oBAAoB;QAC7DjC,OAAOE,GAAGiB,UAAU,CAACmG,MAAMC,IAAI,CAAC;IAClC,GAAG;AACL"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Readiness fixture replay: each committed bundle under
|
|
3
|
+
* `fixtures/readiness/` provides the injectable seams (files,
|
|
4
|
+
* executables, command outputs, codexAuth) plus `expected` — the
|
|
5
|
+
* byte-identical reports the readiness probes must produce replaying
|
|
6
|
+
* the same bundle through their injectable seams.
|
|
7
|
+
*/ import { describe, it, expect } from "vitest";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { getAgentReadinessReports } from "../harnesses/readiness/AgentReadiness.js";
|
|
11
|
+
const READINESS_ROOT = path.resolve(__dirname, "../../../..", "fixtures", "readiness");
|
|
12
|
+
const bundlePaths = fs.existsSync(READINESS_ROOT) ? fs.readdirSync(READINESS_ROOT).filter((f)=>f.endsWith(".json") && !f.startsWith("live")).sort().map((f)=>path.join(READINESS_ROOT, f)) : [];
|
|
13
|
+
function replay(bundle) {
|
|
14
|
+
const executableSet = new Set(bundle.executables);
|
|
15
|
+
const options = {
|
|
16
|
+
homeDir: bundle.options.homeDir,
|
|
17
|
+
path: bundle.options.path,
|
|
18
|
+
assetRoot: bundle.options.assetRoot,
|
|
19
|
+
builtInSkillNames: bundle.options.builtInSkillNames ?? [],
|
|
20
|
+
skillRoots: bundle.options.skillRoots ?? {},
|
|
21
|
+
readFile: async (target)=>{
|
|
22
|
+
if (!(target in bundle.files)) throw new Error("missing");
|
|
23
|
+
return bundle.files[target];
|
|
24
|
+
},
|
|
25
|
+
access: async (target)=>{
|
|
26
|
+
if (executableSet.has(target) || target in bundle.files) return;
|
|
27
|
+
throw new Error("missing");
|
|
28
|
+
},
|
|
29
|
+
runCommand: async (command, args)=>{
|
|
30
|
+
const key = [
|
|
31
|
+
command,
|
|
32
|
+
...args
|
|
33
|
+
].join(" ");
|
|
34
|
+
const stub = bundle.commands[key];
|
|
35
|
+
if (!stub) throw new Error(`unexpected command ${key}`);
|
|
36
|
+
if (stub.ok === false) throw new Error(`command failed: ${key}`);
|
|
37
|
+
return {
|
|
38
|
+
stdout: stub.stdout,
|
|
39
|
+
stderr: stub.stderr ?? ""
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
codexAuth: async ()=>bundle.codexAuth ?? null
|
|
43
|
+
};
|
|
44
|
+
return getAgentReadinessReports(options);
|
|
45
|
+
}
|
|
46
|
+
describe("readiness fixture replay", ()=>{
|
|
47
|
+
it.each(bundlePaths)("%s", async (bundlePath)=>{
|
|
48
|
+
const bundle = JSON.parse(fs.readFileSync(bundlePath, "utf8"));
|
|
49
|
+
const reports = await replay(bundle);
|
|
50
|
+
expect(reports).toEqual(bundle.expected);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=readiness-fixtures.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/__tests__/readiness-fixtures.test.ts"],"sourcesContent":["/**\n * Readiness fixture replay: each committed bundle under\n * `fixtures/readiness/` provides the injectable seams (files,\n * executables, command outputs, codexAuth) plus `expected` — the\n * byte-identical reports the readiness probes must produce replaying\n * the same bundle through their injectable seams.\n */\n\nimport { describe, it, expect } from \"vitest\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport {\n getAgentReadinessReports,\n type AgentReadinessOptions,\n} from \"../harnesses/readiness/AgentReadiness.js\";\n\ninterface ReadinessBundle {\n options: {\n homeDir: string;\n path: string;\n assetRoot?: string;\n builtInSkillNames?: string[];\n skillRoots?: Record<string, string>;\n };\n /** Absolute path → contents, or \"<dir>\" for a directory entry. */\n files: Record<string, string>;\n /** Paths that answer X_OK access. */\n executables: string[];\n /** `\"command arg1 arg2\"` → output; `ok: false` rejects like execFile. */\n commands: Record<string, { stdout: string; stderr?: string; ok?: boolean }>;\n codexAuth?: boolean | null;\n expected: Record<string, unknown>;\n}\n\nconst READINESS_ROOT = path.resolve(__dirname, \"../../../..\", \"fixtures\", \"readiness\");\n\nconst bundlePaths = fs.existsSync(READINESS_ROOT)\n ? fs\n .readdirSync(READINESS_ROOT)\n .filter((f) => f.endsWith(\".json\") && !f.startsWith(\"live\"))\n .sort()\n .map((f) => path.join(READINESS_ROOT, f))\n : [];\n\nfunction replay(bundle: ReadinessBundle): Promise<Record<string, unknown>> {\n const executableSet = new Set(bundle.executables);\n const options: AgentReadinessOptions = {\n homeDir: bundle.options.homeDir,\n path: bundle.options.path,\n assetRoot: bundle.options.assetRoot,\n builtInSkillNames: bundle.options.builtInSkillNames ?? [],\n skillRoots: bundle.options.skillRoots ?? {},\n readFile: async (target) => {\n if (!(target in bundle.files)) throw new Error(\"missing\");\n return bundle.files[target];\n },\n access: async (target) => {\n if (executableSet.has(target) || target in bundle.files) return;\n throw new Error(\"missing\");\n },\n runCommand: async (command, args) => {\n const key = [command, ...args].join(\" \");\n const stub = bundle.commands[key];\n if (!stub) throw new Error(`unexpected command ${key}`);\n if (stub.ok === false) throw new Error(`command failed: ${key}`);\n return { stdout: stub.stdout, stderr: stub.stderr ?? \"\" };\n },\n codexAuth: async () => bundle.codexAuth ?? null,\n };\n return getAgentReadinessReports(options);\n}\n\ndescribe(\"readiness fixture replay\", () => {\n it.each(bundlePaths)(\"%s\", async (bundlePath) => {\n const bundle = JSON.parse(fs.readFileSync(bundlePath, \"utf8\")) as ReadinessBundle;\n const reports = await replay(bundle);\n expect(reports).toEqual(bundle.expected);\n });\n});\n"],"names":["describe","it","expect","fs","path","getAgentReadinessReports","READINESS_ROOT","resolve","__dirname","bundlePaths","existsSync","readdirSync","filter","f","endsWith","startsWith","sort","map","join","replay","bundle","executableSet","Set","executables","options","homeDir","assetRoot","builtInSkillNames","skillRoots","readFile","target","files","Error","access","has","runCommand","command","args","key","stub","commands","ok","stdout","stderr","codexAuth","each","bundlePath","JSON","parse","readFileSync","reports","toEqual","expected"],"mappings":"AAAA;;;;;;CAMC,GAED,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAS;AAC9C,YAAYC,QAAQ,UAAU;AAC9B,YAAYC,UAAU,YAAY;AAClC,SACEC,wBAAwB,QAEnB,2CAA2C;AAoBlD,MAAMC,iBAAiBF,KAAKG,OAAO,CAACC,WAAW,eAAe,YAAY;AAE1E,MAAMC,cAAcN,GAAGO,UAAU,CAACJ,kBAC9BH,GACGQ,WAAW,CAACL,gBACZM,MAAM,CAAC,CAACC,IAAMA,EAAEC,QAAQ,CAAC,YAAY,CAACD,EAAEE,UAAU,CAAC,SACnDC,IAAI,GACJC,GAAG,CAAC,CAACJ,IAAMT,KAAKc,IAAI,CAACZ,gBAAgBO,MACxC,EAAE;AAEN,SAASM,OAAOC,MAAuB;IACrC,MAAMC,gBAAgB,IAAIC,IAAIF,OAAOG,WAAW;IAChD,MAAMC,UAAiC;QACrCC,SAASL,OAAOI,OAAO,CAACC,OAAO;QAC/BrB,MAAMgB,OAAOI,OAAO,CAACpB,IAAI;QACzBsB,WAAWN,OAAOI,OAAO,CAACE,SAAS;QACnCC,mBAAmBP,OAAOI,OAAO,CAACG,iBAAiB,IAAI,EAAE;QACzDC,YAAYR,OAAOI,OAAO,CAACI,UAAU,IAAI,CAAC;QAC1CC,UAAU,OAAOC;YACf,IAAI,CAAEA,CAAAA,UAAUV,OAAOW,KAAK,AAAD,GAAI,MAAM,IAAIC,MAAM;YAC/C,OAAOZ,OAAOW,KAAK,CAACD,OAAO;QAC7B;QACAG,QAAQ,OAAOH;YACb,IAAIT,cAAca,GAAG,CAACJ,WAAWA,UAAUV,OAAOW,KAAK,EAAE;YACzD,MAAM,IAAIC,MAAM;QAClB;QACAG,YAAY,OAAOC,SAASC;YAC1B,MAAMC,MAAM;gBAACF;mBAAYC;aAAK,CAACnB,IAAI,CAAC;YACpC,MAAMqB,OAAOnB,OAAOoB,QAAQ,CAACF,IAAI;YACjC,IAAI,CAACC,MAAM,MAAM,IAAIP,MAAM,CAAC,mBAAmB,EAAEM,KAAK;YACtD,IAAIC,KAAKE,EAAE,KAAK,OAAO,MAAM,IAAIT,MAAM,CAAC,gBAAgB,EAAEM,KAAK;YAC/D,OAAO;gBAAEI,QAAQH,KAAKG,MAAM;gBAAEC,QAAQJ,KAAKI,MAAM,IAAI;YAAG;QAC1D;QACAC,WAAW,UAAYxB,OAAOwB,SAAS,IAAI;IAC7C;IACA,OAAOvC,yBAAyBmB;AAClC;AAEAxB,SAAS,4BAA4B;IACnCC,GAAG4C,IAAI,CAACpC,aAAa,MAAM,OAAOqC;QAChC,MAAM1B,SAAS2B,KAAKC,KAAK,CAAC7C,GAAG8C,YAAY,CAACH,YAAY;QACtD,MAAMI,UAAU,MAAM/B,OAAOC;QAC7BlB,OAAOgD,SAASC,OAAO,CAAC/B,OAAOgC,QAAQ;IACzC;AACF"}
|
package/dist/capacity/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { probeCodexCapacity } from "./sources/codex.js";
|
|
2
2
|
import { type ClaudeCapacityOptions } from "./sources/claude.js";
|
|
3
|
+
import { type DevinCapacityOptions } from "./sources/devin.js";
|
|
3
4
|
import { type PiAnthropicCapacityOptions, type PiOpenAiCapacityOptions, type PiZaiCapacityOptions } from "./sources/pi.js";
|
|
4
5
|
import type { CapacityReport } from "./types.js";
|
|
5
6
|
export type { CapacityReport, CapacityWindow } from "./types.js";
|
|
6
7
|
export type { ClaudeCapacityOptions } from "./sources/claude.js";
|
|
8
|
+
export type { DevinCapacityOptions } from "./sources/devin.js";
|
|
7
9
|
export type { PiAnthropicCapacityOptions as AnthropicCapacityOptions } from "./sources/pi.js";
|
|
8
10
|
export type { PiOpenAiCapacityOptions as OpenAiCapacityOptions, PiZaiCapacityOptions as ZaiCapacityOptions, } from "./sources/pi.js";
|
|
9
11
|
export type CapacityProbeOptions = {
|
|
@@ -16,5 +18,6 @@ export declare function getCodexCapacityReport(options?: CapacityProbeOptions):
|
|
|
16
18
|
export declare function getZaiCapacityReport(options?: PiZaiCapacityOptions): Promise<CapacityReport>;
|
|
17
19
|
export declare function getOpenAiCapacityReport(options?: PiOpenAiCapacityOptions): Promise<CapacityReport>;
|
|
18
20
|
export declare function getClaudeCapacityReport(options?: ClaudeCapacityOptions): Promise<CapacityReport>;
|
|
21
|
+
export declare function getDevinCapacityReport(options?: DevinCapacityOptions): Promise<CapacityReport>;
|
|
19
22
|
export declare function getAnthropicCapacityReport(options?: PiAnthropicCapacityOptions): Promise<CapacityReport>;
|
|
20
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capacity/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAuB,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAIL,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,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