Skip to content
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

fix: frozen status is lost after run #3158

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,22 @@ export default function GenericNode({

useEffect(() => {
if (buildStatus === BuildStatus.BUILT && !isBuilding) {
setNode(data.id, (old) => {
return {
...old,
data: {
...old.data,
node: {
...old.data.node,
lf_version: version,
setNode(
data.id,
(old) => {
return {
...old,
data: {
...old.data,
node: {
...old.data.node,
lf_version: version,
},
},
},
};
});
};
},
false,
);
}
}, [buildStatus, isBuilding]);

Expand Down
12 changes: 9 additions & 3 deletions src/frontend/src/stores/flowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,22 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
);
}
},
setNode: (id: string, change: Node | ((oldState: Node) => Node)) => {
setNode: (
id: string,
change: Node | ((oldState: Node) => Node),
isUserChange: boolean = true,
) => {
let newChange =
typeof change === "function"
? change(get().nodes.find((node) => node.id === id)!)
: change;
get().setNodes((oldNodes) =>
oldNodes.map((node) => {
if (node.id === id) {
if ((node.data as NodeDataType).node?.frozen) {
(newChange.data as NodeDataType).node!.frozen = false;
if (isUserChange) {
if ((node.data as NodeDataType).node?.frozen) {
(newChange.data as NodeDataType).node!.frozen = false;
}
}
return newChange;
}
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/src/types/zustand/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export type FlowStoreType = {
update: Edge[] | ((oldState: Edge[]) => Edge[]),
skipSave?: boolean,
) => void;
setNode: (id: string, update: Node | ((oldState: Node) => Node)) => void;
setNode: (
id: string,
update: Node | ((oldState: Node) => Node),
isUserChange: boolean,
) => void;
getNode: (id: string) => Node | undefined;
deleteNode: (nodeId: string | Array<string>) => void;
deleteEdge: (edgeId: string | Array<string>) => void;
Expand Down
140 changes: 140 additions & 0 deletions src/frontend/tests/end-to-end/generalBugs-shard-10.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { expect, test } from "@playwright/test";
import * as dotenv from "dotenv";
import path from "path";

test("freeze must work correctly", async ({ page }) => {
test.skip(
!process?.env?.OPENAI_API_KEY,
"OPENAI_API_KEY required to run this test",
);

if (!process.env.CI) {
dotenv.config({ path: path.resolve(__dirname, "../../.env") });
}

await page.goto("/");
await page.waitForTimeout(1000);

const promptText = "THIS IS A TEST PROMPT";
const newPromptText = "TEST TEST TEST TEST TEST";

let modalCount = 0;
try {
const modalTitleElement = await page?.getByTestId("modal-title");
if (modalTitleElement) {
modalCount = await modalTitleElement.count();
}
} catch (error) {
modalCount = 0;
}

while (modalCount === 0) {
await page.getByText("New Project", { exact: true }).click();
await page.waitForTimeout(5000);
modalCount = await page.getByTestId("modal-title")?.count();
}

await page.getByRole("heading", { name: "Basic Prompting" }).click();
await page.waitForTimeout(1000);

await page.getByTitle("fit view").click();

await page.getByText("openai").first().click();
await page.keyboard.press("Delete");

//connection 1

const elementPrompt = await page
.getByTestId("handle-prompt-shownode-prompt message-right")
.first();
await elementPrompt.hover();
await page.mouse.down();

await page.locator('//*[@id="react-flow-id"]').hover();

const elementChatOutput = await page
.getByTestId("handle-chatoutput-shownode-text-left")
.first();
await elementChatOutput.hover();
await page.mouse.up();

await page.locator('//*[@id="react-flow-id"]').hover();

await page.getByTestId("promptarea_prompt_template-ExternalLink").click();

await page.getByTestId("modal-promptarea_prompt_template").fill(promptText);

let promptValue = await page
.getByTestId("modal-promptarea_prompt_template")
.inputValue();

await page.getByText("Check & Save").click();

await page.waitForTimeout(3000);

await page.getByTestId("button_run_chat output").click();

await page.waitForTimeout(3000);

await page.getByTestId("button_run_chat output").click();

await page.waitForTimeout(3000);

await page.getByTestId("playground-btn-flow-io").click();

const textContents = await page
.getByTestId("div-chat-message")
.allTextContents();

const concatAllText = textContents.join(" ");

expect(concatAllText).toContain(promptValue);

await page.waitForTimeout(1000);
await page.getByText("Close").last().click();

await page.getByText("Prompt", { exact: true }).click();
await page.getByTestId("more-options-modal").click();

await page.getByText("Freeze", { exact: true }).last().click();

await page.waitForTimeout(1000);
await page.locator('//*[@id="react-flow-id"]').click();

expect(page.getByTestId("icon-Snowflake").first()).toBeVisible();

await page.locator('//*[@id="react-flow-id"]').click();

await page.getByTestId("promptarea_prompt_template-ExternalLink").click();

await page.getByTestId("edit-prompt-sanitized").first().click();

await page
.getByTestId("modal-promptarea_prompt_template")
.fill(newPromptText);

promptValue = await page
.getByTestId("modal-promptarea_prompt_template")
.inputValue();

await page.getByText("Check & Save").click();

await page.getByTestId("button_run_chat output").click();

await page.waitForTimeout(3000);

await page.getByTestId("button_run_chat output").click();

await page.waitForTimeout(3000);

await page.getByTestId("playground-btn-flow-io").click();

const textContents2 = await page
.getByTestId("div-chat-message")
.allTextContents();

const concatAllText2 = textContents2.join(" ");

expect(concatAllText2).toContain(promptText);
expect(concatAllText2).not.toContain(newPromptText);
});
Loading