@tea-agent/loop-agent 0.33.6 → 0.33.7-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -23
- package/dist/application/task-lifecycle/advance.js +4 -254
- package/dist/application/task-lifecycle/gates.js +0 -50
- package/dist/application/task-lifecycle/observe.js +2 -11
- package/dist/commands/init-upgrade.js +1 -32
- package/dist/commands/init.js +3 -94
- package/dist/executors/shell-executor.js +91 -4
- package/dist/executors/shell-write-guard.js +8 -26
- package/dist/shared/operator/capabilities.js +42 -72
- package/dist/task/source-prepare/index.js +0 -2
- package/dist/task/source-prepare/parse-intent.js +10 -58
- package/dist/task/source-prepare/prepare.js +16 -180
- package/dist/task/source-prepare/reference-integrity.js +2 -18
- package/dist/worker/console/app-data.js +0 -2
- package/dist/worker/console/chat/chat-event-store.js +25 -190
- package/dist/worker/console/chat/instruction-skills.js +217 -0
- package/dist/worker/console/chat/pi-console-config.js +32 -250
- package/dist/worker/console/chat/pi-runtime.js +71 -625
- package/dist/worker/console/chat/resource-loader.js +4 -5
- package/dist/worker/console/chat/routes.js +146 -324
- package/dist/worker/console/chat/runtime-context.js +12 -48
- package/dist/worker/console/chat/runtime-selection.js +0 -59
- package/dist/worker/console/chat/shortcuts.js +0 -1
- package/dist/worker/console/chat/tool-adapter.js +3 -9
- package/dist/worker/console/chat/tools.js +1 -5
- package/dist/worker/console/operator-actions.js +68 -559
- package/dist/worker/console/server.js +15 -8
- package/dist/worker/console/static/assets/index-CnUXAqxG.css +1 -0
- package/dist/worker/console/static/assets/index-CteJFFL2.js +29 -0
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +8 -45
- package/dist/worker/console/static-src/operator-chat/refs.js +0 -9
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +0 -16
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +184 -210
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +5 -49
- package/dist/worker/console/static-src/operator-chat/useComposer.js +0 -17
- package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +74 -225
- package/dist/worker/delivery/final-verification.js +5 -13
- package/dist/worker/delivery/package.js +19 -31
- package/dist/worker/delivery/verification-bundle.js +4 -6
- package/dist/worker/observe/static/operator-chrome.css +2 -5
- package/dist/worker/observe/static/operator-chrome.js +1 -6
- package/dist/worker/observe/static/styles.css +9 -39
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +462 -33
- package/dist/workflows/dag/backend-test-case-manifest.js +4 -0
- package/dist/workflows/dag/backend-test-markdown-workflow.js +25 -1
- package/dist/workflows/dag/backend-test-module-stem.js +5 -0
- package/dist/workflows/dag/backend-test-pytest-collection.js +345 -24
- package/dist/workflows/dag/backend-test-scenario-param.js +269 -82
- package/dist/workflows/dag/backend-test-writer-completeness.js +47 -16
- package/dist/workflows/dag/dynamic-runtime/map.js +24 -8
- package/dist/workflows/dag/frontend-worktree-diff.js +27 -12
- package/dist/workflows/dag/init-hybrid.js +46 -34
- package/dist/workflows/dag/types.js +7 -0
- package/dist/workflows/dag/workspace-checkpoint.js +27 -8
- package/docs/templates/backend-test-dag.json +32 -29
- package/harness.json +1 -1
- package/package.json +1 -1
- package/skills/loop-agent/references/command-reference.md +1 -3
- package/skills/loop-agent/references/source-and-plan-practice.md +0 -13
- package/skills/loop-agent/references/task-workflow.md +0 -4
- package/dist/shared/resilient-git.js +0 -133
- package/dist/task/source-prepare/artifact-meta.js +0 -137
- package/dist/task/source-prepare/semantic-intake.js +0 -404
- package/dist/worker/console/dag-execution-receipt.js +0 -380
- package/dist/worker/console/static/assets/index-BUOLppPr.js +0 -28
- package/dist/worker/console/static/assets/index-C1KzazY5.css +0 -1
- package/dist/worker/console/static-src/operator-chat/runtime-snapshot-store.js +0 -257
- package/dist/worker/console/static-src/operator-chat/useRuntimeSnapshot.js +0 -196
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
2
3
|
import { access, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { z } from "zod";
|
|
@@ -8,7 +9,15 @@ const CASE_HEADING = /^##\s+(BE-[A-Z0-9_-]+-\d{3})\b.*$/gm;
|
|
|
8
9
|
const CASE_ID_IN_TEXT = /\bBE-[A-Z0-9_-]+-\d{3}\b/g;
|
|
9
10
|
const NON_CANONICAL_CASE_HEADING = /^##\s+(BE-[A-Z0-9_-]+-(?:\d{2}|\d{2,3}[A-Z]+))\b.*$/gm;
|
|
10
11
|
const AC_ID_IN_TEXT = /\bAC-[A-Z0-9]+(?:-[A-Z0-9]+)*\b/g;
|
|
11
|
-
const
|
|
12
|
+
const SOURCE_RULE_ID_IN_TEXT = /\b(?:AC|REQ|BR)-[A-Z0-9]+(?:-[A-Z0-9]+)*\b/g;
|
|
13
|
+
const SOURCE_ERROR_CODE_IN_TEXT = /\b[A-Z][0-9]{5,}\b/g;
|
|
14
|
+
const JSON_FIELD_IN_TEXT = /["']([A-Za-z][A-Za-z0-9_]*)["']\s*:/g;
|
|
15
|
+
const DTO_FIELD_IN_TEXT = /\b(?:private|public|protected)\s+(?:static\s+)?(?:final\s+)?[A-Za-z_$][A-Za-z0-9_$<>,.?\[\] ]*\s+([a-z][A-Za-z0-9_]*)\s*[;=]/g;
|
|
16
|
+
const NATURAL_BUSINESS_RULE_KEYWORDS = /(?:事务|原子性|回滚|幂等|唯一性|唯一|状态转换|状态流转|权限|角色|租户|跨字段|transaction|atomic|rollback|idempoten|unique|state transition|authorization|permission|tenant|cross-field)/i;
|
|
17
|
+
const NATURAL_BUSINESS_RULE_NORMATIVE = /(?:必须|不得|禁止|仅当|应当|需要|不能|保证|must|shall|required|must not|only when|guarantee)/i;
|
|
18
|
+
// Token form is used for section scanning; anchored form validates full cells.
|
|
19
|
+
const RULE_KEY_TOKEN = /(?:AC|REQ|BR|API|GET|POST|PUT|PATCH|DELETE)-[A-Z0-9]+(?:-[A-Z0-9]+)*|[A-Z][0-9]{5,}/;
|
|
20
|
+
const RULE_KEY = new RegExp(`^(?:${RULE_KEY_TOKEN.source})$`);
|
|
12
21
|
const TEST_POINT = /^TP-[A-Z0-9]+(?:-[A-Z0-9]+)*$/;
|
|
13
22
|
const COVERAGE_HEADERS = [
|
|
14
23
|
"Rule Key",
|
|
@@ -87,6 +96,13 @@ const coverageCaseSchema = z.object({
|
|
|
87
96
|
scenarioTypes: z.array(z.string()),
|
|
88
97
|
declaredScripts: z.array(z.string()),
|
|
89
98
|
declaredPrimarySymbols: z.array(z.string()),
|
|
99
|
+
payloadContract: z.object({
|
|
100
|
+
declared: z.boolean(),
|
|
101
|
+
noPayload: z.boolean(),
|
|
102
|
+
requiredPaths: z.array(z.string()),
|
|
103
|
+
allowedPaths: z.array(z.string()),
|
|
104
|
+
enumValues: z.record(z.string(), z.array(z.string())),
|
|
105
|
+
}).strict(),
|
|
90
106
|
}).strict();
|
|
91
107
|
const coverageRuleSchema = z.object({
|
|
92
108
|
ruleKey: z.string().min(1),
|
|
@@ -102,6 +118,23 @@ const coverageRuleSchema = z.object({
|
|
|
102
118
|
missingTestPoints: z.array(z.string()),
|
|
103
119
|
status: z.enum(["COVERED", "PARTIAL", "GAP", "CONFLICT"]),
|
|
104
120
|
}).strict();
|
|
121
|
+
const sourceCoverageFactSchema = z.object({
|
|
122
|
+
kind: z.enum(["requirement-id", "error-code", "dto-field", "business-rule"]),
|
|
123
|
+
key: z.string().min(1),
|
|
124
|
+
sourcePath: z.string().min(1),
|
|
125
|
+
sourceSha256: sha256Schema,
|
|
126
|
+
lineStart: z.number().int().positive(),
|
|
127
|
+
lineEnd: z.number().int().positive(),
|
|
128
|
+
quote: z.string().min(1).max(1000),
|
|
129
|
+
covered: z.boolean(),
|
|
130
|
+
}).strict();
|
|
131
|
+
const sourceCoverageSchema = z.object({
|
|
132
|
+
sourceFactCount: z.number().int().min(0),
|
|
133
|
+
coveredSourceFactCount: z.number().int().min(0),
|
|
134
|
+
residualSourceFactCount: z.number().int().min(0),
|
|
135
|
+
facts: z.array(sourceCoverageFactSchema),
|
|
136
|
+
residual: z.array(sourceCoverageFactSchema),
|
|
137
|
+
}).strict();
|
|
105
138
|
const coverageScopeSchema = z.object({
|
|
106
139
|
changeClassification: z.enum(CHANGE_CLASSIFICATIONS),
|
|
107
140
|
coveragePolicy: z.enum(COVERAGE_POLICIES),
|
|
@@ -112,13 +145,14 @@ const coverageScopeSchema = z.object({
|
|
|
112
145
|
completenessClaim: z.enum(["affected-operations-full", "affected-scope"]),
|
|
113
146
|
}).strict();
|
|
114
147
|
export const backendTestCaseCoverageFactsSchema = z.object({
|
|
115
|
-
schemaId: z.literal("backend-test-case-coverage-facts-
|
|
116
|
-
schemaVersion: z.literal(
|
|
148
|
+
schemaId: z.literal("backend-test-case-coverage-facts-v4"),
|
|
149
|
+
schemaVersion: z.literal(4),
|
|
117
150
|
taskId: z.string().min(1),
|
|
118
151
|
status: z.enum(["PASS", "FAIL", "UNAVAILABLE"]),
|
|
119
152
|
sourceBinding: sourceBindingSchema,
|
|
120
153
|
inputFiles: z.array(inputFileSchema),
|
|
121
154
|
coverageScope: coverageScopeSchema,
|
|
155
|
+
sourceCoverage: sourceCoverageSchema,
|
|
122
156
|
summary: z.object({
|
|
123
157
|
explicitAcCount: z.number().int().min(0),
|
|
124
158
|
coveredAcCount: z.number().int().min(0),
|
|
@@ -177,12 +211,24 @@ const correspondenceEntrySchema = z.object({
|
|
|
177
211
|
"CROSS_CUTTING_EVIDENCE_MISSING",
|
|
178
212
|
"TEST_POINT_BINDING_DUPLICATE",
|
|
179
213
|
"TEST_POINT_BINDING_EXTRA",
|
|
214
|
+
"PAYLOAD_CONTRACT_UNAVAILABLE",
|
|
215
|
+
"PAYLOAD_SHAPE_MISMATCH",
|
|
180
216
|
]),
|
|
217
|
+
payloadAssessment: z.object({
|
|
218
|
+
status: z.enum(["SAFE", "UNSAFE", "UNAVAILABLE"]),
|
|
219
|
+
requiredPaths: z.array(z.string()),
|
|
220
|
+
allowedPaths: z.array(z.string()),
|
|
221
|
+
observedPaths: z.array(z.string()),
|
|
222
|
+
missingPaths: z.array(z.string()),
|
|
223
|
+
unexpectedPaths: z.array(z.string()),
|
|
224
|
+
enumMismatches: z.array(z.string()),
|
|
225
|
+
}).strict(),
|
|
226
|
+
executionSignature: z.string().min(1).optional(),
|
|
181
227
|
findings: z.array(z.string()),
|
|
182
228
|
}).strict();
|
|
183
229
|
export const backendTestMarkdownPytestCorrespondenceFactsSchema = z.object({
|
|
184
|
-
schemaId: z.literal("backend-test-markdown-pytest-correspondence-facts-
|
|
185
|
-
schemaVersion: z.literal(
|
|
230
|
+
schemaId: z.literal("backend-test-markdown-pytest-correspondence-facts-v3"),
|
|
231
|
+
schemaVersion: z.literal(3),
|
|
186
232
|
taskId: z.string().min(1),
|
|
187
233
|
status: z.enum(["PASS", "FAIL", "UNAVAILABLE"]),
|
|
188
234
|
inputFiles: z.array(inputFileSchema),
|
|
@@ -203,6 +249,10 @@ export const backendTestMarkdownPytestCorrespondenceFactsSchema = z.object({
|
|
|
203
249
|
crossCuttingTestPointCount: z.number().int().min(0),
|
|
204
250
|
unclassifiedTestPointCount: z.number().int().min(0),
|
|
205
251
|
duplicateBindingTestPointCount: z.number().int().min(0),
|
|
252
|
+
payloadSafeCount: z.number().int().min(0),
|
|
253
|
+
payloadUnsafeCount: z.number().int().min(0),
|
|
254
|
+
payloadUnavailableCount: z.number().int().min(0),
|
|
255
|
+
duplicateExecutionSignatureCount: z.number().int().min(0),
|
|
206
256
|
}).strict(),
|
|
207
257
|
entries: z.array(correspondenceEntrySchema),
|
|
208
258
|
findings: z.array(z.string()),
|
|
@@ -236,6 +286,64 @@ function openApiTestPoints(field, dimension, values = []) {
|
|
|
236
286
|
return [`${prefix}-VALID-CLASS`, `${prefix}-VALID-MIXED`, `${prefix}-UPPERCASE`, `${prefix}-WHITESPACE`, `${prefix}-PUNCTUATION`, `${prefix}-SLASH`, `${prefix}-EMOJI`, `${prefix}-CONTROL`];
|
|
237
287
|
return [`${prefix}-PRESENT`, `${prefix}-MISSING`, `${prefix}-NULL`, `${prefix}-WRONG-TYPE`];
|
|
238
288
|
}
|
|
289
|
+
async function collectSourceCoverageFacts(input) {
|
|
290
|
+
const paths = orderedUnique([
|
|
291
|
+
input.sourceBinding.requirementPath,
|
|
292
|
+
...input.sourceBinding.referencePaths,
|
|
293
|
+
]);
|
|
294
|
+
const facts = [];
|
|
295
|
+
const seen = new Set();
|
|
296
|
+
for (const sourcePath of paths) {
|
|
297
|
+
const physicalPath = resolveBoundSourcePath(input.workspaceRoot, input.sourceBinding.taskId, sourcePath);
|
|
298
|
+
let text;
|
|
299
|
+
try {
|
|
300
|
+
text = await readFile(physicalPath, "utf8");
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const sourceSha256 = createHash("sha256").update(await readFile(physicalPath)).digest("hex");
|
|
306
|
+
const lines = text.split(/\r?\n/);
|
|
307
|
+
const add = (kind, key, lineIndex, quote) => {
|
|
308
|
+
const normalizedQuote = quote.trim().slice(0, 1000);
|
|
309
|
+
if (!normalizedQuote)
|
|
310
|
+
return;
|
|
311
|
+
const identity = `${kind}:${key}:${sourcePath}:${lineIndex + 1}`;
|
|
312
|
+
if (seen.has(identity))
|
|
313
|
+
return;
|
|
314
|
+
seen.add(identity);
|
|
315
|
+
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
316
|
+
const covered = kind === "business-rule"
|
|
317
|
+
? input.generatedMarkdown.includes(normalizedQuote)
|
|
318
|
+
: new RegExp(`\\b${escaped}\\b`).test(input.generatedMarkdown);
|
|
319
|
+
facts.push({
|
|
320
|
+
kind,
|
|
321
|
+
key,
|
|
322
|
+
sourcePath,
|
|
323
|
+
sourceSha256,
|
|
324
|
+
lineStart: lineIndex + 1,
|
|
325
|
+
lineEnd: lineIndex + 1,
|
|
326
|
+
quote: normalizedQuote,
|
|
327
|
+
covered,
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
lines.forEach((line, lineIndex) => {
|
|
331
|
+
for (const key of line.match(SOURCE_RULE_ID_IN_TEXT) ?? [])
|
|
332
|
+
add("requirement-id", key, lineIndex, line);
|
|
333
|
+
for (const key of line.match(SOURCE_ERROR_CODE_IN_TEXT) ?? [])
|
|
334
|
+
add("error-code", key, lineIndex, line);
|
|
335
|
+
for (const match of line.matchAll(JSON_FIELD_IN_TEXT))
|
|
336
|
+
add("dto-field", match[1], lineIndex, line);
|
|
337
|
+
for (const match of line.matchAll(DTO_FIELD_IN_TEXT))
|
|
338
|
+
add("dto-field", match[1], lineIndex, line);
|
|
339
|
+
const trimmed = line.trim();
|
|
340
|
+
if (trimmed.length >= 8 && trimmed.length <= 1000 && !/^\s*(?:#|\||[-:]{3,})/.test(trimmed) && NATURAL_BUSINESS_RULE_KEYWORDS.test(trimmed) && NATURAL_BUSINESS_RULE_NORMATIVE.test(trimmed)) {
|
|
341
|
+
add("business-rule", `BR-SOURCE-${sourceSha256.slice(0, 8).toUpperCase()}-L${lineIndex + 1}`, lineIndex, trimmed);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return facts.sort((left, right) => left.kind.localeCompare(right.kind) || left.key.localeCompare(right.key) || left.sourcePath.localeCompare(right.sourcePath) || left.lineStart - right.lineStart);
|
|
346
|
+
}
|
|
239
347
|
function resolveBoundSourcePath(workspaceRoot, taskId, sourcePath) {
|
|
240
348
|
if (path.isAbsolute(sourcePath))
|
|
241
349
|
return sourcePath;
|
|
@@ -385,8 +493,14 @@ function sectionBody(body, aliases) {
|
|
|
385
493
|
}
|
|
386
494
|
function listTokens(body, aliases, pattern) {
|
|
387
495
|
const section = sectionBody(body, aliases).replaceAll("`", "");
|
|
388
|
-
|
|
389
|
-
|
|
496
|
+
// Prefer dedicated token patterns; never strip ^/$ from alternation-based anchors
|
|
497
|
+
// (that would turn `^A$|^B$` into `A$|^B` and break scanning).
|
|
498
|
+
const tokenSource = pattern === RULE_KEY
|
|
499
|
+
? RULE_KEY_TOKEN.source
|
|
500
|
+
: pattern === TEST_POINT
|
|
501
|
+
? TEST_POINT.source.replace(/^\^/, "").replace(/\$$/, "")
|
|
502
|
+
: pattern.source.replace(/^\^/, "").replace(/\$$/, "");
|
|
503
|
+
return orderedUnique(section.match(new RegExp(tokenSource, "g")) ?? []);
|
|
390
504
|
}
|
|
391
505
|
function scenarioTypes(body) {
|
|
392
506
|
return orderedUnique(sectionBody(body, CASE_SECTION_ALIASES.scenarioTypes)
|
|
@@ -423,8 +537,40 @@ function testPointBindingFacts(body, testPoints) {
|
|
|
423
537
|
}
|
|
424
538
|
function declaredPrimarySymbols(body) {
|
|
425
539
|
const value = automationLabelBody(body, ["primary symbol", "Primary Symbol", "主测试符号"]);
|
|
540
|
+
if (/^(?:none|无|n\/a|not-applicable)$/i.test(value.trim()))
|
|
541
|
+
return [];
|
|
426
542
|
return orderedUnique(value.match(/\btest_[A-Za-z0-9_]+\b/g) ?? []);
|
|
427
543
|
}
|
|
544
|
+
function isEvidenceOnlyMarkdownCase(testCase) {
|
|
545
|
+
const hasVariant = testCase.testPointBindings.some((item) => item.mode === "variant");
|
|
546
|
+
const hasNonVariant = testCase.testPointBindings.some((item) => item.mode === "assertion" || item.mode === "cross-cutting");
|
|
547
|
+
return (testCase.declaredScripts.length === 0 &&
|
|
548
|
+
testCase.declaredPrimarySymbols.length === 0 &&
|
|
549
|
+
!hasVariant &&
|
|
550
|
+
hasNonVariant);
|
|
551
|
+
}
|
|
552
|
+
function payloadContract(body) {
|
|
553
|
+
const contractValue = automationLabelBody(body, ["Payload Contract", "载荷合同"]);
|
|
554
|
+
const requiredValue = automationLabelBody(body, ["Payload Required Paths", "载荷必需路径"]);
|
|
555
|
+
const allowedValue = automationLabelBody(body, ["Payload Allowed Paths", "载荷允许路径"]);
|
|
556
|
+
const enumValue = automationLabelBody(body, ["Payload Enum", "载荷枚举"]);
|
|
557
|
+
const tokens = (value) => orderedUnique(value.split(/[,;,;]/).map((item) => item.trim()).filter((item) => /^[A-Za-z_][A-Za-z0-9_.]*$/.test(item)));
|
|
558
|
+
const enumValues = {};
|
|
559
|
+
for (const assignment of enumValue.split(/[,;,;]/).map((item) => item.trim()).filter(Boolean)) {
|
|
560
|
+
const match = /^([A-Za-z_][A-Za-z0-9_.]*)\s*=\s*(.+)$/.exec(assignment);
|
|
561
|
+
if (!match)
|
|
562
|
+
continue;
|
|
563
|
+
enumValues[match[1]] = orderedUnique(match[2].split(/\||\//).map((item) => item.trim().replace(/^['"]|['"]$/g, "")).filter(Boolean));
|
|
564
|
+
}
|
|
565
|
+
const noPayload = /^(?:none|无|not-applicable|n\/a)$/i.test(contractValue);
|
|
566
|
+
return {
|
|
567
|
+
declared: noPayload || requiredValue.length > 0 || allowedValue.length > 0 || enumValue.length > 0,
|
|
568
|
+
noPayload,
|
|
569
|
+
requiredPaths: tokens(requiredValue),
|
|
570
|
+
allowedPaths: tokens(allowedValue),
|
|
571
|
+
enumValues,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
428
574
|
function cleanTitle(heading, id) {
|
|
429
575
|
return heading.replace(/^##\s+/, "").replace(/^BE-[A-Z0-9_-]+-\d{2,3}\s*(?:[||—–-]\s*)?/i, "").trim() || id;
|
|
430
576
|
}
|
|
@@ -466,6 +612,7 @@ async function parseMarkdownCases(workspaceRoot) {
|
|
|
466
612
|
scenarioTypes: scenarioTypes(body),
|
|
467
613
|
declaredScripts: declaredScripts(body),
|
|
468
614
|
declaredPrimarySymbols: declaredPrimarySymbols(body),
|
|
615
|
+
payloadContract: payloadContract(body),
|
|
469
616
|
body,
|
|
470
617
|
});
|
|
471
618
|
}
|
|
@@ -483,8 +630,17 @@ function parseTableRow(line) {
|
|
|
483
630
|
index += 1;
|
|
484
631
|
}
|
|
485
632
|
else if (char === "|") {
|
|
486
|
-
|
|
487
|
-
|
|
633
|
+
const prev = trimmed[index - 1] ?? "";
|
|
634
|
+
const next = trimmed[index + 1] ?? "";
|
|
635
|
+
// In-cell enum/value pipes look like ACTIVE|ARCHIVED (alnum on both sides).
|
|
636
|
+
// Column separators use " | " or touch markdown separator dashes (---|---).
|
|
637
|
+
if (/[A-Za-z0-9_]/.test(prev) && /[A-Za-z0-9_]/.test(next)) {
|
|
638
|
+
current += "|";
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
cells.push(current.trim());
|
|
642
|
+
current = "";
|
|
643
|
+
}
|
|
488
644
|
}
|
|
489
645
|
else {
|
|
490
646
|
current += char;
|
|
@@ -687,7 +843,10 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
687
843
|
if (!rowCaseIds.includes(testCase.caseId))
|
|
688
844
|
findings.push(`${testCase.caseId} references ${ruleKey} but is absent from its Coverage Matrix Case IDs`);
|
|
689
845
|
}
|
|
690
|
-
|
|
846
|
+
const normalizedDeclaredStatus = /^(?:COVERED|PARTIAL|GAP|CONFLICT)$/.test(declaredStatus)
|
|
847
|
+
? declaredStatus
|
|
848
|
+
: "PARTIAL";
|
|
849
|
+
let status = normalizedDeclaredStatus;
|
|
691
850
|
if (status === "COVERED" && missingTestPoints.length > 0)
|
|
692
851
|
status = "PARTIAL";
|
|
693
852
|
if (missingTestPoints.length > 0)
|
|
@@ -707,7 +866,7 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
707
866
|
rule: row.Rule || "unavailable",
|
|
708
867
|
requiredTestPoints,
|
|
709
868
|
caseIds: rowCaseIds,
|
|
710
|
-
declaredStatus:
|
|
869
|
+
declaredStatus: normalizedDeclaredStatus,
|
|
711
870
|
coveredTestPoints,
|
|
712
871
|
missingTestPoints,
|
|
713
872
|
status,
|
|
@@ -749,8 +908,12 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
749
908
|
findings.push(`${testCase.caseId} missing section or entries: 测试点`);
|
|
750
909
|
if (testCase.scenarioTypes.length === 0)
|
|
751
910
|
findings.push(`${testCase.caseId} missing section or entries: 场景类型`);
|
|
752
|
-
if (testCase
|
|
911
|
+
if (isEvidenceOnlyMarkdownCase(testCase)) {
|
|
912
|
+
// Evidence-only meta cases intentionally declare 脚本/primary symbol as 无 and only keep assertion/cross-cutting TPs.
|
|
913
|
+
}
|
|
914
|
+
else if (testCase.declaredPrimarySymbols.length !== 1) {
|
|
753
915
|
findings.push(`${testCase.caseId} must declare exactly one primary symbol`);
|
|
916
|
+
}
|
|
754
917
|
if (testCase.unclassifiedTestPoints.length > 0)
|
|
755
918
|
findings.push(`${testCase.caseId} has unclassified Test Points: ${testCase.unclassifiedTestPoints.join(", ")}`);
|
|
756
919
|
if (testCase.duplicateBindingTestPoints.length > 0)
|
|
@@ -772,8 +935,28 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
772
935
|
if (uniqueOwners.length > 1)
|
|
773
936
|
findings.push(`${testPoint} is bound as a non-cross-cutting Test Point by multiple Cases: ${uniqueOwners.join(", ")}`);
|
|
774
937
|
}
|
|
775
|
-
const
|
|
938
|
+
const generatedMarkdown = [readme, ...cases.map((item) => item.body)].join("\n\n");
|
|
939
|
+
const sourceCoverageFacts = await collectSourceCoverageFacts({
|
|
940
|
+
workspaceRoot: input.workspaceRoot,
|
|
941
|
+
sourceBinding: input.sourceBinding,
|
|
942
|
+
generatedMarkdown,
|
|
943
|
+
});
|
|
944
|
+
const residualSourceFacts = sourceCoverageFacts.filter((fact) => !fact.covered);
|
|
945
|
+
for (const fact of residualSourceFacts) {
|
|
946
|
+
findings.push(`source coverage is missing ${fact.kind} ${fact.key} from ${fact.sourcePath}`);
|
|
947
|
+
}
|
|
948
|
+
const sourceRequirementIds = sourceCoverageFacts
|
|
949
|
+
.filter((fact) => fact.kind === "requirement-id")
|
|
950
|
+
.map((fact) => fact.key);
|
|
951
|
+
const explicitAc = orderedUnique([
|
|
952
|
+
...input.sourceBinding.requirementIds.filter((id) => id.startsWith("AC-")),
|
|
953
|
+
...sourceRequirementIds.filter((id) => id.startsWith("AC-")),
|
|
954
|
+
]);
|
|
776
955
|
const coveredAc = new Set(cases.flatMap((item) => item.acIds));
|
|
956
|
+
for (const acId of explicitAc) {
|
|
957
|
+
if (!coveredAc.has(acId))
|
|
958
|
+
findings.push(`explicit source AC is missing from Markdown Cases: ${acId}`);
|
|
959
|
+
}
|
|
777
960
|
const [enumValueCount, coveredEnumValueCount] = dimensionCounts(rules, /enum/);
|
|
778
961
|
const [boundaryPointCount, coveredBoundaryPointCount] = dimensionCounts(rules, /boundary|length|numeric/);
|
|
779
962
|
const [formatClassCount, coveredFormatClassCount] = dimensionCounts(rules, /format|pattern|charset/);
|
|
@@ -782,8 +965,8 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
782
965
|
const invalidEquivalenceClassCount = rules.reduce((sum, rule) => sum + rule.requiredTestPoints.filter((point) => invalidPointPattern.test(point)).length, 0);
|
|
783
966
|
const coveredInvalidEquivalenceClassCount = rules.reduce((sum, rule) => sum + rule.coveredTestPoints.filter((point) => invalidPointPattern.test(point)).length, 0);
|
|
784
967
|
const facts = backendTestCaseCoverageFactsSchema.parse({
|
|
785
|
-
schemaId: "backend-test-case-coverage-facts-
|
|
786
|
-
schemaVersion:
|
|
968
|
+
schemaId: "backend-test-case-coverage-facts-v4",
|
|
969
|
+
schemaVersion: 4,
|
|
787
970
|
taskId: input.sourceBinding.taskId,
|
|
788
971
|
status: findings.length === 0 ? "PASS" : "FAIL",
|
|
789
972
|
sourceBinding: input.sourceBinding,
|
|
@@ -796,6 +979,13 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
796
979
|
}))).filter(Boolean),
|
|
797
980
|
]),
|
|
798
981
|
coverageScope: coverageScope.scope,
|
|
982
|
+
sourceCoverage: {
|
|
983
|
+
sourceFactCount: sourceCoverageFacts.length,
|
|
984
|
+
coveredSourceFactCount: sourceCoverageFacts.length - residualSourceFacts.length,
|
|
985
|
+
residualSourceFactCount: residualSourceFacts.length,
|
|
986
|
+
facts: sourceCoverageFacts,
|
|
987
|
+
residual: residualSourceFacts,
|
|
988
|
+
},
|
|
799
989
|
summary: {
|
|
800
990
|
explicitAcCount: explicitAc.length,
|
|
801
991
|
coveredAcCount: explicitAc.filter((id) => coveredAc.has(id)).length,
|
|
@@ -846,6 +1036,22 @@ export async function analyzeBackendTestCaseCoverage(input) {
|
|
|
846
1036
|
`- Scope Evidence: ${facts.coverageScope.scopeEvidence.join(", ") || "Unavailable"}`,
|
|
847
1037
|
...(facts.coverageScope.completenessClaim === "affected-scope" ? ["- Coverage is scoped to affected operations; it is not whole-API completeness."] : ["- Coverage fully evaluates the declared affected operations; it is not whole-API completeness unless every operation is explicitly listed."]),
|
|
848
1038
|
"",
|
|
1039
|
+
"## Source Coverage Inventory",
|
|
1040
|
+
"",
|
|
1041
|
+
`- Source facts: ${facts.sourceCoverage.sourceFactCount}`,
|
|
1042
|
+
`- Covered source facts: ${facts.sourceCoverage.coveredSourceFactCount}`,
|
|
1043
|
+
`- Residual source facts: ${facts.sourceCoverage.residualSourceFactCount}`,
|
|
1044
|
+
"",
|
|
1045
|
+
"| Kind | Key | Source Anchor | Source SHA-256 | Exact Quote | Status |",
|
|
1046
|
+
"|---|---|---|---|---|---|",
|
|
1047
|
+
...facts.sourceCoverage.facts.map((fact) => `| ${fact.kind} | ${fact.key} | ${fact.sourcePath}:L${fact.lineStart} | ${fact.sourceSha256} | ${fact.quote.replaceAll("|", "\\|")} | ${fact.covered ? "COVERED" : "MISSING_AFTER_SYNC"} |`),
|
|
1048
|
+
"",
|
|
1049
|
+
"## Residual Missing Source Scenarios",
|
|
1050
|
+
"",
|
|
1051
|
+
...(facts.sourceCoverage.residual.length > 0
|
|
1052
|
+
? facts.sourceCoverage.residual.map((fact) => `- ${fact.kind} \`${fact.key}\` from \`${fact.sourcePath}:L${fact.lineStart}\` (sha256 \`${fact.sourceSha256}\`), quote: “${fact.quote}”: missing after the bounded Markdown synchronization round; no full-coverage claim is allowed.`)
|
|
1053
|
+
: ["- None"]),
|
|
1054
|
+
"",
|
|
849
1055
|
"## Coverage Summary",
|
|
850
1056
|
"",
|
|
851
1057
|
"| Dimension | Total | Covered |",
|
|
@@ -909,6 +1115,103 @@ function symbolCaseId(symbol) {
|
|
|
909
1115
|
const match = symbol.match(/^test_(BE(?:_[A-Z0-9]+)+?_\d{2,3})(?:_|$)/i);
|
|
910
1116
|
return match ? canonicalCaseId(match[1].replaceAll("_", "-")) : undefined;
|
|
911
1117
|
}
|
|
1118
|
+
function pythonPayloadShapes(source) {
|
|
1119
|
+
const program = String.raw `
|
|
1120
|
+
import ast,json,sys
|
|
1121
|
+
source=sys.stdin.buffer.read().decode('utf-8')
|
|
1122
|
+
tree=ast.parse(source)
|
|
1123
|
+
GLOBAL_PAYLOADS={}
|
|
1124
|
+
for top in tree.body:
|
|
1125
|
+
if isinstance(top,ast.Assign):
|
|
1126
|
+
names=[target.id for target in top.targets if isinstance(target,ast.Name)]
|
|
1127
|
+
candidates=[]
|
|
1128
|
+
for node in ast.walk(top.value):
|
|
1129
|
+
if isinstance(node,ast.Call) and isinstance(node.func,ast.Attribute) and node.func.attr == 'param' and node.args and isinstance(node.args[0],ast.Dict): candidates.append(node.args[0])
|
|
1130
|
+
if isinstance(top.value,ast.Dict) and any(name.lower() in {'payload','body','request_body','request_json','dto'} for name in names): candidates.append(top.value)
|
|
1131
|
+
for name in names: GLOBAL_PAYLOADS[name]=candidates
|
|
1132
|
+
FUNCTION_PAYLOADS={}
|
|
1133
|
+
for top in tree.body:
|
|
1134
|
+
if isinstance(top,(ast.FunctionDef,ast.AsyncFunctionDef)) and not top.name.startswith('test_'):
|
|
1135
|
+
candidates=[]
|
|
1136
|
+
assigned={}
|
|
1137
|
+
for node in ast.walk(top):
|
|
1138
|
+
if isinstance(node,ast.Assign) and isinstance(node.value,ast.Dict):
|
|
1139
|
+
for target in node.targets:
|
|
1140
|
+
if isinstance(target,ast.Name): assigned[target.id]=node.value
|
|
1141
|
+
if isinstance(node,ast.Return):
|
|
1142
|
+
if isinstance(node.value,ast.Dict): candidates.append(node.value)
|
|
1143
|
+
elif isinstance(node.value,ast.Name) and node.value.id in assigned: candidates.append(assigned[node.value.id])
|
|
1144
|
+
if candidates: FUNCTION_PAYLOADS[top.name]=candidates
|
|
1145
|
+
|
|
1146
|
+
def literal(node):
|
|
1147
|
+
if isinstance(node, ast.Constant) and isinstance(node.value, (str,int,float,bool,type(None))):
|
|
1148
|
+
return repr(node.value)
|
|
1149
|
+
return None
|
|
1150
|
+
|
|
1151
|
+
def collect_dict(node, prefix, paths, values):
|
|
1152
|
+
if not isinstance(node, ast.Dict): return
|
|
1153
|
+
for key,value in zip(node.keys,node.values):
|
|
1154
|
+
if not isinstance(key, ast.Constant) or not isinstance(key.value,str): continue
|
|
1155
|
+
current = key.value if not prefix else prefix + '.' + key.value
|
|
1156
|
+
paths.add(current)
|
|
1157
|
+
lv=literal(value)
|
|
1158
|
+
if lv is not None: values.setdefault(current,set()).add(lv)
|
|
1159
|
+
if isinstance(value, ast.Dict): collect_dict(value,current,paths,values)
|
|
1160
|
+
elif isinstance(value,(ast.List,ast.Tuple)):
|
|
1161
|
+
for item in value.elts:
|
|
1162
|
+
if isinstance(item,ast.Dict): collect_dict(item,current,paths,values)
|
|
1163
|
+
|
|
1164
|
+
def payload_nodes(fn):
|
|
1165
|
+
result=[]
|
|
1166
|
+
for dec in fn.decorator_list:
|
|
1167
|
+
for node in ast.walk(dec):
|
|
1168
|
+
if isinstance(node,ast.Call) and isinstance(node.func,ast.Attribute) and node.func.attr == 'param' and node.args:
|
|
1169
|
+
if isinstance(node.args[0],ast.Dict): result.append(node.args[0])
|
|
1170
|
+
elif isinstance(node,ast.Name) and node.id in GLOBAL_PAYLOADS:
|
|
1171
|
+
result.extend(GLOBAL_PAYLOADS[node.id])
|
|
1172
|
+
for node in ast.walk(fn):
|
|
1173
|
+
if isinstance(node,ast.Assign):
|
|
1174
|
+
names=[target.id for target in node.targets if isinstance(target,ast.Name)]
|
|
1175
|
+
if any(name.lower() in {'payload','body','request_body','request_json','dto'} for name in names) and isinstance(node.value,ast.Dict): result.append(node.value)
|
|
1176
|
+
if isinstance(node,ast.Call):
|
|
1177
|
+
if isinstance(node.func,ast.Name) and node.func.id in FUNCTION_PAYLOADS:
|
|
1178
|
+
result.extend(FUNCTION_PAYLOADS[node.func.id])
|
|
1179
|
+
override_keys=[]; override_values=[]
|
|
1180
|
+
for keyword in node.keywords:
|
|
1181
|
+
if keyword.arg:
|
|
1182
|
+
override_keys.append(ast.Constant(keyword.arg)); override_values.append(keyword.value)
|
|
1183
|
+
if override_keys: result.append(ast.Dict(keys=override_keys,values=override_values))
|
|
1184
|
+
for keyword in node.keywords:
|
|
1185
|
+
if keyword.arg in {'json','data','payload','body','request_body'} and isinstance(keyword.value,ast.Dict): result.append(keyword.value)
|
|
1186
|
+
return result
|
|
1187
|
+
|
|
1188
|
+
out={}
|
|
1189
|
+
for fn in ast.walk(tree):
|
|
1190
|
+
if isinstance(fn,(ast.FunctionDef,ast.AsyncFunctionDef)) and fn.name.startswith('test_'):
|
|
1191
|
+
paths=set(); values={}
|
|
1192
|
+
for node in payload_nodes(fn): collect_dict(node,'',paths,values)
|
|
1193
|
+
out[fn.name]={'paths':sorted(paths),'values':{key:sorted(items) for key,items in sorted(values.items())}}
|
|
1194
|
+
print(json.dumps(out,ensure_ascii=True))
|
|
1195
|
+
`;
|
|
1196
|
+
// Pass bytes and decode stdin explicitly as UTF-8 in Python. Clean-env
|
|
1197
|
+
// Windows Python may expose stdin as GBK; decoding generated Chinese/emoji
|
|
1198
|
+
// source through that locale can create surrogateescape code points and make
|
|
1199
|
+
// ast.parse fail with "surrogates not allowed".
|
|
1200
|
+
const result = spawnSync("python", ["-c", program], { input: Buffer.from(source, "utf8"), encoding: "utf8", maxBuffer: 4 * 1024 * 1024, windowsHide: true });
|
|
1201
|
+
if (result.status !== 0 || !result.stdout.trim())
|
|
1202
|
+
return new Map();
|
|
1203
|
+
try {
|
|
1204
|
+
const parsed = JSON.parse(result.stdout);
|
|
1205
|
+
return new Map(Object.entries(parsed));
|
|
1206
|
+
}
|
|
1207
|
+
catch {
|
|
1208
|
+
return new Map();
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
function metadataCaseIds(region) {
|
|
1212
|
+
return orderedUnique([...region.matchAll(/^\s*Case-ID\s*:\s*(BE-[A-Z0-9]+(?:-[A-Z0-9]+)*)\s*$/gmi)]
|
|
1213
|
+
.map((match) => canonicalCaseId(match[1])));
|
|
1214
|
+
}
|
|
912
1215
|
function metadataTestPoints(region, label) {
|
|
913
1216
|
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
914
1217
|
const match = new RegExp(`^\\s*${escaped}\\s*:\\s*(.*)$`, "mi").exec(region);
|
|
@@ -928,6 +1231,27 @@ function pytestFunctionRegionStart(source, functionIndex) {
|
|
|
928
1231
|
}
|
|
929
1232
|
return regionStart;
|
|
930
1233
|
}
|
|
1234
|
+
function pytestFunctionBodyEnd(source, signatureEnd, functionIndent) {
|
|
1235
|
+
let cursor = source.indexOf("\n", signatureEnd);
|
|
1236
|
+
if (cursor < 0)
|
|
1237
|
+
return source.length;
|
|
1238
|
+
cursor += 1;
|
|
1239
|
+
const baseIndent = functionIndent.replaceAll("\t", " ").length;
|
|
1240
|
+
while (cursor < source.length) {
|
|
1241
|
+
const nextLine = source.indexOf("\n", cursor);
|
|
1242
|
+
const lineEnd = nextLine < 0 ? source.length : nextLine;
|
|
1243
|
+
const line = source.slice(cursor, lineEnd).replace(/\r$/, "");
|
|
1244
|
+
if (line.trim()) {
|
|
1245
|
+
const indentation = line.match(/^[ \t]*/)?.[0]?.replaceAll("\t", " ").length ?? 0;
|
|
1246
|
+
if (indentation <= baseIndent)
|
|
1247
|
+
return cursor;
|
|
1248
|
+
}
|
|
1249
|
+
if (nextLine < 0)
|
|
1250
|
+
return source.length;
|
|
1251
|
+
cursor = nextLine + 1;
|
|
1252
|
+
}
|
|
1253
|
+
return source.length;
|
|
1254
|
+
}
|
|
931
1255
|
function pytestParameterCollections(source) {
|
|
932
1256
|
const collections = new Map();
|
|
933
1257
|
for (const match of source.matchAll(/^([A-Z][A-Z0-9_]*)\s*=\s*\[([\s\S]*?)^\]/gm)) {
|
|
@@ -939,12 +1263,13 @@ function pytestSymbols(script, source) {
|
|
|
939
1263
|
const matches = [...source.matchAll(/^([ \t]*)(?:async\s+)?def\s+(test_[A-Za-z0-9_]+)\s*\([^)]*\)\s*(?:->\s*[^:\r\n]+)?\s*:/gm)];
|
|
940
1264
|
const regionStarts = matches.map((match) => pytestFunctionRegionStart(source, match.index));
|
|
941
1265
|
const parameterCollections = pytestParameterCollections(source);
|
|
1266
|
+
const payloadShapes = pythonPayloadShapes(source);
|
|
942
1267
|
return matches.map((match, index) => {
|
|
943
1268
|
const regionStart = regionStarts[index];
|
|
944
|
-
const regionEnd =
|
|
1269
|
+
const regionEnd = pytestFunctionBodyEnd(source, match.index + match[0].length, match[1]);
|
|
945
1270
|
const region = source.slice(match.index, regionEnd);
|
|
946
1271
|
const decorators = source.slice(regionStart, match.index);
|
|
947
|
-
const ids =
|
|
1272
|
+
const ids = metadataCaseIds(region);
|
|
948
1273
|
const fromSymbol = symbolCaseId(match[2]);
|
|
949
1274
|
if (fromSymbol)
|
|
950
1275
|
ids.unshift(fromSymbol);
|
|
@@ -954,6 +1279,7 @@ function pytestSymbols(script, source) {
|
|
|
954
1279
|
]);
|
|
955
1280
|
const assertionTestPoints = metadataTestPoints(region, "Assertion-Test-Points");
|
|
956
1281
|
const crossCuttingTestPoints = metadataTestPoints(region, "Cross-Cutting-Test-Points");
|
|
1282
|
+
const payloadShape = payloadShapes.get(match[2]) ?? { paths: [], values: {} };
|
|
957
1283
|
return {
|
|
958
1284
|
script,
|
|
959
1285
|
symbol: match[2],
|
|
@@ -962,9 +1288,51 @@ function pytestSymbols(script, source) {
|
|
|
962
1288
|
parameterIds,
|
|
963
1289
|
assertionTestPoints,
|
|
964
1290
|
crossCuttingTestPoints,
|
|
1291
|
+
payloadPaths: payloadShape.paths,
|
|
1292
|
+
payloadValues: payloadShape.values,
|
|
965
1293
|
};
|
|
966
1294
|
});
|
|
967
1295
|
}
|
|
1296
|
+
function executionSignature(testCase) {
|
|
1297
|
+
const operation = (testCase.body.match(/\b(?:GET|POST|PUT|PATCH|DELETE)\s+\/[^\s`|)]+/i)?.[0] ?? "operation-unavailable").toUpperCase();
|
|
1298
|
+
const inputPartition = [sectionBody(testCase.body, ["测试数据", "Test Data"]), testCase.scenarioTypes.join(" "), testCase.testPoints.join(" ")].join(" ");
|
|
1299
|
+
const precondition = sectionBody(testCase.body, ["前置条件", "Preconditions", "Precondition"]);
|
|
1300
|
+
const expectedOutcome = sectionBody(testCase.body, ["预期结果", "Expected Results", "Expected Result"]);
|
|
1301
|
+
const normalized = [operation, inputPartition, precondition, expectedOutcome]
|
|
1302
|
+
.map((value) => value.replaceAll(/\s+/g, " ").trim().toLowerCase())
|
|
1303
|
+
.join("\n");
|
|
1304
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
1305
|
+
}
|
|
1306
|
+
function assessPayloadContract(testCase, refs) {
|
|
1307
|
+
const observedPaths = orderedUnique(refs.flatMap((item) => item.payloadPaths));
|
|
1308
|
+
const requiredPaths = testCase.payloadContract.requiredPaths;
|
|
1309
|
+
const allowedPaths = testCase.payloadContract.allowedPaths;
|
|
1310
|
+
if (!testCase.payloadContract.declared) {
|
|
1311
|
+
return { status: "UNAVAILABLE", requiredPaths, allowedPaths, observedPaths, missingPaths: [], unexpectedPaths: [], enumMismatches: [] };
|
|
1312
|
+
}
|
|
1313
|
+
const missingPaths = requiredPaths.filter((item) => !observedPaths.includes(item));
|
|
1314
|
+
const unexpectedPaths = testCase.payloadContract.noPayload
|
|
1315
|
+
? observedPaths
|
|
1316
|
+
: allowedPaths.length > 0
|
|
1317
|
+
? observedPaths.filter((item) => !allowedPaths.includes(item) && !allowedPaths.some((allowed) => item.startsWith(`${allowed}.`)))
|
|
1318
|
+
: [];
|
|
1319
|
+
const enumMismatches = [];
|
|
1320
|
+
for (const [field, allowed] of Object.entries(testCase.payloadContract.enumValues)) {
|
|
1321
|
+
const observed = orderedUnique(refs.flatMap((item) => item.payloadValues[field] ?? []).map((value) => value.replace(/^['"]|['"]$/g, "")));
|
|
1322
|
+
for (const value of observed)
|
|
1323
|
+
if (!allowed.includes(value))
|
|
1324
|
+
enumMismatches.push(`${field}=${value}; allowed=${allowed.join("|")}`);
|
|
1325
|
+
}
|
|
1326
|
+
return {
|
|
1327
|
+
status: missingPaths.length > 0 || unexpectedPaths.length > 0 || enumMismatches.length > 0 ? "UNSAFE" : "SAFE",
|
|
1328
|
+
requiredPaths,
|
|
1329
|
+
allowedPaths,
|
|
1330
|
+
observedPaths,
|
|
1331
|
+
missingPaths,
|
|
1332
|
+
unexpectedPaths,
|
|
1333
|
+
enumMismatches,
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
968
1336
|
export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
969
1337
|
const cases = await parseMarkdownCases(input.workspaceRoot);
|
|
970
1338
|
const modulePaths = orderedUnique(cases.map((item) => item.markdownPath));
|
|
@@ -998,21 +1366,44 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
998
1366
|
...crossCuttingTestPoints.filter((point) => crossCuttingBindings.includes(point)),
|
|
999
1367
|
]);
|
|
1000
1368
|
const declaredPrimarySymbol = testCase.declaredPrimarySymbols[0];
|
|
1369
|
+
const evidenceOnly = isEvidenceOnlyMarkdownCase(testCase);
|
|
1001
1370
|
const cardinality = refs.length === 0 ? "1:0" : refs.length === 1 ? "1:1" : "1:N";
|
|
1002
|
-
let status = refs.length === 0
|
|
1371
|
+
let status = evidenceOnly && refs.length === 0
|
|
1372
|
+
? "EXACT_1_TO_1"
|
|
1373
|
+
: refs.length === 0
|
|
1374
|
+
? "MISSING_PYTEST"
|
|
1375
|
+
: refs.length > 1
|
|
1376
|
+
? "MULTIPLE_PYTEST"
|
|
1377
|
+
: "EXACT_1_TO_1";
|
|
1003
1378
|
const entryFindings = [];
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
if (
|
|
1007
|
-
|
|
1008
|
-
if (!declared || declared !== expected || actualScripts.some((script) => script !== expected) || !declaredPrimarySymbol || symbols.some((symbol) => symbol !== declaredPrimarySymbol)) {
|
|
1009
|
-
if (refs.length > 0 && status === "EXACT_1_TO_1")
|
|
1379
|
+
const payloadAssessment = assessPayloadContract(testCase, refs);
|
|
1380
|
+
const signature = executionSignature(testCase);
|
|
1381
|
+
if (evidenceOnly) {
|
|
1382
|
+
if (refs.length > 0) {
|
|
1010
1383
|
status = "SCRIPT_MISMATCH";
|
|
1011
|
-
|
|
1384
|
+
entryFindings.push(`${testCase.caseId} evidence-only Markdown Case must not materialize a business pytest symbol; actualSymbols=${symbols.join(", ") || "none"}`);
|
|
1385
|
+
}
|
|
1012
1386
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1387
|
+
else {
|
|
1388
|
+
if (refs.length === 0)
|
|
1389
|
+
entryFindings.push(`${testCase.caseId} has no pytest symbol`);
|
|
1390
|
+
if (refs.length > 1)
|
|
1391
|
+
entryFindings.push(`${testCase.caseId} maps to multiple pytest symbols: ${symbols.join(", ")}`);
|
|
1392
|
+
if (!declared || declared !== expected || actualScripts.some((script) => script !== expected) || !declaredPrimarySymbol || symbols.some((symbol) => symbol !== declaredPrimarySymbol)) {
|
|
1393
|
+
if (refs.length > 0 && status === "EXACT_1_TO_1")
|
|
1394
|
+
status = "SCRIPT_MISMATCH";
|
|
1395
|
+
entryFindings.push(`${testCase.caseId} script/primary-symbol mapping mismatch: declaredScript=${declared ?? "none"}, expectedScript=${expected}, actual=${actualScripts.join(", ") || "none"}, declaredPrimarySymbol=${declaredPrimarySymbol ?? "none"}, actualSymbols=${symbols.join(", ") || "none"}`);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
const missingVariant = evidenceOnly
|
|
1399
|
+
? []
|
|
1400
|
+
: variantTestPoints.filter((point) => !parameterIds.includes(point));
|
|
1401
|
+
const missingAssertion = evidenceOnly
|
|
1402
|
+
? []
|
|
1403
|
+
: assertionTestPoints.filter((point) => !assertionBindings.includes(point));
|
|
1404
|
+
const missingCrossCutting = evidenceOnly
|
|
1405
|
+
? []
|
|
1406
|
+
: crossCuttingTestPoints.filter((point) => !crossCuttingBindings.includes(point));
|
|
1016
1407
|
const extraPoints = orderedUnique([...parameterIds, ...assertionBindings, ...crossCuttingBindings]).filter((point) => !testCase.testPoints.includes(point));
|
|
1017
1408
|
if (testCase.unclassifiedTestPoints.length > 0 || testCase.duplicateBindingTestPoints.length > 0) {
|
|
1018
1409
|
if (refs.length > 0 && status === "EXACT_1_TO_1")
|
|
@@ -1039,6 +1430,16 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1039
1430
|
status = "TEST_POINT_BINDING_EXTRA";
|
|
1040
1431
|
entryFindings.push(`${testCase.caseId} has extra pytest Test Point bindings: ${extraPoints.join(", ")}`);
|
|
1041
1432
|
}
|
|
1433
|
+
if (payloadAssessment.status === "UNAVAILABLE") {
|
|
1434
|
+
if (refs.length > 0 && status === "EXACT_1_TO_1")
|
|
1435
|
+
status = "PAYLOAD_CONTRACT_UNAVAILABLE";
|
|
1436
|
+
entryFindings.push(`${testCase.caseId} has no deterministic Payload Contract declaration`);
|
|
1437
|
+
}
|
|
1438
|
+
else if (payloadAssessment.status === "UNSAFE") {
|
|
1439
|
+
if (refs.length > 0 && status === "EXACT_1_TO_1")
|
|
1440
|
+
status = "PAYLOAD_SHAPE_MISMATCH";
|
|
1441
|
+
entryFindings.push(`${testCase.caseId} payload contract mismatch: missing=${payloadAssessment.missingPaths.join(", ") || "none"}; unexpected=${payloadAssessment.unexpectedPaths.join(", ") || "none"}; enum=${payloadAssessment.enumMismatches.join(", ") || "none"}`);
|
|
1442
|
+
}
|
|
1042
1443
|
findings.push(...entryFindings);
|
|
1043
1444
|
entries.push({
|
|
1044
1445
|
markdownModule: testCase.markdownPath,
|
|
@@ -1056,6 +1457,8 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1056
1457
|
parameterIds,
|
|
1057
1458
|
cardinality,
|
|
1058
1459
|
status,
|
|
1460
|
+
payloadAssessment,
|
|
1461
|
+
executionSignature: signature,
|
|
1059
1462
|
findings: entryFindings,
|
|
1060
1463
|
});
|
|
1061
1464
|
}
|
|
@@ -1082,9 +1485,27 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1082
1485
|
parameterIds: symbol.parameterIds,
|
|
1083
1486
|
cardinality: "0:1",
|
|
1084
1487
|
status: unknownId ? "EXTRA_PYTEST" : "SYMBOL_MISSING_CASE_ID",
|
|
1488
|
+
payloadAssessment: {
|
|
1489
|
+
status: "UNAVAILABLE",
|
|
1490
|
+
requiredPaths: [],
|
|
1491
|
+
allowedPaths: [],
|
|
1492
|
+
observedPaths: symbol.payloadPaths,
|
|
1493
|
+
missingPaths: [],
|
|
1494
|
+
unexpectedPaths: [],
|
|
1495
|
+
enumMismatches: [],
|
|
1496
|
+
},
|
|
1085
1497
|
findings: [message],
|
|
1086
1498
|
});
|
|
1087
1499
|
}
|
|
1500
|
+
const duplicateSignatures = new Map();
|
|
1501
|
+
for (const entry of entries.filter((item) => item.caseId && item.executionSignature)) {
|
|
1502
|
+
const owners = duplicateSignatures.get(entry.executionSignature) ?? [];
|
|
1503
|
+
owners.push(entry.caseId);
|
|
1504
|
+
duplicateSignatures.set(entry.executionSignature, owners);
|
|
1505
|
+
}
|
|
1506
|
+
const duplicateSignatureGroups = [...duplicateSignatures.entries()].filter(([, owners]) => orderedUnique(owners).length > 1);
|
|
1507
|
+
for (const [signature, owners] of duplicateSignatureGroups)
|
|
1508
|
+
findings.push(`duplicate execution signature ${signature}: ${orderedUnique(owners).join(", ")}`);
|
|
1088
1509
|
const exactModuleCount = modulePaths.filter((modulePath) => {
|
|
1089
1510
|
const expected = expectedScript(modulePath);
|
|
1090
1511
|
const moduleCases = cases.filter((item) => item.markdownPath === modulePath);
|
|
@@ -1092,8 +1513,8 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1092
1513
|
}).length;
|
|
1093
1514
|
const caseEntries = entries.filter((entry) => entry.cardinality !== "0:1");
|
|
1094
1515
|
const facts = backendTestMarkdownPytestCorrespondenceFactsSchema.parse({
|
|
1095
|
-
schemaId: "backend-test-markdown-pytest-correspondence-facts-
|
|
1096
|
-
schemaVersion:
|
|
1516
|
+
schemaId: "backend-test-markdown-pytest-correspondence-facts-v3",
|
|
1517
|
+
schemaVersion: 3,
|
|
1097
1518
|
taskId: input.taskId,
|
|
1098
1519
|
status: findings.length === 0 ? "PASS" : "FAIL",
|
|
1099
1520
|
inputFiles: await inputFileFacts(input.workspaceRoot, [
|
|
@@ -1118,6 +1539,10 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1118
1539
|
crossCuttingTestPointCount: cases.reduce((sum, item) => sum + item.testPointBindings.filter((binding) => binding.mode === "cross-cutting").length, 0),
|
|
1119
1540
|
unclassifiedTestPointCount: cases.reduce((sum, item) => sum + item.unclassifiedTestPoints.length, 0),
|
|
1120
1541
|
duplicateBindingTestPointCount: cases.reduce((sum, item) => sum + item.duplicateBindingTestPoints.length, 0),
|
|
1542
|
+
payloadSafeCount: caseEntries.filter((entry) => entry.payloadAssessment.status === "SAFE").length,
|
|
1543
|
+
payloadUnsafeCount: caseEntries.filter((entry) => entry.payloadAssessment.status === "UNSAFE").length,
|
|
1544
|
+
payloadUnavailableCount: caseEntries.filter((entry) => entry.payloadAssessment.status === "UNAVAILABLE").length,
|
|
1545
|
+
duplicateExecutionSignatureCount: duplicateSignatureGroups.length,
|
|
1121
1546
|
},
|
|
1122
1547
|
entries,
|
|
1123
1548
|
findings: orderedUnique(findings),
|
|
@@ -1145,12 +1570,16 @@ export async function analyzeBackendTestMarkdownPytestCorrespondence(input) {
|
|
|
1145
1570
|
`- Cross-Cutting Test Points: ${facts.summary.crossCuttingTestPointCount}`,
|
|
1146
1571
|
`- Unclassified Test Points: ${facts.summary.unclassifiedTestPointCount}`,
|
|
1147
1572
|
`- Duplicate Test Point Bindings: ${facts.summary.duplicateBindingTestPointCount}`,
|
|
1573
|
+
`- Payload SAFE: ${facts.summary.payloadSafeCount}`,
|
|
1574
|
+
`- Payload UNSAFE: ${facts.summary.payloadUnsafeCount}`,
|
|
1575
|
+
`- Payload UNAVAILABLE: ${facts.summary.payloadUnavailableCount}`,
|
|
1576
|
+
`- Duplicate Execution Signatures: ${facts.summary.duplicateExecutionSignatureCount}`,
|
|
1148
1577
|
"",
|
|
1149
1578
|
"## Correspondence Matrix",
|
|
1150
1579
|
"",
|
|
1151
|
-
"| Markdown Module | Case ID | Variant | Assertion | Cross-Cutting | Mapped | Declared Script | Primary Symbol | Actual Script | Pytest Symbol | Parameter IDs | Cardinality | Status |",
|
|
1152
|
-
"
|
|
1153
|
-
...facts.entries.map((entry) => `| ${entry.markdownModule} | ${entry.caseId ?? "—"} | ${entry.variantTestPoints.join(", ") || "—"} | ${entry.assertionTestPoints.join(", ") || "—"} | ${entry.crossCuttingTestPoints.join(", ") || "—"} | ${entry.mappedTestPoints.join(", ") || "—"} | ${entry.declaredScript ?? "—"} | ${entry.declaredPrimarySymbol ?? "—"} | ${entry.actualScripts.join(", ") || "—"} | ${entry.pytestSymbols.join(", ") || "—"} | ${entry.parameterIds.join(", ") || "—"} | ${entry.cardinality} | ${entry.status} |`),
|
|
1580
|
+
"| Markdown Module | Case ID | Variant | Assertion | Cross-Cutting | Mapped | Declared Script | Primary Symbol | Actual Script | Pytest Symbol | Parameter IDs | Payload | Missing Paths | Unexpected Paths | Enum Mismatch | Cardinality | Status |",
|
|
1581
|
+
"|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|",
|
|
1582
|
+
...facts.entries.map((entry) => `| ${entry.markdownModule} | ${entry.caseId ?? "—"} | ${entry.variantTestPoints.join(", ") || "—"} | ${entry.assertionTestPoints.join(", ") || "—"} | ${entry.crossCuttingTestPoints.join(", ") || "—"} | ${entry.mappedTestPoints.join(", ") || "—"} | ${entry.declaredScript ?? "—"} | ${entry.declaredPrimarySymbol ?? "—"} | ${entry.actualScripts.join(", ") || "—"} | ${entry.pytestSymbols.join(", ") || "—"} | ${entry.parameterIds.join(", ") || "—"} | ${entry.payloadAssessment.status} | ${entry.payloadAssessment.missingPaths.join(", ") || "—"} | ${entry.payloadAssessment.unexpectedPaths.join(", ") || "—"} | ${entry.payloadAssessment.enumMismatches.join(", ") || "—"} | ${entry.cardinality} | ${entry.status} |`),
|
|
1154
1583
|
"",
|
|
1155
1584
|
"## Findings",
|
|
1156
1585
|
"",
|