146 lines
4.1 KiB
TypeScript
146 lines
4.1 KiB
TypeScript
|
|
import { describe, expect, it } from 'vitest'
|
||
|
|
import {
|
||
|
|
createDeterministicLivingSystemPlan,
|
||
|
|
createLivingSystemExecutionReceipt,
|
||
|
|
createLivingSystemEvent,
|
||
|
|
parseLivingSystemPlan,
|
||
|
|
validateLivingSystemPlan,
|
||
|
|
} from './guanghuLivingSystem'
|
||
|
|
|
||
|
|
describe('Guanghu living system contract', () => {
|
||
|
|
it('accepts a model-native navigation plan with a bounded visual scene', () => {
|
||
|
|
const event = createLivingSystemEvent({
|
||
|
|
currentRoute: 'world',
|
||
|
|
intent: 'navigate',
|
||
|
|
requestedRoute: 'fifth-domain',
|
||
|
|
worldOpen: true,
|
||
|
|
receiptIds: ['receipt-001'],
|
||
|
|
now: 1_785_670_000_000,
|
||
|
|
eventId: 'event-001',
|
||
|
|
})
|
||
|
|
const plan = parseLivingSystemPlan(JSON.stringify({
|
||
|
|
version: 1,
|
||
|
|
eventId: 'event-001',
|
||
|
|
intent: 'navigate',
|
||
|
|
planId: 'plan-001',
|
||
|
|
route: 'fifth-domain',
|
||
|
|
requiredTruth: ['receipt-001'],
|
||
|
|
scene: {
|
||
|
|
depth: 'immersive',
|
||
|
|
motion: 'responsive',
|
||
|
|
starDensity: 'rich',
|
||
|
|
connectionEmphasis: 'active-route',
|
||
|
|
},
|
||
|
|
}))
|
||
|
|
|
||
|
|
expect(validateLivingSystemPlan(event, plan)).toEqual({
|
||
|
|
accepted: true,
|
||
|
|
plan,
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('fails closed when a model plan references truth that was not supplied', () => {
|
||
|
|
const event = createLivingSystemEvent({
|
||
|
|
currentRoute: 'world',
|
||
|
|
intent: 'navigate',
|
||
|
|
requestedRoute: 'fifth-domain',
|
||
|
|
worldOpen: true,
|
||
|
|
receiptIds: [],
|
||
|
|
eventId: 'event-002',
|
||
|
|
now: 1,
|
||
|
|
})
|
||
|
|
const plan = parseLivingSystemPlan(JSON.stringify({
|
||
|
|
version: 1,
|
||
|
|
eventId: 'event-002',
|
||
|
|
intent: 'navigate',
|
||
|
|
planId: 'plan-002',
|
||
|
|
route: 'fifth-domain',
|
||
|
|
requiredTruth: ['invented-receipt'],
|
||
|
|
scene: {
|
||
|
|
depth: 'focused', motion: 'quiet', starDensity: 'balanced', connectionEmphasis: 'contextual',
|
||
|
|
},
|
||
|
|
}))
|
||
|
|
|
||
|
|
expect(validateLivingSystemPlan(event, plan)).toEqual({
|
||
|
|
accepted: false,
|
||
|
|
reason: 'unverified_truth',
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('redirects protected routes to the login gate while the world is closed', () => {
|
||
|
|
const event = createLivingSystemEvent({
|
||
|
|
currentRoute: 'world',
|
||
|
|
intent: 'navigate',
|
||
|
|
requestedRoute: 'fifth-domain',
|
||
|
|
worldOpen: false,
|
||
|
|
receiptIds: [],
|
||
|
|
eventId: 'event-003',
|
||
|
|
now: 1,
|
||
|
|
})
|
||
|
|
|
||
|
|
expect(createDeterministicLivingSystemPlan(event)).toMatchObject({
|
||
|
|
route: 'world-login',
|
||
|
|
scene: { depth: 'focused', motion: 'responsive' },
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('rejects a model plan that substitutes a different host action', () => {
|
||
|
|
const event = createLivingSystemEvent({
|
||
|
|
currentRoute: 'world',
|
||
|
|
eventId: 'event-host-action',
|
||
|
|
intent: 'open-knowledge',
|
||
|
|
requestedRoute: 'world',
|
||
|
|
worldOpen: false,
|
||
|
|
receiptIds: [],
|
||
|
|
now: 1,
|
||
|
|
})
|
||
|
|
const plan = parseLivingSystemPlan(JSON.stringify({
|
||
|
|
version: 1,
|
||
|
|
eventId: event.eventId,
|
||
|
|
intent: 'open-agent-workspace',
|
||
|
|
planId: 'substituted-action',
|
||
|
|
route: 'world',
|
||
|
|
requiredTruth: [],
|
||
|
|
scene: {
|
||
|
|
depth: 'overview',
|
||
|
|
motion: 'responsive',
|
||
|
|
starDensity: 'balanced',
|
||
|
|
connectionEmphasis: 'contextual',
|
||
|
|
},
|
||
|
|
}))
|
||
|
|
|
||
|
|
expect(validateLivingSystemPlan(event, plan)).toEqual({
|
||
|
|
accepted: false,
|
||
|
|
reason: 'intent_mismatch',
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('rejects chatty or structurally invalid model output', () => {
|
||
|
|
expect(parseLivingSystemPlan('我来帮你进入第五域')).toBeNull()
|
||
|
|
expect(parseLivingSystemPlan('{"route":"fifth-domain"}')).toBeNull()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('binds a local executor receipt to the accepted event and plan', () => {
|
||
|
|
const plan = createDeterministicLivingSystemPlan(createLivingSystemEvent({
|
||
|
|
currentRoute: 'world',
|
||
|
|
intent: 'navigate',
|
||
|
|
requestedRoute: 'zero-core',
|
||
|
|
worldOpen: true,
|
||
|
|
receiptIds: [],
|
||
|
|
eventId: 'event-004',
|
||
|
|
now: 1,
|
||
|
|
}))
|
||
|
|
|
||
|
|
expect(createLivingSystemExecutionReceipt({ plan, source: 'fallback', now: 2 })).toEqual({
|
||
|
|
version: 1,
|
||
|
|
receiptId: 'local-execution:fallback-event-004',
|
||
|
|
eventId: 'event-004',
|
||
|
|
intent: 'navigate',
|
||
|
|
planId: 'fallback-event-004',
|
||
|
|
route: 'zero-core',
|
||
|
|
source: 'fallback',
|
||
|
|
outcome: 'executed',
|
||
|
|
executedAt: 2,
|
||
|
|
})
|
||
|
|
})
|
||
|
|
})
|