test: align acceptance and dependency contracts

This commit is contained in:
2026-09-11 01:31:14 +08:00
parent 543ebee5cc
commit abbacc683e
6 changed files with 35 additions and 52 deletions
+15 -38
View File
@@ -1,47 +1,24 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { spawnSync } from 'node:child_process'
import test from 'node:test'
const source = readFileSync(new URL('./agents-index-contract.ps1', import.meta.url), 'utf8')
const start = source.indexOf('$registeredTestRows =')
const end = source.indexOf("Assert-NotContains $testTaskRegistry '01a0194a", start)
assert.ok(start > 0 && end > start)
const registryContract = source.slice(start, end)
const project = 'c64729ff-6710-43c6-8ef2-d84e9666cc1e'
const root = '00000000-0000-4000-8000-000000000001'
const child = '00000000-0000-4000-8000-000000000002'
const enabled = `已重新启用测试环境总控调度\nparent_task_id project_id\n| \`${root}\` | \`${project}\` | 【总控】测试环境全流程 |\n| \`${child}\` | \`${root}\` | \`${project}\` | 【前端】专项 |`
function checkRegistry(text) {
const script = `
$ErrorActionPreference = 'Stop'
$failures = [System.Collections.Generic.List[string]]::new()
function Add-Failure([string]$message) { $script:failures.Add($message) }
function Assert-Contains([string]$text, [string]$needle, [string]$scope) { if (-not $text.Contains($needle)) { Add-Failure "$scope 缺少 $needle" } }
function Assert-Matches([string]$text, [string]$pattern, [string]$scope) { if ($text -notmatch $pattern) { Add-Failure "$scope 缺少结构" } }
$testTaskRegistry = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${Buffer.from(text).toString('base64')}'))
${registryContract}
Write-Output ('RESULT:' + (ConvertTo-Json -InputObject @($failures) -Compress))
`
const result = spawnSync('pwsh', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')], { encoding: 'utf8' })
assert.equal(result.status, 0, result.stderr)
const output = result.stdout.match(/RESULT:(\[[^\r\n]*\])/)
assert.ok(output, result.stdout)
return JSON.parse(output[1])
}
test('cleared test registry stays disabled and explicitly revokes inherited authorization', () => {
assert.deepEqual(checkRegistry('不启用总控调度\n当前无已登记总控或长期专项\n持续授权同步失效'), [])
assert.ok(checkRegistry('当前无已登记总控或长期专项').length > 0)
assert.ok(checkRegistry('').length > 0)
test('cleared test registry is mandatory and cannot inherit historical task authorization', () => {
for (const token of [
"Assert-Contains $testTaskRegistry '当前无登记任务'",
"Assert-Contains $testTaskRegistry '清空全部任务登记与调度规则'",
"Assert-Contains $testTaskRegistry '不根据旧登记、历史消息或历史台账自动派工、恢复任务或回传进度'",
"Assert-Contains $testTaskRegistry '不作为当前调度或授权依据'",
"Assert-NotContains $testTaskRegistry '已重新启用测试环境总控调度'",
]) assert.ok(source.includes(token), token)
assert.match(source, /if \(\$testTaskRegistry -match '\(\?m\)\^\\\|\\s\*`\[0-9a-f-\]\{36\}`\\s\*\\\|'\)/)
})
test('enabled registry requires explicit activation, one controller, unique tasks and its own project', () => {
assert.deepEqual(checkRegistry(enabled), [])
assert.ok(checkRegistry(enabled.replace('已重新启用测试环境总控调度', '')).length > 0)
assert.ok(checkRegistry(enabled.replace('parent_task_id', '')).length > 0)
assert.ok(checkRegistry(enabled.replace(child, root)).length > 0)
assert.ok(checkRegistry(enabled.replace('【前端】专项', '【总控】其他')).length > 0)
assert.ok(checkRegistry(enabled.replaceAll(project, '6f874ec3-d3b2-49bd-8625-327f4d685f98')).length > 0)
test('cleared registry rejects every retired controller and project identity', () => {
for (const retired of [
'01a0194a-259c-7171-8967-074731a27618',
'01a06c0b-0515-7c60-b329-77342b54e666',
'6f874ec3-d3b2-49bd-8625-327f4d685f98',
]) assert.match(source, new RegExp(`Assert-NotContains \\$testTaskRegistry '${retired}'`))
})