Repository navigation
Persist Actions-exec answer-to-handle mapping #14105
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
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,59 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test"; | ||
| import { mkdtemp, readFile, rm } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { needsDrewAnswerHandle, raiseNeedsDrew, recordAnswer } from "../src/needs-drew.ts"; | ||
|
|
||
| const tempDirs: string[] = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true }))); | ||
| }); | ||
|
|
||
| async function storeFile(): Promise<string> { | ||
| const dir = await mkdtemp(join(tmpdir(), "needs-drew-writeback-")); | ||
| tempDirs.push(dir); | ||
| return join(dir, "needs-drew.json"); | ||
| } | ||
|
|
||
| const question = (ledgerId: string) => ({ | ||
| ledgerId, | ||
| question: "Approve the extension?", | ||
| options: [{ id: "approve", label: "Approve" }], | ||
| links: [], | ||
| }); | ||
|
|
||
| describe("needs-drew answer-to-handle mapping (#14043 S2)", () => { | ||
| test("an answered Actions-exec question resolves its stored broker handle", async () => { | ||
| // Oracle: the raise must persist source/key/handle, and the answer resolver | ||
| // returns that handle only after first-answer-wins records an answer. | ||
| const file = await storeFile(); | ||
| const ledgerId = "actions-exec-ext:session:42"; | ||
| const raised = await raiseNeedsDrew(file, question(ledgerId), "fleet-actions-exec", ledgerId); | ||
| expect(raised.brokerMapping).toEqual({ | ||
| source: "fleet-actions-exec", | ||
| key: ledgerId, | ||
| handle: "session:42", | ||
| }); | ||
|
|
||
| const answered = await recordAnswer(file, ledgerId, { optionId: "approve", via: "test" }); | ||
| expect(answered).not.toBeNull(); | ||
| expect(needsDrewAnswerHandle(answered!)).toBe("session:42"); | ||
|
|
||
| const stored = JSON.parse(await readFile(file, "utf8")); | ||
| expect(stored.items[0].brokerMapping).toEqual(raised.brokerMapping); | ||
| }); | ||
|
|
||
| test("an answered non-broker question has no handle", async () => { | ||
| // Oracle: non-broker sources never receive a broker mapping, even if a | ||
| // key-shaped value is supplied, so their recorded answers resolve to none. | ||
| const file = await storeFile(); | ||
| const ledgerId = "ordinary-question-7"; | ||
| const raised = await raiseNeedsDrew(file, question(ledgerId), "fleet-queue", "actions-exec-ext:session:7"); | ||
| const answered = await recordAnswer(file, ledgerId, { optionId: "approve", via: "test" }); | ||
|
|
||
| expect(raised.brokerMapping).toBeUndefined(); | ||
| expect(answered).not.toBeNull(); | ||
| expect(needsDrewAnswerHandle(answered!)).toBeNull(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate persisted mapping fields before parsing them.
readNeedsDrewItemschecks onlyledgerIdandtoken. An answered record withbrokerMapping.key: 42therefore reaches this call.key?.trim()then throws instead of rejecting the mapping withnull.Check the mapping shape and string fields before calling
actionsExecMapping. Preserve the existing checks for valid mappings.Based on learnings, runtime boundary data needs validation before code trusts TypeScript field types.
Source: Learnings