Repository navigation
fix(skills): treat YAML and UTF-8 skill resources as text #1915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,82 @@ public void call_loadSkillResourceTool_script_success() { | |
| "content", "echo hello"); | ||
| } | ||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_ymlAsset_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/config.yml"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsExactly( | ||
| "skill_name", "test-skill", | ||
| "file_path", "assets/config.yml", | ||
| "mime_type", "application/yaml", | ||
| "content", "id: a\nname: b\n"); | ||
| } | ||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_yamlAsset_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/config.yaml"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsExactly( | ||
| "skill_name", "test-skill", | ||
| "file_path", "assets/config.yaml", | ||
| "mime_type", "application/yaml", | ||
| "content", "id: a\nname: b\n"); | ||
| } | ||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_uppercaseYamlAsset_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/CONFIG.YAML"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsExactly( | ||
| "skill_name", "test-skill", | ||
| "file_path", "assets/CONFIG.YAML", | ||
| "mime_type", "application/yaml", | ||
| "content", "id: a\nname: b\n"); | ||
| } | ||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_unknownTextExtension_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/config.toml"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsExactly( | ||
| "skill_name", "test-skill", | ||
| "file_path", "assets/config.toml", | ||
| "mime_type", "text/plain", | ||
| "content", "name = \"caf\u00e9\"\n"); | ||
| } | ||
|
Comment on lines
+161
to
+178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_streamDetection_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
|
|
@@ -168,7 +244,28 @@ public void call_loadSkillResourceTool_binaryReference_detected() { | |
|
|
||
| Part binaryPart = parts.get(1); | ||
| assertThat(binaryPart.inlineData().get().mimeType()).hasValue("application/octet-stream"); | ||
| assertThat(binaryPart.inlineData().get().data().get()).isEqualTo(new byte[] {0, 1, 2, 3}); | ||
| assertThat(binaryPart.inlineData().get().data().get()) | ||
| .isEqualTo(new byte[] {(byte) 0xFF, (byte) 0xFE, (byte) 0x80}); | ||
| } | ||
|
|
||
| @Test | ||
| public void call_loadSkillResourceTool_truncatedUtf8_detectedAsBinary() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of( | ||
| "skill_name", "test-skill", "file_path", "references/truncated.dat"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsAtLeast( | ||
| "skill_name", "test-skill", | ||
| "file_path", "references/truncated.dat", | ||
| "mime_type", "application/octet-stream"); | ||
| assertThat((byte[]) response.get("content")).isEqualTo(new byte[] {'a', (byte) 0xC3}); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -321,9 +418,14 @@ private SkillSource createTestSkillSource() { | |
| .frontmatter(Frontmatter.builder().name("test-skill").description("test skill").build()) | ||
| .instructions("Test instructions") | ||
| .addResource("references/my_doc.md", "doc content".getBytes(UTF_8)) | ||
| .addResource("references/binary.dat", new byte[] {0, 1, 2, 3}) | ||
| .addResource("references/binary.dat", new byte[] {(byte) 0xFF, (byte) 0xFE, (byte) 0x80}) | ||
| .addResource("references/truncated.dat", new byte[] {'a', (byte) 0xC3}) | ||
| .addResource("assets/template.txt", "asset content".getBytes(UTF_8)) | ||
| .addResource("scripts/setup.sh", "echo hello".getBytes(UTF_8)) | ||
| .addResource("assets/config.yml", "id: a\nname: b\n".getBytes(UTF_8)) | ||
| .addResource("assets/config.yaml", "id: a\nname: b\n".getBytes(UTF_8)) | ||
| .addResource("assets/CONFIG.YAML", "id: a\nname: b\n".getBytes(UTF_8)) | ||
| .addResource("assets/config.toml", "name = \"caf\u00e9\"\n".getBytes(UTF_8)) | ||
| .addResource("assets/data_no_ext", "<?xml version=\"1.0\"?><root/>".getBytes(UTF_8)) | ||
| .build(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we fall back to strict UTF-8 decoding before
application/octet-streamwhen both guesses return null?Handling only
.ymland.yamlstill leaves other text formats missing from the JDK's MIME table (.toml,.ini,.properties,.sql,.ts,.kt, etc.) falling back toapplication/octet-streamand hitting the same Vertex AI 400. ADK Python and ADK Kotlin instead try a strict UTF-8 decode and treat valid UTF-8 as text.Note that
references/binary.datin the test uses{0, 1, 2, 3}, which is valid UTF-8, so it would need non-UTF-8 bytes (or a NUL check) if we go that route. If you prefer to keep this PR scoped to YAML, that's fine too; we can leave #1893 open for the rest.