snapkitty
agents
python
File size: 2,644 Bytes
662ceed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { lawful, judge, validateAction, checkForbidden, FORBIDDEN_ACTIONS } from '../src/validation.js';
import type { Action } from '../src/types.js';

const validAction: Action = {
  name: 'test', truthful: true, harmful: false, exploitative: false,
  requiresConsent: false, hasConsent: false, witnessed: true, cited: true
};

describe('validation', () => {
  it('lawful returns true for valid action', () => {
    assert.equal(lawful(validAction), true);
  });

  it('lawful returns false when not truthful', () => {
    assert.equal(lawful({ ...validAction, truthful: false }), false);
  });

  it('lawful returns false when harmful', () => {
    assert.equal(lawful({ ...validAction, harmful: true }), false);
  });

  it('lawful returns false when exploitative', () => {
    assert.equal(lawful({ ...validAction, exploitative: true }), false);
  });

  it('lawful returns false when consent required but missing', () => {
    assert.equal(lawful({ ...validAction, requiresConsent: true, hasConsent: false }), false);
  });

  it('lawful returns true when consent required and given', () => {
    assert.equal(lawful({ ...validAction, requiresConsent: true, hasConsent: true }), true);
  });

  it('lawful returns false when not witnessed', () => {
    assert.equal(lawful({ ...validAction, witnessed: false }), false);
  });

  it('lawful returns false when not cited', () => {
    assert.equal(lawful({ ...validAction, cited: false }), false);
  });

  it('judge returns approve for lawful action', () => {
    assert.equal(judge(validAction), 'approve');
  });

  it('judge returns repent for unlawful action', () => {
    assert.equal(judge({ ...validAction, truthful: false }), 'repent');
  });

  it('validateAction returns errors for bad action', () => {
    const errors = validateAction({ ...validAction, truthful: false, harmful: true, cited: false });
    assert.ok(errors.includes('action_not_truthful'));
    assert.ok(errors.includes('action_harmful'));
    assert.ok(errors.includes('not_cited'));
  });

  it('validateAction returns empty for valid action', () => {
    assert.deepEqual(validateAction(validAction), []);
  });

  it('FORBIDDEN_ACTIONS includes deception', () => {
    assert.ok(FORBIDDEN_ACTIONS.includes('deception'));
  });

  it('checkForbidden detects deception', () => {
    assert.equal(checkForbidden('deception'), true);
  });

  it('checkForbidden rejects safe action', () => {
    assert.equal(checkForbidden('prayer'), false);
  });
});