forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 6
fix: v2 - proper hydration of loaded spec #2437
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
Merged
maxy-shpfy
merged 1 commit into
master
from
06-18-fix_v2_-_proper_hydration_of_loaded_spec
Jun 19, 2026
+149
−13
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/routes/v2/pages/Editor/utils/__tests__/hydrateSpecRefs.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { ComponentSpec } from "@/models/componentSpec/entities/componentSpec"; | ||
| import { Task } from "@/models/componentSpec/entities/task"; | ||
| import { IncrementingIdGenerator } from "@/models/componentSpec/factories/idGenerator"; | ||
| import { hydrateLoadedSpecRefs } from "@/routes/v2/pages/Editor/utils/hydrateSpecRefs"; | ||
| import { hydrateComponentReference } from "@/services/componentService"; | ||
| import type { | ||
| ComponentSpec as ComponentSpecJson, | ||
| HydratedComponentReference, | ||
| } from "@/utils/componentSpec"; | ||
|
|
||
| vi.mock("@/services/componentService", () => ({ | ||
| hydrateComponentReference: vi.fn(), | ||
| })); | ||
|
|
||
| const mockHydrate = vi.mocked(hydrateComponentReference); | ||
|
|
||
| const idGen = new IncrementingIdGenerator(); | ||
|
|
||
| function makeContainerSpec(name: string): ComponentSpecJson { | ||
| return { | ||
| name, | ||
| implementation: { container: { image: "alpine" } }, | ||
| }; | ||
| } | ||
|
|
||
| function makeHydratedRef(name: string): HydratedComponentReference { | ||
| return { | ||
| name, | ||
| digest: `digest-${name}`, | ||
| text: `name: ${name}`, | ||
| spec: makeContainerSpec(name), | ||
| }; | ||
| } | ||
|
|
||
| function specWithTask(task: Task): ComponentSpec { | ||
| return new ComponentSpec({ | ||
| $id: idGen.next("spec"), | ||
| name: "Pipeline", | ||
| tasks: [task], | ||
| }); | ||
| } | ||
|
|
||
| describe("hydrateLoadedSpecRefs", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("populates resolvedComponentSpec for a text-only ref", async () => { | ||
| const task = new Task({ | ||
| $id: idGen.next("task"), | ||
| name: "Process", | ||
| componentRef: { text: "name: Foo" }, | ||
| }); | ||
| const spec = specWithTask(task); | ||
|
|
||
| mockHydrate.mockResolvedValue(makeHydratedRef("Foo")); | ||
|
|
||
| expect(task.resolvedComponentSpec).toBeUndefined(); | ||
|
|
||
| await hydrateLoadedSpecRefs(spec); | ||
|
|
||
| expect(mockHydrate).toHaveBeenCalledTimes(1); | ||
| expect(task.resolvedComponentSpec).toBeDefined(); | ||
| expect(task.resolvedComponentSpec?.name).toBe("Foo"); | ||
| }); | ||
|
|
||
| it("recurses into subgraph tasks without re-hydrating the subgraph ref", async () => { | ||
| const innerTask = new Task({ | ||
| $id: idGen.next("task"), | ||
| name: "Inner", | ||
| componentRef: { text: "name: Inner" }, | ||
| }); | ||
| const innerSpec = new ComponentSpec({ | ||
| $id: idGen.next("spec"), | ||
| name: "Subgraph", | ||
| tasks: [innerTask], | ||
| }); | ||
| const subgraphTask = new Task({ | ||
| $id: idGen.next("task"), | ||
| name: "Outer", | ||
| componentRef: { name: "Outer" }, | ||
| subgraphSpec: innerSpec, | ||
| }); | ||
| const spec = specWithTask(subgraphTask); | ||
|
|
||
| mockHydrate.mockResolvedValue(makeHydratedRef("Inner")); | ||
|
|
||
| await hydrateLoadedSpecRefs(spec); | ||
|
|
||
| expect(mockHydrate).toHaveBeenCalledTimes(1); | ||
| expect(innerTask.resolvedComponentSpec).toBeDefined(); | ||
| expect(innerTask.resolvedComponentSpec?.name).toBe("Inner"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { ComponentSpec } from "@/models/componentSpec"; | ||
| import type { Task } from "@/models/componentSpec/entities/task"; | ||
| import { hydrateComponentReference } from "@/services/componentService"; | ||
|
|
||
| /** | ||
| * Hydrate every task's component reference in a freshly loaded spec so the | ||
| * live CSOM always carries a resolvable `componentRef.spec`. | ||
| */ | ||
| export async function hydrateLoadedSpecRefs( | ||
| spec: ComponentSpec, | ||
| ): Promise<void> { | ||
| await Promise.all(spec.tasks.map((task) => hydrateTaskRef(task))); | ||
| } | ||
|
|
||
| async function hydrateTaskRef(task: Task): Promise<void> { | ||
| if (task.subgraphSpec) { | ||
| await hydrateLoadedSpecRefs(task.subgraphSpec); | ||
| return; | ||
| } | ||
|
|
||
| const hydrated = await hydrateComponentReference(task.componentRef); | ||
| if (!hydrated) return; | ||
|
|
||
| task.setComponentRef(hydrated); | ||
|
maxy-shpfy marked this conversation as resolved.
|
||
|
|
||
| if (task.subgraphSpec) { | ||
| await hydrateLoadedSpecRefs(task.subgraphSpec); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.