Skip to content

Commit 797ea57

Browse files
authored
Add safety notes and testing patterns to .NET cookbook recipes (#2026)
* Add safety notes and testing patterns to .NET cookbook recipes * Fix interactive safe testing snippets
1 parent 17b174f commit 797ea57

1 file changed

Lines changed: 135 additions & 2 deletions

File tree

cookbook/copilot-sdk/dotnet/recipe/README.md

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ dotnet run <filename>.cs
2121
| -------------------- | ------------------------------------ | ------------------------------------------ |
2222
| Error Handling | `dotnet run error-handling.cs` | Demonstrates error handling patterns |
2323
| Multiple Sessions | `dotnet run multiple-sessions.cs` | Manages multiple independent conversations |
24-
| Managing Local Files | `dotnet run managing-local-files.cs` | Organizes files using AI grouping |
25-
| PR Visualization | `dotnet run pr-visualization.cs` | Generates PR age charts |
24+
| Managing Local Files ⚠️ | `dotnet run managing-local-files.cs` | Organizes files using AI grouping |
25+
| PR Visualization ℹ️ | `dotnet run pr-visualization.cs` | Generates PR age charts |
2626
| Persisting Sessions | `dotnet run persisting-sessions.cs` | Save and resume sessions across restarts |
27+
| Accessibility Report ℹ️ | `dotnet run accessibility-report.cs` | Analyzes web page accessibility |
28+
| Ralph Loop ⚠️ | `dotnet run ralph-loop.cs` | Autonomous development loop |
2729

2830
### Examples with Arguments
2931

@@ -40,6 +42,137 @@ dotnet run pr-visualization.cs -- --repo github/copilot-sdk
4042
dotnet run managing-local-files.cs
4143
```
4244

45+
## Safety & Prerequisites
46+
47+
Some recipes have side effects or external dependencies. Expand each section for safe testing patterns and prerequisites.
48+
49+
<details>
50+
<summary><strong>⚠️ Managing Local Files</strong> — Modifies your filesystem</summary>
51+
52+
Before running on a real directory, test it on a copy first.
53+
Run these snippets from this recipe directory so the recipe path is captured before switching to the temporary folder.
54+
55+
**PowerShell:**
56+
```powershell
57+
$recipeDir = (Get-Location).Path
58+
$tempDir = New-Item -ItemType Directory -Path ([IO.Path]::Combine([IO.Path]::GetTempPath(), "copilot-test-files"))
59+
@("document1.txt", "image1.png", "data.json") | ForEach-Object {
60+
New-Item -Path "$tempDir/$_" -ItemType File
61+
}
62+
cd $tempDir
63+
dotnet run "$recipeDir/managing-local-files.cs"
64+
# Inspect results, then clean up
65+
Remove-Item $tempDir -Recurse
66+
```
67+
68+
**Bash:**
69+
```bash
70+
recipeDir=$(pwd)
71+
tempDir=$(mktemp -d)
72+
touch "$tempDir"/{document1.txt,image1.png,data.json}
73+
cd "$tempDir"
74+
dotnet run "$recipeDir/managing-local-files.cs"
75+
# Inspect results, then clean up
76+
rm -rf "$tempDir"
77+
```
78+
79+
Edit the `targetFolder` variable in the `.cs` file to point to your test directory before running.
80+
</details>
81+
82+
<details>
83+
<summary><strong>⚠️ Ralph Loop</strong> — Creates git commits and modifies files</summary>
84+
85+
Always run it in an isolated git repository first to verify behavior.
86+
Run these snippets from this recipe directory so the recipe path is captured before switching to the temporary repository.
87+
88+
**PowerShell:**
89+
```powershell
90+
$recipeDir = (Get-Location).Path
91+
$tempDir = New-Item -ItemType Directory -Path ([IO.Path]::Combine([IO.Path]::GetTempPath(), "copilot-test-repo"))
92+
cd $tempDir
93+
git init
94+
git config user.email "test@example.com"
95+
git config user.name "Test User"
96+
97+
# Create a PROMPT_task.md for the recipe to work with
98+
"# Task`nCreate a simple README" | Out-File PROMPT_task.md
99+
dotnet run "$recipeDir/ralph-loop.cs"
100+
101+
# Review commits and changes
102+
git log --oneline
103+
git diff
104+
105+
# Clean up
106+
cd ..
107+
Remove-Item $tempDir -Recurse
108+
```
109+
110+
**Bash:**
111+
```bash
112+
recipeDir=$(pwd)
113+
tempDir=$(mktemp -d)
114+
cd "$tempDir"
115+
git init
116+
git config user.email "test@example.com"
117+
git config user.name "Test User"
118+
119+
# Create a PROMPT_task.md for the recipe to work with
120+
echo -e "# Task\nCreate a simple README" > PROMPT_task.md
121+
dotnet run "$recipeDir/ralph-loop.cs"
122+
123+
# Review commits and changes
124+
git log --oneline
125+
git diff
126+
127+
# Clean up
128+
cd ..
129+
rm -rf "$tempDir"
130+
```
131+
132+
The recipe requires a git repository with at least one `PROMPT_*.md` file and will run in an infinite loop until manually stopped.
133+
</details>
134+
135+
<details>
136+
<summary><strong>ℹ️ Accessibility Report</strong> — Requires Playwright MCP</summary>
137+
138+
This recipe requires Playwright MCP to be installed and available:
139+
140+
```bash
141+
npm install -g @playwright/mcp
142+
```
143+
144+
Or let Node Package Manager install it on-demand. The recipe will attempt to launch `npx @playwright/mcp` automatically. Run the recipe as normal:
145+
146+
```bash
147+
dotnet run accessibility-report.cs
148+
```
149+
150+
The recipe will prompt you for a URL to analyze and generate an accessibility report.
151+
</details>
152+
153+
<details>
154+
<summary><strong>ℹ️ PR Visualization</strong> — Requires GitHub API access</summary>
155+
156+
This recipe requires:
157+
158+
- Access to a GitHub repository (public or private, with appropriate credentials)
159+
- `gh` CLI tool installed and authenticated: https://cli.github.com/
160+
161+
Run with a repository argument:
162+
163+
```bash
164+
dotnet run pr-visualization.cs -- --repo owner/repo-name
165+
```
166+
167+
Example:
168+
169+
```bash
170+
dotnet run pr-visualization.cs -- --repo github/copilot-sdk
171+
```
172+
173+
**Note:** GitHub API requests are rate-limited. Large repositories or frequent runs may hit rate limits. See [GitHub API rate limiting](https://docs.github.com/rest/overview/rate-limits-for-the-rest-api) for details.
174+
</details>
175+
43176
## File-Based Apps
44177

45178
These examples use .NET's file-based app feature, which allows single-file C# programs to:

0 commit comments

Comments
 (0)