| 1 | import { describe, expect, it } from 'vitest';
|
| 2 | import { createIdentity, FixtureFactCheckProvider, TrustEngine } from '@openclasp/core';
|
| 3 | import { createSignedEvent } from '@openclasp/sdk';
|
| 4 |
|
| 5 | describe('general assurance behavior', () => {
|
| 6 | it('does not fact-check opinions as objective truth', async () => {
|
| 7 | const provider = new FixtureFactCheckProvider();
|
| 8 | expect((await provider.check('I think green is the best color')).status).toBe(
|
| 9 | 'not_fact_checkable',
|
| 10 | );
|
| 11 | });
|
| 12 |
|
| 13 | it('requires opt-in and strips payloads from network contributions', () => {
|
| 14 | const engine = new TrustEngine();
|
| 15 | const agent = createIdentity({
|
| 16 | agentId: 'agent:a',
|
| 17 | operatorRef: 'operator:a',
|
| 18 | capabilities: ['chat'],
|
| 19 | });
|
| 20 | engine.registerAgent(agent.identity);
|
| 21 | const event = createSignedEvent(
|
| 22 | {
|
| 23 | protocolVersion: '0.1',
|
| 24 | eventId: crypto.randomUUID(),
|
| 25 | interactionId: crypto.randomUUID(),
|
| 26 | eventType: 'claim',
|
| 27 | agentId: agent.identity.agentId,
|
| 28 | agentVersion: '1.0.0',
|
| 29 | timestamp: new Date().toISOString(),
|
| 30 | visibility: 'network_aggregate',
|
| 31 | provenance: 'observed',
|
| 32 | payload: { rawMessage: 'private conversation', claim: 'secret' },
|
| 33 | },
|
| 34 | agent.keyPair,
|
| 35 | );
|
| 36 | expect(engine.networkContribution(event)).toBeNull();
|
| 37 | engine.setContributionConsent(agent.identity.agentId, true);
|
| 38 | const contribution = engine.networkContribution(event);
|
| 39 | expect(contribution).not.toHaveProperty('payload');
|
| 40 | expect(JSON.stringify(contribution)).not.toContain('private conversation');
|
| 41 | });
|
| 42 |
|
| 43 | it('requires mutual mediation consent', () => {
|
| 44 | const engine = new TrustEngine();
|
| 45 | const conflict = engine.createConflict({
|
| 46 | interactionId: crypto.randomUUID(),
|
| 47 | issue: 'ambiguous requirement',
|
| 48 | participants: ['a', 'b'],
|
| 49 | positions: {},
|
| 50 | evidence: [],
|
| 51 | contractClauses: [],
|
| 52 | missingInformation: [],
|
| 53 | possibleResolutions: ['clarify'],
|
| 54 | });
|
| 55 | engine.permitMediation(conflict.conflictId, 'a');
|
| 56 | expect(() => engine.resolveConflict(conflict.conflictId, 'clarified')).toThrow('Mutual');
|
| 57 | engine.permitMediation(conflict.conflictId, 'b');
|
| 58 | expect(engine.resolveConflict(conflict.conflictId, 'clarified').status).toBe('resolved');
|
| 59 | });
|
| 60 | });
|