Skip to content

Commit 29e4a3d

Browse files
authored
Merge pull request #1740 from Automattic/fix/editor-validate-browser-evidence
Surface editor validation browser evidence
2 parents 4ae169e + bec63a3 commit 29e4a3d

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

packages/cli/src/commands/recipe-run-workflow-evidence.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ function recipeBrowserEvidenceForExecution(execution: RecipeExecutionResult, man
8888
}
8989

9090
const parsed = parseJsonObject(execution.stdout)
91+
if (!parsed && command === "wordpress.editor-validate-blocks") {
92+
const evidence = recipeBrowserEvidenceFromEditorValidateBlocksExecution(execution, manifestFiles)
93+
return evidence ? [evidence] : []
94+
}
9195
if (!parsed) {
9296
return []
9397
}
@@ -99,10 +103,39 @@ function recipeBrowserEvidenceForExecution(execution: RecipeExecutionResult, man
99103
})
100104
}
101105

102-
const evidence = recipeBrowserEvidenceFromParsedExecution(execution, command, parsed, manifestFiles, recipe)
106+
const evidence = command === "wordpress.editor-validate-blocks"
107+
? recipeBrowserEvidenceFromEditorValidateBlocksExecution(execution, manifestFiles, parsed)
108+
: recipeBrowserEvidenceFromParsedExecution(execution, command, parsed, manifestFiles, recipe)
103109
return evidence ? [evidence] : []
104110
}
105111

112+
function recipeBrowserEvidenceFromEditorValidateBlocksExecution(execution: RecipeExecutionResult, manifestFiles: Map<string, ArtifactManifestFile>, parsed?: Record<string, unknown>): RecipeBrowserEvidence | undefined {
113+
const files = recipeBrowserEvidenceFiles({
114+
validateBlocks: "files/browser/editor-validate-blocks.json",
115+
summary: "files/browser/editor-validate-blocks-summary.json",
116+
}, manifestFiles)
117+
const summaryFile = browserEvidenceFileRef("files/browser/editor-validate-blocks-summary.json", manifestFiles)
118+
if (Object.keys(files).length === 0 && !summaryFile) {
119+
return undefined
120+
}
121+
122+
const validation = parsed ?? (typeof execution.result?.stdout === "string" ? parseJsonObject(execution.result.stdout) : undefined)
123+
const summary = stripUndefined({
124+
editorValidateBlocks: validation,
125+
})
126+
return stripUndefined({
127+
schema: "wp-codebox/recipe-browser-evidence/v1",
128+
phase: execution.recipePhase,
129+
index: execution.recipeStepIndex,
130+
command: "wordpress.editor-validate-blocks",
131+
metadata: execution.recipeStepMetadata,
132+
status: execution.exitCode === 0 ? "completed" : "failed",
133+
summaryFile,
134+
files,
135+
summary: Object.keys(summary).length > 0 ? summary : undefined,
136+
}) as RecipeBrowserEvidence
137+
}
138+
106139
function recipeBrowserEvidenceFromParsedExecution(execution: RecipeExecutionResult, command: string, parsed: Record<string, unknown>, manifestFiles: Map<string, ArtifactManifestFile>, recipe: WorkspaceRecipe | undefined): RecipeBrowserEvidence | undefined {
107140
const files = recipeBrowserEvidenceFiles(parsed.files, manifestFiles)
108141
const summaryFile = browserEvidenceFileRef(stringValue((parsed.files as Record<string, unknown> | undefined)?.summary), manifestFiles)
@@ -169,7 +202,7 @@ function browserEvidenceFileRef(path: string | undefined, manifestFiles: Map<str
169202
}
170203

171204
function recipeCommandProducesBrowserEvidence(command: string): boolean {
172-
return command.startsWith("wordpress.browser-") || command === "wordpress.editor-canvas-probe" || command === "wordpress.html-capture" || command === "wordpress.visual-compare"
205+
return command.startsWith("wordpress.browser-") || command === "wordpress.editor-canvas-probe" || command === "wordpress.editor-validate-blocks" || command === "wordpress.html-capture" || command === "wordpress.visual-compare"
173206
}
174207

175208
export async function executeRecipeWorkflowStep(runtime: Runtime, workflowStep: ReturnType<typeof recipeWorkflowSteps>[number], recipeDirectory: string, sandboxWorkspace?: ReturnType<typeof sandboxWorkspaceContract>, artifactRoot?: string, options?: RecipeRunOptions, inputMountPathMap: readonly InputMountPathMapping[] = []): Promise<RecipeExecutionResult> {

tests/recipe-browser-evidence.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ writeFileSync(manifestPath, JSON.stringify({
1414
{ path: "files/browser/visual-compare/diff.png", kind: "browser-visual-diff-screenshot", contentType: "image/png", sha256: "diff-digest" },
1515
{ path: "files/browser/visual-compare/visual-diff.json", kind: "browser-visual-diff", contentType: "application/json", sha256: "visual-diff-digest" },
1616
{ path: "files/browser/visual-compare/summary.json", kind: "browser-summary", contentType: "application/json", sha256: "summary-digest" },
17+
{ path: "files/browser/editor-validate-blocks.json", kind: "editor-validate-blocks", contentType: "application/json", sha256: "editor-validate-digest" },
18+
{ path: "files/browser/editor-validate-blocks-summary.json", kind: "browser-summary", contentType: "application/json", sha256: "editor-summary-digest" },
1719
],
1820
}, null, 2))
1921

@@ -59,3 +61,37 @@ assert.equal(evidence[0]?.files.candidateScreenshot?.path, "files/browser/visual
5961
assert.equal(evidence[0]?.files.diffScreenshot?.path, "files/browser/visual-compare/diff.png")
6062
assert.equal(evidence[0]?.files.visualDiff?.path, "files/browser/visual-compare/visual-diff.json")
6163
assert.equal(evidence[0]?.summaryFile?.path, "files/browser/visual-compare/summary.json")
64+
65+
const editorEvidence = await recipeBrowserEvidence({ manifestPath } as never, [{
66+
id: "editor-validate-1",
67+
command: "wordpress.editor-validate-blocks",
68+
recipeCommand: "wordpress.editor-validate-blocks",
69+
recipePhase: "steps",
70+
recipeStepIndex: 3,
71+
recipeStepMetadata: { fixture_id: "fixture-alpha" },
72+
args: ["target=front-page"],
73+
exitCode: 0,
74+
stdout: `${JSON.stringify({
75+
total_blocks: 2,
76+
valid_blocks: 2,
77+
invalid_blocks: 0,
78+
validation_method: "wp.blocks.validateBlock",
79+
validation_provider: "wordpress-block-editor",
80+
results: [],
81+
})}\n`,
82+
stderr: "",
83+
startedAt: "2026-01-01T00:00:00.000Z",
84+
finishedAt: "2026-01-01T00:00:00.001Z",
85+
}], undefined)
86+
87+
assert.equal(editorEvidence.length, 1)
88+
assert.equal(editorEvidence[0]?.command, "wordpress.editor-validate-blocks")
89+
assert.equal(editorEvidence[0]?.phase, "steps")
90+
assert.equal(editorEvidence[0]?.index, 3)
91+
assert.deepEqual(editorEvidence[0]?.metadata, { fixture_id: "fixture-alpha" })
92+
assert.equal(editorEvidence[0]?.status, "completed")
93+
assert.equal(editorEvidence[0]?.files.validateBlocks?.path, "files/browser/editor-validate-blocks.json")
94+
assert.equal(editorEvidence[0]?.files.validateBlocks?.kind, "editor-validate-blocks")
95+
assert.equal(editorEvidence[0]?.files.summary?.path, "files/browser/editor-validate-blocks-summary.json")
96+
assert.equal(editorEvidence[0]?.summaryFile?.path, "files/browser/editor-validate-blocks-summary.json")
97+
assert.equal((editorEvidence[0]?.summary as { editorValidateBlocks?: { total_blocks?: number } } | undefined)?.editorValidateBlocks?.total_blocks, 2)

0 commit comments

Comments
 (0)