fix: enable Laya language detection and harden live analysis (#18 #19 #20)

Ensure Docker images keep their container-built native dependencies, wait for the Laya sidecar healthcheck, expose accurate Laya readiness, and treat empty AI language batches as fallback failures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-05 23:10:31 +02:00
parent 9cc86485cb
commit 1abc56c90e
7 changed files with 258 additions and 5 deletions

View File

@ -19,6 +19,7 @@ test('status reports an unavailable runtime without throwing', async () => {
});
const status = await service.status();
assert.equal(status.runtimeAvailable, false);
assert.equal(status.ready, false);
assert.equal(status.modelPresent, false);
assert.equal(status.phase, 'idle');
assert.equal(status.downloading, false);
@ -27,6 +28,24 @@ test('status reports an unavailable runtime without throwing', async () => {
assert.equal(status.totalBytes, null);
assert.equal(status.sizeBytes, 0);
assert.equal(status.error, null);
assert.match(status.runtimeError.detail, /Start the Laya sidecar/);
});
test('status does not report ready when a model exists but the runtime is unavailable', async () => {
const modelDir = await fs.mkdtemp(path.join(os.tmpdir(), 'nodecast-laya-offline-model-'));
await fs.writeFile(path.join(modelDir, 'model.bin'), 'model');
const service = new LayaService({
modelDir,
cache: null,
fetch: async () => { throw new Error('connection refused'); }
});
const status = await service.status();
assert.equal(status.modelPresent, true);
assert.equal(status.runtimeAvailable, false);
assert.equal(status.ready, false);
assert.equal(status.runtimeError.message, 'Laya runtime is unavailable');
});
test('model download exposes an indeterminate transition and finishes ready', async () => {
@ -120,6 +139,48 @@ test('batch validation rejects oversized item counts', () => {
);
});
test('language batch sends the Laya contract and parses language confidence without fallback', async () => {
let requestedUrl;
let requestBody;
const service = new LayaService({
cache: null,
batchTimeoutMs: 120000,
fetch: async (url, options) => {
requestedUrl = url;
requestBody = JSON.parse(options.body);
return {
ok: true,
json: async () => ({
results: [
{ answers: { language: { choice: 'fr', answer_confidence: 0.93 } } },
{ answers: { language: { choice: 'en', confidence: 0.81 } } }
]
})
};
}
});
const response = await service.detectBatch({
model: 'multilingual',
items: [
{ id: 'fr-channel', text: 'France 2 FR' },
{ id: 'en-channel', text: 'BBC News UK' }
]
});
assert.equal(requestedUrl, 'http://laya:8000/v1/systemone/batch');
assert.deepEqual(requestBody.states, ['France 2 FR', 'BBC News UK']);
assert.equal(requestBody.model, 'multilingual');
assert.deepEqual(response, {
runtimeAvailable: true,
model: 'multilingual',
results: [
{ id: 'fr-channel', language: 'fr', confidence: 0.93, cached: false },
{ id: 'en-channel', language: 'en', confidence: 0.81, cached: false }
]
});
});
test('identity hints send only sanitized channel metadata to Laya', async () => {
let requestBody;
const service = new LayaService({