Project Files
tools / generate-test-data.js
/**
* generate-test-data.js — Генератор тестовых данных для RAG
*
* Создает набор файлов с известным содержимым для проверки работы поиска.
*
* Использование:
* node generate-test-data.js [output-directory]
*
* Примеры:
* node generate-test-data.js
* node generate-test-data.js C:\test-docs
*/
import fs from "fs";
import path from "path";
function ensureDir(dirPath) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}
function writeFile(dir, name, content) {
const filePath = path.join(dir, name);
fs.writeFileSync(filePath, content, "utf-8");
console.log(` ✅ ${name} (${content.length} chars)`);
}
function generateTestData(outputDir) {
ensureDir(outputDir);
console.log(`📁 Generating test data in: ${outputDir}\n`);
// 1. Документация API
writeFile(outputDir, "api-documentation.md", `# API Documentation — MyProject v2.0
## Authentication
All API requests require authentication using an API key. Include the key in the Authorization header:
\`\`\`
Authorization: Bearer YOUR_API_KEY
\`\`\`
To obtain an API key, visit the developer portal at https://myproject.dev/keys.
## Rate Limits
- Free tier: 100 requests per minute
- Pro tier: 1,000 requests per minute
- Enterprise: Unlimited
## Endpoints
### GET /api/v2/users
Returns a list of all users in your organization.
**Parameters:**
- \`page\` (integer): Page number (default: 1)
- \`limit\` (integer): Items per page (default: 20, max: 100)
- \`sort\` (string): Sort field — "name", "created_at", "email"
**Response:**
\`\`\`json
{
"users": [
{ "id": 1, "name": "Alice", "email": "alice@example.com" },
{ "id": 2, "name": "Bob", "email": "bob@example.com" }
],
"total": 42,
"page": 1
}
\`\`\`
### POST /api/v2/users
Creates a new user.
**Request body:**
\`\`\`json
{
"name": "Charlie",
"email": "charlie@example.com",
"role": "member"
}
\`\`\`
**Roles:** admin, editor, member, viewer
### DELETE /api/v2/users/:id
Deletes a user by ID. Requires admin role.
### GET /api/v2/projects
Returns all projects accessible to the authenticated user.
**Parameters:**
- \`status\` (string): Filter by status — "active", "archived", "draft"
- \`owner\` (integer): Filter by owner user ID
### POST /api/v2/projects
Creates a new project.
**Request body:**
\`\`\`json
{
"name": "My Project",
"description": "A test project",
"visibility": "private"
}
\`\`\`
**Visibility options:** public, private, team
## Error Codes
| Code | Description |
|------|-------------|
| 400 | Bad Request — Invalid parameters |
| 401 | Unauthorized — Invalid or missing API key |
| 403 | Forbidden — Insufficient permissions |
| 404 | Not Found — Resource does not exist |
| 429 | Too Many Requests — Rate limit exceeded |
| 500 | Internal Server Error |
## Webhooks
Register webhook URLs to receive real-time notifications:
\`\`\`
POST /api/v2/webhooks
{
"url": "https://your-server.com/webhook",
"events": ["user.created", "project.updated"]
}
\`\`\`
**Supported events:**
- user.created
- user.deleted
- project.created
- project.updated
- project.deleted
- payment.received
`);
// 2. Конфигурация
writeFile(outputDir, "config.json", JSON.stringify({
"app": {
"name": "MyProject",
"version": "2.0.0",
"environment": "production",
"port": 3000,
"host": "0.0.0.0"
},
"database": {
"host": "db.myproject.internal",
"port": 5432,
"name": "myproject_prod",
"user": "app_user",
"pool_size": 20,
"ssl": true
},
"redis": {
"host": "cache.myproject.internal",
"port": 6379,
"db": 0
},
"logging": {
"level": "info",
"format": "json",
"output": ["stdout", "file"],
"file_path": "/var/log/myproject/app.log"
},
"features": {
"enable_notifications": true,
"enable_analytics": true,
"enable_beta_features": false,
"max_upload_size_mb": 50
}
}, null, 2));
// 3. Заметки о встречах
writeFile(outputDir, "meeting-notes.md", `# Meeting Notes — Q1 2025
## 2025-01-15 — Planning Meeting
**Attendees:** Alice, Bob, Charlie, Diana
**Agenda:**
1. Review Q4 results
2. Set Q1 goals
3. Assign responsibilities
**Decisions:**
- Launch new API v2 by March 1st
- Hire 2 backend developers
- Migrate database to PostgreSQL 16
**Action Items:**
- [ ] Alice: Prepare API specification by Jan 30
- [ ] Bob: Interview candidates for backend positions
- [ ] Charlie: Set up staging environment
- [ ] Diana: Update documentation
---
## 2025-02-01 — Progress Review
**Attendees:** Alice, Bob, Charlie
**Updates:**
- API v2 is 60% complete
- Authentication module finished
- Rate limiting implemented
- Documentation draft ready
**Blockers:**
- Waiting for design team to provide new UI mockups
- Database migration script needs testing
**Next Steps:**
- Complete user management endpoints by Feb 15
- Start integration testing
- Prepare demo for stakeholders
---
## 2025-02-20 — Final Sprint Planning
**Attendees:** Alice, Bob, Charlie, Diana
**Status:**
- API v2 is 85% complete
- 3 out of 5 endpoints fully tested
- Documentation review in progress
**Remaining Tasks:**
- Finish webhook implementation
- Write integration tests
- Performance optimization
- Security audit
**Launch Date:** March 1st, 2025 (confirmed)
`);
// 4. Примеры кода
writeFile(outputDir, "code-examples.py", `"""
MyProject API Client — Python Examples
Version: 2.0
"""
import requests
import json
class APIClient:
"""Client for MyProject API v2."""
BASE_URL = "https://api.myproject.dev/v2"
def __init__(self, api_key: str):
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
})
def get_users(self, page: int = 1, limit: int = 20):
"""Get list of users."""
response = self.session.get(
f"{self.BASE_URL}/users",
params={"page": page, "limit": limit}
)
response.raise_for_status()
return response.json()
def create_user(self, name: str, email: str, role: str = "member"):
"""Create a new user."""
data = {"name": name, "email": email, "role": role}
response = self.session.post(f"{self.BASE_URL}/users", json=data)
response.raise_for_status()
return response.json()
def delete_user(self, user_id: int):
"""Delete a user by ID."""
response = self.session.delete(f"{self.BASE_URL}/users/{user_id}")
response.raise_for_status()
return response.status_code == 200
def get_projects(self, status: str = None, owner: int = None):
"""Get list of projects."""
params = {}
if status:
params["status"] = status
if owner:
params["owner"] = owner
response = self.session.get(f"{self.BASE_URL}/projects", params=params)
response.raise_for_status()
return response.json()
def create_project(self, name: str, description: str = "", visibility: str = "private"):
"""Create a new project."""
data = {"name": name, "description": description, "visibility": visibility}
response = self.session.post(f"{self.BASE_URL}/projects", json=data)
response.raise_for_status()
return response.json()
# Usage example
if __name__ == "__main__":
client = APIClient(api_key="your-api-key-here")
# Get users
users = client.get_users(page=1, limit=10)
print(f"Found {users['total']} users")
# Create a user
new_user = client.create_user(
name="Test User",
email="test@example.com",
role="member"
)
print(f"Created user: {new_user}")
# Create a project
project = client.create_project(
name="My Test Project",
description="A project for testing",
visibility="private"
)
print(f"Created project: {project}")
`);
// 5. README
writeFile(outputDir, "README.md", `# MyProject
A modern API platform for managing users and projects.
## Quick Start
\`\`\`bash
# Install dependencies
npm install
# Start the server
npm start
# Run tests
npm test
\`\`\`
## Project Structure
\`\`\`
myproject/
├── src/
│ ├── api/ # API endpoints
│ ├── models/ # Database models
│ ├── middleware/ # Auth, logging, etc.
│ └── utils/ # Helper functions
├── tests/ # Test files
├── docs/ # Documentation
├── config/ # Configuration files
└── package.json
\`\`\`
## Requirements
- Node.js 18+
- PostgreSQL 15+
- Redis 7+
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| DATABASE_URL | PostgreSQL connection string | - |
| REDIS_URL | Redis connection string | redis://localhost:6379 |
| API_KEY | Secret key for JWT | - |
| PORT | Server port | 3000 |
| NODE_ENV | Environment | development |
## License
MIT License — Copyright 2025 MyProject Inc.
`);
// 6. ЧАВО (FAQ)
writeFile(outputDir, "faq.txt", `Часто задаваемые вопросы (FAQ)
В: Как получить API ключ?
О: Зарегистрируйтесь на developer.myproject.dev и перейдите в раздел "API Keys".
В: Какой лимит запросов для бесплатного тарифа?
О: 100 запросов в минуту. Для увеличения лимита перейдите на Pro тариф.
В: Поддерживается ли GraphQL?
О: Нет, в данный момент поддерживается только REST API. GraphQL планируется в версии 3.0.
В: Как сбросить API ключ?
О: Перейдите в настройки аккаунта → Security → Regenerate API Key. Старый ключ перестанет работать немедленно.
В: Какие форматы данных поддерживаются?
О: JSON для запросов и ответов. CSV доступен для экспорта списков пользователей.
В: Как настроить вебхуки?
О: Используйте endpoint POST /api/v2/webhooks. Укажите URL и список событий.
В: Есть ли SDK для Python?
О: Да, установите через pip: pip install myproject-sdk
В: Как связаться с поддержкой?
О: support@myproject.dev или через чат в developer portal.
В: Где найти changelog?
О: https://myproject.dev/changelog
В: Как удалить аккаунт?
О: Settings → Account → Delete Account. Все данные будут удалены в течение 30 дней.
`);
// 7. Лог-файл
writeFile(outputDir, "server.log", `[2025-03-01 08:00:01] INFO Server starting on port 3000
[2025-03-01 08:00:02] INFO Connected to database: db.myproject.internal:5432/myproject_prod
[2025-03-01 08:00:02] INFO Connected to Redis: cache.myproject.internal:6379
[2025-03-01 08:00:03] INFO Server ready — accepting connections
[2025-03-01 08:15:22] INFO GET /api/v2/users — 200 — 45ms — IP: 192.168.1.10
[2025-03-01 08:15:25] INFO POST /api/v2/users — 201 — 120ms — IP: 192.168.1.10
[2025-03-01 08:20:01] WARN Rate limit approaching for API key: sk_test_*** — 85/100 requests
[2025-03-01 08:20:15] ERROR POST /api/v2/users — 400 — Invalid email format — IP: 10.0.0.5
[2025-03-01 08:25:30] INFO GET /api/v2/projects — 200 — 32ms — IP: 192.168.1.10
[2025-03-01 08:30:00] INFO Webhook delivered: user.created -> https://your-server.com/webhook — 200
[2025-03-01 08:35:12] ERROR GET /api/v2/users/999 — 404 — User not found — IP: 192.168.1.10
[2025-03-01 08:40:00] INFO GET /api/v2/projects?status=active — 200 — 28ms — IP: 192.168.1.10
[2025-03-01 08:45:55] WARN Database connection pool: 18/20 connections in use
[2025-03-01 08:50:01] INFO POST /api/v2/webhooks — 201 — 55ms — IP: 192.168.1.10
[2025-03-01 09:00:00] INFO Health check: all services operational
`);
// 8. CSV данные
writeFile(outputDir, "users.csv", `id,name,email,role,created_at,status
1,Alice Johnson,alice@example.com,admin,2024-01-15,active
2,Bob Smith,bob@example.com,editor,2024-02-20,active
3,Charlie Brown,charlie@example.com,member,2024-03-10,active
4,Diana Prince,diana@example.com,admin,2024-04-05,active
5,Eve Wilson,eve@example.com,viewer,2024-05-18,inactive
6,Frank Castle,frank@example.com,member,2024-06-22,active
7,Grace Hopper,grace@example.com,editor,2024-07-30,active
8,Hank Pym,hank@example.com,member,2024-08-14,inactive
9,Iris West,iris@example.com,viewer,2024-09-01,active
10,Jack Ryan,jack@example.com,member,2024-10-25,active
`);
// 9. YAML конфиг
writeFile(outputDir, "docker-compose.yaml", `version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://app_user:password@db:5432/myproject_prod
- REDIS_URL=redis://cache:6379
- NODE_ENV=production
depends_on:
- db
- cache
restart: unless-stopped
db:
image: postgres:16
environment:
- POSTGRES_DB=myproject_prod
- POSTGRES_USER=app_user
- POSTGRES_PASSWORD=password
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
cache:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
pgdata:
`);
// 10. HTML страница (для теста очистки)
writeFile(outputDir, "about-page.html", `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About MyProject</title>
<script>console.log("analytics")</script>
<style>.hidden { display: none; }</style>
</head>
<body>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/docs">Docs</a>
</nav>
<header>
<h1>About MyProject</h1>
</header>
<main>
<p>MyProject is a modern API platform launched in 2024.</p>
<h2>Our Mission</h2>
<p>We make API development simple and accessible for everyone.</p>
<h2>Team</h2>
<ul>
<li>Alice Johnson — CEO & Founder</li>
<li>Bob Smith — Lead Developer</li>
<li>Charlie Brown — DevOps Engineer</li>
<li>Diana Prince — Head of Product</li>
</ul>
<h2>Contact</h2>
<p>Email: <a href="mailto:info@myproject.dev">info@myproject.dev</a></p>
<p>Address: 123 API Street, San Francisco, CA 94102</p>
</main>
<footer>
<p>© 2025 MyProject Inc. All rights reserved.</p>
</footer>
</body>
</html>`);
console.log(`\n🎉 Generated 10 test files in: ${outputDir}`);
console.log("\n📋 Files created:");
console.log(" 1. api-documentation.md — API docs with endpoints");
console.log(" 2. config.json — Application configuration");
console.log(" 3. meeting-notes.md — Meeting notes Q1 2025");
console.log(" 4. code-examples.py — Python API client");
console.log(" 5. README.md — Project overview");
console.log(" 6. faq.txt — FAQ in Russian");
console.log(" 7. server.log — Server log entries");
console.log(" 8. users.csv — User data table");
console.log(" 9. docker-compose.yaml — Docker configuration");
console.log(" 10. about-page.html — HTML page (for cleaning test)");
console.log("\n💡 Next step: Load these into RAG with:");
console.log(` rag_load_documents { directory: "${outputDir}" }`);
}
// --- CLI ---
const outputDir = process.argv[2] || path.join(process.cwd(), "test-docs");
generateTestData(outputDir);