-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update interrupt semantics (#335)
* feat: Update interrupt semantics * chore: Remove structured output API
- Loading branch information
1 parent
b2ee27b
commit 2a935e1
Showing
6 changed files
with
74 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,7 +1,34 @@ | ||
import { executeFn } from "./execute-fn"; | ||
import { Interrupt } from "./util"; | ||
|
||
describe("executeFn", () => { | ||
it("should run a function with arguments", async () => { | ||
const fn = (val: { [key: string]: string }) => Promise.resolve(val.foo); | ||
const result = await fn({ foo: "bar" }); | ||
expect(result).toBe("bar"); | ||
const result = await executeFn(fn, [{foo: "bar"}] as any); | ||
expect(result).toEqual({ | ||
content: "bar", | ||
type: "resolution", | ||
functionExecutionTime: expect.any(Number), | ||
}); | ||
}); | ||
|
||
it("should extract interrupt from resolution", async () => { | ||
const fn = (_: string) => Promise.resolve(Interrupt.approval()); | ||
const result = await executeFn(fn, [{}] as any); | ||
expect(result).toEqual({ | ||
content: { type: "approval" }, | ||
type: "interrupt", | ||
functionExecutionTime: expect.any(Number), | ||
}); | ||
}); | ||
|
||
it("should extract interrupt from rejection", async () => { | ||
const fn = () => Promise.reject(Interrupt.approval()); | ||
const result = await executeFn(fn, [{}] as any); | ||
expect(result).toEqual({ | ||
content: { type: "approval" }, | ||
type: "interrupt", | ||
functionExecutionTime: expect.any(Number), | ||
}); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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