Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 32 additions & 5 deletions common/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,45 @@ def test_encoding():
print("test_vcon:", _vcon)
test_vcon = vcon.Vcon(_vcon)

# Spec (draft-ietf-vcon-vcon-core-02 §2.3.2): body is always a String. A
# dict/list passed in for convenience is JSON-encoded at the boundary and
# the encoding is forced to "json".
test_vcon.add_attachment(
type="test_encoding_dict_coerced",
body={"key": "value"},
encoding="json",
)
assert test_vcon.find_attachment_by_purpose("test_encoding_dict_coerced") == {
"type": "test_encoding_dict_coerced",
"body": json.dumps({"key": "value"}),
"encoding": "json",
}

test_vcon.add_attachment(
type="test_encoding_list_coerced",
body=["key", "value"],
encoding="base64url",
)
assert test_vcon.find_attachment_by_purpose("test_encoding_list_coerced") == {
"type": "test_encoding_list_coerced",
"body": json.dumps(["key", "value"]),
"encoding": "json",
}

# Invalid JSON string with encoding=json still raises.
with pytest.raises(Exception):
test_vcon.add_attachment(
type="test_encoding",
body={"key": "value"},
type="test_encoding_bad_json",
body="not-valid-json",
encoding="json",
)

# Invalid base64url string with encoding=base64url still raises.
with pytest.raises(Exception):
test_vcon.add_attachment(
type= "test_encoding",
body=["key", "value"],
encoding= "base64url",
type="test_encoding_bad_b64",
body="not valid base64!!!",
encoding="base64url",
)

test_vcon.add_attachment(
Expand Down
4 changes: 3 additions & 1 deletion conserver/links/groq_whisper/test_groq_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ def test_get_transcription(sample_vcon_with_existing_transcript):
assert transcript is not None
assert transcript["type"] == "transcript"
assert transcript["dialog"] == 0
assert transcript["body"]["text"] == "Existing transcript"
# add_analysis JSON-encodes a dict body at the boundary per spec
# (draft-ietf-vcon-vcon-core-02 §2.3.2), so decode before drilling in.
assert Vcon.decoded_body(transcript)["text"] == "Existing transcript"

# Check non-existent transcription
transcript = get_transcription(sample_vcon_with_existing_transcript, 1) # No dialog at index 1
Expand Down
3 changes: 3 additions & 0 deletions conserver/tests/test_link_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def _run(self, vcon, applies=True, side_effect=None):
def test_tag_applied_increments_counter(self, metric_reader):
vcon = make_transcript_vcon()
vcon.analysis[0]["body"] = "Hello world"
vcon.analysis[0]["encoding"] = "none"
self._run(vcon, applies=True)
metrics = extract_metrics(metric_reader)
assert_metric_has_attrs(metrics, "conserver.link.openai.tags_applied",
Expand All @@ -441,6 +442,7 @@ def test_tag_applied_increments_counter(self, metric_reader):
def test_success_records_evaluation_time(self, metric_reader):
vcon = make_transcript_vcon()
vcon.analysis[0]["body"] = "Hello world"
vcon.analysis[0]["encoding"] = "none"
self._run(vcon, applies=True)
metrics = extract_metrics(metric_reader)
assert_metric_has_attrs(metrics, "conserver.link.openai.evaluation_time",
Expand All @@ -450,6 +452,7 @@ def test_success_records_evaluation_time(self, metric_reader):
def test_failure_increments_counter(self, metric_reader):
vcon = make_transcript_vcon()
vcon.analysis[0]["body"] = "Hello world"
vcon.analysis[0]["encoding"] = "none"
self._run(vcon, side_effect=Exception("OpenAI error"))
metrics = extract_metrics(metric_reader)
assert_metric_has_attrs(metrics, "conserver.link.openai.evaluation_failures",
Expand Down