Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
doriansmiley committed May 29, 2024
1 parent adff68d commit 526da21
Showing 1 changed file with 83 additions and 126 deletions.
209 changes: 83 additions & 126 deletions src/app/api/reasoning/programmer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'openai/shims/node';
import { StateConfig, programV1, Context, MachineEvent, Task } from "./";

describe('Testing Programmer', () => {
xtest("Test the programV1 function passing state nodes array", async () => {
test("Test the programV1 function passing state nodes array", async () => {
// TODO refactor this to use the headless interpreter when it's done
return new Promise((resolve, reject) => {
const stateConfigArray: StateConfig[] = [
Expand Down Expand Up @@ -48,10 +48,10 @@ describe('Testing Programmer', () => {
],
},
],
onDone: "FormulationGeneration",
onDone: "FormulationSimulation",
},
{
id: "FormulationGeneration",
id: "FormulationSimulation",
transitions: [
{ on: "CONTINUE", target: "success" },
{ on: "ERROR", target: "failure" },
Expand All @@ -74,6 +74,10 @@ describe('Testing Programmer', () => {
"Recalls a smilar solution to the user query. If a solution is found it will set the existingSolutionFound attribute of the event params to true: `event.payload?.params.existingSolutionFound`",
implementation: (context: Context, event?: MachineEvent) => {
console.log('RecallSolutions implementation called');
machineExecution.send({
type: "CONTINUE",
payload: { RecallSolutions: undefined },
});
},
},
],
Expand All @@ -84,15 +88,10 @@ describe('Testing Programmer', () => {
// this is an example of how you can render a component while the implementation function executes
implementation: (context: Context, event?: MachineEvent) => {
console.log('GenerateIngredientsList implementation called');
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({
type: "CONTINUE",
payload: { GenerateIngredientsList: [] },
});
}
}, 5000);
machineExecution.send({
type: "CONTINUE",
payload: { GenerateIngredientsList: [] },
});
},
},
],
Expand All @@ -102,17 +101,11 @@ describe('Testing Programmer', () => {
description:
"Maintain a comprehensive database of cosmetic ingredients, their properties, potential combinations, and effects. This database includes natural and synthetic ingredients, their usual concentrations in products, and regulatory information.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
// depending on the path taken GenerateIngredientsList could be undefined
const currentList = context.GenerateIngredientsList || [];
callback({
type: "CONTINUE",
payload: { IngredientDatabase: [...currentList, ["Bee Wax 1234 Special Proprietary", "30%", "A"]] },
});
}
}, 5000);
const currentList = context.GenerateIngredientsList || [];
machineExecution.send({
type: "CONTINUE",
payload: { IngredientDatabase: [...currentList, ["Bee Wax 1234 Special Proprietary", "30%", "A"]] },
});
},
transitions: new Map<"CONTINUE" | "ERROR", (context: Context, event: MachineEvent) => boolean>([
[
Expand All @@ -132,12 +125,10 @@ describe('Testing Programmer', () => {
description:
"Ensure that the predicted formula adheres to relevant cosmetic regulations and standards. If this function has an error it will set `context.regulatoryChecksSuccess` to false.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { RegulatoryCheck: "no regulatory issues were found" } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { RegulatoryCheck: "no regulatory issues were found" },
});
},
},
],
Expand All @@ -147,22 +138,17 @@ describe('Testing Programmer', () => {
description:
"Estimate the concentration of each ingredient based on standard industry practices, known effects, and regulatory limits. If this function has an error it will set `context.concentrationEstimationSuccess` to false.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({
type: "CONTINUE",
payload: {
ConcentrationEstimation: [
["ingredient", "tolerance%"],
["Bee Wax", "30-31%"],
["Coconut Oil", "40-45%"],
["Tree Resin", "20-21%%"],
],
},
});
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: {
ConcentrationEstimation: [
["ingredient", "tolerance%"],
["Bee Wax", "30-31%"],
["Coconut Oil", "40-45%"],
["Tree Resin", "20-21%%"],
],
},
});
},
},
],
Expand All @@ -171,12 +157,10 @@ describe('Testing Programmer', () => {
{
description: "Use simulation models to predict how different ingredients interact. This includes stability, texture, and efficacy simulations.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { FormulationSimulation: "no available simulations were found" } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { FormulationSimulation: "no available simulations were found" },
});
},
},
],
Expand All @@ -185,12 +169,10 @@ describe('Testing Programmer', () => {
{
description: "Have cosmetic chemists review the proposed formula for feasibility and safety.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { ExpertReview: "Certified by Dorian Smiley on 2/2/24" } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { ExpertReview: "Certified by Dorian Smiley on 2/2/24" },
});
},
},
],
Expand All @@ -199,12 +181,10 @@ describe('Testing Programmer', () => {
{
description: "Test the proposed formula in a laboratory setting to verify its properties and efficacy.",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { LabTesting: "Certified by Dorian Smiley on 2/2/24" } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { LabTesting: "Certified by Dorian Smiley on 2/2/24" },
});
},
},
],
Expand All @@ -213,12 +193,10 @@ describe('Testing Programmer', () => {
{
description: "Evaluates a generated product formula and rates the result",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { Evaluation: 0.95 } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { Evaluation: 0.95 },
});
},
},
],
Expand All @@ -228,12 +206,10 @@ describe('Testing Programmer', () => {
description:
"Generate the manufacturing steps for a tested and evaluated formula",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { ManufacturingInstructions: "The steps are..." } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { ManufacturingInstructions: "The steps are..." },
});
},
},
],
Expand All @@ -242,12 +218,10 @@ describe('Testing Programmer', () => {
{
description: "Performs market research for the new product",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { MarketResearch: "You market is as follows..." } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { MarketResearch: "You market is as follows..." },
});
},
},
],
Expand All @@ -256,12 +230,10 @@ describe('Testing Programmer', () => {
{
description: "Generates a product description for target customers",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { CreateMarketing: "Here is your marketing claims..." } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { CreateMarketing: "Here is your marketing claims..." },
});
},
},
],
Expand All @@ -270,12 +242,10 @@ describe('Testing Programmer', () => {
{
description: "generates a product image using the generated product description",
implementation: (context: Context, event?: MachineEvent) => {
setTimeout(() => {
// TODO all real implementation
if (callback) {
callback({ type: "CONTINUE", payload: { GenerateProductImage: "https://someurl.com" } });
}
}, 1);
machineExecution.send({
type: "CONTINUE",
payload: { GenerateProductImage: "https://someurl.com" },
});
},
},
],
Expand All @@ -284,9 +254,12 @@ describe('Testing Programmer', () => {
{
description:
"Default state to display for unsupported questions",
component: (context: Context, event?: MachineEvent) => <UnsupportedQuestion />,
implementation: (context: Context, event?: MachineEvent) => {
implementation: (context: Context, event?: MachineEvent) => {
console.log('UnsupportedQuestion implementation called');
machineExecution.send({
type: "CONTINUE",
payload: { UnsupportedQuestion: "UnsupportedQuestion implementation called" },
});
}
},
],
Expand All @@ -295,9 +268,12 @@ describe('Testing Programmer', () => {
{
description:
"Default state to display for unsafe questions",
component: (context: Context, event?: MachineEvent) => <UnsafeQuestion />,
implementation: (context: Context, event?: MachineEvent) => {
implementation: (context: Context, event?: MachineEvent) => {
console.log('UnsafeQuestion implementation called');
machineExecution.send({
type: "CONTINUE",
payload: { UnsafeQuestion: "UnsafeQuestion implementation called" },
});
},
},
]
Expand All @@ -314,8 +290,6 @@ describe('Testing Programmer', () => {
const machineExecution = interpret(withContext).onTransition((state) => {
const type = machineExecution.machine.states[state.value as string]?.meta?.type;

state.context.stack?.push(state.value as string);

switch (state.value) {
case "success":
expect(JSON.stringify(state.context)).toBe(
Expand All @@ -326,36 +300,19 @@ describe('Testing Programmer', () => {
"RecallSolutions",
"GenerateIngredientsList",
"IngredientDatabase",
{
parallelChecks: {
RegulatoryCheck: "pending",
ConcentrationEstimation: "pending",
},
},
"FormulationGeneration",
"success",
],
RecallSolutions: false,
GenerateIngredientsList: [
["ingredient", "%", "phase"],
["Bee Wax", "30%", "A"],
["Coconut Oil", "40%", "A"],
["Tree Resin", "20%", "B"],
"RegulatoryCheck",
"ConcentrationEstimation",
"FormulationSimulation",
],
GenerateIngredientsList: [],
IngredientDatabase: [
["ingredient", "%", "phase"],
["Bee Wax", "30%", "A"],
["Coconut Oil", "40%", "A"],
["Tree Resin", "20%", "B"],
["Bee Wax 1234 Special Proprietary", "30%", "A"],
],
RegulatoryCheck: "no regulatory issues were found",
ConcentrationEstimation: [
["ingredient", "tolerance%"],
["Bee Wax", "30-31%"],
["Coconut Oil", "40-45%"],
["Tree Resin", "20-21%%"],
[
"Bee Wax 1234 Special Proprietary",
"30%",
"A"
]
],
RegulatoryCheck: "no regulatory issues were found"
}),
);
expect(machineExecution.machine.context.stack?.length).toBe(6);
Expand Down

0 comments on commit 526da21

Please sign in to comment.