Compare commits

..
Author SHA1 Message Date
paseo-bot[bot] 20d026977b test(server): verify image hashing yields to the event loop
Observe a loop turn before the first filesystem request. Timer gaps also count CPU work that belongs to other callbacks.
2026-11-23 06:03:08 +00:00
8 changed files with 39 additions and 86 deletions
@@ -94,19 +94,6 @@ describe("Hub session protocol", () => {
expect(SessionOutboundMessageSchema.parse(response)).toEqual(response);
});
test("round-trips the working directory on named-agent validation", () => {
const request = {
type: "hub.execution.agent.validate.request",
requestId: "validate-workspace",
provider: "opencode",
model: "workspace-model",
cwd: "/workspace",
};
expect(SessionInboundMessageSchema.parse(request)).toEqual(request);
expect(SessionInboundMessageSchema.safeParse({ ...request, cwd: 123 }).success).toBe(false);
});
test("accepts the Hub execution create request", () => {
const message = {
type: "hub.execution.agent.create.request",
-1
View File
@@ -3465,7 +3465,6 @@ export const HubExecutionAgentValidateRequestSchema = z.object({
type: z.literal("hub.execution.agent.validate.request"),
requestId: z.string(),
provider: z.string(),
cwd: z.string().optional(),
model: z.string().optional(),
modeId: z.string().optional(),
thinkingOptionId: z.string().optional(),
@@ -6,7 +6,6 @@ import { filterSelectableAgentModels } from "./agent-sdk-types.js";
export interface AgentConfigurationValidationInput {
provider: string;
cwd?: string;
model?: string;
modeId?: string;
thinkingOptionId?: string;
@@ -321,40 +321,6 @@ describe("ProviderSnapshotManager public surface", () => {
}
});
test("validates workspace-only models against the requested working directory", async () => {
const cwd = resolveSnapshotCwd("/tmp/workspace-models");
const model = { provider: "opencode", id: "workspace-model", label: "Workspace model" };
const manager = new ProviderSnapshotManager({
logger: createTestLogger(),
extraClients: {
opencode: createExtraClient("opencode", {
isAvailable: async () => true,
fetchCatalog: async (options) => ({
models: options.scope === "workspace" && options.cwd === cwd ? [model] : [],
modes: [],
}),
}),
},
});
const input = { provider: model.provider, model: model.id };
const unavailable = [
{
path: ["model"],
message: "Model 'workspace-model' is not available for provider 'opencode'",
},
];
try {
await expect(manager.validateAgentConfiguration(input)).resolves.toEqual(unavailable);
await expect(manager.validateAgentConfiguration({ ...input, cwd })).resolves.toEqual([]);
await expect(
manager.validateAgentConfiguration({ ...input, cwd: "/tmp/missing-workspace" }),
).resolves.toEqual(unavailable);
} finally {
manager.destroy();
}
});
test("accepts a legacy Ultra Code choice on a model with an independent effort catalog", async () => {
const manager = new ProviderSnapshotManager({
logger: createTestLogger(),
@@ -650,7 +650,6 @@ export class ProviderSnapshotManager {
const provider = await this.getProvider({
provider: input.provider,
cwd: input.cwd,
wait: true,
});
if (!provider.enabled) {
@@ -185,29 +185,39 @@ test("repeated content is reused without rewriting the attachment", async () =>
test("64 MiB materialization leaves the event loop responsive and preserves bytes", async () => {
const bytes = Buffer.alloc(64 * 1024 * 1024, 37);
const data = bytes.toString("base64");
// Main-thread CPU time between ticks bounds the decode and hash work done on the loop;
// wall-clock gaps on shared CI runners also count preemption and timer granularity.
// File writes stay on fs/promises, so they never block the loop.
const threadCpuMs = () => {
const { user, system } = process.threadCpuUsage();
return (user + system) / 1000;
};
let previous = threadCpuMs();
let longest = 0;
const probe = setInterval(() => {
const now = threadCpuMs();
longest = Math.max(longest, now - previous);
previous = now;
}, 1);
const materializing = new AsyncLocalStorage<boolean>();
let loopAdvanced = false;
let yieldedBeforeFilesystem: boolean | undefined;
const hook = createHook({
init(_id, type) {
// The first filesystem request follows hashing. A later turn could
// come from filesystem I/O even if hashing blocked the event loop.
if (
type === "FSREQPROMISE" &&
materializing.getStore() &&
yieldedBeforeFilesystem === undefined
) {
yieldedBeforeFilesystem = loopAdvanced;
}
},
});
const probe = setImmediate(() => {
loopAdvanced = true;
});
hook.enable();
try {
const result = await materializeProviderImage({ data, mimeType: "image/png" });
await new Promise((resolve) => setTimeout(resolve, 5));
console.log(`64 MiB attachment longest blocking stretch: ${longest.toFixed(2)} ms CPU`);
expect(longest).toBeLessThan(50);
expect(readFileSync(result.path).equals(bytes)).toBe(true);
rmSync(result.path, { force: true });
const result = await materializing.run(true, () =>
materializeProviderImage({ data, mimeType: "image/png" }),
);
try {
expect(yieldedBeforeFilesystem).toBe(true);
expect(readFileSync(result.path).equals(bytes)).toBe(true);
} finally {
rmSync(result.path, { force: true });
}
} finally {
clearInterval(probe);
hook.disable();
clearImmediate(probe);
}
});
@@ -86,29 +86,23 @@ class RejectingHubExecutionAgents implements HubExecutionAgents {
}
describe("HubExecutionController", () => {
test.each([
{ cwd: "/workspace", valid: true },
{ cwd: undefined, valid: false },
{ cwd: "/missing-workspace", valid: false },
])("validates a named agent with cwd $cwd", async ({ cwd, valid }) => {
test("validates a named agent through the daemon provider registry", async () => {
const messages: SessionOutboundMessage[] = [];
const unavailable = { path: ["model"], message: "Model is unavailable" };
const validateAgentConfiguration = async (
input: Omit<HubExecutionAgentValidateRequest, "type" | "requestId">,
) => (input.model === "workspace-model" && input.cwd === "/workspace" ? [] : [unavailable]);
message: Omit<HubExecutionAgentValidateRequest, "type" | "requestId">,
) =>
message.model === "missing" ? [{ path: ["model"], message: "Model is unavailable" }] : [];
const controller = new HubExecutionController({
agents: new ControlledHubExecutionAgents(),
validateAgentConfiguration,
send: (message) => messages.push(message),
});
const scope = cwd === undefined ? {} : { cwd };
await controller.validateAgent({
type: "hub.execution.agent.validate.request",
requestId: "validate-agent",
provider: "opencode",
model: "workspace-model",
...scope,
provider: "codex",
model: "missing",
});
expect(messages).toEqual([
@@ -116,8 +110,8 @@ describe("HubExecutionController", () => {
type: "hub.execution.agent.validate.response",
payload: {
requestId: "validate-agent",
valid,
issues: valid ? [] : [unavailable],
valid: false,
issues: [{ path: ["model"], message: "Model is unavailable" }],
error: null,
},
},
@@ -87,7 +87,6 @@ export class HubExecutionController {
try {
issues = await this.validateAgentConfiguration({
provider: message.provider,
cwd: message.cwd,
model: message.model,
modeId: message.modeId,
thinkingOptionId: message.thinkingOptionId,