@@ -29,6 +29,18 @@ class StaleBaselineError extends OrchestrationError {
2929/** A baseline is a whole graph; anything larger is not one this feature keeps. */
3030const MAX_BASELINE_BYTES = 16 * 1024 * 1024
3131
32+ /** The baseline file's text, refused when the graph is larger than a baseline can be. */
33+ function baselineContent ( baseline : BaselineSnapshot ) : string {
34+ const content = serializeBaseline ( baseline )
35+ if ( Buffer . byteLength ( content , 'utf-8' ) > MAX_BASELINE_BYTES ) {
36+ throw new OrchestrationError (
37+ 'payload_too_large' ,
38+ `This workflow is too large for build notes to keep a baseline of (over ${ MAX_BASELINE_BYTES / 1024 / 1024 } MB)`
39+ )
40+ }
41+ return content
42+ }
43+
3244/** Creates the notes file with its owner row, then the baseline file of the current graph. */
3345export async function createBuildNotesFiles ( params : {
3446 workspaceId : string
@@ -38,6 +50,8 @@ export async function createBuildNotesFiles(params: {
3850 baseline : BaselineSnapshot
3951} ) : Promise < BuildNotesRow > {
4052 const { workspaceId, workflowId, userId } = params
53+ // Refused before the notes exist, so a workflow too large to baseline never gets notes it cannot use.
54+ baselineContent ( params . baseline )
4155 let notes : BuildNotesRow
4256 try {
4357 ; ( { owner : notes } = await createOwnedWorkspaceFile ( {
@@ -79,13 +93,7 @@ export async function writeBaseline(
7993 baseline : BaselineSnapshot ,
8094 author : { userId : string ; source : WorkspaceFileVersionSource }
8195) : Promise < BuildNotesRow > {
82- const content = serializeBaseline ( baseline )
83- if ( Buffer . byteLength ( content , 'utf-8' ) > MAX_BASELINE_BYTES ) {
84- throw new OrchestrationError (
85- 'payload_too_large' ,
86- `This workflow is too large for build notes to keep a baseline of (over ${ MAX_BASELINE_BYTES / 1024 / 1024 } MB)`
87- )
88- }
96+ const content = baselineContent ( baseline )
8997 if ( ! notes . baselineFileId ) {
9098 try {
9199 const { fileId } = await createOwnedWorkspaceFile ( {
0 commit comments