-
Notifications
You must be signed in to change notification settings - Fork 9
fix(chat/runs): install global skills in the headless run path #722
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| import { provisionRunSession } from "../provisionRunSession"; | ||
| import { createSessionWithInitialChat } from "@/lib/sessions/createSessionWithInitialChat"; | ||
| import { connectSandbox } from "@/lib/sandbox/factory"; | ||
| import { markSessionSandboxActive } from "@/lib/sandbox/markSessionSandboxActive"; | ||
| import { discoverSkills } from "@/lib/skills/discoverSkills"; | ||
| import { installSessionGlobalSkills } from "@/lib/sandbox/installSessionGlobalSkills"; | ||
|
|
||
| vi.mock("@/lib/sessions/createSessionWithInitialChat", () => ({ | ||
| createSessionWithInitialChat: vi.fn(), | ||
| })); | ||
| vi.mock("@/lib/sandbox/factory", () => ({ connectSandbox: vi.fn() })); | ||
| vi.mock("@/lib/sandbox/getSessionSandboxName", () => ({ | ||
| getSessionSandboxName: vi.fn(() => "sandbox-name"), | ||
| })); | ||
| vi.mock("@/lib/sandbox/resolveGitUser", () => ({ | ||
| resolveGitUser: vi.fn(async () => ({ name: "x", email: "y" })), | ||
| })); | ||
| vi.mock("@/lib/github/getServiceGithubToken", () => ({ | ||
| getServiceGithubToken: vi.fn(() => "gh-token"), | ||
| })); | ||
| vi.mock("@/lib/sandbox/markSessionSandboxActive", () => ({ | ||
| markSessionSandboxActive: vi.fn(), | ||
| })); | ||
| vi.mock("@/lib/skills/discoverSkills", () => ({ discoverSkills: vi.fn(async () => []) })); | ||
| vi.mock("@/lib/skills/getSandboxSkillDirectories", () => ({ | ||
| getSandboxSkillDirectories: vi.fn(async () => ["/skills"]), | ||
| })); | ||
| vi.mock("@/lib/sandbox/installSessionGlobalSkills", () => ({ | ||
| installSessionGlobalSkills: vi.fn(async () => undefined), | ||
| })); | ||
|
|
||
| const session = { | ||
| id: "session-1", | ||
| clone_url: "https://github.com/org/repo", | ||
| sandbox_state: { type: "vercel" }, | ||
| }; | ||
| const updated = { ...session }; | ||
| const chat = { id: "chat-1" }; | ||
| const sandbox = { | ||
| getState: () => ({ type: "vercel" }), | ||
| workingDirectory: "/work", | ||
| }; | ||
|
|
||
| describe("provisionRunSession", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.mocked(createSessionWithInitialChat).mockResolvedValue({ | ||
| ok: true, | ||
| session, | ||
| chat, | ||
| } as never); | ||
| vi.mocked(connectSandbox).mockResolvedValue(sandbox as never); | ||
| vi.mocked(markSessionSandboxActive).mockResolvedValue(updated as never); | ||
| }); | ||
|
|
||
| it("installs global skills into the sandbox before discovering them", async () => { | ||
| await provisionRunSession({ accountId: "account-1", title: "t" }); | ||
|
|
||
| // Headless runs must PROVISION skills, not just discover them (chat#1822). | ||
| expect(installSessionGlobalSkills).toHaveBeenCalledWith({ | ||
| sessionRow: updated, | ||
| sandbox, | ||
| }); | ||
|
|
||
| const installOrder = vi.mocked(installSessionGlobalSkills).mock.invocationCallOrder[0]; | ||
| const discoverOrder = vi.mocked(discoverSkills).mock.invocationCallOrder[0]; | ||
| expect(installOrder).toBeLessThan(discoverOrder); | ||
| }); | ||
|
|
||
| it("still completes the run when skill install fails (best-effort)", async () => { | ||
| vi.mocked(installSessionGlobalSkills).mockRejectedValueOnce(new Error("install boom")); | ||
|
|
||
| const result = await provisionRunSession({ accountId: "account-1", title: "t" }); | ||
|
|
||
| expect(result.session).toEqual(updated); | ||
| expect(discoverSkills).toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
File
provisionRunSession.tsexceeds the 100-line limit (111 lines) after this change, violating the maintainability rule's file-length and single-responsibility constraints.Prompt for AI agents