hololake-system-architecture/product-source/guanghu-knowledge-base/server/channel-runtime.test.ts

35 lines
1.4 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { applyChannelPatch, defaultChannelState, KNOWLEDGE_MODULE_ID, normalizeChannelState } from './channel-runtime.js';
test('module removal unmounts the module but preserves a reversible before state', () => {
const receipt = applyChannelPatch(defaultChannelState('2026-08-09T00:00:00.000Z'), {
operation: 'set_module_state',
moduleId: KNOWLEDGE_MODULE_ID,
installed: false,
}, '2026-08-09T00:01:00.000Z');
assert.equal(receipt.after.modules[0].installed, false);
assert.equal(receipt.after.modules[0].mounted, false);
assert.equal(receipt.before.modules[0].installed, true);
assert.equal(receipt.after.revision, 1);
});
test('unknown modules fail closed instead of becoming UI-only entries', () => {
assert.throws(() => applyChannelPatch(defaultChannelState(), {
operation: 'set_module_state',
moduleId: 'UNREGISTERED-MODULE',
installed: true,
}), /未在光湖注册表登记/);
});
test('stored state is normalized against the current official registry', () => {
const state = normalizeChannelState({
schema: 'hololake.personal-channel-state/v1',
channelId: 'CHANNEL-ICE-001',
revision: 3,
updatedAt: '2026-08-09T00:00:00.000Z',
modules: [{ id: KNOWLEDGE_MODULE_ID, installed: false, mounted: true, order: 0 }],
});
assert.equal(state.modules[0].installed, false);
assert.equal(state.modules[0].mounted, false);
});