一键导入
csv-test-data-generation
Generate CSV test data with correct quoting, encoding, and PowerShell-based mutation patterns for scenario-based test suites
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate CSV test data with correct quoting, encoding, and PowerShell-based mutation patterns for scenario-based test suites
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | csv-test-data-generation |
| description | Generate CSV test data with correct quoting, encoding, and PowerShell-based mutation patterns for scenario-based test suites |
Scope: This skill covers the how for CSV file operations — mutation tooling, PowerShell patterns, quote escaping, encoding, and manifest.json reference format. It is designed to be loaded alongside the
generate-test-data-from-sampleprompt, which defines the what (business rules, scenario selection, and validation requirements).
Use this skill when: Creating or mutating
.csvscenario files from a happy-path template where quote escaping, encoding, and column-index targeting are required.
Import-Csv/Export-Csv for structured mutations; use text manipulation only for header-row changes or when Import-Csv would re-encode values unexpectedly.Copy-Item "src/packing-lists/{exporter}/HappyPath.csv" "src/packing-lists/{exporter}/test-scenarios/{scenario}/{filename}.csv"
# Read
$rows = Import-Csv "src/packing-lists/{exporter}/test-scenarios/{scenario}/{filename}.csv"
# Mutate (e.g. corrupt commodity_code in rows 1 and 2, 0-indexed in array)
$rows[0].commodity_code = '@123456'
$rows[1].commodity_code = 'ABC123'
# Write back
$rows | Export-Csv "src/packing-lists/{exporter}/test-scenarios/{scenario}/{filename}.csv" -NoTypeInformation
Warning:
Export-Csvalways writes a UTF-8 file with a type-information header row unless-NoTypeInformationis specified. Always include-NoTypeInformation.
Import-Csv/Export-Csv cannot reliably mutate header names alone. Use text replacement for header-only scenarios:
$content = Get-Content "path/to/file.csv" -Raw
$content = $content -replace 'Commodity Code', '' # clear header
Set-Content "path/to/file.csv" $content -NoNewline
Always verify the header row after mutation with:
(Get-Content "path/to/file.csv" -First 1)
CSV quote handling is the most common source of errors:
| Intended value | In CSV file | PowerShell Export-Csv result |
|---|---|---|
Product Name | Product Name | Product Name |
"Product Name" (literal quotes) | """Product Name""" | """Product Name""" |
| Value containing comma | "value,with,commas" | auto-wrapped |
Key rule: To represent a literal double-quote character inside a CSV field, use two double-quotes ("").
When generating the DescriptionHasDoubleQuotesShould_Pass scenario for CSV files:
"Product Name" (with actual quote characters)"""Product Name"""$rows[0].description = '"Product Name"' and let Export-Csv handle the escaping$bytes = [System.IO.File]::ReadAllBytes("path/to/HappyPath.csv")
if ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) { "UTF-8 BOM" } else { "UTF-8 no BOM" }
CSV columns are documented in manifest.json using 1-based indices:
Import-Csv, columns are accessed by their header name as properties (e.g., $row.commodity_code)Import-Csv/Export-Csv.Defra software development standards for Node.js and .NET government services. Use when writing, reviewing, or refactoring code in a Defra digital service repository. Activates for Hapi framework projects, CDP platform services, and .NET ASP.NET Core Minimal API services.
Generate Excel test data with style-safe workbook mutations, merged-cell handling, and mapping verification for scenario-based test suites
Generate PDF test data with true in-place content stream mutations for integration testing