Eliminate lint warnings and remove await-in-loop patterns
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
ff65c1356f
commit
f153feb623
6 files changed
+74
-32
No files matched your search
@@ -91,7 +91,7 @@ function approvalDetail(event: ProviderEvent): string | undefined {
|
||||
|
||||
function derivePendingApprovals(events: ProviderEvent[]): PendingApprovalCard[] {
|
||||
const pending = new Map<string, PendingApprovalCard>();
|
||||
const ordered = [...events].reverse();
|
||||
const ordered = events.toReversed();
|
||||
|
||||
for (const event of ordered) {
|
||||
if (event.method === "session/closed" || event.method === "session/exited") {
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function Sidebar() {
|
||||
const handleAddProject = () => {
|
||||
const cwd = newCwd.trim();
|
||||
if (!cwd) return;
|
||||
const name = cwd.split("/").filter(Boolean).pop() ?? "project";
|
||||
const name = cwd.split("/").findLast((segment) => segment.length > 0) ?? "project";
|
||||
const project: Project = {
|
||||
id: crypto.randomUUID(),
|
||||
name,
|
||||
@@ -107,7 +107,21 @@ export default function Sidebar() {
|
||||
if (!projectId) return;
|
||||
|
||||
event.preventDefault();
|
||||
handleNewThread(projectId);
|
||||
dispatch({
|
||||
type: "ADD_THREAD",
|
||||
thread: {
|
||||
id: crypto.randomUUID(),
|
||||
codexThreadId: null,
|
||||
projectId,
|
||||
title: "New thread",
|
||||
model: state.projects.find((project) => project.id === projectId)?.model ?? DEFAULT_MODEL,
|
||||
session: null,
|
||||
messages: [],
|
||||
events: [],
|
||||
error: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onWindowKeyDown);
|
||||
@@ -174,7 +188,7 @@ export default function Sidebar() {
|
||||
{state.projects.map((project) => {
|
||||
const threads = state.threads
|
||||
.filter((t) => t.projectId === project.id)
|
||||
.sort((a, b) => {
|
||||
.toSorted((a, b) => {
|
||||
const byDate = new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
|
||||
if (byDate !== 0) return byDate;
|
||||
return b.id.localeCompare(a.id);
|
||||
|
||||
@@ -68,7 +68,7 @@ export function buildBootstrapInput(
|
||||
let includedNewestFirst: string[] = [];
|
||||
for (const block of newestFirstBlocks) {
|
||||
const nextNewestFirst = [...includedNewestFirst, block];
|
||||
const nextChronological = [...nextNewestFirst].reverse();
|
||||
const nextChronological = nextNewestFirst.toReversed();
|
||||
const omittedCount = newestFirstBlocks.length - nextChronological.length;
|
||||
const transcriptBody =
|
||||
omittedCount > 0
|
||||
@@ -80,7 +80,7 @@ export function buildBootstrapInput(
|
||||
includedNewestFirst = nextNewestFirst;
|
||||
}
|
||||
|
||||
let includedChronological = [...includedNewestFirst].reverse();
|
||||
let includedChronological = includedNewestFirst.toReversed();
|
||||
while (true) {
|
||||
const omittedCount = newestFirstBlocks.length - includedChronological.length;
|
||||
const transcriptBody =
|
||||
|
||||
@@ -28,7 +28,7 @@ function applyTheme(theme: Theme, suppressTransitions = false) {
|
||||
document.documentElement.classList.toggle("dark", isDark);
|
||||
if (suppressTransitions) {
|
||||
// Force a reflow so the no-transitions class takes effect before removal
|
||||
document.documentElement.offsetHeight;
|
||||
void document.documentElement.offsetHeight;
|
||||
requestAnimationFrame(() => {
|
||||
document.documentElement.classList.remove("no-transitions");
|
||||
});
|
||||
|
||||
+44
-16
@@ -382,34 +382,62 @@ async function main() {
|
||||
}
|
||||
|
||||
const maxPortRetryAttempts = 10;
|
||||
for (let attempt = 0; attempt < maxPortRetryAttempts; attempt += 1) {
|
||||
const runWithRetry = async (
|
||||
currentOptions: CliOptions,
|
||||
attempt: number,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await runCli(options);
|
||||
await runCli(currentOptions);
|
||||
return;
|
||||
} catch (error) {
|
||||
const canRetryWithNextPorts =
|
||||
isPortInUseError(error) &&
|
||||
!options.backendPortLocked &&
|
||||
!options.webPortLocked &&
|
||||
!currentOptions.backendPortLocked &&
|
||||
!currentOptions.webPortLocked &&
|
||||
attempt < maxPortRetryAttempts - 1;
|
||||
if (canRetryWithNextPorts) {
|
||||
const nextBackendPort = options.backendPort + 1;
|
||||
const nextWebPort = options.webPort + 1;
|
||||
const nextBackendPort = currentOptions.backendPort + 1;
|
||||
const nextWebPort = currentOptions.webPort + 1;
|
||||
process.stderr.write(
|
||||
`Ports ${options.backendPort}/${options.webPort} busy; retrying with ${nextBackendPort}/${nextWebPort}.\n`,
|
||||
`Ports ${currentOptions.backendPort}/${currentOptions.webPort} busy; retrying with ${nextBackendPort}/${nextWebPort}.\n`,
|
||||
);
|
||||
return runWithRetry(
|
||||
{
|
||||
...currentOptions,
|
||||
backendPort: nextBackendPort,
|
||||
webPort: nextWebPort,
|
||||
},
|
||||
attempt + 1,
|
||||
);
|
||||
options = {
|
||||
...options,
|
||||
backendPort: nextBackendPort,
|
||||
webPort: nextWebPort,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
||||
process.stderr.write(`${formatStartupError(error, options)}\n`);
|
||||
process.exit(1);
|
||||
return;
|
||||
const wrappedError = new Error("CLI startup failed.");
|
||||
(wrappedError as Error & { cause?: unknown }).cause = {
|
||||
originalError: error,
|
||||
options: currentOptions,
|
||||
};
|
||||
throw wrappedError;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await runWithRetry(options, 0);
|
||||
} catch (error) {
|
||||
const wrappedCause = (error as Error & { cause?: unknown }).cause as
|
||||
| {
|
||||
originalError?: unknown;
|
||||
options?: CliOptions;
|
||||
}
|
||||
| undefined;
|
||||
const wrapped = wrappedCause ?? {
|
||||
originalError: error,
|
||||
options,
|
||||
};
|
||||
const failedOptions = wrapped.options ?? options;
|
||||
process.stderr.write(
|
||||
`${formatStartupError(wrapped.originalError ?? error, failedOptions)}\n`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,27 +82,27 @@ async function sendRequest(
|
||||
}),
|
||||
);
|
||||
|
||||
while (true) {
|
||||
const waitForMatchingResponse = async (): Promise<WsResponseMessage> => {
|
||||
const message = await nextMessage();
|
||||
if (message.type !== "response") {
|
||||
continue;
|
||||
return waitForMatchingResponse();
|
||||
}
|
||||
if (message.id !== id) {
|
||||
continue;
|
||||
return waitForMatchingResponse();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
return waitForMatchingResponse();
|
||||
}
|
||||
|
||||
const servers: Array<{ close: () => Promise<void> }> = [];
|
||||
|
||||
afterEach(async () => {
|
||||
while (servers.length > 0) {
|
||||
const server = servers.pop();
|
||||
if (!server) break;
|
||||
await server.close();
|
||||
}
|
||||
const snapshot = [...servers];
|
||||
servers.length = 0;
|
||||
await Promise.all(snapshot.map((server) => server.close()));
|
||||
});
|
||||
|
||||
describe("runtimeApiServer", () => {
|
||||
|
||||
Reference in new issue
Block a user