-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue with loading not working , relaxes restriction on requ…
…iring an input nodes as part of execution via options (#594)
- Loading branch information
Showing
6 changed files
with
89 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tokens-studio/graph-engine": patch | ||
--- | ||
|
||
Fixes an issue with loading not working , relaxes restriction on requiring an input nodes as part of execution via options |
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
48 changes: 48 additions & 0 deletions
48
packages/graph-engine/tests/suites/graph/execution.test.ts
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Graph } from '../../../src/graph/graph.js'; | ||
import { Node, NumberSchema } from '../../../src/index.js'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
class ExternalNode extends Node { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.addOutput('foo', { type: NumberSchema }); | ||
} | ||
|
||
async execute() { | ||
const val = await this.load('foo'); | ||
this.outputs.foo.set(val); | ||
} | ||
} | ||
|
||
describe('Graph/execution', () => { | ||
test('throws an error when the external loader can be caught', async () => { | ||
const graph = new Graph(); | ||
|
||
new ExternalNode({ id: 'a', graph }); | ||
|
||
let thrown; | ||
try { | ||
await graph.execute(); | ||
} catch (err) { | ||
thrown = err; | ||
} finally { | ||
expect(thrown).toBeDefined(); | ||
expect(thrown.message).toEqual('No external loader specified'); | ||
} | ||
}); | ||
|
||
test('External loading works as expected', async () => { | ||
const graph = new Graph(); | ||
|
||
graph.externalLoader = async () => { | ||
return 5; | ||
}; | ||
|
||
new ExternalNode({ id: 'a', graph }); | ||
|
||
await graph.execute(); | ||
|
||
expect(graph.nodes.a.outputs.foo.value).toEqual(5); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Graph } from '../../../src/graph/graph.js'; | ||
import { describe, expect, test } from 'vitest'; | ||
import Passthrough from '../../../src/nodes/generic/passthrough.js'; | ||
|
||
describe('Graph/options', () => { | ||
test('throws an error if strict mode is enabled', async () => { | ||
const graph = new Graph(); | ||
|
||
new Passthrough({ id: 'a', graph }); | ||
let thrown; | ||
try { | ||
await graph.execute({ | ||
strict: true, | ||
inputs: { | ||
foo: { | ||
value: 1 | ||
} | ||
} | ||
}); | ||
} catch (err) { | ||
thrown = err; | ||
} finally { | ||
expect(thrown).toBeDefined(); | ||
expect(thrown.message).toEqual('No input node found'); | ||
} | ||
}); | ||
}); |
13 changes: 0 additions & 13 deletions
13
packages/graph-engine/vitest.config.ts.timestamp-1732108255012-05584d17095ba.mjs
This file was deleted.
Oops, something went wrong.