114 lines
4 KiB
TypeScript
114 lines
4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { AiModelProvider } from './aiTargets'
|
|
import { compilePersonaLanguageGoalBinding } from './personaLanguageGoalBinding'
|
|
import type { PersonaRepositoryBinding } from './personaRepositoryBinding'
|
|
|
|
const provider: AiModelProvider = {
|
|
id: 'local-model-service',
|
|
name: 'Local model',
|
|
kind: 'ollama',
|
|
base_url: null,
|
|
api_key_storage: 'none',
|
|
api_key_env_var: null,
|
|
headers: null,
|
|
models: [{
|
|
id: 'declared-model',
|
|
capabilities: { streaming: false, tools: false, vision: false, json_mode: true, reasoning: false },
|
|
}],
|
|
}
|
|
|
|
const repositoryBinding: PersonaRepositoryBinding = {
|
|
personaId: 'ICE-P-ZY001',
|
|
repositoryPath: '/persona/ice-p-zy001',
|
|
gitHead: 'a'.repeat(40),
|
|
repositoryClean: true,
|
|
brainEntry: 'brain/CORE.hdlp',
|
|
currentCheckpoint: '.hololake/persona/CURRENT.hdlp',
|
|
humanResponsibilitySubject: 'ICE-GL∞',
|
|
modelProviderId: 'local-model-service',
|
|
modelId: 'declared-model',
|
|
modelBaseUrl: 'http://localhost:11434/v1',
|
|
organContracts: [{
|
|
organId: 'fact-sense.repository',
|
|
kind: 'FACT_SENSE',
|
|
mode: 'read-only',
|
|
paths: ['brain/CORE.hdlp', 'brain/B0.hdlp'],
|
|
inputSchema: 'hololake.pncc-fact-question/v1',
|
|
outputSchema: 'hololake.pncc-fact-result/v1',
|
|
permissions: ['READ_DECLARED_PATHS', 'RUN_MANIFEST_PINNED_MODEL'],
|
|
modelInferenceAllowed: true,
|
|
realityActionsAllowed: false,
|
|
activatable: true,
|
|
implementationState: 'IMPLEMENTED',
|
|
}],
|
|
cognitiveGravity: {
|
|
schema: 'hololake.persona-cognitive-gravity-evidence/v1',
|
|
subjectPersonaId: 'ICE-P-ZY001',
|
|
sourcePath: 'brain/B0.hdlp',
|
|
sourceHash: 'b'.repeat(64),
|
|
frameSchema: 'guanghu.zhuyuan-cognitive-gravity-frame/v1',
|
|
},
|
|
}
|
|
|
|
const deviceIdentityReceipt = {
|
|
schema: 'guanghu.router-device/v1',
|
|
device_id: 'HL-12345678-1234-1234-1234-123456789abc',
|
|
public_key: 'public-key-evidence',
|
|
}
|
|
|
|
const common = {
|
|
repositoryBinding,
|
|
provider,
|
|
modelId: 'declared-model',
|
|
deviceIdentityReceipt,
|
|
requestId: 'PNCC-LANGUAGE-001',
|
|
modelInstanceId: 'MODEL-INSTANCE-001',
|
|
developmentId: 'DEV-20260811-010',
|
|
sourceLanguageAnchor: 'HLP-CURRENT-ARCH-001@2026-08-12.4',
|
|
}
|
|
|
|
describe('compilePersonaLanguageGoalBinding', () => {
|
|
it('materializes the catalog runtime endpoint and exact read-only wake evidence', () => {
|
|
const binding = compilePersonaLanguageGoalBinding(common)
|
|
expect(binding.provider.base_url).toBe('http://localhost:11434/v1')
|
|
expect(binding.wake).toMatchObject({
|
|
repositoryPath: '/persona/ice-p-zy001',
|
|
expectedPersonaId: 'ICE-P-ZY001',
|
|
nodeId: deviceIdentityReceipt.device_id,
|
|
organId: 'fact-sense.repository',
|
|
attribution: {
|
|
humanResponsibilitySubject: 'ICE-GL∞',
|
|
personaCognitiveAuthor: 'ICE-P-ZY001',
|
|
authorizationScope: 'LOCAL_PERSONA_PARTNER_FACT_SENSE',
|
|
},
|
|
})
|
|
})
|
|
|
|
it('refuses a dirty persona root', () => {
|
|
expect(() => compilePersonaLanguageGoalBinding({
|
|
...common, repositoryBinding: { ...repositoryBinding, repositoryClean: false },
|
|
})).toThrow('PERSONA_LANGUAGE_REPOSITORY_DIRTY')
|
|
})
|
|
|
|
it('refuses model or endpoint drift from the manifest', () => {
|
|
expect(() => compilePersonaLanguageGoalBinding({
|
|
...common, provider: { ...provider, base_url: 'http://127.0.0.1:1234/v1' },
|
|
})).toThrow('PERSONA_LANGUAGE_MODEL_BINDING_MISMATCH')
|
|
})
|
|
|
|
it('refuses an unregistered device receipt', () => {
|
|
expect(() => compilePersonaLanguageGoalBinding({
|
|
...common, deviceIdentityReceipt: { schema: 'wrong', device_id: 'LOCAL' },
|
|
})).toThrow('PERSONA_LANGUAGE_DEVICE_IDENTITY_INVALID')
|
|
})
|
|
|
|
it('refuses ambiguous fact-sense authority', () => {
|
|
expect(() => compilePersonaLanguageGoalBinding({
|
|
...common,
|
|
repositoryBinding: {
|
|
...repositoryBinding,
|
|
organContracts: [...repositoryBinding.organContracts, { ...repositoryBinding.organContracts[0], organId: 'fact-sense.second' }],
|
|
},
|
|
})).toThrow('PERSONA_LANGUAGE_FACT_ORGAN_BINDING_AMBIGUOUS')
|
|
})
|
|
})
|