fix(pi-embedded-runner): propagate sender identity to fix Feishu doc create auto-grant (#32915)

Merged via squash.

Prepared head SHA: efb229307559ad37062b454da444567f5dca8a96
Co-authored-by: cszhouwei <1811726+cszhouwei@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Wei Zhou
2026-03-07 06:31:15 +08:00
committed by GitHub
parent 91494b2596
commit e601bf2d8e
3 changed files with 40 additions and 0 deletions

View File

@@ -803,6 +803,10 @@ export async function runEmbeddedPiAgent(
groupChannel: params.groupChannel,
groupSpace: params.groupSpace,
spawnedBy: params.spawnedBy,
senderId: params.senderId,
senderName: params.senderName,
senderUsername: params.senderUsername,
senderE164: params.senderE164,
senderIsOwner: params.senderIsOwner,
currentChannelId: params.currentChannelId,
currentThreadTs: params.currentThreadTs,

View File

@@ -10,6 +10,40 @@ describe("runEmbeddedPiAgent usage reporting", () => {
vi.clearAllMocks();
});
it("forwards sender identity fields into embedded attempts", async () => {
mockedRunEmbeddedAttempt.mockResolvedValueOnce({
aborted: false,
promptError: null,
timedOut: false,
sessionIdUsed: "test-session",
assistantTexts: ["Response 1"],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
await runEmbeddedPiAgent({
sessionId: "test-session",
sessionKey: "test-key",
sessionFile: "/tmp/session.json",
workspaceDir: "/tmp/workspace",
prompt: "hello",
timeoutMs: 30000,
runId: "run-sender-forwarding",
senderId: "user-123",
senderName: "Josh Lehman",
senderUsername: "josh",
senderE164: "+15551234567",
});
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledWith(
expect.objectContaining({
senderId: "user-123",
senderName: "Josh Lehman",
senderUsername: "josh",
senderE164: "+15551234567",
}),
);
});
it("reports total usage from the last turn instead of accumulated total", async () => {
// Simulate a multi-turn run result.
// Turn 1: Input 100, Output 50. Total 150.