Skip to content

Commit ba87433

Browse files
committed
fix: split current profile validation entrypoint
1 parent 8583ab4 commit ba87433

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"test:pack-clean": "node scripts/test-pack-clean.js",
4040
"test:published-package-scripts": "node scripts/test-published-package-scripts-contract.js",
4141
"test:profile-governance": "node scripts/test-validate-profile.js",
42+
"test:profile-current": "node scripts/validate-all-profiles.js --current-only",
4243
"test:profile-all": "node scripts/validate-all-profiles.js",
44+
"test:profile-workspace": "node scripts/validate-all-profiles.js",
4345
"test:readme-governance": "node scripts/test-readme-governance.js",
4446
"site:generate-data": "node scripts/generate-public-site-data.js",
4547
"test:public-product-expression": "node scripts/test-public-product-expression.js",

‎scripts/test-validate-profile.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ function runValidateAll(workspaceRoot) {
105105
})
106106
}
107107

108+
function runValidateCurrent(workspaceRoot) {
109+
return spawnSync(process.execPath, [ALL_SCRIPT, '--workspace', workspaceRoot, '--current-only'], {
110+
cwd: workspaceRoot,
111+
encoding: 'utf8'
112+
})
113+
}
114+
108115
function createWorkspaceNamespaceWorkspace(projectInfo) {
109116
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'devcodex-validate-profile-ws-'))
110117
TEMP_ROOTS.push(root)
@@ -1245,6 +1252,26 @@ function main() {
12451252

12461253
assert.strictEqual(allProfilesResult.status, 0, allProfilesOutput)
12471254
assert.match(allProfilesOutput, /checked=2/)
1255+
1256+
const currentOnlyRoot = createWorkspaceNamespaceWorkspace(currentProjectInfo())
1257+
writeFile(currentOnlyRoot, '.devcodex/devcodex/profile/01-项目信息.md', currentProjectInfo())
1258+
writeFile(currentOnlyRoot, '.devcodex/chat/profile/01-项目信息.md', [
1259+
currentProjectInfo(),
1260+
'',
1261+
'- Profile 档位:profile-standard。'
1262+
].join('\n'))
1263+
const currentOnlyResult = runValidateCurrent(currentOnlyRoot)
1264+
const currentOnlyOutput = `${currentOnlyResult.stdout}\n${currentOnlyResult.stderr}`
1265+
assert.strictEqual(currentOnlyResult.status, 0, currentOnlyOutput)
1266+
assert.match(currentOnlyOutput, /\[profile-current\] current-project=devcodex checked=1 errors=0 warnings=0/)
1267+
assert.doesNotMatch(currentOnlyOutput, /workspace-debt/)
1268+
1269+
const workspaceDebtResult = runValidateAll(currentOnlyRoot)
1270+
const workspaceDebtOutput = `${workspaceDebtResult.stdout}\n${workspaceDebtResult.stderr}`
1271+
assert.strictEqual(workspaceDebtResult.status, 1, workspaceDebtOutput)
1272+
assert.match(workspaceDebtOutput, /\[profile-all\] current-project=devcodex checked=1 errors=0 warnings=0/)
1273+
assert.match(workspaceDebtOutput, /\[profile-all\] workspace-debt checked=2 errors=1 warnings=0/)
1274+
assert.match(workspaceDebtOutput, /profile-standard requires 04-测试规范\.md/)
12481275
const batchEResult = spawnSync(process.execPath, [path.join(ROOT, 'scripts', 'test-v1178-batch-e.js')], {
12491276
cwd: ROOT,
12501277
encoding: 'utf8'

‎scripts/validate-all-profiles.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function samePath(a, b) {
2828

2929
const workspaceRoot = path.resolve(argValue('--workspace') || path.dirname(ROOT))
3030
const strictWarnings = args.includes('--strict-warnings')
31+
const currentOnly = args.includes('--current-only')
3132
const devcodexRoot = path.join(workspaceRoot, '.devcodex')
3233
const workspaceProfile = path.join(devcodexRoot, 'workspace', 'profile')
3334
const sourceProjectRoot = path.join(workspaceRoot, path.basename(ROOT))
@@ -137,6 +138,17 @@ const currentCounts = countKinds(currentProject)
137138
const workspaceCounts = countKinds(workspaceDebt)
138139
const allCounts = countKinds(results)
139140

141+
if (currentOnly) {
142+
console.log(`[profile-current] current-project=${sourceNamespace} checked=${currentProject.length} errors=${currentCounts.error} warnings=${currentCounts.warning} strictWarnings=${strictWarnings}`)
143+
for (const result of currentProject) printResult(result, '[profile-current]')
144+
if (!currentProject.length) {
145+
console.error(`[profile-current] missing current project profile namespace: ${sourceNamespace}`)
146+
process.exit(1)
147+
}
148+
if (currentCounts.error || (strictWarnings && currentCounts.warning)) process.exit(1)
149+
process.exit(0)
150+
}
151+
140152
console.log(`[profile-all] current-project=${sourceNamespace} checked=${currentProject.length} errors=${currentCounts.error} warnings=${currentCounts.warning}`)
141153
for (const result of currentProject) printResult(result, '[profile-all][current-project]')
142154

0 commit comments

Comments
 (0)