super-productivity/electron/common-const.test.cjs
Harbinger 8171bb05d0
refactor(sync): remove unused error classes, dialog, and constructor-time logging (phase 1, #8325) (#8510)
* fix(op-log): lock snapshot save to prevent lost-update window

saveCurrentStateAsSnapshot() read NgRx state then lastSeq without
holding OPERATION_LOG lock. An op appended between the two reads would
get seq <= lastAppliedOpSeq but its effect would be absent from the
snapshot. On next hydration the tail replay would start after that seq,
silently skipping the op forever.

Fix: wrap in lockService.request(LOCK_NAMES.OPERATION_LOG, ...) and
read lastSeq BEFORE state snapshot so the worst interleaving degrades
to harmless re-replay (idempotent) rather than a missed op.

Fixes #8308

* fix(op-log): address review feedback on snapshot lock PR

- Amend JSDoc idempotency claim: syncTimeSpent is additive on re-replay
- Add inline note about compaction's opposite read order and worse failure mode
- Add lock regression tests (#8308): lock acquired, read order, error handling

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

* refactor(sync): remove unused error classes, dialog, and constructor-time logging

Phase 1 of #8325: clean up orphaned sync error types and their UI.

Removed error classes that are no longer thrown anywhere:
- NoEtagAPIError, FileExistsAPIError (unused API errors)
- RevMismatchForModelError, SyncInvalidTimeValuesError (superseded by file-based flow)
- RevMapModelMismatchErrorOnDownload/Upload, NoRemoteModelFile, NoRemoteMetaFile
- LockPresentError, LockFromLocalClientPresentError, MetaNotReadyError, InvalidRevMapError

Removed DialogSyncErrorComponent and all references in SyncWrapperService
(_forceDownload, _handleIncoherentTimestampsDialog, _handleIncompleteSyncDialog,
_openSyncErrorDialog, _extractModelIdFromError).

Removed constructor-time logging from JsonParseError, ModelValidationError,
DataValidationFailedError — these errors are logged at the catch site; redundant
construction-time logs risk leaking user data.

Cleaned up dead translation keys (D_INCOMPLETE_SYNC block, DIALOG_RESULT_ERROR,
ERROR_DATA_IS_CURRENTLY_WRITTEN) from en.json and t.const.ts.

Updated file-based-sync-flowchart.md to reflect the removed error types.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-20 13:36:56 +02:00

63 lines
2.3 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
require('ts-node/register/transpile-only');
const { isGnomeDesktopEnv, isWaylandEnv, isGnomeWaylandEnv } = require(
path.resolve(__dirname, 'common.const.ts'),
);
test('isGnomeDesktopEnv: detects GNOME from desktop env vars', () => {
assert.equal(isGnomeDesktopEnv('linux', { XDG_CURRENT_DESKTOP: 'GNOME' }), true);
assert.equal(isGnomeDesktopEnv('linux', { XDG_CURRENT_DESKTOP: 'ubuntu:GNOME' }), true);
assert.equal(isGnomeDesktopEnv('linux', { DESKTOP_SESSION: 'ubuntu' }), true);
assert.equal(isGnomeDesktopEnv('linux', { XDG_SESSION_DESKTOP: 'gnome' }), true);
});
test('isGnomeDesktopEnv: false for non-GNOME / non-linux', () => {
assert.equal(isGnomeDesktopEnv('linux', { XDG_CURRENT_DESKTOP: 'KDE' }), false);
assert.equal(isGnomeDesktopEnv('linux', {}), false);
// env vars are present but platform is not linux
assert.equal(isGnomeDesktopEnv('win32', { XDG_CURRENT_DESKTOP: 'GNOME' }), false);
assert.equal(isGnomeDesktopEnv('darwin', { XDG_CURRENT_DESKTOP: 'GNOME' }), false);
});
test('isWaylandEnv: detects Wayland via session type or display', () => {
assert.equal(isWaylandEnv('linux', { XDG_SESSION_TYPE: 'wayland' }), true);
// some sessions only set WAYLAND_DISPLAY
assert.equal(isWaylandEnv('linux', { WAYLAND_DISPLAY: 'wayland-0' }), true);
});
test('isWaylandEnv: false for X11 / non-linux', () => {
assert.equal(isWaylandEnv('linux', { XDG_SESSION_TYPE: 'x11' }), false);
assert.equal(isWaylandEnv('linux', {}), false);
assert.equal(isWaylandEnv('win32', { WAYLAND_DISPLAY: 'wayland-0' }), false);
});
test('isGnomeWaylandEnv: only true for GNOME AND Wayland together', () => {
// GNOME + Wayland -> the one combination the kill-switch targets
assert.equal(
isGnomeWaylandEnv('linux', {
XDG_CURRENT_DESKTOP: 'GNOME',
XDG_SESSION_TYPE: 'wayland',
}),
true,
);
// GNOME on X11 keeps the feature
assert.equal(
isGnomeWaylandEnv('linux', {
XDG_CURRENT_DESKTOP: 'GNOME',
XDG_SESSION_TYPE: 'x11',
}),
false,
);
// non-GNOME Wayland (e.g. KDE) is unaffected
assert.equal(
isGnomeWaylandEnv('linux', {
XDG_CURRENT_DESKTOP: 'KDE',
XDG_SESSION_TYPE: 'wayland',
}),
false,
);
});