Skip to content

Commit

Permalink
fix(core): allow unknown in task & test results
Browse files Browse the repository at this point in the history
This adds a bit of future-proofing for schema changes to test and task
results.

If unknown fields are not allowed in task and test results, new fields
stored on results generated by newer versions of the framework
may cause errors when read by older versions which do not recognize
the new fields.
  • Loading branch information
thsig authored and eysi09 committed Jan 21, 2020
1 parent 5a2ab0d commit 5870acf
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 65 deletions.
63 changes: 33 additions & 30 deletions garden-service/src/types/plugin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,39 @@ export interface RunResult {
output?: string
}

export const runResultSchema = joi.object().keys({
moduleName: joi.string().description("The name of the module that was run."),
command: joi
.array()
.items(joi.string())
.required()
.description("The command that was run in the module."),
version: joi.string().description("The string version of the module."),
success: joi
.boolean()
.required()
.description("Whether the module was successfully run."),
startedAt: joi
.date()
.required()
.description("When the module run was started."),
completedAt: joi
.date()
.required()
.description("When the module run was completed."),
log: joi
.string()
.allow("")
.default("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
})
export const runResultSchema = joi
.object()
.unknown(true)
.keys({
moduleName: joi.string().description("The name of the module that was run."),
command: joi
.array()
.items(joi.string())
.required()
.description("The command that was run in the module."),
version: joi.string().description("The string version of the module."),
success: joi
.boolean()
.required()
.description("Whether the module was successfully run."),
startedAt: joi
.date()
.required()
.description("When the module run was started."),
completedAt: joi
.date()
.required()
.description("When the module run was completed."),
log: joi
.string()
.allow("")
.default("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
})

export const artifactsPathSchema = joi
.string()
Expand Down
73 changes: 38 additions & 35 deletions garden-service/src/types/plugin/task/getTaskResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,44 @@ export interface GetTaskResultParams<T extends Module = Module> extends PluginTa
taskVersion: ModuleVersion
}

export const taskResultSchema = joi.object().keys({
moduleName: joi.string().description("The name of the module that the task belongs to."),
taskName: joi.string().description("The name of the task that was run."),
command: joi
.array()
.items(joi.string())
.required()
.description("The command that the task ran in the module."),
version: joi.string().description("The string version of the task."),
success: joi
.boolean()
.required()
.description("Whether the task was successfully run."),
startedAt: joi
.date()
.required()
.description("When the task run was started."),
completedAt: joi
.date()
.required()
.description("When the task run was completed."),
log: joi
.string()
.required()
.allow("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
outputs: joi
.object()
.pattern(/.+/, joiPrimitive())
.description("A map of primitive values, output from the task."),
})
export const taskResultSchema = joi
.object()
.unknown(true)
.keys({
moduleName: joi.string().description("The name of the module that the task belongs to."),
taskName: joi.string().description("The name of the task that was run."),
command: joi
.array()
.items(joi.string())
.required()
.description("The command that the task ran in the module."),
version: joi.string().description("The string version of the task."),
success: joi
.boolean()
.required()
.description("Whether the task was successfully run."),
startedAt: joi
.date()
.required()
.description("When the task run was started."),
completedAt: joi
.date()
.required()
.description("When the task run was completed."),
log: joi
.string()
.required()
.allow("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
outputs: joi
.object()
.pattern(/.+/, joiPrimitive())
.description("A map of primitive values, output from the task."),
})

export const getTaskResult = {
description: dedent`
Expand Down

0 comments on commit 5870acf

Please sign in to comment.