atlas-iac/testing/tests/test_hermes_hux_runtime_stop_node.js

42 lines
2.1 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const test = require('node:test');
const api = require('../../dockerfiles/hermes-webui-hux/runtime/autonomy-privacy.js');
const document = {createElement() { return {}; }};
const CONVERSATION = 'conv_alpha1234';
test('stop without a server run mapping cancels only the owned model response', async () => {
let calls = 0;
const runtime = api.createRuntime({document, conversationId: CONVERSATION,
fetcher: async () => { calls += 1; throw new Error('HUX must not be called'); },
stopModelResponse: async () => ({accepted: true}), canStopModelResponse: () => true});
assert.deepEqual(await runtime.stopRun(), {modelStopped: true, verified: false});
assert.equal(calls, 0);
});
test('stop never reports completion when owner cancellation is absent or refused', async () => {
const absent = api.createRuntime({document, conversationId: CONVERSATION, fetcher: async () => {}});
await assert.rejects(absent.stopRun(), /No owned model response/);
const refused = api.createRuntime({document, conversationId: CONVERSATION, fetcher: async () => {},
stopModelResponse: async () => ({accepted: false}), canStopModelResponse: () => true});
assert.deepEqual(await refused.stopRun(), {modelStopped: false, verified: false});
});
test('browser run mappings accept only opaque run ids', () => {
for (const runId of ['active-stream', 'run:forged', '../run', 'run_x']) {
assert.throws(() => api.createRuntime({document, conversationId: CONVERSATION,
runId, fetcher: async () => {}}), /run id/);
}
assert.doesNotThrow(() => api.createRuntime({document, conversationId: CONVERSATION,
runId: 'run_0123456789abcdef', fetcher: async () => {}}));
});
test('a missing HUX stop receipt remains explicitly unverified', async () => {
const runtime = api.createRuntime({document, conversationId: CONVERSATION,
runId: 'run_0123456789abcdef', fetcher: async () => { throw new Error('offline'); },
stopModelResponse: async () => ({accepted: true}), canStopModelResponse: () => true});
assert.deepEqual(await runtime.stopRun(), {modelStopped: true, verified: false});
});