Skip to content

Commit 30e2a07

Browse files
naoki1213mjCopilot
andcommitted
feat: add Copilot agents, instructions, skills, and security fixes
- Add 5 custom agents (data-validator, doc-writer, documentor, error-handler, reviewer) - Add 3 instruction files (python-style, test-standards, data-quality) - Add 2 skills (security-audit, pr-review) - Fix security issues in books.py (logging, encoding, temp file handling) - Update test mock to match new tempfile.mkstemp usage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a962436 commit 30e2a07

12 files changed

Lines changed: 367 additions & 7 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Analyzes JSON data files for missing or malformed entries
3+
---
4+
5+
You analyze JSON data files for missing or malformed entries.
6+
7+
**Focus areas:**
8+
- Empty or missing author fields
9+
- Invalid years (year=0, future years, negative years)
10+
- Missing required fields (title, author, year, read)
11+
- Duplicate entries

.github/agents/doc-writer.agent.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Technical writer for clear Python documentation
3+
---
4+
5+
You are a technical writer who creates clear Python documentation.
6+
7+
**Standards:**
8+
- Google-style docstrings
9+
- Include parameter types and return values
10+
- Add usage examples for public methods
11+
- Note any exceptions raised

.github/agents/documentor.agent.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: documentor
3+
description: Technical writer for clear and complete documentation
4+
---
5+
6+
# Documentation Agent
7+
8+
You are a technical writer who creates clear documentation.
9+
10+
**Documentation standards:**
11+
- Start with a one-sentence summary
12+
- Include usage examples
13+
- Document parameters and return values
14+
- Note any gotchas or limitations
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Reviews Python code for error handling consistency
3+
---
4+
5+
You review Python code for error handling consistency.
6+
7+
**Standards:**
8+
- No bare except clauses
9+
- Use custom exceptions where appropriate
10+
- All file operations use context managers
11+
- Consistent return types for success/failure

.github/agents/reviewer.agent.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: reviewer
3+
description: Senior code reviewer focused on security and best practices
4+
---
5+
6+
# Code Reviewer Agent
7+
8+
You are a senior code reviewer focused on code quality.
9+
10+
**Review priorities:**
11+
1. Security vulnerabilities
12+
2. Performance issues
13+
3. Maintainability concerns
14+
4. Best practice violations
15+
16+
**Output format:**
17+
Provide issues as a numbered list with severity tags:
18+
[CRITICAL], [HIGH], [MEDIUM], [LOW]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
description: JSON データエントリのバリデーション規約
3+
applyTo: "samples/**/data.json"
4+
---
5+
6+
# データ品質ガイドライン
7+
8+
`data.json` の書籍エントリは以下のバリデーション規約に従ってください。
9+
10+
## 必須フィールド
11+
12+
すべてのエントリに以下の4フィールドが必要です:
13+
14+
| フィールド || 制約 |
15+
|---|---|---|
16+
| `title` | string | 空文字・空白のみは不可 |
17+
| `author` | string | 空文字・空白のみは不可 |
18+
| `year` | number (整数) | `0 ≤ year ≤ 現在年 + 1` |
19+
| `read` | boolean | `true` または `false` |
20+
21+
## 有効なエントリの例
22+
23+
```json
24+
{
25+
"title": "1984",
26+
"author": "George Orwell",
27+
"year": 1949,
28+
"read": true
29+
}
30+
```
31+
32+
## 無効なエントリの例
33+
34+
```json
35+
// ❌ 著者が空
36+
{ "title": "Unknown Book", "author": "", "year": 2020, "read": false }
37+
38+
// ❌ 年が負数
39+
{ "title": "Bad Year", "author": "Author", "year": -1, "read": false }
40+
41+
// ❌ 年が未来すぎる(現在年+1 を超える)
42+
{ "title": "Future Book", "author": "Author", "year": 2099, "read": false }
43+
44+
// ❌ 必須フィールド(read)が欠落
45+
{ "title": "No Status", "author": "Author", "year": 2020 }
46+
```
47+
48+
## バリデーションチェックリスト
49+
50+
データファイルを編集・作成する際に確認すること:
51+
52+
- [ ] すべてのエントリに `title`, `author`, `year`, `read` の4フィールドがある
53+
- [ ] `title``author` が空文字でない
54+
- [ ] `year` が 0 以上かつ来年以下の整数である
55+
- [ ] `read``true` または `false`(文字列ではなく boolean)である
56+
- [ ] 同一タイトルの重複エントリがない
57+
- [ ] ファイル全体が有効な JSON 配列 `[...]` である
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
description: PEP 8 準拠と型ヒントの規約
3+
applyTo: "samples/**/*.py"
4+
---
5+
6+
# Python スタイルガイド
7+
8+
このプロジェクトの Python コードは以下の規約に従ってください。
9+
10+
## インポート
11+
12+
- ファイル先頭に `from __future__ import annotations` を記述する
13+
- 標準ライブラリ → サードパーティ → ローカルの順でグループ化する
14+
- 各グループ間は空行で区切る
15+
16+
```python
17+
from __future__ import annotations
18+
19+
import json
20+
from dataclasses import dataclass, asdict
21+
from datetime import datetime
22+
```
23+
24+
## 型ヒント
25+
26+
- すべての関数に引数の型と戻り値の型を注釈する
27+
- モダンな構文を使用する: `list[Book]``List[Book]` ではなく)
28+
- Union 型は `|` 演算子を使用する: `Book | None``Optional[Book]` ではなく)
29+
30+
```python
31+
def find_by_title(self, title: str) -> Book | None:
32+
```
33+
34+
## 命名規約
35+
36+
- 定数: `UPPER_SNAKE_CASE`(例: `DATA_FILE`
37+
- クラス: `PascalCase`(例: `BookCollection`
38+
- 関数・メソッド: `snake_case`(例: `add_book`
39+
- プライベートメソッド: `_` プレフィックス(例: `_read_json`
40+
- 例外クラス: `<Domain>Error` パターン(例: `BookValidationError`
41+
42+
## ドキュメンテーション
43+
44+
- Google スタイルの docstring を使用する
45+
- `Args:`, `Returns:`, `Raises:` セクションを含める
46+
- パブリックメソッドには `Example:` セクション(doctest 形式)を含める
47+
48+
```python
49+
def add_book(self, title: str, author: str, year: int) -> Book:
50+
"""Add a new book to the collection and persist the change.
51+
52+
Args:
53+
title: The book's title. Must not be empty.
54+
author: The author's name. Must not be empty.
55+
year: The publication year.
56+
57+
Returns:
58+
The newly created Book instance.
59+
60+
Raises:
61+
BookValidationError: If validation fails.
62+
63+
Example:
64+
>>> collection.add_book("1984", "George Orwell", 1949)
65+
"""
66+
```
67+
68+
## データモデル
69+
70+
- データクラスには `@dataclass` デコレータを使用する
71+
- 例外は専用の基底クラスから継承する階層にする
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
description: テストファイルでの pytest 規約
3+
applyTo: "samples/**/test_*.py,samples/**/tests/**/*.py"
4+
---
5+
6+
# テスト規約(pytest)
7+
8+
このプロジェクトのテストコードは以下の pytest 規約に従ってください。
9+
10+
## ファイル・関数の命名
11+
12+
- テストファイル: `test_<module>.py`
13+
- テスト関数: `test_<feature>_<scenario>`(例: `test_add_book_empty_title`
14+
- テストクラス: `Test<Feature><Scenario>`(関連シナリオのグループ化用)
15+
16+
```python
17+
class TestFindByAuthorPartialMatch:
18+
"""Substring of the author name should still find matching books."""
19+
```
20+
21+
## フィクスチャ
22+
23+
- `@pytest.fixture()` を使用し、説明的な名前をつける
24+
- テストファイルの分離には `tmp_path` を使用する
25+
- フィクスチャの連鎖で複雑なセットアップを構築する
26+
27+
```python
28+
@pytest.fixture()
29+
def collection(tmp_path):
30+
"""Create a BookCollection with temporary storage."""
31+
temp_file = tmp_path / "data.json"
32+
temp_file.write_text("[]")
33+
return BookCollection(data_file=str(temp_file))
34+
35+
@pytest.fixture()
36+
def orwell_collection(collection):
37+
"""Collection pre-loaded with two George Orwell books."""
38+
collection.add_book("1984", "George Orwell", 1949)
39+
collection.add_book("Animal Farm", "George Orwell", 1945)
40+
return collection
41+
```
42+
43+
## アサーション
44+
45+
- シンプルな `assert` 文を使用する(`self.assertEqual` ではなく)
46+
- 例外テストには `pytest.raises``match` パラメータ付きで使用する
47+
- 出力キャプチャには `capsys` フィクスチャを使用する
48+
49+
```python
50+
def test_add_book_empty_title(collection):
51+
with pytest.raises(BookValidationError, match="Title cannot be empty"):
52+
collection.add_book("", "Author", 2020)
53+
```
54+
55+
```python
56+
def test_handle_add_output(mock_input, mock_collection, capsys):
57+
book_app.handle_add()
58+
output = capsys.readouterr().out
59+
assert "Book added successfully" in output
60+
```
61+
62+
## モック
63+
64+
- `@patch()` デコレータで外部依存をモックする
65+
- `side_effect` でユーザー入力をシミュレーションする
66+
- `assert_called_once_with` で呼び出しを検証する
67+
68+
```python
69+
@patch("book_app.collection")
70+
@patch("builtins.input", side_effect=["The Hobbit", "Tolkien", "1937"])
71+
def test_handle_add_valid_input(mock_input, mock_collection, capsys):
72+
book_app.handle_add()
73+
mock_collection.add_book.assert_called_once_with("The Hobbit", "Tolkien", 1937)
74+
```
75+
76+
## テスト構成
77+
78+
- 論理セクションをコメントで区切る: `# --- Adding Books ---`
79+
- 1テスト1アサーション(関連する検証はまとめてよい)
80+
- テスト間の状態汚染を防ぐため `tmp_path` で分離する

.github/skills/pr-review/SKILL.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: pr-review
3+
description: Team-standard PR review checklist
4+
---
5+
6+
# PR Review
7+
8+
Review code changes against team standards:
9+
10+
## Security Checklist
11+
- [ ] No hardcoded secrets or API keys
12+
- [ ] Input validation on all user data
13+
- [ ] No bare except clauses
14+
- [ ] No sensitive data in logs
15+
16+
## Code Quality
17+
- [ ] Functions under 50 lines
18+
- [ ] No print statements in production code
19+
- [ ] Type hints on public functions
20+
- [ ] Context managers for file I/O
21+
- [ ] No TODOs without issue references
22+
23+
## Testing
24+
- [ ] New code has tests
25+
- [ ] Edge cases covered
26+
- [ ] No skipped tests without explanation
27+
28+
## Documentation
29+
- [ ] API changes documented
30+
- [ ] Breaking changes noted
31+
- [ ] README updated if needed
32+
33+
## Output Format
34+
Provide results as:
35+
- ✅ PASS: Items that look good
36+
- ⚠️ WARN: Items that could be improved
37+
- ❌ FAIL: Items that must be fixed before merge
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: security-audit
3+
description: Security-focused code review checking OWASP (Open Web Application Security Project) Top 10 vulnerabilities
4+
---
5+
6+
# Security Audit
7+
8+
Perform a security audit checking for:
9+
10+
## Injection Vulnerabilities
11+
- SQL injection (string concatenation in queries)
12+
- Command injection (unsanitized shell commands)
13+
- LDAP injection
14+
- XPath injection
15+
16+
## Authentication Issues
17+
- Hardcoded credentials
18+
- Weak password requirements
19+
- Missing rate limiting
20+
- Session management flaws
21+
22+
## Sensitive Data
23+
- Plaintext passwords
24+
- API keys in code
25+
- Logging sensitive information
26+
- Missing encryption
27+
28+
## Access Control
29+
- Missing authorization checks
30+
- Insecure direct object references
31+
- Path traversal vulnerabilities
32+
33+
## Output
34+
For each issue found, provide:
35+
1. File and line number
36+
2. Vulnerability type
37+
3. Severity (CRITICAL/HIGH/MEDIUM/LOW)
38+
4. Recommended fix

0 commit comments

Comments
 (0)