fix: track Laya language batches and normalize labels (#22)
Report post-projection Laya language detection as a busy analysis phase and normalize Laya language labels before caching and display. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -152,8 +152,8 @@ test('language batch sends the Laya contract and parses language confidence with
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
results: [
|
||||
{ answers: { language: { choice: 'fr', answer_confidence: 0.93 } } },
|
||||
{ answers: { language: { choice: 'en', confidence: 0.81 } } }
|
||||
{ answers: { language: { choice: 'French', answer_confidence: 0.93 } } },
|
||||
{ answers: { language: { choice: 'English', confidence: 0.81 } } }
|
||||
]
|
||||
})
|
||||
};
|
||||
@ -181,6 +181,45 @@ test('language batch sends the Laya contract and parses language confidence with
|
||||
});
|
||||
});
|
||||
|
||||
test('language batch preserves explicit other and maps an unfamiliar label to unknown', async () => {
|
||||
const service = new LayaService({
|
||||
cache: null,
|
||||
fetch: async () => ({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
results: [
|
||||
{ answers: { language: { choice: 'Other', confidence: 0.72 } } },
|
||||
{ answers: { language: { choice: 'Klingon', confidence: 0.99 } } }
|
||||
]
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
const response = await service.detectBatch({
|
||||
items: [{ id: 'other', text: 'Autre' }, { id: 'strange', text: 'Qapla' }]
|
||||
});
|
||||
|
||||
assert.deepEqual(response.results, [
|
||||
{ id: 'other', language: 'other', confidence: 0.72, cached: false },
|
||||
{ id: 'strange', language: 'unknown', confidence: 0.99, cached: false }
|
||||
]);
|
||||
});
|
||||
|
||||
test('language batch rejects a successful HTTP response without a usable language answer', async () => {
|
||||
const service = new LayaService({
|
||||
cache: null,
|
||||
fetch: async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ results: [{ answers: { language: { confidence: 0.9 } } }] })
|
||||
})
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
service.detectBatch({ items: [{ id: 'missing', text: 'Missing language' }] }),
|
||||
error => error instanceof LayaRequestError && error.statusCode === 502
|
||||
);
|
||||
});
|
||||
|
||||
test('identity hints send only sanitized channel metadata to Laya', async () => {
|
||||
let requestBody;
|
||||
const service = new LayaService({
|
||||
|
||||
Reference in New Issue
Block a user