-
Notifications
You must be signed in to change notification settings - Fork 333
fix(seed): stop go-sdk idempotency-headers fixture from overwriting its nested config #17318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { FernSeedConfig } from "../config/index.js"; | ||
| import { validateFixtureOutputFolders } from "../validateFixtureOutputFolders.js"; | ||
|
|
||
| function workspaceConfig( | ||
| fixtures: Record<string, FernSeedConfig.FixtureConfigurations[]> | ||
| ): FernSeedConfig.SeedWorkspaceConfiguration { | ||
| return { fixtures } as FernSeedConfig.SeedWorkspaceConfiguration; | ||
| } | ||
|
|
||
| describe("validateFixtureOutputFolders", () => { | ||
| it("allows a single configuration writing to the fixture root", () => { | ||
| const errors = validateFixtureOutputFolders({ | ||
| workspaceName: "go-sdk", | ||
| workspaceConfig: workspaceConfig({ streaming: [{ outputFolder: "." }] }) | ||
| }); | ||
| expect(errors).toEqual([]); | ||
| }); | ||
|
|
||
| it("allows multiple configurations in distinct output folders", () => { | ||
| const errors = validateFixtureOutputFolders({ | ||
| workspaceName: "go-sdk", | ||
| workspaceConfig: workspaceConfig({ | ||
| "idempotency-headers": [ | ||
| { outputFolder: "no-custom-config" }, | ||
| { outputFolder: "auto-generate-idempotency-key" } | ||
| ] | ||
| }) | ||
| }); | ||
| expect(errors).toEqual([]); | ||
| }); | ||
|
|
||
| it("rejects a configuration writing to the fixture root alongside a nested configuration", () => { | ||
| const errors = validateFixtureOutputFolders({ | ||
| workspaceName: "go-sdk", | ||
| workspaceConfig: workspaceConfig({ | ||
| "idempotency-headers": [{ outputFolder: "." }, { outputFolder: "auto-generate-idempotency-key" }] | ||
| }) | ||
| }); | ||
| expect(errors).toHaveLength(1); | ||
| expect(errors[0]).toContain('fixture "idempotency-headers"'); | ||
| expect(errors[0]).toContain('"auto-generate-idempotency-key"'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||
| import { FernSeedConfig } from "./config/index.js"; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Generation wipes a fixture's output folder before writing files, so a configuration | ||||||||||||||||
| * that writes to the fixture root ("." ) destroys the output of any sibling configuration | ||||||||||||||||
| * nested underneath it. | ||||||||||||||||
| */ | ||||||||||||||||
| export function validateFixtureOutputFolders({ | ||||||||||||||||
| workspaceName, | ||||||||||||||||
| workspaceConfig | ||||||||||||||||
| }: { | ||||||||||||||||
| workspaceName: string; | ||||||||||||||||
| workspaceConfig: FernSeedConfig.SeedWorkspaceConfiguration; | ||||||||||||||||
| }): string[] { | ||||||||||||||||
| const errors: string[] = []; | ||||||||||||||||
| for (const [fixture, configurations] of Object.entries(workspaceConfig.fixtures ?? {})) { | ||||||||||||||||
| const outputFolders = configurations.map((configuration) => configuration.outputFolder); | ||||||||||||||||
| if (outputFolders.length > 1 && outputFolders.includes(".")) { | ||||||||||||||||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 suggestion The check only catches the literal
Suggested change
(and adjust the message body accordingly). At minimum, normalize |
||||||||||||||||
| errors.push( | ||||||||||||||||
| `${workspaceName}: fixture "${fixture}" has an outputFolder of "." alongside ${outputFolders | ||||||||||||||||
| .filter((outputFolder) => outputFolder !== ".") | ||||||||||||||||
| .map((outputFolder) => `"${outputFolder}"`) | ||||||||||||||||
| .join(", ")}. ` + | ||||||||||||||||
| `Give every configuration its own output folder so they do not overwrite each other.` | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| return errors; | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 suggestion
loadGeneratorWorkspacesis called by every seed command, so one malformedseed.ymlin an unrelated generator now hard-fails all of them. Consider collecting errors across workspaces and throwing once at the end (so users see every problem), or warning + skipping like thedisabledbranch above.