chore: reformat

This commit is contained in:
can1357
2026-03-14 10:46:26 +01:00
parent 7bf5cea3a3
commit 3056caee91
8 changed files with 76 additions and 37 deletions
@@ -36,7 +36,11 @@ const testContext = {
messages: [{ role: "user", content: "hello", timestamp: Date.now() }],
} as const;
function getRequestHeader(input: string | URL | Request, init: RequestInit | undefined, headerName: string): string | null {
function getRequestHeader(
input: string | URL | Request,
init: RequestInit | undefined,
headerName: string,
): string | null {
if (input instanceof Request) {
return input.headers.get(headerName);
}
@@ -137,13 +141,10 @@ describe("Anthropic Copilot auth config", () => {
const requestedInitiators: Array<string | null> = [];
global.fetch = vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
requestedInitiators.push(getRequestHeader(input, init, "X-Initiator"));
return new Response(
JSON.stringify({ error: { type: "authentication_error", message: "Unauthorized" } }),
{
status: 401,
headers: { "Content-Type": "application/json" },
},
);
return new Response(JSON.stringify({ error: { type: "authentication_error", message: "Unauthorized" } }), {
status: 401,
headers: { "Content-Type": "application/json" },
});
}) as unknown as typeof fetch;
const model = makeCopilotClaudeModel();
@@ -22,7 +22,11 @@ function getRequestUrl(input: string | URL | Request): string {
return typeof input === "string" ? input : input.toString();
}
function getRequestHeader(input: string | URL | Request, init: RequestInit | undefined, headerName: string): string | null {
function getRequestHeader(
input: string | URL | Request,
init: RequestInit | undefined,
headerName: string,
): string | null {
if (input instanceof Request) {
return input.headers.get(headerName);
}
+7 -7
View File
@@ -288,13 +288,13 @@ async function runPhase1(options: {
}
if (result.kind === "no_output") {
markStage1SucceededNoOutput(db, {
threadId: claim.threadId,
ownershipToken: claim.ownershipToken,
sourceUpdatedAt: claim.sourceUpdatedAt,
nowSec: unixNow(),
cwd: claim.cwd,
});
markStage1SucceededNoOutput(db, {
threadId: claim.threadId,
ownershipToken: claim.ownershipToken,
sourceUpdatedAt: claim.sourceUpdatedAt,
nowSec: unixNow(),
cwd: claim.cwd,
});
stats.succeededNoOutput += 1;
return;
}
@@ -5,4 +5,4 @@ Do not use tools.
Do not ask follow-up questions.
Question:
{{question}}
</btw>
</btw>
@@ -23,7 +23,16 @@ import {
toError,
} from "@oh-my-pi/pi-utils";
import { ArtifactManager } from "./artifacts";
import { type BlobPutResult, BlobStore, externalizeImageData, externalizeImageDataUrl, isBlobRef, isImageDataUrl, resolveImageData, resolveImageDataUrl } from "./blob-store";
import {
type BlobPutResult,
BlobStore,
externalizeImageData,
externalizeImageDataUrl,
isBlobRef,
isImageDataUrl,
resolveImageData,
resolveImageDataUrl,
} from "./blob-store";
import {
type BashExecutionMessage,
type CustomMessage,
@@ -988,7 +997,12 @@ async function truncateForPersistence(obj: unknown, blobStore: BlobStore, key?:
const contentEntry = entries.find(([childKey]) => childKey === "content");
const lineCountEntry = entries.find(([childKey]) => childKey === "lineCount");
if (contentEntry && typeof contentEntry[1] === "string" && lineCountEntry && typeof lineCountEntry[1] === "number") {
if (
contentEntry &&
typeof contentEntry[1] === "string" &&
lineCountEntry &&
typeof lineCountEntry[1] === "number"
) {
const content = contentEntry[1];
const updatedEntries = entries.map(([childKey, value]) =>
childKey === "lineCount" ? ([childKey, content.split("\n").length] as const) : ([childKey, value] as const),
@@ -5,8 +5,13 @@ import { TempDir } from "@oh-my-pi/pi-utils";
const compactMock = vi.fn();
mock.module("../src/session/compaction", () => ({
calculateContextTokens: (usage: { totalTokens?: number; input: number; output: number; cacheRead: number; cacheWrite: number }) =>
usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite,
calculateContextTokens: (usage: {
totalTokens?: number;
input: number;
output: number;
cacheRead: number;
cacheWrite: number;
}) => usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite,
calculatePromptTokens: () => 0,
collectEntriesForBranchSummary: () => [],
compact: compactMock,
@@ -127,10 +132,13 @@ describe("AgentSession compaction Copilot initiator attribution", async () => {
expect(model.headers?.["X-Initiator"]).toBeUndefined();
}
async function triggerAutoCompaction(session: {
agent: { emitExternalEvent: (event: unknown) => void };
subscribe: (listener: (event: { type: string }) => void) => () => void;
}, model: { api: string; provider: string; id: string; contextWindow: number }) {
async function triggerAutoCompaction(
session: {
agent: { emitExternalEvent: (event: unknown) => void };
subscribe: (listener: (event: { type: string }) => void) => () => void;
},
model: { api: string; provider: string; id: string; contextWindow: number },
) {
const { promise, resolve } = Promise.withResolvers<void>();
const unsubscribe = session.subscribe(event => {
if (event.type === "auto_compaction_end") {
@@ -169,7 +177,11 @@ describe("AgentSession compaction Copilot initiator attribution", async () => {
await session.compact();
expect(compactMock).toHaveBeenCalledTimes(1);
const compactModel = compactMock.mock.calls[0]?.[1] as { provider: string; id: string; headers?: Record<string, string> };
const compactModel = compactMock.mock.calls[0]?.[1] as {
provider: string;
id: string;
headers?: Record<string, string>;
};
const compactOptions = compactMock.mock.calls[0]?.[5] as { initiatorOverride?: string } | undefined;
expect(compactModel.provider).toBe("github-copilot");
expect(compactModel.id).toBe(model.id);
@@ -183,7 +195,11 @@ describe("AgentSession compaction Copilot initiator attribution", async () => {
await triggerAutoCompaction(session, model);
expect(compactMock).toHaveBeenCalledTimes(1);
const compactModel = compactMock.mock.calls[0]?.[1] as { provider: string; id: string; headers?: Record<string, string> };
const compactModel = compactMock.mock.calls[0]?.[1] as {
provider: string;
id: string;
headers?: Record<string, string>;
};
const compactOptions = compactMock.mock.calls[0]?.[5] as { initiatorOverride?: string } | undefined;
expect(compactModel.provider).toBe("github-copilot");
expect(compactModel.id).toBe(model.id);
@@ -197,7 +213,11 @@ describe("AgentSession compaction Copilot initiator attribution", async () => {
await session.compact();
expect(compactMock).toHaveBeenCalledTimes(1);
const compactModel = compactMock.mock.calls[0]?.[1] as { provider: string; id: string; headers?: Record<string, string> };
const compactModel = compactMock.mock.calls[0]?.[1] as {
provider: string;
id: string;
headers?: Record<string, string>;
};
const compactOptions = compactMock.mock.calls[0]?.[5] as { initiatorOverride?: string } | undefined;
expect(compactModel.provider).toBe("github-copilot");
expect(compactModel.id).toBe(model.id);
@@ -211,11 +231,15 @@ describe("AgentSession compaction Copilot initiator attribution", async () => {
await triggerAutoCompaction(session, model);
expect(compactMock).toHaveBeenCalledTimes(1);
const compactModel = compactMock.mock.calls[0]?.[1] as { provider: string; id: string; headers?: Record<string, string> };
const compactModel = compactMock.mock.calls[0]?.[1] as {
provider: string;
id: string;
headers?: Record<string, string>;
};
const compactOptions = compactMock.mock.calls[0]?.[5] as { initiatorOverride?: string } | undefined;
expect(compactModel.provider).toBe("github-copilot");
expect(compactModel.id).toBe(model.id);
expectNoForcedCopilotHeader(compactModel);
expect(compactOptions?.initiatorOverride).toBe("agent");
});
});
});
@@ -26,12 +26,8 @@ describe("memory project isolation", () => {
]);
// Insert stage1 outputs directly (bypassing job machinery)
db.run(
"INSERT INTO stage1_outputs VALUES ('thread-a', 1000, 'alpha raw memory', 'alpha summary', null, 999)",
);
db.run(
"INSERT INTO stage1_outputs VALUES ('thread-b', 1001, 'beta raw memory', 'beta summary', null, 999)",
);
db.run("INSERT INTO stage1_outputs VALUES ('thread-a', 1000, 'alpha raw memory', 'alpha summary', null, 999)");
db.run("INSERT INTO stage1_outputs VALUES ('thread-b', 1001, 'beta raw memory', 'beta summary', null, 999)");
const aOutputs = listStage1OutputsForGlobal(db, 100, CWD_A);
const bOutputs = listStage1OutputsForGlobal(db, 100, CWD_B);
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { describe, expect, it } from "bun:test";
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
import { SessionManager, type SessionMessageEntry } from "@oh-my-pi/pi-coding-agent/session/session-manager";
import { getBlobsDir, TempDir } from "@oh-my-pi/pi-utils";