Format & lint

This commit is contained in:
Andras Schmelczer 2026-04-25 17:55:46 +01:00
parent fefac224b0
commit 7f62273e72
179 changed files with 2210 additions and 1319 deletions

View file

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { choose } from "../utils/choose";
import { v4 as uuidv4 } from "uuid";
import { assert } from "../utils/assert";
@ -109,7 +110,6 @@ export class MockAgent extends MockClient {
);
}
public async act(): Promise<void> {
const options: (() => Promise<unknown>)[] = [
this.createFileAction.bind(this),
@ -125,7 +125,6 @@ export class MockAgent extends MockClient {
options.push(this.enableSyncAction.bind(this));
}
options.push(
this.renameFileAction.bind(this),
this.updateFileAction.bind(this),
@ -136,7 +135,6 @@ export class MockAgent extends MockClient {
options.push(this.deleteFileAction.bind(this));
}
if (Math.random() < 0.015 && this.doResets) {
// we can't just queue this up as once it's destroyed, no more method calls can go to SyncClient
await this.resetClient();
@ -164,7 +162,7 @@ export class MockAgent extends MockClient {
// pending operations.
if (
error instanceof Error &&
error.message?.includes("SyncClient destroyed")
error.message.includes("SyncClient destroyed")
) {
this.client.logger.info(
`Action interrupted by destroy: ${error}`
@ -262,17 +260,18 @@ export class MockAgent extends MockClient {
"Local files: " + Array.from(this.files.keys()).join(", ")
);
otherAgent.client.logger.info(
"Other agent's data: " + JSON.stringify(otherAgent.data, null, 2)
"Other agent's data: " +
JSON.stringify(otherAgent.data, null, 2)
);
otherAgent.client.logger.info(
"Other agent's files: " + Array.from(otherAgent.files.keys()).join(", ")
"Other agent's files: " +
Array.from(otherAgent.files.keys()).join(", ")
);
throw e;
}
}
public assertAllContentIsPresentOnce(): void {
if (this.useSlowFileEvents) {
this.client.logger.info(
@ -349,7 +348,6 @@ export class MockAgent extends MockClient {
}
}
private async resetClient(): Promise<void> {
this.client.logger.info(`Resetting client ${this.name}`);
await this.client.destroy();
@ -372,8 +370,7 @@ export class MockAgent extends MockClient {
`Decided to create file ${file} with content ${content}`
);
return this.write(file, new TextEncoder().encode(` ${content} `),);
return this.write(file, new TextEncoder().encode(` ${content} `));
}
// Binary file creation — exercises the putBinary server path (not in mergeable_file_extensions)
@ -393,7 +390,7 @@ export class MockAgent extends MockClient {
`Decided to create binary file ${file}: ${uuid}`
);
return this.write(file, bytes,);
return this.write(file, bytes);
}
private async disableSyncAction(): Promise<void> {
@ -433,9 +430,8 @@ export class MockAgent extends MockClient {
// assertion to fail when the sync engine replaces binary content
// at a mergeable path).
const ext = file.substring(file.lastIndexOf("."));
const newName = ext === ".bin"
? this.getBinaryFileName()
: this.getFileName();
const newName =
ext === ".bin" ? this.getBinaryFileName() : this.getFileName();
if (
(!this.lastSyncEnabledState &&
@ -479,14 +475,10 @@ export class MockAgent extends MockClient {
`Decided to update file ${file} with ${content}`
);
this.doNotTouchWhileOffline.push(file);
await this.atomicUpdateText(
file,
(old) => ({
text: old.text + ` ${content} `,
cursors: []
})
);
await this.atomicUpdateText(file, (old) => ({
text: old.text + ` ${content} `,
cursors: []
}));
}
private async updateBinaryFileAction(): Promise<void> {
@ -506,12 +498,10 @@ export class MockAgent extends MockClient {
return;
}
const { uuid, bytes } = this.getBinaryContent();
const { uuid: _uuid, bytes } = this.getBinaryContent();
// Remove the old UUID since binary updates are last-write-wins
this.removeBinaryUuid(file);
this.client.logger.info(
`Decided to update binary file ${file}`
);
this.client.logger.info(`Decided to update binary file ${file}`);
this.doNotTouchWhileOffline.push(file);
await this.write(file, bytes);
}
@ -531,7 +521,6 @@ export class MockAgent extends MockClient {
`Deleting file: ${file} with:\n content '${new TextDecoder().decode(this.files.get(file))}'`
);
await this.delete(file);
}
private getContent(): string {
@ -546,8 +535,7 @@ export class MockAgent extends MockClient {
const content = new TextDecoder().decode(existing);
if (!content.startsWith("BINARY:")) return;
const uuid = content.slice("BINARY:".length);
const idx = this.writtenBinaryContents.indexOf(uuid);
if (idx !== -1) this.writtenBinaryContents.splice(idx, 1);
utils.removeFromArray(this.writtenBinaryContents, uuid);
}
private getBinaryContent(): { uuid: string; bytes: Uint8Array } {

View file

@ -40,7 +40,6 @@ export class MockClient extends debugging.InMemoryFileSystem {
await this.client.start();
}
public override async write(
path: RelativePath,
content: Uint8Array
@ -50,14 +49,14 @@ export class MockClient extends debugging.InMemoryFileSystem {
this.files.set(path, content);
if (isNew) {
this.executeFileOperation(async () => { this.client.syncLocallyCreatedFile(path); }
);
this.executeFileOperation(async () => {
this.client.syncLocallyCreatedFile(path);
});
} else {
this.executeFileOperation(
async () => { this.client.syncLocallyUpdatedFile({ relativePath: path }); },
);
this.executeFileOperation(async () => {
this.client.syncLocallyUpdatedFile({ relativePath: path });
});
}
}
public override async atomicUpdateText(
@ -73,20 +72,18 @@ export class MockClient extends debugging.InMemoryFileSystem {
const newContentUint8Array = new TextEncoder().encode(newContent);
this.files.set(path, newContentUint8Array);
this.executeFileOperation(
async () => { this.client.syncLocallyUpdatedFile({ relativePath: path }); },
);
this.executeFileOperation(async () => {
this.client.syncLocallyUpdatedFile({ relativePath: path });
});
return newContent;
}
public override async delete(path: RelativePath): Promise<void> {
this.files.delete(path);
this.executeFileOperation(
async () => { this.client.syncLocallyDeletedFile(path); },
);
this.executeFileOperation(async () => {
this.client.syncLocallyDeletedFile(path);
});
}
public override async rename(
@ -101,17 +98,15 @@ export class MockClient extends debugging.InMemoryFileSystem {
if (oldPath !== newPath) {
this.files.delete(oldPath);
}
this.executeFileOperation(
async () => { this.client.syncLocallyUpdatedFile({
this.executeFileOperation(async () => {
this.client.syncLocallyUpdatedFile({
oldPath,
relativePath: newPath
}); },
);
});
});
}
protected executeFileOperation(
callback: () => unknown,
): void {
protected executeFileOperation(callback: () => unknown): void {
if (this.useSlowFileEvents) {
// we aren't the best client and it takes some time to notice changes
setTimeout(callback, Math.random() * 100);

View file

@ -119,9 +119,6 @@ async function runTest({
await sleep(2000);
}
for (const client of clients) {
try {
logger.info(`Destroying ${client.name}`);
@ -254,11 +251,7 @@ process.on("uncaughtException", (error) => {
});
process.on("unhandledRejection", (error, _promise) => {
if (
error instanceof Error &&
(
error.name === "SyncResetError")
) {
if (error instanceof Error && error.name === "SyncResetError") {
return;
}

View file

@ -12,9 +12,7 @@ export class TestErrorTracker {
public checkAndThrow(): void {
if (this.firstError !== null) {
const { agentName, message } = this.firstError;
throw new Error(
`ERROR-level log from ${agentName}: ${message}`
);
throw new Error(`ERROR-level log from ${agentName}: ${message}`);
}
}