fix: separate progress author and board identity

This commit is contained in:
WuYongJie 2026-09-02 18:47:14 +08:00
parent 88526b9619
commit 992e5a6da7
2 changed files with 51 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { createHash } from 'node:crypto'
import { spawnSync } from 'node:child_process'
import { fileURLToPath, pathToFileURL } from 'node:url'
@ -112,6 +113,24 @@ export function normalizeRepoName(value = '') {
return value.trim().replace(/\/$/, '').replace(/\.git$/i, '').split('/').at(-1)?.replace(/^.*@/, '') || ''
}
export function buildApiContext(env) {
return {
department: env.DEPARTMENT || '',
project: env.PROJECT || '',
developer: env.DEVELOPER_CONTEXT || '',
project_description: env.PROJECT_DESCRIPTION || '',
}
}
export function makeFeatureCatalogKey(repoName, definitions) {
const signature = definitions
.map((rule) => `${rule.moduleName}\u0000${rule.featureName}`)
.sort()
.join('\u0001')
const digest = createHash('sha256').update(signature).digest('hex').slice(0, 16)
return `${normalizeRepoName(repoName)}:feature-catalog:${digest}`
}
function normalizeUrl(value = '') {
return value ? value.trim().replace(/\/+$/, '').toLowerCase() : ''
}
@ -285,9 +304,10 @@ export async function main(argv = process.argv.slice(2)) {
const env = parseEnv(fs.readFileSync(envPath, 'utf8'))
const apiBase = (env.API_BASE || DEFAULT_API_BASE).replace(/\/$/, '')
if (!env.API_KEY) fail(`API_KEY_NOT_CONFIGURED:${envPath}`)
for (const field of ['OWNER_EMAIL', 'DEPARTMENT', 'PROJECT', 'REPO_NAME', 'PRODUCTION_URL', 'DEPLOYMENT_NAME']) {
for (const field of ['OWNER_EMAIL', 'DEVELOPER_CONTEXT', 'PROJECT_DESCRIPTION', 'DEPARTMENT', 'PROJECT', 'REPO_NAME', 'PRODUCTION_URL', 'DEPLOYMENT_NAME']) {
if (!env[field]) fail(`CONFIG_FIELD_MISSING:${field}`)
}
const apiContext = buildApiContext(env)
const status = values.status || 'code_complete'
const testStatus = values['test-status'] || (status === 'code_complete' ? 'not_run' : null)
const acceptanceEvidence = values['acceptance-evidence'] || null
@ -358,9 +378,10 @@ export async function main(argv = process.argv.slice(2)) {
const definitions = [...new Map(candidates.map(({ rule }) => [rule.key, rule])).values()]
const resolved = await apiRequest(apiBase, env.API_KEY, `/projects/${project.projectId}/features/resolve`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': `${normalizeRepoName(env.REPO_NAME)}:feature-catalog:v1` },
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': makeFeatureCatalogKey(env.REPO_NAME, definitions) },
body: JSON.stringify({
context: { department: env.DEPARTMENT, project: env.PROJECT, developer: env.OWNER_EMAIL || '' },
context: apiContext,
project_description: env.PROJECT_DESCRIPTION,
items: definitions.map((rule) => ({ module_name: rule.moduleName, feature_name: rule.featureName, create_module: true })),
}),
})
@ -392,7 +413,8 @@ export async function main(argv = process.argv.slice(2)) {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': candidate.key },
body: JSON.stringify({
context: { department: env.DEPARTMENT, project: env.PROJECT, developer: env.OWNER_EMAIL || '' },
context: apiContext,
project_description: env.PROJECT_DESCRIPTION,
commits: [commit],
updates: [update],
}),

View File

@ -2,13 +2,38 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildApiContext,
classifyCommit,
makeFeatureCatalogKey,
makeIdempotencyKey,
normalizeRepoName,
selectUniqueProject,
validateStatusEvidence,
} from '../../scripts/kaifa-progress-sync.mjs'
test('keeps Git author filtering separate from the board developer identity', () => {
assert.deepEqual(buildApiContext({
OWNER_EMAIL: '549727955@qq.com',
DEVELOPER_CONTEXT: '魔礼红',
PROJECT_DESCRIPTION: '真实项目介绍',
DEPARTMENT: '财务中心',
PROJECT: '财务系统',
}), {
department: '财务中心',
project: '财务系统',
developer: '魔礼红',
project_description: '真实项目介绍',
})
})
test('feature catalog idempotency changes with the exact requested definitions', () => {
const first = makeFeatureCatalogKey('CaiWuXiTong', [{ moduleName: '快递与审批', featureName: 'E 签宝状态轮询' }])
const same = makeFeatureCatalogKey('CaiWuXiTong', [{ featureName: 'E 签宝状态轮询', moduleName: '快递与审批' }])
const second = makeFeatureCatalogKey('CaiWuXiTong', [{ moduleName: '快递与审批', featureName: '钉钉应付流程' }])
assert.equal(first, same)
assert.notEqual(first, second)
})
test('normalizes repository names and builds a stable idempotency key', () => {
assert.equal(normalizeRepoName('http://git.example.com/team/CaiWuXiTong.git'), 'CaiWuXiTong')
assert.equal(makeIdempotencyKey('CaiWuXiTong', 'abc123', 'testing'), 'CaiWuXiTong:abc123:testing')