Repository navigation
Fix out-of-range @ref result references in program interpreter #393
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
Merged
Tal Zaccai (TalZaccai)
merged 2 commits into
main
from
talzaccai-fix-negative-ref-index
Jul 27, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
| import { describe, it } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { evaluateJsonProgram, createModuleTextFromProgram, Program } from "../dist/ts/index.js"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // evaluateJsonProgram result-reference bounds checking | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("evaluateJsonProgram result references", () => { | ||
| async function run(program: Program) { | ||
| const calls: Array<{ func: string; args: unknown[] }> = []; | ||
| const result = await evaluateJsonProgram(program, async (func, args) => { | ||
| calls.push({ func, args }); | ||
| return { func, args }; | ||
| }); | ||
| return { result, calls }; | ||
| } | ||
|
|
||
| it("resolves a valid reference to a preceding step", async () => { | ||
| const program: Program = { | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 0 }] }, | ||
| ], | ||
| }; | ||
| const { calls } = await run(program); | ||
| assert.deepEqual(calls[1].args, [{ func: "first", args: [] }]); | ||
| }); | ||
|
|
||
| it("throws on a negative reference instead of yielding undefined", async () => { | ||
| const program: Program = { | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": -1 }] }, | ||
| ], | ||
| }; | ||
| await assert.rejects(run(program), /Invalid result reference/); | ||
| }); | ||
|
|
||
| it("throws on a non-integer reference", async () => { | ||
| const program: Program = { | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 0.5 }] }, | ||
| ], | ||
| }; | ||
| await assert.rejects(run(program), /Invalid result reference/); | ||
| }); | ||
|
|
||
| it("throws on an out-of-upper-bound reference", async () => { | ||
| const program: Program = { | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 5 }] }, | ||
| ], | ||
| }; | ||
| await assert.rejects(run(program), /Invalid result reference/); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // createModuleTextFromProgram result-reference bounds checking | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("createModuleTextFromProgram result references", () => { | ||
| it("emits a step reference for a valid index", () => { | ||
| const result = createModuleTextFromProgram({ | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 0 }] }, | ||
| ], | ||
| }); | ||
| assert.equal(result.success, true); | ||
| assert.match((result as { data: string }).data, /step1/); | ||
| }); | ||
|
|
||
| it("rejects a negative index", () => { | ||
| const result = createModuleTextFromProgram({ | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": -1 }] }, | ||
| ], | ||
| }); | ||
| assert.equal(result.success, false); | ||
| }); | ||
|
|
||
| it("rejects a non-integer index", () => { | ||
| const result = createModuleTextFromProgram({ | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 0.5 }] }, | ||
| ], | ||
| }); | ||
| assert.equal(result.success, false); | ||
| }); | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
| it("rejects an out-of-upper-bound index", () => { | ||
| const result = createModuleTextFromProgram({ | ||
| "@steps": [ | ||
| { "@func": "first" }, | ||
| { "@func": "second", "@args": [{ "@ref": 5 }] }, | ||
| ], | ||
| }); | ||
| assert.equal(result.success, false); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.