← 教程列表
coding

Layer 3: Environment Guards

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 8 阅读

**Purpose:** Prevent dangerous operations in specific contexts ```typescript async function gitInit(directory: string) { // In tests, refuse git init outside temp directories if (process.env.NODE_ENV === 'test') { const normalized = normalize(resolve(directory)); const tmpDir = normalize(resolve(tmpdir())); if (!normalized.startsWith(tmpDir)) { throw new Error( `Refusing git init outside temp dir during tests: ${directory}` ); } } // ... proceed } ```

← 返回教程列表 AI8899 · 内容仅供学习参考