Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 79 additions & 79 deletions main.js

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
},
"dependencies": {
"@callumalpass/mdbase-interop": "0.1.0-rc.2",
"@mdbase-dev/connect-protocol": "0.1.0-beta.40",
"@mdbase-dev/connect-sync": "0.1.0-beta.40",
"@mdbase-dev/connect-protocol": "0.1.0-beta.41",
"@mdbase-dev/connect-sync": "0.1.0-beta.41",
"ajv": "^8.20.0",
"ajv-formats": "^3.0.1",
"picomatch": "^4.0.5"
Expand Down
8 changes: 6 additions & 2 deletions src/connectSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,13 @@ export class ConnectSyncController {
}
}

async resolveConflict(recordId: string, resolution: "local" | "remote"): Promise<MirrorStatus> {
async resolveConflict(
objectId: string,
decisionId: string,
resolution: "local" | "remote",
): Promise<MirrorStatus> {
const mirror = await this.createMirror();
await mirror.resolveConflict(recordId, resolution);
await mirror.resolveConflict(objectId, decisionId, resolution);
return mirror.status();
}

Expand Down
15 changes: 15 additions & 0 deletions src/syncPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ function actionEntry(action: MirrorPlanAction): SyncPreviewEntry {
...(action.entity === "record" ? { recordId: action.identity } : { fileId: action.identity }),
};
}
if (action.command === "clear_conflict") {
const object = action.expected_local.state === "exact"
? action.expected_local.object
: action.expected_remote.state === "exact"
? action.expected_remote.object
: undefined;
return {
kind: action.entity === "file" ? "file" : "document",
path: object?.path ?? action.identity,
direction: "attention",
action: "fix",
detail: `Local and hosted ${action.entity} content now matches; clear the resolved conflict.`,
...(action.entity === "record" ? { recordId: action.identity } : { fileId: action.identity }),
};
}
const localCommand = action.command.endsWith("_local");
const object = "target" in action ? action.target : action.source;
const path = action.command === "move_local" || action.command === "move_remote"
Expand Down
12 changes: 10 additions & 2 deletions src/workspaceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,11 @@ export class MdbaseWorkspaceView extends ItemView {
for (const conflict of status.conflicts) {
const row = section.createDiv({ cls: "mdbase-conflict-row" });
const text = row.createDiv();
text.createEl("strong", { text: conflict.path ?? conflict.record_id });
text.createEl("strong", { text: conflict.path ?? conflict.object_id });
text.createDiv({
text: conflict.entity === "file" ? "Binary file conflict" : "Note conflict",
cls: "mdbase-muted",
});
text.createDiv({ text: conflict.message });
const actions = row.createDiv({ cls: "mdbase-actions" });
for (const resolution of ["local", "remote"] as const) {
Expand All @@ -1161,7 +1165,11 @@ export class MdbaseWorkspaceView extends ItemView {
});
button.disabled = this.busy;
button.onclick = () => void this.perform(async () => {
this.mirrorStatus = await this.host.connectSync.resolveConflict(conflict.record_id, resolution);
this.mirrorStatus = await this.host.connectSync.resolveConflict(
conflict.object_id,
conflict.decision_id,
resolution,
);
this.render();
});
}
Expand Down
38 changes: 38 additions & 0 deletions test/syncPreview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,41 @@ test("plan conflicts and blocking issues are shown as attention without inventin
assert.deepEqual(preview.entries.map((entry) => entry.direction), ["attention", "attention"]);
assert.deepEqual(preview.collisions, ["notes/collision.md"]);
});

test("resolved conflict cleanup is projected without inventing a transfer", () => {
const exact = {
state: "exact" as const,
object: {
entity: "file" as const,
identity: "file-1",
path: "images/resolved.png",
revision: "file:resolved",
payload_revision: `sha256:${"4".repeat(64)}`,
size: 12,
},
};
const preview = previewFromPlan(plan({
actions: [{
command: "clear_conflict",
action_id: "clear-file-conflict",
depends_on: [],
entity: "file",
identity: "file-1",
expected_local: exact,
expected_remote: exact,
reason: "pending",
}],
summary: { uploads: 0, downloads: 0, conflicts: 0, blocking_issues: 0 },
}));

assert.deepEqual(preview.entries, [{
kind: "file",
path: "images/resolved.png",
direction: "attention",
action: "fix",
detail: "Local and hosted file content now matches; clear the resolved conflict.",
fileId: "file-1",
}]);
assert.equal(preview.download_files, 0);
assert.equal(preview.upload_files, 0);
});
Loading