Add ks-zl skill
This commit is contained in:
134
scripts/test-requirement-search.ps1
Normal file
134
scripts/test-requirement-search.ps1
Normal file
@@ -0,0 +1,134 @@
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$buildScript = Join-Path $scriptDir "build-requirement-index.ps1"
|
||||
$searchScript = Join-Path $scriptDir "search-requirements.ps1"
|
||||
|
||||
$tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("ks-zl-search-test-" + [System.Guid]::NewGuid().ToString("N"))
|
||||
New-Item -ItemType Directory -Path $tempRoot | Out-Null
|
||||
|
||||
function New-TestRequirementPackage {
|
||||
param(
|
||||
[string]$Domain,
|
||||
[string]$Slug,
|
||||
[string]$Title,
|
||||
[string[]]$Tags,
|
||||
[string]$Feature,
|
||||
[string]$Rules,
|
||||
[string]$Acceptance
|
||||
)
|
||||
|
||||
$packageDir = Join-Path $tempRoot (Join-Path $Domain (Join-Path "requirement-packages" $Slug))
|
||||
New-Item -ItemType Directory -Path (Join-Path $packageDir "references") -Force | Out-Null
|
||||
New-Item -ItemType File -Path (Join-Path $packageDir "decisions.md") -Force | Out-Null
|
||||
New-Item -ItemType File -Path (Join-Path $packageDir "acceptance.md") -Force | Out-Null
|
||||
|
||||
$tagLines = ($Tags | ForEach-Object { " - $_" }) -join "`n"
|
||||
$content = @(
|
||||
"---"
|
||||
"title: $Title"
|
||||
"category: $Domain/requirement-packages"
|
||||
"tags:"
|
||||
$tagLines
|
||||
"status: requirement-draft"
|
||||
"updated: 2026-05-13"
|
||||
"source: test"
|
||||
"---"
|
||||
""
|
||||
"# $Title"
|
||||
""
|
||||
"## 功能"
|
||||
"- $Feature"
|
||||
""
|
||||
"## 流程"
|
||||
"1. 发起请求。"
|
||||
""
|
||||
"## 数据表"
|
||||
"不涉及表"
|
||||
""
|
||||
"## 字典"
|
||||
"不新增字典"
|
||||
""
|
||||
"## 业务规则"
|
||||
"- $Rules"
|
||||
""
|
||||
"## 验收"
|
||||
"- $Acceptance"
|
||||
""
|
||||
"## 移植说明"
|
||||
"- 跨技术栈必须保留业务语义。"
|
||||
"- 来源实现仅作参考。"
|
||||
""
|
||||
"## 来源依据"
|
||||
"- 测试样例。"
|
||||
""
|
||||
"## 待确认"
|
||||
"- 无"
|
||||
""
|
||||
"## Related"
|
||||
"- None yet."
|
||||
) -join "`n"
|
||||
|
||||
Set-Content -LiteralPath (Join-Path $packageDir "requirement.md") -Value $content -Encoding UTF8
|
||||
}
|
||||
|
||||
try {
|
||||
New-TestRequirementPackage `
|
||||
-Domain "order" `
|
||||
-Slug "refund-approval" `
|
||||
-Title "退款审批" `
|
||||
-Tags @("refund", "approval", "order") `
|
||||
-Feature "提交退款申请后按审批规则生成审批任务。" `
|
||||
-Rules "退款金额超过阈值时必须进入人工审批。" `
|
||||
-Acceptance "搜索退款审批时该功能排在最前。"
|
||||
|
||||
New-TestRequirementPackage `
|
||||
-Domain "inventory" `
|
||||
-Slug "stock-sync" `
|
||||
-Title "库存同步" `
|
||||
-Tags @("stock", "sync") `
|
||||
-Feature "同步外部库存数量。" `
|
||||
-Rules "库存同步失败时记录重试。" `
|
||||
-Acceptance "搜索库存时可命中该功能。"
|
||||
|
||||
$indexPath = Join-Path $tempRoot "_indexes\requirements-index.json"
|
||||
& $buildScript -Root $tempRoot -OutputPath $indexPath | Out-Null
|
||||
|
||||
if (-not (Test-Path -LiteralPath $indexPath)) {
|
||||
throw "Expected index file was not created."
|
||||
}
|
||||
|
||||
$index = Get-Content -Raw -Encoding UTF8 -LiteralPath $indexPath | ConvertFrom-Json
|
||||
if (@($index).Count -ne 2) {
|
||||
throw "Expected 2 indexed requirement packages, got $(@($index).Count)."
|
||||
}
|
||||
|
||||
$refundResults = & $searchScript -Root $tempRoot -IndexPath $indexPath -Query "退款 审批" -Top 1 -Json |
|
||||
ConvertFrom-Json
|
||||
|
||||
if (@($refundResults).Count -ne 1) {
|
||||
throw "Expected one search result for refund query."
|
||||
}
|
||||
|
||||
if ($refundResults[0].slug -ne "refund-approval") {
|
||||
throw "Expected refund-approval to be the top result, got '$($refundResults[0].slug)'."
|
||||
}
|
||||
|
||||
$inventoryResults = & $searchScript -Root $tempRoot -IndexPath $indexPath -Query "库存" -Top 1 -Json |
|
||||
ConvertFrom-Json
|
||||
|
||||
if ($inventoryResults[0].slug -ne "stock-sync") {
|
||||
throw "Expected stock-sync to be the top inventory result, got '$($inventoryResults[0].slug)'."
|
||||
}
|
||||
|
||||
Write-Host "Requirement search tests passed."
|
||||
}
|
||||
finally {
|
||||
if (Test-Path -LiteralPath $tempRoot) {
|
||||
Remove-Item -LiteralPath $tempRoot -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user