Files
openbot/scripts/cursor-model-set-e2e.ts
Aleksander DygońandClaude Opus 5.5 03c2ff34c2 Remove code comments and add the no-comments rule (#12604)
* Remove code comments and add the no-comments rule

Remove the comments from first-party code and configuration files:
TS/JS, JSX, CSS, SQL migrations, Swift, Kotlin, Gradle, shell,
Docker, systemd, Nix, YAML, TOML, JSONC and GritQL.

Keep only what a tool reads: license headers, shebangs, compiler
and lint directives, JSDoc types in plain .js files, generated file
headers, GritQL scope lines, the install-server.sh help text and the
openbot-boat-pre-stop marker. Vendored code, fixtures and released
schemas keep their comments.

Add the rule to AGENTS.md, and change the docs that asked for
comments. Add two i18n keys that only comments named to
RELEASED_SOURCE_KEYS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep comments that are data in strings

The benchmark task files in opencode-free-models-bench.ts tell the
model what each function must do. The sample file and HTML page in
the two stories are display content. Put their comments back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep released migrations and mobile native inputs unchanged

check:migrations compares each released migration with v0.73.0 byte
for byte, so restore src/backend/migrations. A change to a native
build input of apps/mobile makes a new runtime version, so restore
those files and the extra fingerprint sources.

List these files and the comment markers that a tool reads in
AGENTS.md. Remove the last requests for comments in
src/renderer/AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 12:19:28 +01:00

143 lines
5.7 KiB
TypeScript

import assert from "node:assert/strict";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import type { AgentClient } from "../src/backend/agent-client";
import type { AgentCliInfo } from "../src/backend/cli";
import { NO_PROVIDER_CREDENTIALS, requireProviderDriver } from "../src/backend/provider-drivers";
import { installFakeAgent, readJsonl, runTurn, startThread, stopClients, type TurnResult } from "./provider-fakes/host";
const OUT = resolve(import.meta.dirname, "../.openbot-build/cursor-model-set-e2e");
const MEDIUM = "gpt-5.6-sol[context=272k,reasoning=medium,fast=false]";
const HIGH = "gpt-5.6-sol[context=272k,reasoning=high,fast=false]";
interface SetEntry {
method: string;
value: string;
failed?: boolean;
}
interface Step {
name: string;
sets: SetEntry[];
turn?: TurnResult;
}
interface Report {
passed: boolean;
steps: Step[];
}
const root = await mkdtemp(join(tmpdir(), "openbot-cursor-model-set-e2e-"));
const report: Report = { passed: false, steps: [] };
const clients: AgentClient[] = [];
try {
const workspace = join(root, "workspace");
await mkdir(workspace);
const log = join(root, "sets.jsonl");
const failFlag = join(root, "fail-next-set");
const reorderFlag = join(root, "reorder-sets");
const executable = join(root, "cursor", "cursor-agent");
await installFakeAgent(executable, "cursor-model-set", {
FAKE_LOG: log,
FAKE_FAIL_NEXT_SET: failFlag,
FAKE_REORDER_SETS: reorderFlag,
});
const cli: AgentCliInfo = { executable, version: "2026.10.22-27dcf5f", source: "managed" };
const client = requireProviderDriver("cursor").createClient(cli, 10_000, NO_PROVIDER_CREDENTIALS);
clients.push(client);
client.start();
let seen = 0;
const step = async (name: string, action: () => Promise<TurnResult | undefined>): Promise<Step> => {
const turn = await action();
const all = await readJsonl<SetEntry>(log);
const result: Step = { name, sets: all.slice(seen), ...(turn ? { turn } : {}) };
seen = all.length;
report.steps.push(result);
return result;
};
const values = (entry: Step) => entry.sets.map((set) => set.value);
let first = "";
const open = await step("open thread 1 on medium", async () => {
first = await startThread(client, { cwd: workspace, model: MEDIUM });
return undefined;
});
assert.deepEqual(values(open), [MEDIUM], "The first thread sets its model one time.");
for (const name of ["turn 1 on medium", "turn 2 on medium"]) {
const same = await step(name, () => runTurn(client, first, { model: MEDIUM, text: "ping" }));
assert.deepEqual(values(same), [], "A turn on the model the process runs on sends no model set.");
assert.equal(same.turn?.reply, `Model: ${MEDIUM}`, "The turn runs on its model.");
assert.equal(same.turn?.status, "completed", "The turn completes.");
}
let second = "";
const other = await step("open thread 2 on high", async () => {
second = await startThread(client, { cwd: workspace, model: HIGH });
return undefined;
});
assert.deepEqual(values(other), [HIGH], "A thread on another model sets it.");
const back = await step("turn on thread 1 after thread 2", () =>
runTurn(client, first, { model: MEDIUM, text: "ping" }),
);
assert.deepEqual(values(back), [MEDIUM], "A turn after another thread changed the model sets its own again.");
assert.equal(back.turn?.reply, `Model: ${MEDIUM}`, "The turn runs on its own model.");
await writeFile(failFlag, "");
const failed = await step("turn on thread 2 with a failed set", () =>
runTurn(client, second, { model: HIGH, text: "ping" }).catch((error: unknown) => ({
reply: "",
error: error instanceof Error ? error.message : String(error),
status: null,
})),
);
assert.deepEqual(
failed.sets.map((set) => set.failed === true),
[true],
"The model set of this turn fails.",
);
assert.match(failed.turn?.error ?? "", /Invalid model value/, "The turn reports the failure.");
const retried = await step("turn on thread 2 after the failed set", () =>
runTurn(client, second, { model: HIGH, text: "ping" }),
);
assert.deepEqual(values(retried), [HIGH], "After a failed set, the next turn sends the set again.");
assert.equal(retried.turn?.reply, `Model: ${HIGH}`, "The turn runs on its model.");
assert.equal(retried.turn?.status, "completed", "The turn completes.");
await writeFile(reorderFlag, "");
const overlap = await step("overlapping turns on thread 1 and thread 2", async () => {
const first1 = runTurn(client, first, { model: MEDIUM, text: "ping" });
await new Promise<void>((resolveWait) => {
const poll = setInterval(async () => {
if ((await readJsonl<SetEntry>(log)).length > seen) {
clearInterval(poll);
resolveWait();
}
}, 10);
});
const second2 = runTurn(client, second, { model: HIGH, text: "ping" });
await Promise.all([first1, second2]);
return undefined;
});
assert.deepEqual(values(overlap), [MEDIUM, HIGH], "Both turns set their model.");
await rm(reorderFlag);
const afterOverlap = await step("turn on thread 1 after the overlap", () =>
runTurn(client, first, { model: MEDIUM, text: "ping" }),
);
assert.deepEqual(values(afterOverlap), [MEDIUM], "After overlapping sets, the next turn sends its set.");
assert.equal(afterOverlap.turn?.reply, `Model: ${MEDIUM}`, "The turn runs on its own model.");
report.passed = true;
} finally {
await stopClients(clients);
await mkdir(OUT, { recursive: true });
await writeFile(join(OUT, "report.json"), `${JSON.stringify(report, null, 2)}\n`);
await rm(root, { recursive: true, force: true });
}
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);