-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-speech-rules.js
More file actions
136 lines (117 loc) · 4.23 KB
/
test-speech-rules.js
File metadata and controls
136 lines (117 loc) · 4.23 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env node
// Simple test script to validate the speech rule engine
// Run with: node test-speech-rules.js
const { extractIntent, processTranscript } = require('./utils/speechRuleEngine.ts');
// Mock protocol and run data for testing
const mockProtocol = {
id: 'plasmid-miniprep-neb-t1110',
name: 'Plasmid Miniprep (NEB #T1110)',
steps: [
{
id: 'step-1',
title: 'Pellet bacterial culture',
description: 'Pellet 1–5 ml bacterial culture by centrifugation for 30 seconds.',
estimatedDuration: 2,
},
{
id: 'step-2',
title: 'Resuspend in Buffer B1',
description: 'Resuspend the pellet in 200 μl of Monarch Buffer B1.',
estimatedDuration: 2,
},
{
id: 'step-3',
title: 'Lyse with Buffer B2',
description: 'Add 200 μl of Monarch Buffer B2, gently invert 5–6 times.',
estimatedDuration: 2,
},
],
};
const mockRun = {
id: 'test-run-1',
protocolId: 'plasmid-miniprep-neb-t1110',
currentStepIndex: 0,
completedSteps: [],
status: 'in_progress',
};
// Test cases for each intent
const testCases = [
// NEXT_STEP tests
{ input: "next step", expectedIntent: 'NEXT_STEP' },
{ input: "go to next", expectedIntent: 'NEXT_STEP' },
{ input: "proceed", expectedIntent: 'NEXT_STEP' },
{ input: "continue", expectedIntent: 'NEXT_STEP' },
{ input: "step complete", expectedIntent: 'NEXT_STEP' },
{ input: "done", expectedIntent: 'NEXT_STEP' },
// ADD_NOTE tests
{ input: "add note the pellet looked cloudy", expectedIntent: 'ADD_NOTE' },
{ input: "note that the solution turned pink", expectedIntent: 'ADD_NOTE' },
{ input: "make a note buffer was cold", expectedIntent: 'ADD_NOTE' },
{ input: "save note centrifuge speed was 5000 rpm", expectedIntent: 'ADD_NOTE' },
// QUERY_STEP_N tests
{ input: "what's step 3", expectedIntent: 'QUERY_STEP_N' },
{ input: "read step 2", expectedIntent: 'QUERY_STEP_N' },
{ input: "tell me step three", expectedIntent: 'QUERY_STEP_N' },
{ input: "what is step 1", expectedIntent: 'QUERY_STEP_N' },
{ input: "step 2", expectedIntent: 'QUERY_STEP_N' },
// UNKNOWN tests
{ input: "hello there", expectedIntent: 'UNKNOWN' },
{ input: "how are you", expectedIntent: 'UNKNOWN' },
{ input: "random text", expectedIntent: 'UNKNOWN' },
];
console.log('🧪 Testing Speech Rule Engine\n');
console.log('=' .repeat(50));
let passed = 0;
let failed = 0;
testCases.forEach((testCase, index) => {
try {
const result = extractIntent(testCase.input);
const success = result.intent === testCase.expectedIntent;
console.log(`\nTest ${index + 1}: "${testCase.input}"`);
console.log(`Expected: ${testCase.expectedIntent}`);
console.log(`Got: ${result.intent}`);
console.log(`Status: ${success ? '✅ PASS' : '❌ FAIL'}`);
if (result.entities.noteContent) {
console.log(`Note content: "${result.entities.noteContent}"`);
}
if (result.entities.stepNumber) {
console.log(`Step number: ${result.entities.stepNumber}`);
}
if (success) {
passed++;
} else {
failed++;
}
} catch (error) {
console.log(`\nTest ${index + 1}: "${testCase.input}"`);
console.log(`❌ ERROR: ${error.message}`);
failed++;
}
});
console.log('\n' + '=' .repeat(50));
console.log(`\n📊 Test Results: ${passed} passed, ${failed} failed`);
// Test full processing pipeline
console.log('\n🔄 Testing Full Processing Pipeline\n');
console.log('-' .repeat(30));
const pipelineTests = [
"next step",
"add note the solution was very viscous",
"what's step 2"
];
pipelineTests.forEach((input, index) => {
try {
console.log(`\nPipeline Test ${index + 1}: "${input}"`);
const result = processTranscript(mockRun, mockProtocol, input);
console.log(`Intent: ${result.intent}`);
console.log(`Reply: "${result.replyText}"`);
console.log(`State Updates: ${result.stateUpdates.length}`);
result.stateUpdates.forEach(update => {
console.log(` - ${update.type}: ${JSON.stringify(update.payload || {})}`);
});
console.log('Logs:');
result.logs.forEach(log => console.log(` 📝 ${log}`));
} catch (error) {
console.log(`❌ Pipeline Error: ${error.message}`);
}
});
console.log('\n✨ Speech rule engine testing complete!');