-
Notifications
You must be signed in to change notification settings - Fork 60
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
Support outputs on tests #324
Support outputs on tests #324
Conversation
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Rebase, add some to the documentation (DEVELOPER_GUIDE on writing tests probably).
I suggest wrapping up the chapter output into a class and refactoring all the helper methods as class methods, it will make things a lot cleaner/better organized.
tools/src/tester/helpers.ts
Outdated
if (evaluations.some(e => e.result === Result.ERROR)) return Result.ERROR | ||
if (evaluations.some(e => e.result === Result.FAILED)) return Result.FAILED | ||
if (evaluations.some(e => e.result === Result.SKIPPED)) return Result.SKIPPED | ||
return Result.PASSED | ||
} | ||
|
||
export function extract_output_values(response: ActualResponse, chapterOutput?: Output): EvaluationWithOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor into ChapterOutput
, I think it should be constructed from ActualResponse
, be a method on ActualResponse
, or something like that.
@@ -1,5 +1,7 @@ | |||
/* eslint-disable */ | |||
|
|||
import { ChapterOutput } from "./eval.types"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not supposed to be edited by hand. It's generated from running npx ts-node tools/src/tester/_generate_story_types.ts
.
The goal is maintaining parity between the JSON Schemas defined in test_story.schema.yaml
and the TS types defined here.
The test framework actually went through a refactor after you pulled from |
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
tools/src/tester/ChapterReader.ts
Outdated
import { Agent } from 'https' | ||
import { StoryOutputs } from './types/eval.types' | ||
import { string } from 'yaml/dist/schema/common/string' | ||
import { resolve_params, resolve_value } from './helpers' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If resolve_params
and resolve_value
are only meant to be used in this class, shouldn't they be defined here instead?
tools/src/tester/helpers.ts
Outdated
if (evaluations.some(e => e.result === Result.ERROR)) return Result.ERROR | ||
if (evaluations.some(e => e.result === Result.FAILED)) return Result.FAILED | ||
if (evaluations.some(e => e.result === Result.SKIPPED)) return Result.SKIPPED | ||
return Result.PASSED | ||
} | ||
|
||
export function extract_output_values(response: ActualResponse, chapterOutput?: Output): EvaluationWithOutput | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chapterOutput
-> chapter_output
tools/src/tester/StoryEvaluator.ts
Outdated
} | ||
} | ||
return evaluations | ||
} | ||
|
||
async evaluate_supplemental_chapter(chapter: SupplementalChapter, story_outputs: StoryOutputs): Promise<ChapterEvaluation> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both evaluate_supplemental_chapters
and #evaluate_supplemental_chapters
is confusing especially when they call each other. I think this calls for a SupplementalChapterEvaluation
class similar to ChapterEvaluation
now. They will most likely have a lot in common and we can DRY that as well.
tools/src/tester/StoryEvaluator.ts
Outdated
import ChapterEvaluator from './ChapterEvaluator' | ||
import type ChapterReader from './ChapterReader' | ||
import SharedResources from './SharedResources' | ||
import { overall_result } from './helpers' | ||
import { check_story_variables, extract_output_values, overall_result } from './helpers' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If check_story_variables
is only used here, it should be defined here instead.
chapters: [], | ||
message: variables_error | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These errors should be assigned to the chapters that throw them so the viewer can pinpoint where to fix.
tools/src/tester/ResultsDisplayer.ts
Outdated
@@ -41,7 +41,7 @@ export default class ResultsDisplayer { | |||
|
|||
#display_story (): void { | |||
const result = this.evaluation.result | |||
const message = this.evaluation.full_path | |||
const message = this.evaluation.message || this.evaluation.full_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this we wont need this change anymore.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #324 +/- ##
===========================================
- Coverage 78.88% 63.22% -15.67%
===========================================
Files 42 45 +3
Lines 1184 1365 +181
Branches 261 316 +55
===========================================
- Hits 934 863 -71
- Misses 250 502 +252 ☔ View full report in Codecov by Sentry. |
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Changes AnalysisCommit SHA: b8ccfca API ChangesSummary
ReportThe full API changes report is available at: https://github.com/opensearch-project/opensearch-api-specification/actions/runs/9467793824/artifacts/1590084965 API Coverage
|
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miguel-vila Let's get this merged? Iterate to green and say when you think you're done with the changes?
I don't love it that we're adding a ton of things to helpers
, that's an OO anti-pattern. Consider refactoring those. Can also be refactired later.
* @param output | ||
* @returns | ||
*/ | ||
static create_dummy_from_output (output: Output): ChapterOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this seems unnecessary, do new ChapterOutput
where it's called?
const title = `${chapter.method} ${chapter.path}` | ||
const response = await this._chapter_reader.read(chapter, story_outputs) | ||
const status = chapter.status ?? [200, 201] | ||
const output_values = extract_output_values(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should read response.output_values
, it's very business-logic specific to the reponse.
tools/src/tester/ChapterEvaluator.ts
Outdated
const operation = this._operation_locator.locate_operation(chapter) | ||
if (operation == null) return { title: chapter.synopsis, overall: { result: Result.FAILED, message: `Operation "${chapter.method.toUpperCase()} ${chapter.path}" not found in the spec.` } } | ||
const params = this.#evaluate_parameters(chapter, operation) | ||
const request_body = this.#evaluate_request_body(chapter, operation) | ||
const status = this.#evaluate_status(chapter, response) | ||
const payload = status.result === Result.PASSED ? this.#evaluate_payload(response, operation) : { result: Result.SKIPPED } | ||
const output_values = extract_output_values(response, chapter.output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract_output_values
should either be a private method on ChapterEvaluator
or maybe this works better as chapter.output.extract_output_values_from_response(response)
?
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
@@ -78,15 +77,15 @@ test('extract_output_values', () => { | |||
d: 'payload.a.arr[0].d', | |||
e: 'payload.a.arr[1].e' | |||
} | |||
expect(extract_output_values(response, output1)).toEqual(passed_output({ | |||
expect(ChapterOutput.extract_output_values(response, output1)).toEqual(passed_output({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ChapterOutput
is something that is the result of an Output
(a schema) and a response (values). I think the OO way should be closer to this:
new ChapterOutput(output, values)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nhtruong take a look, I am good without all the refactors, can be done later
Adds a way to describe outputs in chapters, that can be used for later requests in the params or in the request bodies.
Added some unit tests and an integration test that uses this feature.