@aramassa/ai-rules 0.1.1-npmjs.20250910072942 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifact/chatmodes/Bug Reproduce.md +296 -0
- package/artifact/chatmodes/Instruction Improve.md +17 -3
- package/artifact/chatmodes/Planning.md +234 -20
- package/artifact/instructions/planning.md +188 -7
- package/artifact/instructions/rules/development/chrome-extension-general.md +121 -0
- package/artifact/instructions/rules/development/chrome-extension-html.md +157 -0
- package/artifact/instructions/rules/development/chrome-extension-javascript.md +190 -0
- package/artifact/instructions/rules/development/chrome-extension-manifest.md +110 -0
- package/artifact/instructions/rules/development/electron.md +258 -0
- package/artifact/instructions/rules/test/environment-independent-paths.md +206 -0
- package/artifact/prompts/todo_plans.prompt.md +47 -0
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +273 -19
- package/dist/utils/pathExpansion.d.ts +24 -0
- package/dist/utils/pathExpansion.d.ts.map +1 -0
- package/dist/utils/pathExpansion.js +67 -0
- package/package.json +5 -3
- package/presets/README.md +26 -0
- package/presets/chatmodes.yaml +16 -51
- package/presets/chrome-extension.yaml +50 -0
- package/presets/electron.yaml +11 -0
- package/presets/prompts/todo-planning.yaml +8 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: test
|
|
3
|
+
category: best-practices
|
|
4
|
+
focus: environment-independence
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 環境非依存テスト実行のためのパス指定ルール
|
|
8
|
+
|
|
9
|
+
## 概要
|
|
10
|
+
|
|
11
|
+
テスト実行は、ローカル環境でもCI環境でもどちらでもパスするように気をつける必要があります。パス指定などは絶対パス指定にせず、環境に依存しない書き方をすることが重要です。
|
|
12
|
+
|
|
13
|
+
## 背景・理由
|
|
14
|
+
|
|
15
|
+
コーディングするのはAIだけではありません。手動で修正した内容が問題ないかの確認を実施する際に、ローカル環境でテストがこけてしまうと困ります。CI環境とローカル環境の差異によるテスト失敗を防ぐため、環境に依存しないテストコードの作成が必要です。
|
|
16
|
+
|
|
17
|
+
## 基本原則
|
|
18
|
+
|
|
19
|
+
### 1. 絶対パスの使用を避ける
|
|
20
|
+
|
|
21
|
+
- **禁止**: `/home/user/project/test-data/sample.txt` のような絶対パス指定
|
|
22
|
+
- **推奨**: 相対パス や Node.js の `path` モジュールを使った動的パス生成
|
|
23
|
+
|
|
24
|
+
### 2. 一時ディレクトリの適切な使用
|
|
25
|
+
|
|
26
|
+
- **推奨**: `os.tmpdir()` と `mkdtemp()` の組み合わせを使用
|
|
27
|
+
- **理由**: OS固有の一時ディレクトリ場所を自動で取得し、ユニークなディレクトリを作成
|
|
28
|
+
|
|
29
|
+
### 3. プラットフォーム依存機能の適切な処理
|
|
30
|
+
|
|
31
|
+
- **推奨**: テスト前後で環境変数やプラットフォーム情報を保存・復元
|
|
32
|
+
- **推奨**: プラットフォーム固有の機能は条件分岐で対応
|
|
33
|
+
|
|
34
|
+
## 実装パターン
|
|
35
|
+
|
|
36
|
+
### パターン 1: 一時ディレクトリの使用
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
40
|
+
import path from "path";
|
|
41
|
+
import os from "os";
|
|
42
|
+
|
|
43
|
+
describe("Example Test", () => {
|
|
44
|
+
let testTempDir: string;
|
|
45
|
+
|
|
46
|
+
beforeEach(async () => {
|
|
47
|
+
// 環境に依存しない一時ディレクトリの作成
|
|
48
|
+
testTempDir = await mkdtemp(path.join(os.tmpdir(), "test-prefix-"));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(async () => {
|
|
52
|
+
// テスト後のクリーンアップ
|
|
53
|
+
try {
|
|
54
|
+
await rm(testTempDir, { recursive: true, force: true });
|
|
55
|
+
} catch {
|
|
56
|
+
// エラーは無視(クリーンアップエラーは致命的ではない)
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should work with temporary files", async () => {
|
|
61
|
+
const testFile = path.join(testTempDir, "test.txt");
|
|
62
|
+
// テスト実装...
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### パターン 2: 環境変数の保存・復元
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
describe("Environment Test", () => {
|
|
71
|
+
let originalEnv: NodeJS.ProcessEnv;
|
|
72
|
+
let originalPlatform: string;
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
// 元の環境を保存
|
|
76
|
+
originalEnv = { ...process.env };
|
|
77
|
+
originalPlatform = process.platform;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
// 環境を復元
|
|
82
|
+
process.env = originalEnv;
|
|
83
|
+
Object.defineProperty(process, 'platform', {
|
|
84
|
+
value: originalPlatform
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should handle platform differences", () => {
|
|
89
|
+
// プラットフォーム固有のテスト...
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### パターン 3: 相対パスの適切な解決
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import path from "path";
|
|
98
|
+
|
|
99
|
+
describe("Path Resolution Test", () => {
|
|
100
|
+
it("should resolve paths correctly", () => {
|
|
101
|
+
// ❌ 絶対パス(環境依存)
|
|
102
|
+
// const filePath = "/home/user/project/src/cli.ts";
|
|
103
|
+
|
|
104
|
+
// ✅ 相対パス(環境非依存)
|
|
105
|
+
const filePath = path.resolve("src/cli.ts");
|
|
106
|
+
|
|
107
|
+
// ✅ パッケージルートからの相対パス
|
|
108
|
+
const packageRoot = findPackageRoot();
|
|
109
|
+
const configPath = path.join(packageRoot, "config/settings.json");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### パターン 4: CLI実行時のパス指定
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { execSync } from "child_process";
|
|
118
|
+
import path from "path";
|
|
119
|
+
|
|
120
|
+
describe("CLI Test", () => {
|
|
121
|
+
it("should execute CLI with proper paths", () => {
|
|
122
|
+
const testSrcDir = path.join(testTempDir, "test-src");
|
|
123
|
+
|
|
124
|
+
// ❌ 絶対パスでCLIファイル指定
|
|
125
|
+
// execSync(`/home/user/project/dist/cli.js extract --src ${testSrcDir}`);
|
|
126
|
+
|
|
127
|
+
// ✅ 相対パスでCLIファイル指定
|
|
128
|
+
execSync(`npx tsx src/cli.ts extract --src ${testSrcDir}`, {
|
|
129
|
+
cwd: process.cwd(), // 現在の作業ディレクトリを明示
|
|
130
|
+
stdio: "pipe"
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 避けるべきパターン
|
|
137
|
+
|
|
138
|
+
### ❌ 絶対パスの直接指定
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// 悪い例: ユーザーディレクトリやシステムパスの直接指定
|
|
142
|
+
const testFile = "/home/runner/project/test/data.txt";
|
|
143
|
+
const configPath = "C:\\Users\\user\\project\\config.json";
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### ❌ プラットフォーム固有パスの固定
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// 悪い例: パス区切り文字の直接使用
|
|
150
|
+
const filePath = "src/utils/helper.js"; // Windowsでは問題になる可能性
|
|
151
|
+
// 良い例: path.join() の使用
|
|
152
|
+
const filePath = path.join("src", "utils", "helper.js");
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### ❌ 環境変数の復元なし
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// 悪い例: テスト後に環境を復元しない
|
|
159
|
+
it("should test with modified env", () => {
|
|
160
|
+
process.env.TEST_VAR = "test-value";
|
|
161
|
+
// テスト後も環境変数が残り、他のテストに影響する
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## クリーンアップのベストプラクティス
|
|
166
|
+
|
|
167
|
+
### 確実なリソース解放
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
afterEach(async () => {
|
|
171
|
+
// ファイルシステムリソースの解放
|
|
172
|
+
try {
|
|
173
|
+
await rm(testTempDir, { recursive: true, force: true });
|
|
174
|
+
} catch {
|
|
175
|
+
// クリーンアップエラーは無視(テストの失敗より重要ではない)
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### プロセス状態の復元
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
afterEach(() => {
|
|
184
|
+
// プロセス状態を確実に復元
|
|
185
|
+
process.env = originalEnv;
|
|
186
|
+
process.chdir(originalCwd);
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## CI/ローカル共通の注意点
|
|
191
|
+
|
|
192
|
+
1. **タイムアウト設定**: CI環境では処理が遅い場合があるため、適切なタイムアウト値を設定
|
|
193
|
+
2. **並列実行対応**: 複数のテストが同時実行されても競合しないよう、ユニークな識別子を使用
|
|
194
|
+
3. **権限問題の回避**: 読み取り専用ファイルや権限制限のあるディレクトリを避ける
|
|
195
|
+
4. **パスの長さ制限**: Windows環境での長いパス名制限を考慮
|
|
196
|
+
|
|
197
|
+
## 検証方法
|
|
198
|
+
|
|
199
|
+
テストが環境非依存であることを確認する方法:
|
|
200
|
+
|
|
201
|
+
1. **ローカルでの実行**: `npm test`
|
|
202
|
+
2. **異なるワーキングディレクトリからの実行**: 別のディレクトリからテストを実行
|
|
203
|
+
3. **CI環境での実行**: GitHub Actions や他のCI環境での動作確認
|
|
204
|
+
4. **異なるOS環境**: 可能であれば Windows/Linux/macOS での動作確認
|
|
205
|
+
|
|
206
|
+
このルールに従うことで、テストはどの環境でも一貫して動作し、開発者の生産性向上とCI/CDパイプラインの安定性を実現できます。
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: prompt
|
|
3
|
+
category: todo-planning
|
|
4
|
+
focus: workflow-management
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TODO Plans 作成ルール
|
|
8
|
+
|
|
9
|
+
## 基本ルール
|
|
10
|
+
|
|
11
|
+
- 今後の計画を立てる際は、必ず `todo_plans/` に記載する
|
|
12
|
+
- ファイル名規則は、`YYYYMMDD_[タイトル].md`
|
|
13
|
+
- 計画が不要になった場合は削除する。Git の履歴で過去の計画は追跡できるため、アーカイブせずにリポジトリをすっきり保つ
|
|
14
|
+
|
|
15
|
+
## ワークフロー管理
|
|
16
|
+
|
|
17
|
+
### todo_plans の役割
|
|
18
|
+
|
|
19
|
+
#### todo_plans段階
|
|
20
|
+
|
|
21
|
+
- **目的**: 将来の計画とアイデアの整理
|
|
22
|
+
- **期間**: プロジェクトのアイデア段階
|
|
23
|
+
- **成果物**: 計画の概要と方向性
|
|
24
|
+
- **品質基準**: 実現したいことが明確に記述されている
|
|
25
|
+
|
|
26
|
+
## 実践ガイドライン
|
|
27
|
+
|
|
28
|
+
- 将来実装したい機能やアイデアは、必ず todo_plans/ に記載する
|
|
29
|
+
- 計画の内容は、実現したいことと大まかな方向性を記述する
|
|
30
|
+
- 詳細な実装方法は不要。コンセプトレベルで十分
|
|
31
|
+
- 計画が変更されたり不要になった場合は、ファイルを削除してリポジトリを整理する
|
|
32
|
+
|
|
33
|
+
## ファイル名規則の例
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
todo_plans/
|
|
37
|
+
├── 20250911_API機能拡張構想.md
|
|
38
|
+
├── 20250911_パフォーマンス改善アイデア.md
|
|
39
|
+
└── 20250911_新機能企画書.md
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 注意事項
|
|
43
|
+
|
|
44
|
+
- todo_plans は「将来やりたいこと」「検討したいアイデア」の整理段階
|
|
45
|
+
- 具体的な実装計画ではなく、方向性やコンセプトを記録する
|
|
46
|
+
- 実装に着手する際は、別途 change_plans でより詳細な計画を立てる
|
|
47
|
+
- 長期的なビジョンや中期的な目標の管理に活用する
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAygBA;;GAEG;AACH,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,MAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAyBpG"}
|