Skip to content

Commit

Permalink
Deleted ChapterOutput.create_dummy_from_output. (#340)
Browse files Browse the repository at this point in the history
* Deleted ChapterOutput.create_dummy_from_output.

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Jun 12, 2024
1 parent ecd4e41 commit 49cd814
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
54 changes: 22 additions & 32 deletions tools/src/tester/ChapterOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,39 @@ import _ from 'lodash'

export class ChapterOutput {
private outputs: Record<string, any>
constructor (outputs: Record<string, any>) {

constructor(outputs: Record<string, any>) {
this.outputs = outputs
}

get_output (name: string): any {
get(name: string): any {
return this.outputs[name]
}

set_output (name: string, value: any): void {
set(name: string, value: any): void {
this.outputs[name] = value
}

/**
* Creates a dummy ChapterOutput from an Output object
* where the values will be the response paths.
* Used for a validation check.
* @param output
* @returns
*/
static create_dummy_from_output (output: Output): ChapterOutput {
return new ChapterOutput(output)
}

static extract_output_values (response: ActualResponse, output?: Output): EvaluationWithOutput | undefined {
static extract_output_values(response: ActualResponse, output?: Output): EvaluationWithOutput | undefined {
if (!output) return undefined
const chapter_output = new ChapterOutput({})
for (const [name, path] of Object.entries(output)) {
const [source, ...rest] = path.split('.')
const keys = rest.join('.')
let value: any
if (source === 'payload') {
if (response.payload === undefined) {
return { result: Result.ERROR, message: 'No payload found in response, but expected output: ' + path }
const chapter_output = new ChapterOutput({})
for (const [name, path] of Object.entries(output)) {
const [source, ...rest] = path.split('.')
const keys = rest.join('.')
let value: any
if (source === 'payload') {
if (response.payload === undefined) {
return { result: Result.ERROR, message: 'No payload found in response, but expected output: ' + path }
}
value = keys.length === 0 ? response.payload : _.get(response.payload, keys)
if (value === undefined) {
return { result: Result.ERROR, message: `Expected to find non undefined value at \`${path}\`.` }
}
} else {
return { result: Result.ERROR, message: 'Unknown output source: ' + source }
}
value = keys.length === 0 ? response.payload : _.get(response.payload, keys)
if (value === undefined) {
return { result: Result.ERROR, message: `Expected to find non undefined value at \`${path}\`.` }
}
} else {
return { result: Result.ERROR, message: 'Unknown output source: ' + source }
chapter_output.set(name, value)
}
chapter_output.set_output(name, value)
}
return { result: Result.PASSED, output: chapter_output }
return { result: Result.PASSED, output: chapter_output }
}
}
2 changes: 1 addition & 1 deletion tools/src/tester/StoryEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class StoryEvaluator {
return this.#failed_evaluation(title, 'An episode must have an id to store its output')
}
if (episode.id !== undefined && episode.output !== undefined) {
story_outputs.set_chapter_output(episode.id, ChapterOutput.create_dummy_from_output(episode.output))
story_outputs.set_chapter_output(episode.id, new ChapterOutput(episode.output))
}
return { title, overall: { result: Result.PASSED } }
}
Expand Down
4 changes: 2 additions & 2 deletions tools/src/tester/StoryOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class StoryOutputs {
}

has_output_value (chapter_id: string, output_name: string): boolean {
return this.has_chapter(chapter_id) && this.outputs[chapter_id].get_output(output_name) !== undefined
return this.has_chapter(chapter_id) && this.outputs[chapter_id].get(output_name) !== undefined
}

set_chapter_output (chapter_id: string, output: ChapterOutput): void {
Expand All @@ -32,7 +32,7 @@ export class StoryOutputs {

get_output_value (chapter_id: string, output_name: string): any {
const output = this.outputs[chapter_id]
return output !== undefined ? output.get_output(output_name) : undefined
return output !== undefined ? output.get(output_name) : undefined
}

resolve_params (parameters: Record<string, Parameter>): Record<string, Parameter> {
Expand Down

0 comments on commit 49cd814

Please sign in to comment.