Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import type * as EffectAcpSchema from "effect-acp/schema";
3
4import {
5 DEVIN_RESOURCE_TEXT_MAX_CHARS,
6 normalizeDevinResourceContent,
7} from "./DevinResourceSupport.ts";
8
9describe("Devin ACP resource normalization", () => {
10 // Task 2 did not observe resource content from the installed Devin CLI. These are
11 // intentionally synthetic, typed ACP schema fixtures; they are not live Devin evidence.
12 it("normalizes a typed ACP resource-link fixture", () => {
13 const fixture = {
14 type: "content",
15 content: {
16 type: "resource_link",
17 uri: "urn:acp:fixture:resource-link",
18 name: "schema fixture",
19 description: "typed protocol fixture",
20 mimeType: "text/markdown",
21 },
22 } satisfies EffectAcpSchema.ToolCallContent;
23
24 expect(normalizeDevinResourceContent(fixture)).toEqual({
25 kind: "resource",
26 resource: {
27 uri: "urn:acp:fixture:resource-link",
28 name: "schema fixture",
29 description: "typed protocol fixture",
30 mimeType: "text/markdown",
31 },
32 });
33 });
34
35 it("normalizes a typed ACP embedded-text resource fixture", () => {
36 const fixture = {
37 type: "content",
38 content: {
39 type: "resource",
40 resource: {
41 uri: "urn:acp:fixture:embedded-text",
42 mimeType: "text/plain",
43 text: "protocol fixture",
44 },
45 },
46 } satisfies EffectAcpSchema.ToolCallContent;
47
48 expect(normalizeDevinResourceContent(fixture)).toEqual({
49 kind: "resource",
50 resource: {
51 uri: "urn:acp:fixture:embedded-text",
52 mimeType: "text/plain",
53 text: "protocol fixture",
54 },
55 });
56 });
57
58 it("omits null optional resource-link metadata", () => {
59 const fixture = {
60 type: "content",
61 content: {
62 type: "resource_link",
63 uri: "https://resources.example/acp/null-metadata",
64 name: "ACP reference",
65 description: null,
66 mimeType: null,
67 },
68 } satisfies EffectAcpSchema.ToolCallContent;
69
70 expect(normalizeDevinResourceContent(fixture)).toEqual({
71 kind: "resource",
72 resource: {
73 uri: "https://resources.example/acp/null-metadata",
74 name: "ACP reference",
75 },
76 });
77 });
78
79 it("rejects malformed optional resource content without throwing", () => {
80 expect(
81 normalizeDevinResourceContent({
82 type: "content",
83 content: { type: "resource", resource: { uri: 42, text: "fixture" } },
84 }),
85 ).toEqual({ kind: "unsupported", reason: "invalid" });
86 });
87
88 it("rejects resource content missing its required URI", () => {
89 expect(
90 normalizeDevinResourceContent({
91 type: "content",
92 content: { type: "resource_link", name: "fixture" },
93 }),
94 ).toEqual({ kind: "unsupported", reason: "invalid" });
95 });
96
97 it("rejects oversized embedded text", () => {
98 const fixture = {
99 type: "content",
100 content: {
101 type: "resource",
102 resource: {
103 uri: "https://resources.example/acp/oversized",
104 text: "x".repeat(DEVIN_RESOURCE_TEXT_MAX_CHARS + 1),
105 },
106 },
107 } satisfies EffectAcpSchema.ToolCallContent;
108
109 expect(normalizeDevinResourceContent(fixture)).toEqual({
110 kind: "unsupported",
111 reason: "oversized",
112 });
113 });
114
115 it("rejects a protocol-schema embedded blob without decoding it", () => {
116 const fixture = {
117 type: "content",
118 content: {
119 type: "resource",
120 resource: {
121 uri: "https://resources.example/acp/binary",
122 mimeType: "application/octet-stream",
123 blob: "opaque-binary-fixture",
124 },
125 },
126 } satisfies EffectAcpSchema.ToolCallContent;
127
128 expect(normalizeDevinResourceContent(fixture)).toEqual({
129 kind: "unsupported",
130 reason: "binary",
131 });
132 });
133
134 it("rejects a malformed blob field rather than treating it as text", () => {
135 expect(
136 normalizeDevinResourceContent({
137 type: "content",
138 content: {
139 type: "resource",
140 resource: {
141 uri: "urn:acp:fixture:malformed-blob",
142 text: "typed protocol fixture",
143 blob: 42,
144 },
145 },
146 }),
147 ).toEqual({ kind: "unsupported", reason: "invalid" });
148 });
149});