Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,28 @@ class AIGuardInternalTests extends DDSpecification {
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the adapter is re-created on every where: row. Consider moving it to a @Shared field.

void 'test adapter serializes content parts'() {
Comment thread
smola marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move this new coverage to JUnit 5

The root AGENTS.md test-framework guideline says to always use JUnit 5 and not write new Groovy/Spock tests, migrating existing Groovy tests when touched. Adding this new Spock feature method extends the Groovy suite instead of moving the coverage to JUnit 5, so this should be rewritten as a JUnit 5 test rather than adding another Spock case.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Nope. Nope.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a way codex is right :)

given:
final adapter = new Moshi.Builder().add(new AIGuardInternal.AIGuardFactory()).build()
.adapter(AIGuard.Message)

expect:
// STRICT enforces array element ordering (object key order is always ignored), so a regression
// that serialized the content parts out of sequence would be caught here
JSONAssert.assertEquals(expected, adapter.toJson(message), JSONCompareMode.STRICT)

where:
message | expected
AIGuard.Message.message('user', [] as List<AIGuard.ContentPart>) | '{"role": "user", "content": []}'
AIGuard.Message.message('user', [AIGuard.ContentPart.text('Hello world')]) | '{"role": "user", "content": [{"type": "text", "text": "Hello world"}]}'
AIGuard.Message.message('user', [AIGuard.ContentPart.imageUrl('https://example.com/image.jpg')]) | '{"role": "user", "content": [{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}]}'
AIGuard.Message.message('user', [
AIGuard.ContentPart.text('Describe this image:'),
Comment thread
smola marked this conversation as resolved.
AIGuard.ContentPart.imageUrl('https://example.com/image.jpg'),
AIGuard.ContentPart.text('What do you see?')
]) | '{"role": "user", "content": [{"type": "text", "text": "Describe this image:"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}, {"type": "text", "text": "What do you see?"}]}'
}

void 'test backward compatibility with string content'() {
given:
final aiguard = mockClient(200, [data: [attributes: [action: 'ALLOW', reason: 'Good']]])
Expand Down