- Removed `test:ai`, `test:settings`, and `test:workbench` scripts from package.json. - Updated test plan documentation to reflect the removal of `test:workbench`. - Enhanced argument parsing in release scripts to ensure required values are provided. - Added validation for unknown arguments in release scripts. - Improved error handling for invalid arguments in test workflow. - Updated unit tests to cover new validation logic for release arguments.
83 lines
2.7 KiB
JavaScript
83 lines
2.7 KiB
JavaScript
const valueAfter = (args, name) => {
|
|
const index = args.indexOf(name)
|
|
if (index < 0) return ''
|
|
const value = args[index + 1]
|
|
if (!value || value.startsWith('--')) throw new Error(`${name} requires a value`)
|
|
return value
|
|
}
|
|
|
|
const VALUE_OPTIONS = new Set(['--tag', '--domain', '--suite', '--group', '--case'])
|
|
const FLAG_OPTIONS = new Set([
|
|
'--prepare-only',
|
|
'--test-only',
|
|
'--publish-only',
|
|
'--fresh-knowledge-cache'
|
|
])
|
|
|
|
export const validateReleaseArgs = (args) => {
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
const argument = args[index]
|
|
if (VALUE_OPTIONS.has(argument)) {
|
|
const value = args[index + 1]
|
|
if (!value || value.startsWith('--')) {
|
|
throw new Error(`${argument} requires a value`)
|
|
}
|
|
index += 1
|
|
continue
|
|
}
|
|
if (FLAG_OPTIONS.has(argument)) continue
|
|
throw new Error(`unknown argument: ${argument}`)
|
|
}
|
|
}
|
|
|
|
export const readRegressionSelection = (args) => {
|
|
const domain = valueAfter(args, '--domain')
|
|
const suite = valueAfter(args, '--suite')
|
|
const groups = []
|
|
const caseIds = []
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
const name = args[index]
|
|
if (name === '--group' || name === '--case') {
|
|
const value = args[index + 1]
|
|
if (!value || value.startsWith('--')) throw new Error(`${name} requires a value`)
|
|
if (name === '--group') groups.push(value)
|
|
else caseIds.push(value)
|
|
index += 1
|
|
}
|
|
}
|
|
const freshKnowledgeCache = args.includes('--fresh-knowledge-cache')
|
|
|
|
if (suite && !domain) throw new Error('--suite requires --domain')
|
|
if (groups.length > 0 && (!domain || !suite)) {
|
|
throw new Error('--group requires --domain and --suite')
|
|
}
|
|
if (suite === 'showcase' || groups.includes('showcase')) {
|
|
throw new Error('不允许选择 showcase;请使用 pnpm test:showcase')
|
|
}
|
|
|
|
const workflowArgs = []
|
|
if (domain) workflowArgs.push('--domain', domain)
|
|
if (suite) workflowArgs.push('--suite', suite)
|
|
for (const group of groups) workflowArgs.push('--group', group)
|
|
for (const caseId of caseIds) workflowArgs.push('--case', caseId)
|
|
if (freshKnowledgeCache) workflowArgs.push('--fresh-knowledge-cache')
|
|
|
|
const selected = Boolean(domain || suite || groups.length > 0 || caseIds.length > 0)
|
|
return {
|
|
workflowArgs,
|
|
state: {
|
|
mode: selected ? 'selected' : 'full',
|
|
...(domain ? { domain } : {}),
|
|
...(suite ? { suite } : {}),
|
|
...(groups.length > 0 ? { groups } : {}),
|
|
...(caseIds.length > 0 ? { cases: caseIds } : {}),
|
|
...(freshKnowledgeCache ? { freshKnowledgeCache: true } : {})
|
|
}
|
|
}
|
|
}
|
|
|
|
export const hasRegressionSelectionArgs = (args) =>
|
|
args.some((arg) =>
|
|
['--domain', '--suite', '--group', '--case', '--fresh-knowledge-cache'].includes(arg)
|
|
)
|