Skip to content

Commit 95e5715

Browse files
committed
Satisfy oxfmt and unused-binding lint on compaction rebase
1 parent 6c24c54 commit 95e5715

4 files changed

Lines changed: 37 additions & 22 deletions

File tree

src/mcp/plugin.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ export function mcpClientTools(
116116
...(contextDir !== undefined ? { contextDir } : {}),
117117
}
118118
: undefined;
119-
const content = await truncateToolResultContent(
120-
flattened,
121-
undefined,
122-
spill,
123-
);
119+
const content = await sanitizeMcpResultContent(flattened, spill);
124120
return { callId: call.id, content };
125121
} catch (err) {
126122
const message = err instanceof Error ? err.message : String(err);

src/plugins/tool-result-secret-scrub.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ describe("toolResultSecretScrubPlugin", () => {
7373

7474
test("scrubs grep tool results", async () => {
7575
const plugin = toolResultSecretScrubPlugin();
76-
const handler = plugin.middleware!(
76+
if (plugin.middleware === undefined)
77+
throw new Error("expected middleware plugin");
78+
const handler = plugin.middleware(
7779
next("secrets/.env:1:TOKEN=supersecretvalue"),
7880
);
7981
const result = await handler(
@@ -83,10 +85,11 @@ describe("toolResultSecretScrubPlugin", () => {
8385
expect(result.content).toContain(CREDENTIAL_REDACTION);
8486
expect(result.content).not.toContain("supersecretvalue");
8587
});
86-
8788
test("scrubs error results without stringifying object content", async () => {
8889
const plugin = toolResultSecretScrubPlugin();
89-
const handler = plugin.middleware!(
90+
if (plugin.middleware === undefined)
91+
throw new Error("expected middleware plugin");
92+
const handler = plugin.middleware(
9093
next(
9194
{
9295
message: "failed with sk-abcdefghijklmnopqrstuvwxyz012345",
@@ -142,7 +145,9 @@ describe("toolResultSecretScrubPlugin", () => {
142145
const body =
143146
"Matching agent profiles:\n\n### leaky\n\nSystem prompt / body:\n" +
144147
"Use token sk-abcdefghijklmnopqrstuvwxyz012345 when calling the provider.";
145-
const handler = plugin.middleware!(next(body));
148+
if (plugin.middleware === undefined)
149+
throw new Error("expected middleware plugin");
150+
const handler = plugin.middleware(next(body));
146151
const result = await handler(
147152
{ id: "c2", name: "search_agents", arguments: { query: "leaky" } },
148153
new AbortController().signal,

src/session/assemble-runtime.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function stubChatAgentWiring(
152152
computeAdvertised: () => [],
153153
activateTools: () => false,
154154
inactivityTimeoutMs: 1_000,
155-
onTasksChange: () => {},
156-
requestContinuation: () => {},
155+
onTasksChange: () => undefined,
156+
requestContinuation: () => undefined,
157157
getProvider: () => ({ providerName: "test", model: "m" }),
158158
getWorkdir: () => "/build-dir",
159159
getSessionId: () => "test-session",
@@ -169,7 +169,7 @@ function stubChatAgentWiring(
169169
],
170170
getDefaultSource: () => "s",
171171
getCompactor: () => stubCompactor("build"),
172-
onBuilt: () => {},
172+
onBuilt: () => undefined,
173173
...overrides,
174174
};
175175
}
@@ -182,7 +182,7 @@ describe("assembleChatAgent", () => {
182182
const fakeStorage = {
183183
readBlob: async () => new Uint8Array(),
184184
} as unknown as ContextStore;
185-
const fakeAgent = { close: async () => {} } as unknown as Agent;
185+
const fakeAgent = { close: async () => undefined } as unknown as Agent;
186186

187187
await withMockedModuleDuring(
188188
import.meta.resolve("./optimized-context-store.js"),
@@ -256,7 +256,7 @@ describe("assembleChatAgent", () => {
256256
const fakeStorage = {
257257
readBlob: async () => new Uint8Array(),
258258
} as unknown as ContextStore;
259-
const fakeAgent = { close: async () => {} } as unknown as Agent;
259+
const fakeAgent = { close: async () => undefined } as unknown as Agent;
260260
const authorize = stubAuthorize();
261261
let capturedStorage: ContextStore | undefined;
262262
let capturedAuthorize: unknown;

src/session/compaction-archive.test.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function tempDir(): string {
2323
return fs.mkdtempSync(path.join(os.tmpdir(), "compaction-archive-"));
2424
}
2525

26+
function required<T>(value: T | undefined, label: string): T {
27+
if (value === undefined) throw new Error(`expected ${label}`);
28+
return value;
29+
}
30+
2631
function inbound(
2732
partial: Partial<InboundMessage> & { content?: string },
2833
): InboundMessage {
@@ -151,8 +156,12 @@ describe("primary message admission", () => {
151156
inbound({ content: "also sk-abcdefghijklmnopqrstuvwxyz012345" }),
152157
);
153158
expect(delivered).toHaveLength(2);
154-
expect(delivered[0]!.content).toContain(CREDENTIAL_REDACTION);
155-
expect(delivered[1]!.content).toContain(CREDENTIAL_REDACTION);
159+
expect(required(delivered[0], "first delivery").content).toContain(
160+
CREDENTIAL_REDACTION,
161+
);
162+
expect(required(delivered[1], "second delivery").content).toContain(
163+
CREDENTIAL_REDACTION,
164+
);
156165
});
157166

158167
test("history and archive share the same admitted representation", async () => {
@@ -190,16 +199,19 @@ describe("primary message admission", () => {
190199
);
191200
await archive.awaitPendingWrites();
192201
expect(delivered).toHaveLength(1);
193-
const admitted = delivered[0]!.content!;
202+
const admitted = required(
203+
required(delivered[0], "first delivery").content,
204+
"admitted content",
205+
);
194206
expect(admitted).toContain(CREDENTIAL_REDACTION);
195207
expect(admitted).not.toContain("sk-abcdefghijklmnopqrstuvwxyz012345");
196208
const occurrences = await archive.listOccurrences();
197209
expect(occurrences).toHaveLength(1);
198-
expect(occurrences[0]!.kind).toBe("user_message");
210+
expect(required(occurrences[0], "occurrence").kind).toBe("user_message");
199211
const archived = await archive.readAuthorizedPayload(
200-
occurrences[0]!.occurrenceId,
212+
required(occurrences[0], "occurrence").occurrenceId,
201213
);
202-
const history = createInboundTurn(delivered[0]!);
214+
const history = createInboundTurn(required(delivered[0], "first delivery"));
203215
const historyText = history?.content.find((block) => block.type === "text");
204216
expect(historyText?.type === "text" ? historyText.text : undefined).toBe(
205217
archived,
@@ -244,8 +256,10 @@ describe("primary message admission", () => {
244256
const occurrences = await archive.listOccurrences();
245257
expect(occurrences).toHaveLength(1);
246258
expect(
247-
await archive.readAuthorizedPayload(occurrences[0]!.occurrenceId),
248-
).toBe(`[From: user@local]\n\n${sent[0]!}`);
259+
await archive.readAuthorizedPayload(
260+
required(occurrences[0], "occurrence").occurrenceId,
261+
),
262+
).toBe(`[From: user@local]\n\n${required(sent[0], "sent")}`);
249263
});
250264
});
251265

0 commit comments

Comments
 (0)