diff --git a/lib/src/app/app_metadata.dart b/lib/src/app/app_metadata.dart index 1761dcb9..ade34c77 100644 --- a/lib/src/app/app_metadata.dart +++ b/lib/src/app/app_metadata.dart @@ -1 +1 @@ -const busyMarkAppVersion = '0.7.0'; +const busyMarkAppVersion = '0.7.1'; diff --git a/lib/src/workspace/presentation/workspace_screen.dart b/lib/src/workspace/presentation/workspace_screen.dart index 0a5db429..65311ff1 100644 --- a/lib/src/workspace/presentation/workspace_screen.dart +++ b/lib/src/workspace/presentation/workspace_screen.dart @@ -2354,8 +2354,8 @@ IconData _sidebarTabIcon(_SidebarTab tab, TextDirection direction) { } bool _sidebarTabAvailable(WidgetRef ref, _SidebarTab tab) => switch (tab) { - _SidebarTab.git || - _SidebarTab.gitLog => ref.read(gitControllerProvider).repositoryInfo != null, + // The folder workspace tabs expose Git before discovery; selecting either + // view starts the shared sidebar's discovery and trust flow. _SidebarTab.outline => ref.read(workspaceControllerProvider).activeBuffer != null, _ => true, diff --git a/linux/io.busystack.busymark.metainfo.xml b/linux/io.busystack.busymark.metainfo.xml index a5a1c4fd..39bc9634 100644 --- a/linux/io.busystack.busymark.metainfo.xml +++ b/linux/io.busystack.busymark.metainfo.xml @@ -88,6 +88,7 @@ https://github.com/busystack/busymark/issues + diff --git a/pubspec.yaml b/pubspec.yaml index 1884be72..5ec74aee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: busymark description: Local-first Markdown and Writerside-compatible documentation editor. publish_to: 'none' -version: 0.7.0 +version: 0.7.1 environment: sdk: ">=3.12.1 <4.0.0" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 14b47211..8f2508b8 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: busymark title: BusyMark -version: "0.7.0" +version: "0.7.1" summary: Markdown and Writerside documentation editor # Snap Store listing translations are managed outside this Flutter package. # Update store metadata when approved translated listing text is supplied. diff --git a/test/src/app_smoke_test.dart b/test/src/app_smoke_test.dart index 22f1eff3..b0ccfdc0 100644 --- a/test/src/app_smoke_test.dart +++ b/test/src/app_smoke_test.dart @@ -192,8 +192,9 @@ void main() { expect({ for (final e in menus.entries) e['label']: e['mnemonic'], }, expected); - expect(menus.enabled('Commit'), isFalse); - expect(menus.enabled('Git Log'), isFalse); + expect(container.read(gitControllerProvider).repositoryInfo, isNull); + expect(menus.enabled('Commit'), isTrue); + expect(menus.enabled('Git Log'), isTrue); expect(menus.enabled('Files'), isTrue); menus.close(); await tester.pumpAndSettle(); @@ -7669,6 +7670,9 @@ code bool descendantWorkspace = false, bool switchingWorkspace = false, bool delayDiscovery = false, + bool repositoryDiscovered = true, + bool hasRepository = true, + bool nestedRepository = false, WorkspaceKind kind = WorkspaceKind.markdownFolder, }) async { final temp = Directory.systemTemp.createTempSync('busymark_tab_actions_'); @@ -7689,7 +7693,12 @@ code paths: paths, kind: kind, ); - final sharedClient = _SearchableGitReadFixture(_gitDiffState(temp.path)); + final repositoryRoot = nestedRepository ? '${temp.path}/nested' : temp.path; + Directory(repositoryRoot).createSync(recursive: true); + final gitState = _gitDiffState(repositoryRoot); + final sharedClient = _SearchableGitReadFixture( + hasRepository ? gitState : const GitState(), + ); if (delayDiscovery) sharedClient.discoveryGate = Completer(); final container = ProviderContainer( overrides: [ @@ -7717,7 +7726,10 @@ code startupPathProvider.overrideWithValue(workspaceRoot), if (git) gitControllerProvider.overrideWith( - () => _PresetGitController(_gitDiffState(temp.path)), + () => _PresetGitController( + gitState, + initiallyDiscovered: repositoryDiscovered, + ), ), ], ); @@ -7792,6 +7804,191 @@ code ); } + for (final kind in [ + WorkspaceKind.markdownFolder, + WorkspaceKind.writersideModule, + ]) { + for (final view in ['Commit', 'Git Log']) { + testWidgets( + '${kind.name} Sidebar selector opens $view before discovery and confirms trust explicitly', + (tester) async { + tester.view.physicalSize = const Size(1440, 1000); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final fixture = await tabWorkspace( + tester, + git: true, + openGitComparisons: false, + trustGit: false, + delayDiscovery: true, + repositoryDiscovered: false, + kind: kind, + ); + final container = fixture.container; + final workspace = container + .read(workspaceControllerProvider) + .workspace!; + final buffer = container + .read(workspaceControllerProvider) + .activeBuffer; + expect(container.read(gitControllerProvider).repositoryInfo, isNull); + expect(fixture.sharedClient.discoveryEntered.isCompleted, isFalse); + final menus = NativeMenuProbe(tester); + await tester.tap( + find.byKey(const ValueKey('workspace-sidebar-view-menu')), + ); + await tester.pumpAndSettle(); + expect(menus.enabled('Commit'), isTrue); + expect(menus.enabled('Git Log'), isTrue); + await menus.choose(view, settle: false); + await pumpUntil( + tester, + () => fixture.sharedClient.discoveryEntered.isCompleted, + operation: 'start $view discovery through the Sidebar selector', + ); + expect(container.read(gitControllerProvider).repositoryInfo, isNull); + expect(find.byType(shared.GitFeatureSidebar), findsNothing); + fixture.sharedClient.discoveryGate!.complete(); + await pumpUntil( + tester, + () => find.byType(shared.GitFeatureSidebar).evaluate().isNotEmpty, + operation: 'discover the authoring workspace root', + ); + final sidebar = tester.widget( + find.byType(shared.GitFeatureSidebar), + ); + expect( + sidebar.view, + view == 'Git Log' + ? shared.GitSidebarView.log + : shared.GitSidebarView.commit, + ); + expect( + sidebar.controller.session.repository.root, + workspace.rootPath, + ); + expect(fixture.sharedClient.statusReads, greaterThan(0)); + expect(sidebar.trusted, isFalse); + expect( + container + .read(appSettingsControllerProvider) + .trustsGitWorkspace(workspace.rootPath), + isFalse, + ); + if (view == 'Git Log') { + expect(find.byType(shared.GitLogView), findsOneWidget); + await tester.tap( + find.byKey(const ValueKey('workspace-sidebar-view-menu')), + ); + await tester.pumpAndSettle(); + await menus.choose('Commit'); + } + expect(find.text(l10n.gitOperationsRequireTrust), findsOneWidget); + expect(find.byType(shared.GitCommitView), findsNothing); + await tester.tap(find.text(l10n.gitTrustWorkspace)); + await pumpUntil( + tester, + () => find.byType(shared.GitNativeDialog).evaluate().isNotEmpty, + operation: 'show explicit trust confirmation', + ); + expect( + container + .read(appSettingsControllerProvider) + .trustsGitWorkspace(workspace.rootPath), + isFalse, + ); + expect(find.textContaining(workspace.rootPath), findsOneWidget); + await tester.tap( + find.byKey(const ValueKey('busy-mark-git-trust-confirm')), + ); + await pumpUntil( + tester, + () => find.byType(shared.GitCommitView).evaluate().isNotEmpty, + operation: 'show authorized Commit after confirmation', + ); + expect( + container + .read(appSettingsControllerProvider) + .trustsGitWorkspace(workspace.rootPath), + isTrue, + ); + expect( + container.read(workspaceControllerProvider).activeBuffer, + same(buffer), + ); + expect(fixture.service.saveCount, 0); + expect(_comparisonTabs(container).entries, isEmpty); + expect(tester.takeException(), isNull); + }, + ); + + for (final outcome in ['non-Git', 'failure', 'ancestor', 'nested']) { + testWidgets( + '${kind.name} Sidebar selector opens $view with $outcome discovery UI', + (tester) async { + tester.view.physicalSize = const Size(1440, 1000); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final fixture = await tabWorkspace( + tester, + git: true, + openGitComparisons: false, + trustGit: false, + repositoryDiscovered: false, + hasRepository: outcome != 'non-Git', + descendantWorkspace: outcome == 'ancestor', + nestedRepository: outcome == 'nested', + kind: kind, + ); + expect( + fixture.container.read(gitControllerProvider).repositoryInfo, + isNull, + ); + if (outcome == 'failure') { + fixture.sharedClient.discoveryError = const shared.GitException( + shared.GitErrorCode.disconnected, + ); + } + await _chooseNativeSidebar(tester, view); + await pumpUntil( + tester, + () => switch (outcome) { + 'non-Git' => + find.text(l10n.gitNotRepositoryMessage).evaluate().isNotEmpty, + 'failure' => + find.byType(shared.GitFailurePanel).evaluate().isNotEmpty, + _ => + find + .text(l10n.gitWorkspaceRootRequired) + .evaluate() + .isNotEmpty, + }, + operation: 'retain the existing $outcome discovery UI', + ); + expect(fixture.sharedClient.discoveryEntered.isCompleted, isTrue); + expect(fixture.sharedClient.statusReads, 0); + expect(find.byType(shared.GitCommitView), findsNothing); + expect(find.byType(shared.GitLogView), findsNothing); + expect(find.text(l10n.gitTrustWorkspace), findsNothing); + expect( + find.text(l10n.gitHostInitializeHere), + outcome == 'non-Git' ? findsOneWidget : findsNothing, + ); + expect( + find.text(l10n.gitHostCloneRepository2), + outcome == 'non-Git' ? findsOneWidget : findsNothing, + ); + expect(fixture.service.saveCount, 0); + expect(_comparisonTabs(fixture.container).entries, isEmpty); + expect(tester.takeException(), isNull); + }, + ); + } + } + } + testWidgets( 'a discovery retry leaves its failure state and reaches exclusive trust', (tester) async { @@ -22885,9 +23082,10 @@ class _DeferredWorkspaceSearchService extends WorkspaceService { } class _PresetGitController extends GitController { - _PresetGitController(this.initialState); + _PresetGitController(this.initialState, {this.initiallyDiscovered = true}); final GitState initialState; + final bool initiallyDiscovered; String? loadedFileHistoryPath; List stagedPaths = const []; int branchLoadCount = 0; @@ -22895,7 +23093,7 @@ class _PresetGitController extends GitController { int commitComparisonCount = 0; @override - GitState build() => initialState; + GitState build() => initiallyDiscovered ? initialState : const GitState(); void replaceStatus(GitStatusSnapshot status) { state = state.copyWith(statusSnapshot: status); @@ -22919,6 +23117,9 @@ class _PresetGitController extends GitController { // real association and metadata replacement have separate Git regressions. expect(repository.root, initialState.repositoryInfo!.rootPath); expect(repository.gitDir, initialState.repositoryInfo!.gitDirPath); + if (!initiallyDiscovered) { + state = initialState.copyWith(attachedWorkspace: workspace); + } } @override @@ -23832,6 +24033,7 @@ Future _chooseNativeSidebar(WidgetTester tester, String label) async { (entry) => (entry as Map)['label'] == label, ); expect(index, greaterThanOrEqualTo(0)); + expect((entries[index] as Map)['enabled'], isTrue); selected = true; return index; }); diff --git a/test/src/local_history_workspace_test.dart b/test/src/local_history_workspace_test.dart index 6ffcdeb0..04db6ebe 100644 --- a/test/src/local_history_workspace_test.dart +++ b/test/src/local_history_workspace_test.dart @@ -3665,8 +3665,13 @@ void main() { test( 'cancelled named Save As detaches source history and reopens separately', () async { - final sourcePath = p.join(root.path, 'A.md'); - final destinationPath = p.join(root.path, 'B.md'); + // Keep the history store outside the watched authoring workspace, as in + // the application, so its staging renames are not external file moves. + final workspaceRoot = await Directory( + p.join(root.path, 'workspace'), + ).create(); + final sourcePath = p.join(workspaceRoot.path, 'A.md'); + final destinationPath = p.join(workspaceRoot.path, 'B.md'); await File(sourcePath).writeAsString('Original A\n'); final historyRoot = Directory(p.join(root.path, 'history')); final diskStore = FileLocalHistoryStore( @@ -3688,6 +3693,12 @@ void main() { final history = harness.container.read( localHistoryControllerProvider.notifier, ); + // Provider disposal cancels future work but cannot await accepted I/O. + // Settle it before disposing either controller or deleting historyRoot. + addTearDown(() async { + expect(await history.flushAll(harness.state.documentBuffers), isTrue); + await harness.controller.flushPersistence(); + }); await harness.controller.openPath(sourcePath); final sourceId = (await diskStore.load()).documents.single.id; harness.controller.updateActiveText('Save As B\n'); @@ -3772,6 +3783,13 @@ void main() { final reopenedHistory = reopened.container.read( localHistoryControllerProvider.notifier, ); + addTearDown(() async { + expect( + await reopenedHistory.flushAll(reopened.state.documentBuffers), + isTrue, + ); + await reopened.controller.flushPersistence(); + }); await reopened.controller.openPath(sourcePath); await _waitFor( () => diff --git a/test/src/visualization_packaging_audit_test.dart b/test/src/visualization_packaging_audit_test.dart index 668d4362..88279817 100644 --- a/test/src/visualization_packaging_audit_test.dart +++ b/test/src/visualization_packaging_audit_test.dart @@ -29,10 +29,10 @@ void main() { 'linux/io.busystack.busymark.metainfo.xml', ).readAsStringSync(); - expect(pubspec, contains(RegExp(r'^version: 0\.7\.0$', multiLine: true))); + expect(pubspec, contains(RegExp(r'^version: 0\.7\.1$', multiLine: true))); expect( snapcraft, - contains(RegExp(r'^version: "0\.7\.0"$', multiLine: true)), + contains(RegExp(r'^version: "0\.7\.1"$', multiLine: true)), ); expect(snapcraft, contains(RegExp(r'^grade: stable$', multiLine: true))); expect( @@ -59,7 +59,7 @@ void main() { ), ), ); - expect(metainfo, contains('