Skip to content

Commit 8af896a

Browse files
CopilotMohabMohie
andcommitted
Fix security vulnerabilities and add demonstration of new approach
Co-authored-by: MohabMohie <[email protected]>
1 parent bd078c6 commit 8af896a

File tree

4 files changed

+526
-129
lines changed

4 files changed

+526
-129
lines changed

demo-autobot-approach.mjs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Demonstration script to show that the new AutoBot approach works
4+
* This script demonstrates:
5+
* 1. Documentation loading works correctly
6+
* 2. Enhanced system instruction is generated properly
7+
* 3. Key SHAFT topics are included in the context
8+
*/
9+
10+
import { loadDocumentation, getGitHubRepositoryContext } from './netlify/functions/docs-loader.mjs';
11+
12+
console.log('===========================================');
13+
console.log('AutoBot Documentation-Based Approach Demo');
14+
console.log('===========================================\n');
15+
16+
// Step 1: Load Documentation
17+
console.log('Step 1: Loading Documentation...');
18+
console.log('─────────────────────────────────────────');
19+
const startTime = Date.now();
20+
const documentation = loadDocumentation();
21+
const githubContext = getGitHubRepositoryContext();
22+
const loadTime = Date.now() - startTime;
23+
24+
if (!documentation || !githubContext) {
25+
console.error('❌ FAILED: Could not load documentation');
26+
process.exit(1);
27+
}
28+
29+
console.log(`✅ SUCCESS: Loaded ${documentation.length.toLocaleString()} characters in ${loadTime}ms`);
30+
console.log(` - Documentation: ${documentation.length.toLocaleString()} chars`);
31+
console.log(` - GitHub Context: ${githubContext.length.toLocaleString()} chars`);
32+
console.log();
33+
34+
// Step 2: Show what's included
35+
console.log('Step 2: Documentation Content Analysis');
36+
console.log('─────────────────────────────────────────');
37+
38+
// Count documents
39+
const docCount = (documentation.match(/## Document:/g) || []).length;
40+
console.log(`✅ Loaded ${docCount} documentation files`);
41+
42+
// Show key topics included
43+
const keyTopics = {
44+
'Web/GUI Testing': documentation.includes('Element_Actions'),
45+
'API Testing': documentation.includes('Request_Builder'),
46+
'Mobile Testing': documentation.includes('mobile'),
47+
'Database Testing': documentation.includes('DB_Actions'),
48+
'CLI Testing': documentation.includes('Terminal_Actions'),
49+
'Configuration': documentation.includes('properties'),
50+
'Validations': documentation.includes('Validations'),
51+
'Browser Actions': documentation.includes('Browser_Actions'),
52+
};
53+
54+
console.log('\n📚 Key Topics Included:');
55+
for (const [topic, included] of Object.entries(keyTopics)) {
56+
console.log(` ${included ? '✅' : '❌'} ${topic}`);
57+
}
58+
console.log();
59+
60+
// Step 3: Show sample content
61+
console.log('Step 3: Sample Documentation Content');
62+
console.log('─────────────────────────────────────────');
63+
64+
// Find and show a sample from API documentation
65+
const apiDocStart = documentation.indexOf('## Document: Keywords/API/Request_Builder.md');
66+
if (apiDocStart > -1) {
67+
const apiSample = documentation.substring(apiDocStart, apiDocStart + 500);
68+
console.log('Sample from API Request Builder documentation:\n');
69+
console.log(apiSample);
70+
console.log('...\n');
71+
}
72+
73+
// Step 4: Enhanced System Instruction
74+
console.log('Step 4: Enhanced System Instruction Generation');
75+
console.log('─────────────────────────────────────────');
76+
77+
const systemInstruction = 'You are AutoBot, a helpful SHAFT assistant.';
78+
const enhancedSystemInstruction = `${documentation}\n\n${githubContext}\n\n---\n\n${systemInstruction}\n\nIMPORTANT: Use ONLY the documentation provided above.`;
79+
80+
console.log(`✅ Enhanced instruction length: ${enhancedSystemInstruction.length.toLocaleString()} characters`);
81+
console.log(` - Within Gemini limit (500KB): ${enhancedSystemInstruction.length < 500000 ? 'YES ✅' : 'NO ❌'}`);
82+
console.log(` - Includes full documentation: ${enhancedSystemInstruction.includes('SHAFT Engine User Guide') ? 'YES ✅' : 'NO ❌'}`);
83+
console.log(` - Includes GitHub context: ${enhancedSystemInstruction.includes('github.com/ShaftHQ') ? 'YES ✅' : 'NO ❌'}`);
84+
console.log();
85+
86+
// Step 5: Demonstrate searchable content
87+
console.log('Step 5: Demonstrate Question-Answer Capability');
88+
console.log('─────────────────────────────────────────');
89+
90+
const sampleQuestions = [
91+
{ q: 'How to create an API instance?', search: 'SHAFT.API' },
92+
{ q: 'How to perform browser actions?', search: 'Browser_Actions' },
93+
{ q: 'How to configure SHAFT?', search: 'properties' },
94+
{ q: 'How to validate elements?', search: 'Element_Validations' },
95+
];
96+
97+
console.log('Sample questions that can be answered from the loaded documentation:\n');
98+
for (const { q, search } of sampleQuestions) {
99+
const canAnswer = documentation.includes(search);
100+
console.log(`Q: "${q}"`);
101+
console.log(` ${canAnswer ? '✅' : '❌'} Information available (contains "${search}")\n`);
102+
}
103+
104+
// Step 6: Show the difference from old approach
105+
console.log('Step 6: Comparison with Old Approach');
106+
console.log('─────────────────────────────────────────');
107+
console.log('OLD APPROACH (Google Search Grounding):');
108+
console.log(' ❌ Fetches data from internet at runtime');
109+
console.log(' ❌ May include third-party sources');
110+
console.log(' ❌ Results can vary based on search results');
111+
console.log(' ❌ Depends on external Google Search API');
112+
console.log(' ❌ Cannot trace answer to specific documentation');
113+
console.log();
114+
console.log('NEW APPROACH (Local Documentation):');
115+
console.log(' ✅ Uses only official SHAFT documentation');
116+
console.log(' ✅ No external API calls during queries');
117+
console.log(' ✅ Consistent, reproducible answers');
118+
console.log(' ✅ All answers traceable to docs');
119+
console.log(' ✅ Documentation loaded once and cached');
120+
console.log();
121+
122+
// Summary
123+
console.log('===========================================');
124+
console.log('Summary');
125+
console.log('===========================================');
126+
console.log(`✅ Documentation loaded successfully (${docCount} files)`);
127+
console.log(`✅ Enhanced instruction generated (${(enhancedSystemInstruction.length / 1024).toFixed(1)} KB)`);
128+
console.log(`✅ All key SHAFT topics included`);
129+
console.log(`✅ Ready to provide accurate, documentation-based answers`);
130+
console.log('✅ No internet searches or external dependencies');
131+
console.log('\n🎉 The new AutoBot approach is working correctly!\n');

demo-output.txt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
===========================================
2+
AutoBot Documentation-Based Approach Demo
3+
===========================================
4+
5+
Step 1: Loading Documentation...
6+
─────────────────────────────────────────
7+
[Documentation Loader] Successfully loaded 41 documentation files
8+
✅ SUCCESS: Loaded 240,202 characters in 5ms
9+
- Documentation: 240,202 chars
10+
- GitHub Context: 1,082 chars
11+
12+
Step 2: Documentation Content Analysis
13+
─────────────────────────────────────────
14+
✅ Loaded 41 documentation files
15+
16+
📚 Key Topics Included:
17+
✅ Web/GUI Testing
18+
✅ API Testing
19+
✅ Mobile Testing
20+
✅ Database Testing
21+
✅ CLI Testing
22+
✅ Configuration
23+
✅ Validations
24+
✅ Browser Actions
25+
26+
Step 3: Sample Documentation Content
27+
─────────────────────────────────────────
28+
Sample from API Request Builder documentation:
29+
30+
## Document: Keywords/API/Request_Builder.md
31+
32+
---
33+
id: Request_Builder
34+
title: Request Builder
35+
sidebar_label: Builder
36+
---
37+
38+
## SHAFT API
39+
40+
In order to interact with APIs, you need an instance of SHAFT.API class and give it the base serviceURI
41+
42+
```java
43+
import com.shaft.driver.SHAFT;
44+
45+
SHAFT.API api = new SHAFT.API("https://jsonplaceholder.typicode.com");
46+
```
47+
Now you have api object with the base serviceURI to start working with it with the Request Builder
48+
49+
## Request Builder
50+
51+
Now you can start buildin
52+
...
53+
54+
Step 4: Enhanced System Instruction Generation
55+
─────────────────────────────────────────
56+
✅ Enhanced instruction length: 241,391 characters
57+
- Within Gemini limit (500KB): YES ✅
58+
- Includes full documentation: YES ✅
59+
- Includes GitHub context: YES ✅
60+
61+
Step 5: Demonstrate Question-Answer Capability
62+
─────────────────────────────────────────
63+
Sample questions that can be answered from the loaded documentation:
64+
65+
Q: "How to create an API instance?"
66+
✅ Information available (contains "SHAFT.API")
67+
68+
Q: "How to perform browser actions?"
69+
✅ Information available (contains "Browser_Actions")
70+
71+
Q: "How to configure SHAFT?"
72+
✅ Information available (contains "properties")
73+
74+
Q: "How to validate elements?"
75+
✅ Information available (contains "Element_Validations")
76+
77+
Step 6: Comparison with Old Approach
78+
─────────────────────────────────────────
79+
OLD APPROACH (Google Search Grounding):
80+
❌ Fetches data from internet at runtime
81+
❌ May include third-party sources
82+
❌ Results can vary based on search results
83+
❌ Depends on external Google Search API
84+
❌ Cannot trace answer to specific documentation
85+
86+
NEW APPROACH (Local Documentation):
87+
✅ Uses only official SHAFT documentation
88+
✅ No external API calls during queries
89+
✅ Consistent, reproducible answers
90+
✅ All answers traceable to docs
91+
✅ Documentation loaded once and cached
92+
93+
===========================================
94+
Summary
95+
===========================================
96+
✅ Documentation loaded successfully (41 files)
97+
✅ Enhanced instruction generated (235.7 KB)
98+
✅ All key SHAFT topics included
99+
✅ Ready to provide accurate, documentation-based answers
100+
✅ No internet searches or external dependencies
101+
102+
🎉 The new AutoBot approach is working correctly!
103+

0 commit comments

Comments
 (0)