From aab965d3d03cfab471b5311a43dcd48472cfe41a Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Sun, 21 Apr 2024 17:10:50 -0400 Subject: [PATCH] fix --- .../commands/test/test-runner/TestRunner.ts | 149 +++++++++--------- .../basicauth/client.go | 6 + .../client/client.go | 6 + .../.inputs/config.json | 2 +- .../circular-references/.inputs/config.json | 2 +- seed/go-sdk/examples/snippet.json | 2 +- seed/go-sdk/folders/.inputs/config.json | 2 +- seed/go-sdk/imdb/.inputs/config.json | 2 +- seed/go-sdk/optional/.inputs/config.json | 2 +- .../reserved-keywords/.inputs/config.json | 2 +- seed/go-sdk/trace/.inputs/config.json | 19 --- seed/go-sdk/unknown/.inputs/config.json | 2 +- 12 files changed, 91 insertions(+), 105 deletions(-) diff --git a/packages/seed/src/commands/test/test-runner/TestRunner.ts b/packages/seed/src/commands/test/test-runner/TestRunner.ts index 8e3c55eb669..7d3fc7199ad 100644 --- a/packages/seed/src/commands/test/test-runner/TestRunner.ts +++ b/packages/seed/src/commands/test/test-runner/TestRunner.ts @@ -72,7 +72,7 @@ export declare namespace TestRunner { } export abstract class TestRunner { - private built: boolean = false; + private buildInvocation: Promise | undefined; protected readonly generator: GeneratorWorkspace; protected readonly lock: Semaphore; protected readonly taskContextFactory: TaskContextFactory; @@ -98,24 +98,13 @@ export abstract class TestRunner { * Runs the generator. */ public async run({ fixture, configuration }: TestRunner.RunArgs): Promise { - if (!this.built) { - await this.build(); - this.built = true; + if (this.buildInvocation == undefined) { + this.buildInvocation = this.build(); } + await this.buildInvocation; const metrics: TestRunner.TestCaseMetrics = {}; - const fixtureConfig = this.generator.workspaceConfig.fixtures?.[fixture]; - if (fixtureConfig == null) { - return { - type: "failure", - cause: "invalid-fixture", - message: `Fixture ${fixture} not found.`, - id: fixture, - metrics - }; - } - const id = configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`; const absolutePathToAPIDefinition = AbsoluteFilePath.of( path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture) @@ -138,76 +127,80 @@ export abstract class TestRunner { } taskContext.logger.debug("Acquiring lock..."); - await this.lock.acquire(); - taskContext.logger.info("Running generator..."); try { - const generationStopwatch = new Stopwatch(); - generationStopwatch.start(); - await this.runGenerator({ - id, - fernWorkspace, - absolutePathToWorkspace: this.generator.absolutePathToWorkspace, - irVersion: this.generator.workspaceConfig.irVersion, - outputVersion: configuration?.outputVersion, - language: this.generator.workspaceConfig.language, - selectAudiences: configuration?.audiences, - fixture, - customConfig: configuration?.customConfig, - publishConfig: configuration?.publishConfig ?? undefined, - taskContext, - outputDir: - configuration == null - ? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture)) - : join( - this.generator.absolutePathToWorkspace, - RelativeFilePath.of(fixture), - RelativeFilePath.of(configuration.outputFolder) - ), - outputMode: configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode, - outputFolder, - keepDocker: this.keepDocker, - publishMetadata: configuration?.publishMetadata ?? undefined - }); - generationStopwatch.stop(); - metrics.generationTime = generationStopwatch.duration(); - } catch (error) { - return { - type: "failure", - cause: "generation", - id: fixture, - metrics - }; - } - - if (this.skipScripts) { + await this.lock.acquire(); + taskContext.logger.info("Running generator..."); + try { + const generationStopwatch = new Stopwatch(); + generationStopwatch.start(); + await this.runGenerator({ + id, + fernWorkspace, + absolutePathToWorkspace: this.generator.absolutePathToWorkspace, + irVersion: this.generator.workspaceConfig.irVersion, + outputVersion: configuration?.outputVersion, + language: this.generator.workspaceConfig.language, + selectAudiences: configuration?.audiences, + fixture, + customConfig: configuration?.customConfig, + publishConfig: configuration?.publishConfig ?? undefined, + taskContext, + outputDir: + configuration == null + ? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture)) + : join( + this.generator.absolutePathToWorkspace, + RelativeFilePath.of(fixture), + RelativeFilePath.of(configuration.outputFolder) + ), + outputMode: configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode, + outputFolder, + keepDocker: this.keepDocker, + publishMetadata: configuration?.publishMetadata ?? undefined + }); + generationStopwatch.stop(); + metrics.generationTime = generationStopwatch.duration(); + } catch (error) { + return { + type: "failure", + cause: "generation", + id: fixture, + metrics + }; + } + + if (this.skipScripts) { + return { + type: "success", + id: fixture, + metrics + }; + } + + const scriptStopwatch = new Stopwatch(); + scriptStopwatch.start(); + + const scriptResponse = await this.scriptRunner.run({ taskContext, fixture, outputFolder }); + + scriptStopwatch.stop(); + metrics.compileTime = scriptStopwatch.duration(); + + if (scriptResponse.type === "failure") { + return { + type: "failure", + cause: "compile", + id: fixture, + metrics + }; + } return { type: "success", id: fixture, metrics }; + } finally { + this.lock.release(); } - - const scriptStopwatch = new Stopwatch(); - scriptStopwatch.start(); - - const scriptResponse = await this.scriptRunner.run({ taskContext, fixture, outputFolder }); - - scriptStopwatch.stop(); - metrics.compileTime = scriptStopwatch.duration(); - - if (scriptResponse.type === "failure") { - return { - type: "failure", - cause: "compile", - id: fixture, - metrics - }; - } - return { - type: "success", - id: fixture, - metrics - }; } /** diff --git a/seed/go-sdk/basic-auth-environment-variables/basicauth/client.go b/seed/go-sdk/basic-auth-environment-variables/basicauth/client.go index 062c72fac6b..c56a9f0952a 100644 --- a/seed/go-sdk/basic-auth-environment-variables/basicauth/client.go +++ b/seed/go-sdk/basic-auth-environment-variables/basicauth/client.go @@ -12,7 +12,10 @@ import ( option "github.com/basic-auth-environment-variables/fern/option" io "io" http "net/http" +<<<<<<< HEAD os "os" +======= +>>>>>>> 925464783 (fix) ) type Client struct { @@ -23,12 +26,15 @@ type Client struct { func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) +<<<<<<< HEAD if options.Username == "" { options.Username = os.Getenv("USERNAME") } if options.Password == "" { options.Password = os.Getenv("PASSWORD") } +======= +>>>>>>> 925464783 (fix) return &Client{ baseURL: options.BaseURL, caller: core.NewCaller( diff --git a/seed/go-sdk/basic-auth-environment-variables/client/client.go b/seed/go-sdk/basic-auth-environment-variables/client/client.go index 7db92b53328..6f01cee070e 100644 --- a/seed/go-sdk/basic-auth-environment-variables/client/client.go +++ b/seed/go-sdk/basic-auth-environment-variables/client/client.go @@ -7,7 +7,10 @@ import ( core "github.com/basic-auth-environment-variables/fern/core" option "github.com/basic-auth-environment-variables/fern/option" http "net/http" +<<<<<<< HEAD os "os" +======= +>>>>>>> 925464783 (fix) ) type Client struct { @@ -20,12 +23,15 @@ type Client struct { func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) +<<<<<<< HEAD if options.Username == "" { options.Username = os.Getenv("USERNAME") } if options.Password == "" { options.Password = os.Getenv("PASSWORD") } +======= +>>>>>>> 925464783 (fix) return &Client{ baseURL: options.BaseURL, caller: core.NewCaller( diff --git a/seed/go-sdk/circular-references-advanced/.inputs/config.json b/seed/go-sdk/circular-references-advanced/.inputs/config.json index 69e25227331..b06dd99cc6f 100644 --- a/seed/go-sdk/circular-references-advanced/.inputs/config.json +++ b/seed/go-sdk/circular-references-advanced/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "api", + "workspaceName": "circular-references-advanced", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/circular-references/.inputs/config.json b/seed/go-sdk/circular-references/.inputs/config.json index a6bf0be9736..b08a9d937ab 100644 --- a/seed/go-sdk/circular-references/.inputs/config.json +++ b/seed/go-sdk/circular-references/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "api", + "workspaceName": "circular-references", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/examples/snippet.json b/seed/go-sdk/examples/snippet.json index 58c2f2ec0f3..d97fbbd4a9c 100644 --- a/seed/go-sdk/examples/snippet.json +++ b/seed/go-sdk/examples/snippet.json @@ -57,7 +57,7 @@ }, "snippet": { "type": "go", - "client": "import (\n\tcontext \"context\"\n\tfern \"github.com/examples/fern\"\n\tfernclient \"github.com/examples/fern/client\"\n\toption \"github.com/examples/fern/option\"\n)\n\nclient := fernclient.NewClient(\n\toption.WithToken(\n\t\t\"\u003cYOUR_AUTH_TOKEN\u003e\",\n\t),\n\toption.WithBaseURL(\n\t\tfern.Environments.Production,\n\t),\n)\nresponse, err := client.Service.CreateMovie(\n\tcontext.TODO(),\n\t\u0026fern.Movie{\n\t\tId: \"movie-c06a4ad7\",\n\t\tPrequel: fern.String(\n\t\t\t\"movie-cv9b914f\",\n\t\t),\n\t\tTitle: \"The Boy and the Heron\",\n\t\tFrom: \"Hayao Miyazaki\",\n\t\tRating: 8,\n\t\tTag: \"tag-wf9as23d\",\n\t\tMetadata: map[string]interface{}{\n\t\t\t\"actors\": []interface{}{\n\t\t\t\t\"Christian Bale\",\n\t\t\t\t\"Florence Pugh\",\n\t\t\t\t\"Willem Dafoe\",\n\t\t\t},\n\t\t\t\"releaseDate\": \"2023-12-08\",\n\t\t\t\"ratings\": map[string]interface{}{\n\t\t\t\t\"rottenTomatoes\": 97,\n\t\t\t\t\"imdb\": 7.6,\n\t\t\t},\n\t\t},\n\t},\n)\n" + "client": "import (\n\tcontext \"context\"\n\tfern \"github.com/examples/fern\"\n\tfernclient \"github.com/examples/fern/client\"\n\toption \"github.com/examples/fern/option\"\n)\n\nclient := fernclient.NewClient(\n\toption.WithToken(\n\t\t\"\u003cYOUR_AUTH_TOKEN\u003e\",\n\t),\n\toption.WithBaseURL(\n\t\tfern.Environments.Production,\n\t),\n)\nresponse, err := client.Service.CreateMovie(\n\tcontext.TODO(),\n\t\u0026fern.Movie{\n\t\tId: \"movie-c06a4ad7\",\n\t\tPrequel: fern.String(\n\t\t\t\"movie-cv9b914f\",\n\t\t),\n\t\tTitle: \"The Boy and the Heron\",\n\t\tFrom: \"Hayao Miyazaki\",\n\t\tRating: 8,\n\t\tTag: \"tag-wf9as23d\",\n\t\tMetadata: map[string]interface{}{\n\t\t\t\"actors\": []interface{}{\n\t\t\t\t\"Christian Bale\",\n\t\t\t\t\"Florence Pugh\",\n\t\t\t\t\"Willem Dafoe\",\n\t\t\t},\n\t\t\t\"releaseDate\": \"2023-12-08\",\n\t\t\t\"ratings\": map[string]interface{}{\n\t\t\t\t\"imdb\": 7.6,\n\t\t\t\t\"rottenTomatoes\": 97,\n\t\t\t},\n\t\t},\n\t},\n)\n" } }, { diff --git a/seed/go-sdk/folders/.inputs/config.json b/seed/go-sdk/folders/.inputs/config.json index c8500069817..e5de4c2ef54 100644 --- a/seed/go-sdk/folders/.inputs/config.json +++ b/seed/go-sdk/folders/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "api", + "workspaceName": "folders", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/imdb/.inputs/config.json b/seed/go-sdk/imdb/.inputs/config.json index c0043e64866..47d9ea9972f 100644 --- a/seed/go-sdk/imdb/.inputs/config.json +++ b/seed/go-sdk/imdb/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "api", + "workspaceName": "imdb", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/optional/.inputs/config.json b/seed/go-sdk/optional/.inputs/config.json index d8877a9f781..7f99e4c900d 100644 --- a/seed/go-sdk/optional/.inputs/config.json +++ b/seed/go-sdk/optional/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "objects-with-imports", + "workspaceName": "optional", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/reserved-keywords/.inputs/config.json b/seed/go-sdk/reserved-keywords/.inputs/config.json index 33ad83c3cfb..ca80a82f033 100644 --- a/seed/go-sdk/reserved-keywords/.inputs/config.json +++ b/seed/go-sdk/reserved-keywords/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "nursery-api", + "workspaceName": "reserved-keywords", "organization": "seed", "environment": { "type": "local" diff --git a/seed/go-sdk/trace/.inputs/config.json b/seed/go-sdk/trace/.inputs/config.json index d54ee0cb1c4..e69de29bb2d 100644 --- a/seed/go-sdk/trace/.inputs/config.json +++ b/seed/go-sdk/trace/.inputs/config.json @@ -1,19 +0,0 @@ -{ - "irFilepath": "./ir.json", - "output": { - "mode": { - "repoUrl": "https://github.com/trace/fern", - "version": "0.0.1", - "type": "github" - }, - "path": "../" - }, - "workspaceName": "trace", - "organization": "seed", - "environment": { - "type": "local" - }, - "dryRun": false, - "whitelabel": false, - "writeUnitTests": true -} \ No newline at end of file diff --git a/seed/go-sdk/unknown/.inputs/config.json b/seed/go-sdk/unknown/.inputs/config.json index fd076bbcd6c..c92e2116f3a 100644 --- a/seed/go-sdk/unknown/.inputs/config.json +++ b/seed/go-sdk/unknown/.inputs/config.json @@ -8,7 +8,7 @@ }, "path": "../" }, - "workspaceName": "unknown-as-any", + "workspaceName": "unknown", "organization": "seed", "environment": { "type": "local"