From c69f84edf503351305cffb03002c1b95a6be51b9 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 23 Feb 2025 16:45:52 +0000 Subject: [PATCH] Fix agent behaviour --- .../file-operations/safe-filesystem-operations.ts | 2 +- frontend/sync-client/src/services/sync-service.ts | 1 - .../sync-client/src/sync-operations/syncer.ts | 1 + frontend/test-client/src/agent/mock-agent.ts | 15 ++++++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/sync-client/src/file-operations/safe-filesystem-operations.ts b/frontend/sync-client/src/file-operations/safe-filesystem-operations.ts index 94ee8ad4..e493d12f 100644 --- a/frontend/sync-client/src/file-operations/safe-filesystem-operations.ts +++ b/frontend/sync-client/src/file-operations/safe-filesystem-operations.ts @@ -1,5 +1,5 @@ -import type { FileSystemOperations } from "dist/types"; import type { RelativePath } from "src/persistence/database"; +import type { FileSystemOperations } from "./filesystem-operations"; export class FileNotFoundError extends Error { public constructor(message: string) { diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index 392a4d21..e60fcaf2 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -8,7 +8,6 @@ import type { } from "../persistence/database"; import type { Logger } from "src/tracing/logger"; import { retriedFetchFactory } from "src/utils/retried-fetch"; -import type { SyncSettings } from "dist/types"; import type { Settings } from "src/persistence/settings"; export interface CheckConnectionResult { diff --git a/frontend/sync-client/src/sync-operations/syncer.ts b/frontend/sync-client/src/sync-operations/syncer.ts index 2ca399a6..5b1f78ea 100644 --- a/frontend/sync-client/src/sync-operations/syncer.ts +++ b/frontend/sync-client/src/sync-operations/syncer.ts @@ -206,6 +206,7 @@ export class Syncer { await this.operations.read(relativePath); const contentHash = hash(contentBytes); + // todo: make this smarter so that offline files can be renamed & edited at the same time const originalFile = findMatchingFileBasedOnHash( contentHash, locallyPossiblyDeletedFiles diff --git a/frontend/test-client/src/agent/mock-agent.ts b/frontend/test-client/src/agent/mock-agent.ts index dc0fb6f4..a933b98f 100644 --- a/frontend/test-client/src/agent/mock-agent.ts +++ b/frontend/test-client/src/agent/mock-agent.ts @@ -224,6 +224,16 @@ export class MockAgent extends MockClient { private async renameFileAction(files: RelativePath[]): Promise { const file = choose(files); + + // We can't edit files offline that have been renamed while offline. + // Otherwise, the resolution logic couldn't handle it. + if (this.doNotTouch.includes(file)) { + this.client.logger.info( + `Skipping file ${file} because it has been updated while offline` + ); + return; + } + const newName = this.getFileName(); if (await this.exists(newName)) { @@ -242,7 +252,7 @@ export class MockAgent extends MockClient { const file = choose(files); // We can't edit files offline that have been renamed while offline. - // Othwersie, the resolution logic couldn't handle it. + // Otherwise, the resolution logic couldn't handle it. if (this.doNotTouch.includes(file)) { this.client.logger.info( `Skipping file ${file} because it has been renamed while offline` @@ -254,6 +264,9 @@ export class MockAgent extends MockClient { this.client.logger.info( `Decided to update file ${file} with ${content}` ); + if (!this.client.settings.getSettings().isSyncEnabled) { + this.doNotTouch.push(file); + } await this.atomicUpdateText(file, (old) => old + ` |${content}| `); }