-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement inspect-result tool #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shadowusr
merged 4 commits into
master
from
users/shadowusr/TESTPLANE-994.inspect-result
May 17, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8eae8de
feat: implement inspect-result tool
shadowusr eba6898
fix: update html-reporter for enhanced error messages on download fai…
shadowusr ab926f1
fix: return all attempts in inspect-result tool by default
shadowusr 81e032c
fix: fix remaining review issues
shadowusr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { readResultsFromReport, type ReporterTestResult } from "html-reporter/experimental/sdk"; | ||
| import { createErrorResponse, createSimpleResponse } from "../../responses/index.js"; | ||
| import { StandaloneTool, ToolKind } from "../../types.js"; | ||
| import { downloadReportIfNeeded } from "../../utils/html-report.js"; | ||
| import { toTestResultView } from "../../utils/test-result-view.js"; | ||
| import { inspectResultSchema } from "./schema.js"; | ||
|
|
||
| export { inspectResultSchema } from "./schema.js"; | ||
|
|
||
| function getInspectResultSelectionError( | ||
| results: readonly ReporterTestResult[], | ||
| args: { name: string; browser: string; attempt?: number }, | ||
| ): string { | ||
| const resultsWithMatchingName = results.filter(result => result.fullName === args.name); | ||
|
|
||
| if (!resultsWithMatchingName.length) { | ||
| return `Test with name "${args.name}" wasn't found in this report. You can check what tests are available with the "test-results" tool.`; | ||
| } | ||
|
|
||
| const resultsWithMatchingBrowser = resultsWithMatchingName.filter(result => result.browserId === args.browser); | ||
| if (!resultsWithMatchingBrowser.length) { | ||
| const availableBrowsers = [...new Set(resultsWithMatchingName.map(result => result.browserId))].sort(); | ||
|
|
||
| return `Test with name "${args.name}" wasn't run in browser "${args.browser}", it was run only in: ${availableBrowsers.join(", ")}.`; | ||
| } | ||
|
|
||
| const availableAttempts = resultsWithMatchingBrowser.map(result => result.attempt).sort(); | ||
|
|
||
| return `No attempt ${args.attempt} found for test "${args.name}" in browser "${args.browser}". Available attempts: ${availableAttempts.join(", ")}.`; | ||
| } | ||
|
|
||
| function sortAttempts<T extends ReporterTestResult>(results: readonly T[]): T[] { | ||
| return [...results].sort((left, right) => { | ||
|
shadowusr marked this conversation as resolved.
|
||
| if (left.attempt !== right.attempt) { | ||
| return left.attempt - right.attempt; | ||
| } | ||
|
|
||
| return (left.timestamp ?? 0) - (right.timestamp ?? 0); | ||
| }); | ||
| } | ||
|
|
||
| function findTestResults( | ||
| results: readonly ReporterTestResult[], | ||
| args: { name: string; browser: string; attempt?: number }, | ||
| ): ReporterTestResult[] { | ||
| const matchingAttempts = results.filter( | ||
| result => result.fullName === args.name && result.browserId === args.browser, | ||
| ); | ||
|
|
||
| if (!matchingAttempts.length) { | ||
| throw new Error(getInspectResultSelectionError(results, args)); | ||
| } | ||
|
|
||
| if (args.attempt === undefined) { | ||
| return sortAttempts(matchingAttempts); | ||
| } | ||
|
|
||
| const matchingAttempt = matchingAttempts.find(result => result.attempt === args.attempt); | ||
|
|
||
| if (!matchingAttempt) { | ||
| throw new Error(getInspectResultSelectionError(results, args)); | ||
| } | ||
|
|
||
| return [matchingAttempt]; | ||
| } | ||
|
|
||
| const inspectResultCb: StandaloneTool<typeof inspectResultSchema>["cb"] = async args => { | ||
| try { | ||
| const reportPath = await downloadReportIfNeeded(args.report); | ||
| const results = await readResultsFromReport(reportPath); | ||
| const selectedResults = findTestResults(results, args); | ||
| const views = selectedResults.map(result => | ||
| toTestResultView(result, [], { includeBase64: args.includeBase64 }), | ||
| ); | ||
| const view = args.attempt === undefined ? views : views[0]; | ||
|
|
||
| return createSimpleResponse(JSON.stringify(view, null, args.pretty ? 2 : 0)); | ||
| } catch (error) { | ||
| console.error("Error inspecting test result from report:", error); | ||
|
|
||
| return createErrorResponse( | ||
| "Error inspecting test result from report", | ||
| error instanceof Error ? error : undefined, | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| export const inspectResult: StandaloneTool<typeof inspectResultSchema> = { | ||
| kind: ToolKind.Standalone, | ||
| name: "inspect-result", | ||
| description: "Read a Testplane HTML report and inspect test result attempt details as JSON", | ||
| schema: inspectResultSchema, | ||
| cb: inspectResultCb, | ||
| cli: { | ||
| positional: ["report"], | ||
| section: "Reports", | ||
| examples: [ | ||
| 'testplane-cli inspect-result /path/to/html-report --name "checkout submits order" --browser chrome', | ||
| 'testplane-cli inspect-result /path/to/html-report --name "checkout submits order" --browser chrome --attempt 0', | ||
| 'testplane-cli inspect-result /path/to/html-report --name "checkout submits order" --browser chrome --no-pretty', | ||
| ], | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const inspectResultSchema = { | ||
| report: z | ||
| .string() | ||
| .min(1) | ||
| .transform(value => value.trim()) | ||
| .describe("Path or URL to a Testplane HTML report directory, report HTML file, or databaseUrls.json"), | ||
| name: z | ||
| .string() | ||
| .min(1) | ||
| .transform(value => value.trim()) | ||
| .describe("Full test name to inspect"), | ||
| browser: z | ||
| .string() | ||
| .min(1) | ||
| .transform(value => value.trim()) | ||
| .describe("Browser id to inspect"), | ||
| attempt: z | ||
| .number() | ||
| .int() | ||
| .min(0, "--attempt must be >= 0") | ||
| .optional() | ||
| .describe( | ||
| "Attempt index to inspect. When omitted, all attempts for the selected test and browser are returned", | ||
| ), | ||
| pretty: z.boolean().default(true).describe("Pretty-print JSON output. Use --no-pretty for compact JSON"), | ||
| includeBase64: z | ||
| .boolean() | ||
| .default(false) | ||
| .describe( | ||
| "Include base64 image payloads in result images and errors. Omitted by default to keep output compact", | ||
| ), | ||
| }; | ||
|
|
||
| export const inspectResultObjectSchema = z.object(inspectResultSchema); | ||
| export type InspectResultArgs = z.output<typeof inspectResultObjectSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.