MCPcopy Create free account
hub / github.com/METR/vivaria / validateBuildSteps

Function validateBuildSteps

server/src/aws/validateBuildSteps.ts:5–38  ·  view source on GitHub ↗
(taskFamilyDirectory: string, buildStepsBeforeValidation: BuildStep[])

Source from the content-addressed store, hash-verified

3import { BuildStep, FileBuildStep, ShellBuildStep } from '../Driver'
4
5export async function validateBuildSteps(taskFamilyDirectory: string, buildStepsBeforeValidation: BuildStep[]) {
6 return await Promise.all(
7 buildStepsBeforeValidation.map(async buildStep => {
8 switch (buildStep.type) {
9 case 'shell':
10 return ShellBuildStep.parse(buildStep)
11 case 'file': {
12 const { source, destination } = FileBuildStep.parse(buildStep)
13
14 const taskFamilyDirectoryRealPath = await realpath(taskFamilyDirectory)
15 // realpath expands symlinks, so we don't have to worry about symlinks pointing to files outside the task family directory.
16 const sourceRealPath = await realpath(join(taskFamilyDirectory, source))
17 if (!sourceRealPath.startsWith(taskFamilyDirectoryRealPath)) {
18 throw new Error(
19 `Path to copy ${source}'s realpath is ${sourceRealPath}, which is not within the task family directory ${taskFamilyDirectory}.`,
20 )
21 }
22
23 return {
24 type: 'file' as const,
25 sourceWithinTaskFamilyDirectory: source,
26 destination,
27 }
28 }
29 default:
30 // This function checks that buildStep is of type never, to ensure that getPackerTemplate explicitly validates all types
31 // of build steps.
32 ;((val: never) => {
33 throw new Error(`Unexpected value for buildStep.type. buildStep: ${JSON.stringify(val)}`)
34 })(buildStep)
35 }
36 }),
37 )
38}

Callers 2

getPackerTemplateFunction · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected