@eyeoverthink/sva-gate 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +1,84 @@
1
- // Regression tests for the 2026-12-04 review: the bundled privacy membrane (stream guard leak, strict unseal,
2
- // regex cost), the bundled skill crystallizer (quantity/negation/ambiguity refusals), and README/serverInfo versions.
3
- import test from 'node:test';
4
- import assert from 'node:assert/strict';
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import { fileURLToPath } from 'node:url';
8
- import {
9
- detect, SealSession, StreamSealGuard, induce, applySpec, explainApply, novelWording, createMcpHandler,
10
- } from '../src/index.js';
11
- import { SERVER_INFO } from '../src/mcp-server.js';
12
-
13
- const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
14
- const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
15
- // A public example token, assembled at run time so secret scanners do not flag the test file.
16
- const JWT = ['eyJhbGciOiJIUzI1NiJ9', 'eyJzdWIiOiIxMjM0NTY3ODkwIn0', 'SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'].join('.');
17
- const PEM = '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASC\n-----END PRIVATE KEY-----';
18
-
19
- const stream = (chunks) => { const g = new StreamSealGuard(); return { out: chunks.map((c) => g.push(c)).join('') + g.flush(), g }; };
20
-
21
- test('bundled StreamSealGuard: fragments that arrive as their own chunk do not leak (2.0.x leaked these)', () => {
22
- const cases = [
23
- [['Contact', ' el', 'ena', '@', 'north', 'star', '.org', ' today'], 'elena', 'northstar'],
24
- [['the password is', ' hunter22', ' ok'], 'hunter22'],
25
- [['auth ', JWT.slice(0, 10), JWT.slice(10), ' end'], 'eyJhbGciOi', 'SflKxw'],
26
- [['key: ', PEM.slice(0, 40), PEM.slice(40), ' done'], 'MIIEvQ'],
27
- [['Patient ', 'Dr', '. Elena', ' Ruiz', ' was seen'], 'Elena', 'Ruiz'],
28
- [['key sk-' + 'A'.repeat(40), 'B'.repeat(20) + ' done'], 'AAAA', 'BBBB'],
29
- ];
30
- for (const [chunks, ...secrets] of cases) {
31
- const { out, g } = stream(chunks);
32
- for (const s of secrets) assert.ok(!out.includes(s), `${JSON.stringify(chunks)} leaked ${s}: ${out}`);
33
- assert.equal(g.session.audit(out).clean, true);
34
- }
35
- });
36
-
37
- test('bundled membrane: strict unseal, single-pass unseal, linear detection', () => {
38
- const s = new SealSession();
39
- s.apply('mail elena@northstar.org', detect('mail elena@northstar.org'));
40
- assert.equal(s.unseal('EMAIL_1 and ⟦EMAIL_1⟧', { strict: true }), 'EMAIL_1 and elena@northstar.org');
41
- const t = performance.now();
42
- detect('a.'.repeat(50000));
43
- detect('token' + ' '.repeat(100000));
44
- assert.ok(performance.now() - t < 3000);
45
- });
46
-
47
- test('bundled crystallizer refuses quantity words, negations and ambiguous rules', () => {
48
- const skill = { params: { properties: {
49
- price: { type: 'number' }, d1: { type: 'number', description: 'decimal fraction' }, d2: { type: 'number', description: 'decimal fraction' } } } };
50
- const pos = [
51
- { task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
52
- { task: 'A $80 pair of shoes is 15% off, then an extra 20% off. What is the final price?', input: { price: 80, d1: 0.15, d2: 0.2 } },
53
- { task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
54
- ];
55
- const { spec } = induce(pos, [], skill);
56
- assert.equal(applySpec(spec, 'Two $240 coats are each 25% off, then an extra 10% off. What is the final price?'), null);
57
- assert.equal(explainApply(spec, 'A $240 coat is not 25% off, then an extra 10% off. What is the final price?').refused, 'modifier');
58
- assert.ok(novelWording(pos, 'A $240 coat is not 25% off, then an extra 10% off. What is the final price?').length > 0);
59
- const posEq = pos.map((e) => ({ task: e.task.replace(/extra \d+%/, `extra ${e.input.d1 * 100}%`), input: { ...e.input, d2: e.input.d1 } }));
60
- const eq = induce(posEq, [], skill).spec;
61
- assert.equal(explainApply(eq, 'A $240 coat is 40% off, then an extra 10% off. What is the final price?').refused, 'ambiguous');
62
- });
63
-
64
- test('MCP sva_crystallize_skill reports the refusal reason', () => {
65
- const handle = createMcpHandler();
66
- const res = handle({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'sva_crystallize_skill', arguments: {
67
- skill: { params: { properties: { price: { type: 'number' }, d1: { type: 'number', description: 'decimal fraction' }, d2: { type: 'number', description: 'decimal fraction' } } } },
68
- examples: [
69
- { task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
70
- { task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
71
- ],
72
- testTask: 'Two $240 coats are each 25% off, then an extra 10% off. What is the final price?',
73
- } } });
74
- const out = JSON.parse(res.result.content[0].text);
75
- assert.equal(out.testResult.routed, false);
76
- assert.equal(out.testResult.refused.reason, 'modifier');
77
- });
78
-
79
- test('README heading and MCP serverInfo match package.json version', () => {
80
- const readme = fs.readFileSync(path.join(ROOT, 'README.md'), 'utf8');
81
- assert.equal(readme.split(/\r?\n/)[0], `# \`@eyeoverthink/sva-gate\` (\`v${PKG.version}\`)`);
82
- assert.equal(SERVER_INFO.version, PKG.version);
83
- assert.ok(!/IETF `?draft-zambo/.test(readme), 'AER-1 is an individual draft, not an IETF document');
84
- });
1
+ // Regression tests for the 2026-12-04 review: the bundled privacy membrane (stream guard leak, strict unseal,
2
+ // regex cost), the bundled skill crystallizer (quantity/negation/ambiguity refusals), and README/serverInfo versions.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import {
9
+ detect, SealSession, StreamSealGuard, induce, applySpec, explainApply, novelWording, createMcpHandler,
10
+ } from '../src/index.js';
11
+ import { SERVER_INFO } from '../src/mcp-server.js';
12
+
13
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
14
+ const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
15
+ // A public example token, assembled at run time so secret scanners do not flag the test file.
16
+ const JWT = ['eyJhbGciOiJIUzI1NiJ9', 'eyJzdWIiOiIxMjM0NTY3ODkwIn0', 'SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'].join('.');
17
+ const PEM = '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASC\n-----END PRIVATE KEY-----';
18
+
19
+ const stream = (chunks) => { const g = new StreamSealGuard(); return { out: chunks.map((c) => g.push(c)).join('') + g.flush(), g }; };
20
+
21
+ test('bundled StreamSealGuard: fragments that arrive as their own chunk do not leak (2.0.x leaked these)', () => {
22
+ const cases = [
23
+ [['Contact', ' el', 'ena', '@', 'north', 'star', '.org', ' today'], 'elena', 'northstar'],
24
+ [['the password is', ' hunter22', ' ok'], 'hunter22'],
25
+ [['auth ', JWT.slice(0, 10), JWT.slice(10), ' end'], 'eyJhbGciOi', 'SflKxw'],
26
+ [['key: ', PEM.slice(0, 40), PEM.slice(40), ' done'], 'MIIEvQ'],
27
+ [['Patient ', 'Dr', '. Elena', ' Ruiz', ' was seen'], 'Elena', 'Ruiz'],
28
+ [['key sk-' + 'A'.repeat(40), 'B'.repeat(20) + ' done'], 'AAAA', 'BBBB'],
29
+ ];
30
+ for (const [chunks, ...secrets] of cases) {
31
+ const { out, g } = stream(chunks);
32
+ for (const s of secrets) assert.ok(!out.includes(s), `${JSON.stringify(chunks)} leaked ${s}: ${out}`);
33
+ assert.equal(g.session.audit(out).clean, true);
34
+ }
35
+ });
36
+
37
+ test('bundled membrane: strict unseal, single-pass unseal, linear detection', () => {
38
+ const s = new SealSession();
39
+ s.apply('mail elena@northstar.org', detect('mail elena@northstar.org'));
40
+ assert.equal(s.unseal('EMAIL_1 and ⟦EMAIL_1⟧', { strict: true }), 'EMAIL_1 and elena@northstar.org');
41
+ const t = performance.now();
42
+ detect('a.'.repeat(50000));
43
+ detect('token' + ' '.repeat(100000));
44
+ assert.ok(performance.now() - t < 3000);
45
+ });
46
+
47
+ test('bundled crystallizer refuses quantity words, negations and ambiguous rules', () => {
48
+ const skill = { params: { properties: {
49
+ price: { type: 'number' }, d1: { type: 'number', description: 'decimal fraction' }, d2: { type: 'number', description: 'decimal fraction' } } } };
50
+ const pos = [
51
+ { task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
52
+ { task: 'A $80 pair of shoes is 15% off, then an extra 20% off. What is the final price?', input: { price: 80, d1: 0.15, d2: 0.2 } },
53
+ { task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
54
+ ];
55
+ const { spec } = induce(pos, [], skill);
56
+ assert.equal(applySpec(spec, 'Two $240 coats are each 25% off, then an extra 10% off. What is the final price?'), null);
57
+ assert.equal(explainApply(spec, 'A $240 coat is not 25% off, then an extra 10% off. What is the final price?').refused, 'modifier');
58
+ assert.ok(novelWording(pos, 'A $240 coat is not 25% off, then an extra 10% off. What is the final price?').length > 0);
59
+ const posEq = pos.map((e) => ({ task: e.task.replace(/extra \d+%/, `extra ${e.input.d1 * 100}%`), input: { ...e.input, d2: e.input.d1 } }));
60
+ const eq = induce(posEq, [], skill).spec;
61
+ assert.equal(explainApply(eq, 'A $240 coat is 40% off, then an extra 10% off. What is the final price?').refused, 'ambiguous');
62
+ });
63
+
64
+ test('MCP sva_crystallize_skill reports the refusal reason', () => {
65
+ const handle = createMcpHandler();
66
+ const res = handle({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'sva_crystallize_skill', arguments: {
67
+ skill: { params: { properties: { price: { type: 'number' }, d1: { type: 'number', description: 'decimal fraction' }, d2: { type: 'number', description: 'decimal fraction' } } } },
68
+ examples: [
69
+ { task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
70
+ { task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
71
+ ],
72
+ testTask: 'Two $240 coats are each 25% off, then an extra 10% off. What is the final price?',
73
+ } } });
74
+ const out = JSON.parse(res.result.content[0].text);
75
+ assert.equal(out.testResult.routed, false);
76
+ assert.equal(out.testResult.refused.reason, 'modifier');
77
+ });
78
+
79
+ test('README heading and MCP serverInfo match package.json version', () => {
80
+ const readme = fs.readFileSync(path.join(ROOT, 'README.md'), 'utf8');
81
+ assert.equal(readme.split(/\r?\n/)[0], `# \`@eyeoverthink/sva-gate\` (\`v${PKG.version}\`)`);
82
+ assert.equal(SERVER_INFO.version, PKG.version);
83
+ assert.ok(!/IETF `?draft-zambo/.test(readme), 'AER-1 is an individual draft, not an IETF document');
84
+ });