Merge branch 'main' into hosted
This commit is contained in:
commit
7155a0616e
@ -216,10 +216,17 @@ function App() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedHistory = [
|
let historyTree;
|
||||||
...extractHistoryTree(appHistory, currentVersion),
|
try {
|
||||||
updateInstruction,
|
historyTree = extractHistoryTree(appHistory, currentVersion);
|
||||||
];
|
} catch {
|
||||||
|
toast.error(
|
||||||
|
"Version history is invalid. This shouldn't happen. Please contact support or open a Github issue."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedHistory = [...historyTree, updateInstruction];
|
||||||
|
|
||||||
if (shouldIncludeResultImage) {
|
if (shouldIncludeResultImage) {
|
||||||
const resultImage = await takeScreenshot();
|
const resultImage = await takeScreenshot();
|
||||||
|
|||||||
@ -53,7 +53,26 @@ const longerBranchingHistory: History = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
test("should only include history from this point onward", () => {
|
const basicBadHistory: History = [
|
||||||
|
{
|
||||||
|
type: "ai_create",
|
||||||
|
parentIndex: null,
|
||||||
|
code: "<html>1. create</html>",
|
||||||
|
inputs: {
|
||||||
|
image_url: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "ai_edit",
|
||||||
|
parentIndex: 2, // <- Bad parent index
|
||||||
|
code: "<html>2. edit with better icons</html>",
|
||||||
|
inputs: {
|
||||||
|
prompt: "use better icons",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
test("should correctly extract the history tree", () => {
|
||||||
expect(extractHistoryTree(basicLinearHistory, 2)).toEqual([
|
expect(extractHistoryTree(basicLinearHistory, 2)).toEqual([
|
||||||
"<html>1. create</html>",
|
"<html>1. create</html>",
|
||||||
"use better icons",
|
"use better icons",
|
||||||
@ -93,11 +112,12 @@ test("should only include history from this point onward", () => {
|
|||||||
"<html>3. edit with better icons and red text</html>",
|
"<html>3. edit with better icons and red text</html>",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Errors - TODO: Handle these
|
// Errors
|
||||||
|
|
||||||
// Bad index
|
// Bad index
|
||||||
// TODO: Throw an exception instead?
|
expect(() => extractHistoryTree(basicLinearHistory, 100)).toThrow();
|
||||||
expect(extractHistoryTree(basicLinearHistory, 100)).toEqual([]);
|
expect(() => extractHistoryTree(basicLinearHistory, -2)).toThrow();
|
||||||
expect(extractHistoryTree(basicLinearHistory, -2)).toEqual([]);
|
|
||||||
|
|
||||||
// Bad tree
|
// Bad tree
|
||||||
|
expect(() => extractHistoryTree(basicBadHistory, 1)).toThrow();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -22,9 +22,7 @@ export function extractHistoryTree(
|
|||||||
// Move to the parent of the current item
|
// Move to the parent of the current item
|
||||||
currentIndex = item.parentIndex;
|
currentIndex = item.parentIndex;
|
||||||
} else {
|
} else {
|
||||||
// TODO: Throw an exception here?
|
throw new Error("Malformed history: missing parent index");
|
||||||
// Break the loop if the item is not found (should not happen in a well-formed history)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user