Skip to content

Commit 9c9bf55

Browse files
committed
unit tests added
1 parent 73e311b commit 9c9bf55

File tree

15 files changed

+3138
-198
lines changed

15 files changed

+3138
-198
lines changed

app/api/generate/[fileName]/route.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ import { NextRequest, NextResponse } from 'next/server'
22
import { readFile } from 'fs/promises'
33
import path from 'path'
44
import type { WizardResponses } from '@/types/wizard'
5-
import { getTemplateConfig } from '@/lib/template-config'
5+
import { getTemplateConfig, type TemplateKey } from '@/lib/template-config'
6+
7+
// Helper function to map output file types to template types
8+
function mapOutputFileToTemplateType(outputFile: string): string {
9+
const mapping: Record<string, string> = {
10+
'instructions-md': 'copilot-instructions',
11+
'cursor-rules': 'cursor-rules',
12+
'json-rules': 'json-rules',
13+
'agents-md': 'agents'
14+
}
15+
return mapping[outputFile] || outputFile
16+
}
617

718
export async function POST(
819
request: NextRequest,
@@ -13,7 +24,24 @@ export async function POST(
1324
const body = await request.json()
1425
const responses: WizardResponses = body
1526

16-
const templateConfig = getTemplateConfig(fileName)
27+
// Determine template configuration based on the request
28+
let templateConfig
29+
30+
// Check if this is a combination-based request
31+
if (responses.preferredIde && responses.outputFile) {
32+
const templateKey: TemplateKey = {
33+
ide: responses.preferredIde,
34+
templateType: mapOutputFileToTemplateType(responses.outputFile),
35+
framework: responses.frameworkSelection || undefined
36+
}
37+
templateConfig = getTemplateConfig(templateKey)
38+
}
39+
40+
// Fallback to legacy fileName-based approach
41+
if (!templateConfig) {
42+
templateConfig = getTemplateConfig(fileName)
43+
}
44+
1745
if (!templateConfig) {
1846
return NextResponse.json(
1947
{ error: `Template not found for fileName: ${fileName}` },

components/instructions-wizard.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import commitsData from "@/data/commits.json"
1717
import filesData from "@/data/files.json"
1818
import { InstructionsAnswerCard } from "./instructions-answer-card"
1919

20+
import { ANALYTICS_EVENTS } from "@/lib/analytics-events"
21+
import { track } from "@/lib/mixpanel"
22+
2023
const FRAMEWORK_STEP_ID = "frameworks"
2124
const FRAMEWORK_QUESTION_ID = "frameworkSelection"
2225

@@ -504,6 +507,7 @@ export function InstructionsWizard({ onClose }: InstructionsWizardProps) {
504507
}
505508

506509
const generateInstructionsFile = async () => {
510+
track(ANALYTICS_EVENTS.CREATE_INSTRUCTIONS_FILE)
507511
// Create a JSON object with question IDs as keys and their answers as values
508512
const questionsAndAnswers: WizardResponses = {
509513
preferredIde: null,
@@ -577,6 +581,14 @@ export function InstructionsWizard({ onClose }: InstructionsWizardProps) {
577581
})
578582
})
579583

584+
// Ensure we have the combination data for the API
585+
// The API will now use preferredIde + outputFile + frameworkSelection to determine the template
586+
console.log('Template combination data:', {
587+
ide: questionsAndAnswers.preferredIde,
588+
outputFile: questionsAndAnswers.outputFile,
589+
framework: questionsAndAnswers.frameworkSelection
590+
})
591+
580592
// console.log('Questions and Answers JSON:', JSON.stringify(questionsAndAnswers, null, 2))
581593

582594
// Call the API to generate the instructions file

data/files.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
"icon": "markdown",
99
"docs": "https://docs.github.com/en/copilot"
1010
},
11+
{
12+
"id": "agents-md",
13+
"label": "Agents Development Guide",
14+
"filename": "agents.md",
15+
"format": "markdown",
16+
"enabled": true,
17+
"icon": "markdown",
18+
"docs": "https://docs.github.com/en/copilot"
19+
},
1120
{
1221
"id": "cursor-rules",
1322
"label": "Cursor Rules",
@@ -25,4 +34,4 @@
2534
"icon": "json",
2635
"docs": "https://json-schema.org/"
2736
}
28-
]
37+
]

data/ides.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"enabled": true,
77
"docs": "https://code.visualstudio.com/docs",
88
"outputFiles": [
9-
"instructions-md"
9+
"instructions-md",
10+
"agents-md"
1011
]
1112
},
1213
{
@@ -41,4 +42,4 @@
4142
"json-rules"
4243
]
4344
}
44-
]
45+
]

file-templates/agents-template.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Agents Development Guide
2+
3+
This guide provides development conventions and best practices for building AI agent applications.
4+
5+
## Project Overview
6+
7+
- IDE: **{{preferredIde}}**
8+
- Framework/Language: **{{frameworkSelection}}** / **{{language}}**
9+
- Build tooling: **{{tooling}}**
10+
- Primary focus: **{{projectPriority}}**
11+
12+
## Development Standards
13+
14+
### Code Organization
15+
- File structure: **{{fileStructure}}**
16+
- Folder organization: **{{folders}}**
17+
- Naming conventions:
18+
- Variables/functions: **{{variableNaming}}**
19+
- Files: **{{fileNaming}}**
20+
- Components/classes: **{{componentNaming}}**
21+
22+
### Code Style & Quality
23+
- Code style: **{{codeStyle}}**
24+
- Export style: **{{exports}}**
25+
- Comments: **{{comments}}**
26+
- Testing:
27+
- Unit tests: **{{testingUT}}**
28+
- E2E tests: **{{testingE2E}}**
29+
30+
## Agent-Specific Patterns
31+
32+
### State Management
33+
- State handling: **{{stateManagement}}**
34+
- Data fetching: **{{dataFetching}}**
35+
36+
### API Integration
37+
- API layer: **{{apiLayer}}**
38+
- Authentication: **{{auth}}**
39+
- Validation: **{{validation}}**
40+
41+
### Performance & Monitoring
42+
- Logging: **{{logging}}**
43+
- Performance considerations: **{{reactPerf}}**
44+
45+
## Collaboration & Git
46+
47+
### Version Control
48+
- Commit style: **{{commitStyle}}**
49+
- PR rules: **{{prRules}}**
50+
51+
### Team Collaboration
52+
- Collaboration approach: **{{collaboration}}**
53+
54+
---
55+
56+
*This agents guide was generated based on your project configuration and can be customized for your specific agent development needs.*
Lines changed: 103 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,145 @@
1-
# Copilot Instructions
1+
---
2+
# Configuration for Copilot in this project
3+
applyTo: "**/*.{ts,tsx,js,jsx,md}" # apply to all code files by default
4+
---
25

3-
These instructions define how GitHub Copilot should assist in this project.
4-
They are tailored to our selected IDE, framework, and coding conventions, based on real developer practices.
6+
# Project Overview
7+
These are the conventions and guardrails Copilot should follow when generating code, tests, commits, and PRs in our project.
8+
They reflect the decisions we made (IDE, framework, language) and real-world best practices.
59

610
---
711

8-
## Environment
12+
## 1. Project Context & Priorities
13+
14+
- IDE: **{{preferredIde}}**
15+
- Framework: **{{frameworkSelection}}**
16+
- Build tooling: **{{tooling}}**
17+
- Language: **{{language}}**
918

10-
- **IDE**: {{preferredIde}}
11-
- **Framework**: {{frameworkSelection}}
12-
- **Build Tooling**: {{tooling}}
13-
- **Language**: {{language}}
19+
- Primary focus: **{{projectPriority}}**
20+
21+
> Use this context — when Copilot needs to choose between simpler vs. more optimized code, prefer what aligns with **{{projectPriority}}**.
1422
1523
---
1624

17-
## Project Priorities
25+
## 2. Naming, Style & Structure Rules
26+
27+
### Naming & Exports
1828

19-
- **Primary focus**: {{projectPriority}}
20-
- **Code style**: {{codeStyle}}
21-
- **Variable naming**: {{variableNaming}}
22-
- **File naming**: {{fileNaming}}
23-
- **Component naming**: {{componentNaming}}
24-
- **Exports**: {{exports}}
25-
- **Comments & documentation**: {{comments}}
26-
- **Collaboration rules**: {{collaboration}}
29+
- Variables, functions, object keys: **{{variableNaming}}**
30+
- Files & modules: **{{fileNaming}}**
31+
- Components, types: **{{componentNaming}}**
32+
- Always use **{{exports}}** exports style
33+
- Comments & documentation style: **{{comments}}**
34+
- Code style: follow **{{codeStyle}}**
35+
36+
### File and Folder Structure
37+
38+
- Component / UI layout organization: **{{fileStructure}}**
39+
- Styling approach: **{{styling}}**
40+
- State management: adopt **{{stateManagement}}**
41+
- API layer organization: put remote calls in **{{apiLayer}}**
42+
- Folder strategy: **{{folders}}**
43+
44+
> Copilot should not generate code outside these structures or naming patterns.
2745
2846
---
2947

30-
## Architecture & Structure
48+
## 3. Testing & Quality Assurance
49+
50+
- Unit tests: **{{testingUT}}**
51+
- E2E / integration: **{{testingE2E}}**
3152

32-
- **Component structure**: {{fileStructure}}
33-
- **Styling approach**: {{styling}}
34-
- **State management**: {{stateManagement}}
35-
- **API layer**: {{apiLayer}}
36-
- **Folder structure**: {{folders}}
53+
**Rules**
54+
- Use descriptive test names.
55+
- Always include both “happy path” and edge cases.
56+
- Avoid large tests that span too many modules.
57+
- Tests should live alongside modules (or in designated `__tests__` folder per convention).
3758

3859
---
3960

40-
## Testing
61+
## 4. Performance & Data Loading
4162

42-
- **Unit testing**: {{testingUT}}
43-
- **End-to-End (E2E) testing**: {{testingE2E}}
63+
- Data fetching approach: **{{dataFetching}}**
64+
- React performance optimizations: **{{reactPerf}}**
65+
66+
**Do**
67+
- Use pagination or limit responses.
68+
- Memoize computations or components when data is large.
69+
- Lazy-load modules/components that aren’t critical at startup.
70+
71+
**Don’t**
72+
- Fetch all data at once without constraints.
73+
- Place heavy logic in render without memoization.
4474

4575
---
4676

47-
## Performance Guidelines
77+
## 5. Security, Validation, Logging
4878

49-
- **Data fetching**: {{dataFetching}}
50-
- **React performance**: {{reactPerf}}
79+
- Secrets / auth handling: **{{auth}}**
80+
- Input validation: **{{validation}}**
81+
- Logging style: **{{logging}}**
82+
83+
**Rules**
84+
- Never embed secrets in code; always use environment variables.
85+
- Validate all incoming data (API or client side) using the chosen validation library.
86+
- Logging messages should never reveal secrets or PII.
87+
- Use structured or contextual logs (vs. free-form `console.log`) especially in production.
5188

5289
---
5390

54-
## Security Guidelines
91+
## 6. Commit & PR Conventions
92+
93+
- Commit message style: **{{commitStyle}}**
94+
- PR rules: **{{prRules}}**
5595

56-
- **Authentication & secrets**: {{auth}}
57-
- **Validation**: {{validation}}
58-
- **Logging**: {{logging}}
96+
**Do**
97+
- Write commit messages that follow the agreed style (e.g. `feat: add login`)
98+
- Keep PRs small and focused
99+
- Always link the issue or ticket
100+
- If PR introduces new API or breaking change, update the documentation
101+
102+
**Don’t**
103+
- Use vague commit messages like “fix stuff”
104+
- Combine unrelated changes in one commit or PR
59105

60106
---
61107

62-
## Commits & Pull Requests
108+
## 7. Copilot Usage Guidance
63109

64-
- **Commit style**: {{commitStyle}}
65-
- **Pull request rules**: {{prRules}}
110+
- Use Copilot to scaffold boilerplate (e.g. `useQuery`, component boilerplate), not to bypass core logic.
111+
- When writing prompts/comments for Copilot, embed **context** (e.g. expected return shape, types).
112+
- When Copilot suggests code that violates naming, structure, or validation rules – override or reject it.
113+
- For ambiguous design choices, ask for clarification in comments (e.g. “// Should this go in services or hooks?”).
114+
- Prefer completions that respect folder boundaries and import paths (don’t let Copilot propose imports from “wrong” layers).
66115

67116
---
68117

69-
## IDE-Specific Guidance
118+
## 8. IDE-Specific Rules & Settings
119+
120+
For **VS Code**:
70121

71-
For **VS Code**:
72-
- Always include a `.editorconfig`.
73-
- Enable **Prettier** and **ESLint** extensions.
74-
- Turn on `editor.formatOnSave: true`.
75-
- Suggested extensions:
76-
- `dbaeumer.vscode-eslint`
77-
- `esbenp.prettier-vscode`
78-
- `formulahendry.auto-rename-tag`
122+
- Use `.editorconfig` for consistent indent / line endings
123+
- Enable **Prettier** and **ESLint**, synced to our style rules
124+
- Set `editor.formatOnSave = true`
125+
- Suggested extensions: `dbaeumer.vscode-eslint`, `esbenp.prettier-vscode`, `formulahendry.auto-rename-tag`
126+
- Avoid conflicting formatters or duplicated rules
127+
128+
> These help Copilot suggestions align more closely with how your code will be formatted and linted.
79129
80130
---
81131

82-
## Copilot Usage Guidelines
132+
## 9. Caveats & Overrides
83133

84-
- Use Copilot to generate **boilerplate**, but always review before committing.
85-
- When writing tests, describe expected behavior clearly so Copilot can produce meaningful cases.
86-
- Prefer completions aligned with **our conventions** (naming, structure, testing).
87-
- Reject or edit Copilot suggestions that break the rules above.
134+
- If a feature is experimental or out-of-scope, document it in comments.
135+
- In rare cases, exceptions may be allowed — but always document why.
136+
- Always run linters and tests on generated code before merging.
88137

89138
---
90139

91140
## Notes
92141

93-
- This file is auto-generated by **DevContext**.
94-
- Regenerate this file whenever project priorities, frameworks, or rules change.
142+
- This instructions file was **auto-generated** based on your chosen configuration.
143+
- Regenerate it whenever your JSON configuration changes (framework, naming, testing, etc.).
144+
- You may also split this file into domain-specific `.instructions.md` files using `applyTo` frontmatter if your project grows.
145+

0 commit comments

Comments
 (0)