diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3e822966b..a13cfafde4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -276,7 +276,7 @@ jobs: image_cache: ghcr.io/${{ github.repository_owner }}/simplex-chat-build-cache:${{ matrix.os }}-${{ matrix.arch }}-ghc${{ matrix.ghc }} source_hashes: dist-newstyle/sources.sha256 concurrency: &linux-concurrency - group: ${{ github.workflow }}-${{ github.ref }}-linux-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-${{ needs.maybe-release.outputs.libs_tag }} + group: ${{ github.workflow }}-${{ github.ref }}-linux-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.ghc }}${{ matrix.postgres && '-postgres' || '' }}-${{ needs.maybe-release.outputs.libs_tag }} cancel-in-progress: ${{ github.event_name != 'push' }} strategy: fail-fast: false @@ -378,7 +378,7 @@ jobs: toolchain=$(docker exec builder dpkg-query -W -f '${db:Status-Status} ${binary:Package} ${Version}\n' 'binutils*' 'cpp*' 'gcc*' '*-dev' | grep '^installed ' | sha256sum | cut -c1-16) target=ubuntu-${{ matrix.os }}-${{ matrix.arch }}-ghc${{ matrix.ghc }}-$toolchain echo "deps=deps-$target" >> "$GITHUB_OUTPUT" - echo "dist=dist-$target" >> "$GITHUB_OUTPUT" + echo "dist=${{ env.dist_name || 'dist' }}-$target" >> "$GITHUB_OUTPUT" echo "dist_lib=dist-lib-$target" >> "$GITHUB_OUTPUT" - name: Restore dependencies from cache @@ -474,14 +474,14 @@ jobs: run: | scripts/ci/prune-old-builds.sh dist-newstyle cabal update - cabal build -j --enable-tests ${{ env.ghc_options }} + cabal build -j --enable-tests ${{ env.ghc_options }} ${{ env.cabal_targets }} mkdir -p /out - for i in simplex-chat simplex-chat-test; do + for i in ${{ env.bins || 'simplex-chat simplex-chat-test' }}; do bin=$(find /project/dist-newstyle -name "$i" -type f -executable) chmod +x "$bin" cp "$bin" /out/ done - strip /out/simplex-chat + [ ! -f /out/simplex-chat ] || strip /out/simplex-chat # Also for pull requests that change the chat core, for the package tests. - name: Build library @@ -658,6 +658,36 @@ jobs: github_ref: ${{ github.ref }} github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Node.js for tests + if: matrix.should_run == true && matrix.arch == 'x86_64' + uses: actions/setup-node@v7 + with: + node-version: 22 + + - name: Build badge web app for tests + if: matrix.should_run == true && matrix.arch == 'x86_64' + working-directory: apps/simplex-store-service/web + run: | + npm ci + npm run build + + - name: Install PostgreSQL 15 client tools + if: matrix.postgres == true + shell: bash + run: | + sudo install -d /usr/share/postgresql-common/pgdg + sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc + sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + sudo apt update + sudo apt -y install postgresql-client-15 + + - name: Start PostgreSQL + if: matrix.postgres == true + shell: bash + run: | + docker run -d --name postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres:15 -c max_connections=3000 -c fsync=off + timeout 60 sh -c 'until pg_isready -h localhost; do sleep 1; done' + - name: Mount RAM disk for tests if: matrix.should_run == true && matrix.arch == 'x86_64' shell: bash @@ -667,6 +697,7 @@ jobs: sudo chown $(id -u):$(id -g) tests/tmp - name: Run tests + id: tests if: matrix.should_run == true && matrix.arch == 'x86_64' timeout-minutes: 120 shell: bash @@ -675,7 +706,22 @@ jobs: TESTS: ${{ github.event_name == 'workflow_dispatch' && inputs.tests || '' }} PR_BODY: ${{ github.event.pull_request.draft == true && github.event.pull_request.body || '' }} ATTEMPTS: ${{ (github.ref == 'refs/heads/stable' || startsWith(github.ref, 'refs/tags/v')) && 3 || 1 }} - run: scripts/ci/run-tests.sh timeout 35m ./simplex-chat-test + run: scripts/ci/run-tests.sh timeout ${{ env.test_timeout || '35m' }} ./simplex-chat-test + + - name: Check generated files + id: generated + if: ${{ !cancelled() && steps.tests.outcome != 'skipped' }} + shell: bash + run: | + git diff > "$RUNNER_TEMP/generated-files.patch" + git diff --stat --exit-code + + - name: Upload generated files + if: ${{ !cancelled() && steps.generated.outcome == 'failure' }} + uses: actions/upload-artifact@v7 + with: + name: generated-files-ubuntu-${{ matrix.os }}-ghc${{ matrix.ghc }}${{ matrix.postgres && '-postgres' || '' }} + path: ${{ runner.temp }}/generated-files.patch # Compiling the desktop and Android targets of :common in parallel exceeds the 2 GB Kotlin daemon heap. # cmakeBuildAndCopy links the JNI library against libsimplex, which this job does not build. @@ -1169,6 +1215,46 @@ jobs: test=$(cabal list-bin --constraint 'simplexmq +client_postgres' --constraint 'simplex-chat +client_postgres' simplex-chat-test | tail -n 1) "$test" --fail-on=empty -m "Supporter badges" -m "SimpleX store service" -m "StoreService names" +# ================================= +# Linux PostgreSQL Tests +# ================================= + + test-postgres: + name: "ubuntu-${{ matrix.os }}-${{ matrix.arch }} (PostgreSQL tests), GHC: ${{ matrix.ghc }}" + needs: [maybe-release, variables] + if: needs.maybe-release.outputs.haskell == 'true' && !(github.ref == 'refs/heads/stable' || startsWith(github.ref, 'refs/tags/v')) + runs-on: ${{ matrix.runner }} + permissions: + contents: write + packages: write + env: + image_cache: ghcr.io/${{ github.repository_owner }}/simplex-chat-build-cache:${{ matrix.os }}-${{ matrix.arch }}-ghc${{ matrix.ghc }} + source_hashes: dist-newstyle/sources.sha256 + opt: O0 + ghc_options: --ghc-options=-O0 + cache_o0: false + cabal_targets: --constraint 'simplexmq +client_postgres' --constraint 'simplex-chat +client_postgres' test:simplex-chat-test + bins: simplex-chat-test + dist_name: dist-postgres + test_timeout: 60m + PGHOST: localhost + ALLOW_EMPTY: true + concurrency: *linux-concurrency + strategy: + fail-fast: false + matrix: + include: + - os: 22.04 + os_underscore: 22_04 + arch: x86_64 + runner: "ubuntu-22.04" + should_run: true + ghc: ${{ needs.variables.outputs.GHC_VER }} + hash: 'sha256:5c8b2c0a6c745bc177669abfaa716b4bc57d58e2ea3882fb5da67f4d59e3dda5' + kotlin: false + postgres: true + steps: *linux-steps + # ========================= # MacOS Build # ========================= @@ -1420,6 +1506,7 @@ jobs: ln -s /Volumes/tests tests/tmp - name: Run tests + id: tests if: matrix.should_run == true && matrix.arch == 'aarch64' timeout-minutes: 120 shell: bash @@ -1441,6 +1528,21 @@ jobs: exit 1 fi + - name: Check generated files + id: generated + if: ${{ !cancelled() && steps.tests.outcome != 'skipped' }} + shell: bash + run: | + git diff > "$RUNNER_TEMP/generated-files.patch" + git diff --stat --exit-code + + - name: Upload generated files + if: ${{ !cancelled() && steps.generated.outcome == 'failure' }} + uses: actions/upload-artifact@v7 + with: + name: generated-files-${{ matrix.os }} + path: ${{ runner.temp }}/generated-files.patch + - name: Build library id: mac_lib_build if: ${{ !cancelled() && matrix.should_run == true && needs.maybe-release.outputs.libs_tag && steps.mac_cli_build.outcome == 'success' }} @@ -2024,8 +2126,8 @@ jobs: if: steps.plan.outputs.nodejs_version working-directory: packages/simplex-chat-nodejs run: | - (cd ../simplex-chat-client/types/typescript && npm install --no-audit --no-fund && npx tsc) - npm install --ignore-scripts --no-save --no-audit --no-fund ../simplex-chat-client/types/typescript + (cd ../simplex-chat-client/types/typescript && "$GITHUB_WORKSPACE/scripts/ci/npm-install.sh" && npx tsc) + "$GITHUB_WORKSPACE/scripts/ci/npm-install.sh" --ignore-scripts --no-save ../simplex-chat-client/types/typescript npx tsc && cp src/simplex.* dist npx jest tests/libs.test.ts tests/api.unit.test.ts @@ -2041,7 +2143,7 @@ jobs: VERSION: ${{ steps.plan.outputs.types_version }} DIST_TAG: ${{ steps.plan.outputs.types_dist_tag }} run: | - npm install --no-audit --no-fund + "$GITHUB_WORKSPACE/scripts/ci/npm-install.sh" npm publish --provenance --access public --tag "$DIST_TAG" echo "version=$VERSION" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/reproduce-schedule.yml b/.github/workflows/reproduce-schedule.yml index 0febed4c87..0aa14b21df 100644 --- a/.github/workflows/reproduce-schedule.yml +++ b/.github/workflows/reproduce-schedule.yml @@ -7,7 +7,7 @@ on: jobs: reproduce: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Get latest release shell: bash @@ -22,9 +22,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - with: - ref: ${{ env.TAG }} - repository: simplex-chat/simplex-chat # Otherwise we run out of disk space with Docker build - name: Free disk space diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 7628eb1f9a..192f1f7caa 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -28,6 +28,10 @@ jobs: with: node-version: ${{ matrix.node-version }} + - name: Install dependencies + working-directory: website + run: ../scripts/ci/npm-install.sh + - name: Install dependencies & build run: | ./website/web.sh diff --git a/CLAUDE.md b/CLAUDE.md index 2c3cceced7..f490f20416 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,4 +1,5 @@ @docs/CONTRIBUTING.md @docs/contributing/PROJECT.md @docs/contributing/CODE.md +@docs/contributing/TESTS.md @scripts/ci/README.md diff --git a/Dockerfile.build b/Dockerfile.build index f18f608612..43b44ca7c3 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -54,6 +54,7 @@ RUN apt-get update --error-on=any && \ wget \ fuse3 \ file \ + fontconfig \ appstream \ gpg \ zipalign \ @@ -98,6 +99,7 @@ WORKDIR /home/${USER_NAME} # Setup basic env variables (required) ENV HOME="/home/${USER_NAME}" USER="${USER_NAME}" +ENV CABAL_DIR="$HOME/.cabal" # Adjust PATH ENV PATH="$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH" diff --git a/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift b/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift index 555ff9d429..508606e124 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/MarkdownFileView.swift @@ -3,6 +3,7 @@ import SimpleXChat import Ink private let MAX_MARKDOWN_VIEW_SIZE: Int64 = 1_048_576 +private let MAX_MARKDOWN_COPY_SIZE: Int64 = 131_072 private let MAX_MARKDOWN_LINE_LENGTH = 15_000 private let MAX_MARKDOWN_NESTING = 16 private let MAX_MARKDOWN_LINK_NESTING = 4 @@ -27,7 +28,7 @@ func showMarkdownFile(_ file: CIFile) { let hasBidiControls = text.unicodeScalars.contains(where: isBidiControl) await MainActor.run { showAppSheet { - MarkdownFileView(file: file, fileSource: fileSource, lines: shownLines, html: html, hasBidiControls: hasBidiControls) + MarkdownFileView(file: file, fileSource: fileSource, text: text, lines: shownLines, html: html, hasBidiControls: hasBidiControls) } } } catch { @@ -166,10 +167,31 @@ private func openMarkdownFileLink(_ url: URL) { } } +func copyMarkdownFile(_ file: CIFile, _ text: String) { + if file.fileSize > MAX_MARKDOWN_COPY_SIZE { + showAlert( + NSLocalizedString("File too large", comment: "alert title"), + message: String.localizedStringWithFormat( + NSLocalizedString("Your file is %@. Do you want to copy it?", comment: "alert message"), + ByteCountFormatter.string(fromByteCount: file.fileSize, countStyle: .binary) + ), + actions: {[ + cancelAlertAction, + UIAlertAction(title: NSLocalizedString("Copy", comment: "alert button"), style: .default) { _ in + UIPasteboard.general.string = text + } + ]} + ) + } else { + UIPasteboard.general.string = text + } +} + struct MarkdownFileView: View { @AppStorage(DEFAULT_MARKDOWN_FILE_TEXT_VIEW) private var textView = false let file: CIFile let fileSource: CryptoFile + let text: String let lines: [String] let html: String? let hasBidiControls: Bool @@ -203,6 +225,11 @@ struct MarkdownFileView: View { .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItemGroup(placement: .navigationBarTrailing) { + Button { + copyMarkdownFile(file, text) + } label: { + Image(systemName: "doc.on.doc") + } if html != nil { Button { textView.toggle() @@ -221,3 +248,17 @@ struct MarkdownFileView: View { .navigationViewStyle(.stack) } } + +struct MarkdownFileView_Previews: PreviewProvider { + static var previews: some View { + let text = "# Release notes\n\n- markdown files in chats\n- a button to copy the file\n" + MarkdownFileView( + file: CIFile.getSample(fileName: "notes.md", fileSize: Int64(text.utf8.count), filePath: "notes.md"), + fileSource: CryptoFile.plain("notes.md"), + text: text, + lines: text.components(separatedBy: "\n"), + html: nil, + hasBidiControls: false + ) + } +} diff --git a/apps/ios/SimpleX Snapshots/References/MarkdownFileView-dark-large.png b/apps/ios/SimpleX Snapshots/References/MarkdownFileView-dark-large.png new file mode 100644 index 0000000000..a9969a1186 Binary files /dev/null and b/apps/ios/SimpleX Snapshots/References/MarkdownFileView-dark-large.png differ diff --git a/apps/ios/SimpleX Snapshots/References/MarkdownFileView-light-large.png b/apps/ios/SimpleX Snapshots/References/MarkdownFileView-light-large.png new file mode 100644 index 0000000000..e0ce6284ae Binary files /dev/null and b/apps/ios/SimpleX Snapshots/References/MarkdownFileView-light-large.png differ diff --git a/apps/ios/SimpleX Snapshots/SnapshotTests.swift b/apps/ios/SimpleX Snapshots/SnapshotTests.swift index fc47a3a336..a3ccd35cdc 100644 --- a/apps/ios/SimpleX Snapshots/SnapshotTests.swift +++ b/apps/ios/SimpleX Snapshots/SnapshotTests.swift @@ -728,6 +728,7 @@ private func previewScenes() -> [SnapshotScene] { SnapshotScene(IntegrityErrorItemView_Previews.self, allSizes: true), SnapshotScene(LargeLinkPreview_Previews.self, allSizes: true), SnapshotScene(LocalAuthView_Previews.self), + SnapshotScene(MarkdownFileView_Previews.self, device: true), SnapshotScene(MarkdownHelp_Previews.self), SnapshotScene(MarkedDeletedItemView_Previews.self, allSizes: true), SnapshotScene(MemberAdmissionView_Previews.self), diff --git a/apps/ios/SimpleX Unit Tests/MarkdownFileTests.swift b/apps/ios/SimpleX Unit Tests/MarkdownFileTests.swift new file mode 100644 index 0000000000..92e931f3e5 --- /dev/null +++ b/apps/ios/SimpleX Unit Tests/MarkdownFileTests.swift @@ -0,0 +1,26 @@ +import XCTest +import UIKit +@testable import SimpleX +@testable import SimpleXChat + +final class MarkdownFileTests: XCTestCase { + @MainActor + func testCopyAsksAbove128KB() async throws { + let text = "alpha\n\ngamma" + UIPasteboard.general.string = "unchanged" + copyMarkdownFile(CIFile.getSample(fileSize: 131_072), text) + XCTAssertEqual(UIPasteboard.general.string, text) + UIPasteboard.general.string = "unchanged" + copyMarkdownFile(CIFile.getSample(fileSize: 131_073), text) + try await waitFor { (getTopViewController() as? UIAlertController)?.isBeingPresented == false } + let alert = try XCTUnwrap(getTopViewController() as? UIAlertController) + XCTAssertEqual(alert.title, "File too large") + XCTAssertEqual(alert.message, "Your file is 128 KB. Do you want to copy it?") + XCTAssertEqual(UIPasteboard.general.string, "unchanged") + let copy = try XCTUnwrap(alert.actions.first { $0.title == "Copy" }) + let handler = unsafeBitCast(copy.value(forKey: "handler") as AnyObject, to: (@convention(block) (UIAlertAction) -> Void).self) + await withCheckedContinuation { done in alert.dismiss(animated: false) { done.resume() } } + handler(copy) + XCTAssertEqual(UIPasteboard.general.string, text) + } +} diff --git a/apps/ios/SimpleX Unit Tests/NameAlertsTests.swift b/apps/ios/SimpleX Unit Tests/NameAlertsTests.swift index 6b3290c351..36b22f4016 100644 --- a/apps/ios/SimpleX Unit Tests/NameAlertsTests.swift +++ b/apps/ios/SimpleX Unit Tests/NameAlertsTests.swift @@ -221,6 +221,29 @@ final class NameAlertsTests: XCTestCase { XCTAssertEqual(shownLocalChats, ["@3"]) } + @MainActor + func testGroupLinkAsAddress() async throws { + try recorded("connect/group-link-as-address") + connect("GROUP_LINK") + try await assertTexts(["Invalid connection link", "Please check that you used the correct link or ask your contact to send you another one.", "Ok"]) + } + + @MainActor + func testGroupLinkAsChannel() async throws { + try recorded("connect/group-link-as-channel") + connect("GROUP_LINK") + try await assertTexts(["Invalid connection link", "Please check that you used the correct link or ask your contact to send you another one.", "Ok"]) + } + + @MainActor + func testRejectedContactInChatList() async throws { + try recorded("connect/request-rejected") + ChatModel.shared.updateChats(try apiGetChats()) + guard case let .direct(contact)? = ChatModel.shared.getContactChat(2)?.chatInfo else { return XCTFail("contact not decoded: \(ChatModel.shared.chats.map(\.id))") } + XCTAssertEqual(contact.contactStatus.rawValue, "rejected") + XCTAssertFalse(contact.active) + } + @MainActor func testNameMovedEvent() async throws { var contact = Contact.sampleData diff --git a/apps/ios/SimpleX.xcodeproj/project.pbxproj b/apps/ios/SimpleX.xcodeproj/project.pbxproj index 530bc4c124..3242c7ea27 100644 --- a/apps/ios/SimpleX.xcodeproj/project.pbxproj +++ b/apps/ios/SimpleX.xcodeproj/project.pbxproj @@ -272,6 +272,7 @@ E5AEC0C22F9C000100270665 /* SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5AEC0C12F9C000100270665 /* SnapshotTests.swift */; }; 4E57A1E70000000000000006 /* NameAlertsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E57A1E70000000000000005 /* NameAlertsTests.swift */; }; 4E57A1E70000000000000014 /* ChatItemUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */; }; + 6D4F1C2A9B3E000000000002 /* MarkdownFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */; }; E5AEC0AF2F91A73500270665 /* ComposeChatLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5AEC0AE2F91A73500270665 /* ComposeChatLinkView.swift */; }; E5C0BBE82F82B45500EA7527 /* SimpleXAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E5C0BBE72F82B45500EA7527 /* SimpleXAssets.xcassets */; }; E5C0BBEB2F82B45500EA7527 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E5C0BBEA2F82B45500EA7527 /* SharedAssets.xcassets */; }; @@ -684,6 +685,7 @@ E5AEC0C32F9C000100270665 /* SimpleX Snapshots.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SimpleX Snapshots.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 4E57A1E70000000000000005 /* NameAlertsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameAlertsTests.swift; sourceTree = ""; }; 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatItemUpdateTests.swift; sourceTree = ""; }; + 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownFileTests.swift; sourceTree = ""; }; 4E57A1E70000000000000007 /* SimpleX Unit Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SimpleX Unit Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; E5AEC0AE2F91A73500270665 /* ComposeChatLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeChatLinkView.swift; sourceTree = ""; }; E5C0BBE72F82B45500EA7527 /* SimpleXAssets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = SimpleXAssets.xcassets; sourceTree = ""; }; @@ -1038,6 +1040,7 @@ children = ( 4E57A1E70000000000000005 /* NameAlertsTests.swift */, 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */, + 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */, ); path = "SimpleX Unit Tests"; sourceTree = ""; @@ -1926,6 +1929,7 @@ files = ( 4E57A1E70000000000000006 /* NameAlertsTests.swift in Sources */, 4E57A1E70000000000000014 /* ChatItemUpdateTests.swift in Sources */, + 6D4F1C2A9B3E000000000002 /* MarkdownFileTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 74d514922d..8d1e53b7a7 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -2760,6 +2760,7 @@ public enum ContactStatus: String, Decodable, Hashable { case active = "active" case deleted = "deleted" case deletedByUser = "deletedByUser" + case rejected = "rejected" } public struct ContactRef: Decodable, Equatable, Hashable { diff --git a/apps/multiplatform/build.gradle.kts b/apps/multiplatform/build.gradle.kts index ee64060206..9688e3a268 100644 --- a/apps/multiplatform/build.gradle.kts +++ b/apps/multiplatform/build.gradle.kts @@ -107,6 +107,14 @@ configure(subprojects) { if (jvmVersion.isPresent) jvmTarget = jvmVersion.get() } } + + configurations.configureEach { + resolutionStrategy.eachDependency { + if (requested.group == "org.jetbrains.skiko" && requested.version == "0.9.4.2") { + useVersion("0.9.24") + } + } + } } tasks.register("clean", Delete::class) { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 403af4185a..959c4315e0 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2105,7 +2105,8 @@ enum class ConnectionMode { enum class ContactStatus { @SerialName("active") Active, @SerialName("deleted") Deleted, - @SerialName("deletedByUser") DeletedByUser; + @SerialName("deletedByUser") DeletedByUser, + @SerialName("rejected") Rejected; } @Serializable diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/MarkdownFileView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/MarkdownFileView.kt index a763e47d43..7681120144 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/MarkdownFileView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/MarkdownFileView.kt @@ -1,18 +1,22 @@ package chat.simplex.common.views.chat.item import SectionBottomSpacer +import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.items import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.* import androidx.compose.runtime.* +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.UriHandler +import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString @@ -25,6 +29,7 @@ import chat.simplex.common.model.* import chat.simplex.common.model.ChatController.appPrefs import chat.simplex.common.platform.* import chat.simplex.common.ui.theme.DEFAULT_PADDING +import chat.simplex.common.ui.theme.SimpleXTheme import chat.simplex.common.ui.theme.WarningOrange import chat.simplex.common.views.chat.topPaddingToContent import chat.simplex.common.views.helpers.* @@ -41,6 +46,7 @@ import dev.icerock.moko.resources.compose.painterResource import dev.icerock.moko.resources.compose.stringResource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.ast.ASTNode @@ -56,6 +62,8 @@ import java.util.Base64 private const val DATA_IMAGE = "data:image/" private val IMAGE_TYPES = listOf(ImageFileType.JPEG, ImageFileType.PNG) private const val MAX_MARKDOWN_VIEW_SIZE: Long = 1_048_576 +private const val MAX_MARKDOWN_COPY_SIZE = 131_072 +private const val MAX_ANDROID_COPY_SIZE = 524_288 private const val MAX_MARKDOWN_LINE_LENGTH = 15_000 private const val MAX_MARKDOWN_DEPTH = 32 private const val MAX_MARKDOWN_TABLE_ROWS = 200 @@ -67,7 +75,9 @@ private val bidiControlChar = Regex("[\\u061C\\u200E\\u200F\\u202A-\\u202E\\u206 private val invisibleCharMarkerStyle = SpanStyle(color = WarningOrange) -private class MarkdownDocument(val lines: List, val formatted: State.Success?, val hasBidiControls: Boolean) +internal class MarkdownLine(val text: String, val lineBreak: Boolean) + +internal class MarkdownDocument(val text: String, val lines: List, val formatted: State.Success?, val hasBidiControls: Boolean) fun isMarkdownFile(file: CIFile): Boolean = file.fileSize <= MAX_MARKDOWN_VIEW_SIZE && file.fileName.substringAfterLast('.', "").lowercase() in listOf("md", "markdown") @@ -90,26 +100,31 @@ fun showMarkdownFile(file: CIFile) { AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error), e.message) return@withLongRunningApi } - val text = decodedText(bytes) - val lines = text.lines() - val formatted = if (lines.all { it.length <= MAX_MARKDOWN_LINE_LENGTH }) formattedWithinLimits(text) else null - val document = MarkdownDocument( - lines.flatMap { line -> line.chunked(MAX_MARKDOWN_LINE_LENGTH).ifEmpty { listOf("") } }, - formatted, - bidiControlChar.containsMatchIn(text) - ) + val document = markdownDocument(bytes) withContext(Dispatchers.Main) { if (appPlatform.isDesktop && ModalManager.center.isTopModalOpen(ModalViewId.MARKDOWN_FILE)) ModalManager.center.closeModal() - ModalManager.center.showModal(id = ModalViewId.MARKDOWN_FILE, endButtons = { - if (formatted != null) MarkdownViewSwitch() - MarkdownFileSaveButton(file, bytes) - }) { + ModalManager.center.showModal(id = ModalViewId.MARKDOWN_FILE, endButtons = { MarkdownFileButtons(file, bytes, document) }) { key(this) { MarkdownFileView(file.fileName, document) } } } } } +internal suspend fun markdownDocument(bytes: ByteArray): MarkdownDocument { + val text = decodedText(bytes) + val lines = text.lines() + val formatted = if (lines.all { it.length <= MAX_MARKDOWN_LINE_LENGTH }) formattedWithinLimits(text) else null + return MarkdownDocument( + text, + lines.flatMapIndexed { i, line -> + val chunks = line.chunked(MAX_MARKDOWN_LINE_LENGTH).ifEmpty { listOf("") } + chunks.mapIndexed { j, chunk -> MarkdownLine(chunk, lineBreak = i < lines.lastIndex && j == chunks.lastIndex) } + }, + formatted, + bidiControlChar.containsMatchIn(text) + ) +} + private fun decodedText(bytes: ByteArray): String = Charsets.UTF_8.newDecoder() .onMalformedInput(CodingErrorAction.REPLACE) @@ -145,6 +160,39 @@ private fun MarkdownViewSwitch() { } } +@Composable +private fun MarkdownFileButtons(file: CIFile, bytes: ByteArray, document: MarkdownDocument) { + MarkdownFileCopyButton(document.text, bytes.size, if (appPlatform.isAndroid) MAX_ANDROID_COPY_SIZE else null) + if (document.formatted != null) MarkdownViewSwitch() + MarkdownFileSaveButton(file, bytes) +} + +@Composable +internal fun MarkdownFileCopyButton(text: String, fileSize: Int, maxSize: Int?) { + val clipboard = LocalClipboardManager.current + IconButton({ + val copy = { + clipboard.setText(AnnotatedString(text)) + showToast(generalGetString(MR.strings.copied)) + } + when { + maxSize != null && fileSize > maxSize -> AlertManager.shared.showAlertMsg( + generalGetString(MR.strings.markdown_file_too_large), + String.format(generalGetString(MR.strings.markdown_file_copy_limit), formatBytes(maxSize.toLong())) + ) + fileSize > MAX_MARKDOWN_COPY_SIZE -> AlertManager.shared.showAlertDialog( + title = generalGetString(MR.strings.markdown_file_too_large), + text = String.format(generalGetString(MR.strings.markdown_file_copy_large), formatBytes(fileSize.toLong())), + confirmText = generalGetString(MR.strings.copy_verb), + onConfirm = copy + ) + else -> copy() + } + }) { + Icon(painterResource(MR.images.ic_content_copy), stringResource(MR.strings.copy_verb), tint = MaterialTheme.colors.primary) + } +} + @Composable private fun MarkdownFileSaveButton(file: CIFile, bytes: ByteArray) { val saveFileLauncher = rememberFileChooserLauncher(false, bytes) { to: URI? -> @@ -156,14 +204,17 @@ private fun MarkdownFileSaveButton(file: CIFile, bytes: ByteArray) { } @Composable -private fun MarkdownFileView(fileName: String, document: MarkdownDocument) { +internal fun MarkdownFileView(fileName: String, document: MarkdownDocument) { val textView = remember { appPrefs.markdownFileTextView.state } val formatted = document.formatted if (textView.value || formatted == null) { SelectionContainer { MarkdownFileColumn(fileName, document.hasBidiControls) { items(document.lines) { line -> - Text(remember(line) { withInvisibleCharMarkers(line) }, Modifier.padding(horizontal = DEFAULT_PADDING), fontFamily = FontFamily.Monospace) + Box(Modifier.padding(horizontal = DEFAULT_PADDING)) { + Text(remember(line) { withInvisibleCharMarkers(line.text) }, fontFamily = FontFamily.Monospace) + if (line.lineBreak) SelectableLineBreak() + } } } } @@ -172,6 +223,11 @@ private fun MarkdownFileView(fileName: String, document: MarkdownDocument) { } } +@Composable +private fun BoxScope.SelectableLineBreak() { + Text("\n", Modifier.align(Alignment.BottomEnd).height(1.dp).clearAndSetSemantics {}) +} + private fun withInvisibleCharMarkers(line: String): AnnotatedString = buildAnnotatedString { var start = 0 invisibleChar.findAll(line).forEach { @@ -294,3 +350,15 @@ private fun hasImageSignature(base64: String): Boolean { val header = runCatching { Base64.getDecoder().decode(base64.take(12)) }.getOrNull() ?: return false return IMAGE_TYPES.any { it.matches(header) } } + +@Preview +@Composable +fun PreviewMarkdownFileView() { + val bytes = remember { "# Release notes\n\n- markdown files in chats\n- a button to copy the file\n".encodeToByteArray() } + val document = remember { runBlocking { markdownDocument(bytes) } } + SimpleXTheme { + ModalView(close = {}, endButtons = { MarkdownFileButtons(CIFile.getSample(fileName = "notes.md"), bytes, document) }) { + MarkdownFileView("notes.md", document) + } + } +} diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/QRCode.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/QRCode.kt index 07dbb6aaea..eef8f963ab 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/QRCode.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/QRCode.kt @@ -77,9 +77,9 @@ fun QRCode( val errorLevel = if (small) QrCode.ErrorLevel.M else QrCode.ErrorLevel.L val fixedQRCode = LocalFixedQRCode.current val qr = remember(connReq, tintColor, withLogo) { - (fixedQRCode ?: qrCodeBitmap(connReq, 1024, errorLevel)).replaceColor(Color.Black.toArgb(), tintColor.toArgb()) - .let { if (withLogo) it.addLogo(logoSize) else it } - } + (fixedQRCode ?: qrCodeBitmap(connReq, 1024, errorLevel))?.replaceColor(Color.Black.toArgb(), tintColor.toArgb()) + ?.let { if (withLogo) it.addLogo(logoSize) else it } + } ?: return Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { Image( bitmap = qr, @@ -92,8 +92,8 @@ fun QRCode( .then(modifier) .clickable { scope.launch { - val image = qrCodeBitmap(connReq, 1024, errorLevel).replaceColor(Color.Black.toArgb(), tintColor.toArgb()) - .let { if (withLogo) it.addLogo(logoSize) else it } + val image = qrCodeBitmap(connReq, 1024, errorLevel)?.replaceColor(Color.Black.toArgb(), tintColor.toArgb()) + ?.let { if (withLogo) it.addLogo(logoSize) else it } ?: return@launch val file = saveTempImageUncompressed(image, true) if (file != null) { shareFile("", CryptoFile.plain(file.absolutePath)) @@ -105,8 +105,13 @@ fun QRCode( } } -fun qrCodeBitmap(content: String, size: Int = 1024, errorLevel: QrCode.ErrorLevel): ImageBitmap { - val qrCode = QrCodeEncoder().addAutomatic(content).setError(errorLevel).fixate() +fun qrCodeBitmap(content: String, size: Int = 1024, errorLevel: QrCode.ErrorLevel): ImageBitmap? { + val qrCode = try { + QrCodeEncoder().addAutomatic(content).setError(errorLevel).fixate() + } catch (e: Exception) { + Log.e(TAG, "qrCodeBitmap error: ${e.message}") + return null + } /** See [QrCodeGeneratorImage.initialize] and [FiducialImageEngine.configure] for size calculation */ val numModules = QrCode.totalModules(qrCode.version) // Hide border on light themes to make it fit to the same place as camera in QRCodeScanner. diff --git a/apps/multiplatform/common/src/commonMain/moko-resources/base/strings.xml b/apps/multiplatform/common/src/commonMain/moko-resources/base/strings.xml index af5b3a089d..27cf5f7f17 100644 --- a/apps/multiplatform/common/src/commonMain/moko-resources/base/strings.xml +++ b/apps/multiplatform/common/src/commonMain/moko-resources/base/strings.xml @@ -721,6 +721,9 @@ Formatted view Text view This file has text direction characters. The text can be shown in a different order than it is written. + File too large + Only files up to %s can be copied. Save the file to open it in another app. + Your file is %s. Do you want to copy it? Loading the file Please, wait while the file is being loaded from the linked mobile File error diff --git a/apps/multiplatform/common/src/commonTest/kotlin/chat/simplex/app/ContactStatusTest.kt b/apps/multiplatform/common/src/commonTest/kotlin/chat/simplex/app/ContactStatusTest.kt new file mode 100644 index 0000000000..d1ba98ac1f --- /dev/null +++ b/apps/multiplatform/common/src/commonTest/kotlin/chat/simplex/app/ContactStatusTest.kt @@ -0,0 +1,16 @@ +package chat.simplex.app + +import chat.simplex.common.model.ContactStatus +import chat.simplex.common.model.json +import kotlin.test.Test +import kotlin.test.assertEquals + +class ContactStatusTest { + @Test + fun testContactStatusesOfCore() { + listOf("active", "deleted", "deletedByUser", "rejected").forEach { status -> + val decoded = json.decodeFromString(ContactStatus.serializer(), "\"$status\"") + assertEquals("\"$status\"", json.encodeToString(ContactStatus.serializer(), decoded)) + } + } +} diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/BubbleLayoutTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/BubbleLayoutTest.kt index 2ce3febff7..46c52526b0 100644 --- a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/BubbleLayoutTest.kt +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/BubbleLayoutTest.kt @@ -33,6 +33,18 @@ import kotlin.math.roundToInt import kotlin.test.Test import kotlin.test.assertEquals +private val TIME_BELOW_TEXT_PX = mapOf( + 0.7f to listOf(0, 0, 0), + 0.8f to listOf(1, 0, 0), + 0.9f to listOf(-1, 0, 0), + 1f to listOf(0, 0, -1), + 1.1f to listOf(0, 0, 0), + 1.2f to listOf(1, 1, 0), + 1.3f to listOf(0, 0, 0), + 1.4f to listOf(-1, 0, 0), + 1.5f to listOf(0, 0, 0), +) + class BubbleLayoutTest { private val density = Density(1f) private val inset = with(density) { BUBBLE_TEXT_INSET.roundToPx() } @@ -138,14 +150,14 @@ class BubbleLayoutTest { } @Test - fun timeDrawnOnTextBaseline() { + fun timeOffsetFromTextBaseline() { val texts = listOf<@Composable () -> TextStyle>( { TextStyle(fontFamily = Inter, fontSize = 16.sp).merge(bubbleTextStyle(16.sp, HighOrLowlight)) }, { TextStyle(fontFamily = Inter, fontSize = 13.sp, lineHeight = 18.sp, lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None)).merge(bubbleLineHeight(18.sp)) }, { TextStyle(fontFamily = Inter, fontSize = 16.sp).merge(bubbleLineHeight(16.sp * INTER_LINE_HEIGHT)) }, ) - for (fontScale in listOf(0.7f, 0.8f, 0.9f, 1f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f)) { - texts.forEachIndexed { i, textStyle -> + val timeBelowText = TIME_BELOW_TEXT_PX.keys.associateWith { fontScale -> + texts.map { textStyle -> val image = renderScene { CompositionLocalProvider(LocalBubbleLayout provides true, LocalDensity provides Density(1f, fontScale)) { Row(Modifier.background(Color.White)) { @@ -159,9 +171,10 @@ class BubbleLayoutTest { } } } - assertEquals(lastInkRow(image, placed.getValue("text")), lastInkRow(image, placed.getValue("time")), "text $i at font scale $fontScale") + lastInkRow(image, placed.getValue("time")) - lastInkRow(image, placed.getValue("text")) } } + assertEquals(TIME_BELOW_TEXT_PX, timeBelowText) } private fun lastInkRow(image: Image, area: Placed): Int { diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/FallbackFontTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/FallbackFontTest.kt new file mode 100644 index 0000000000..6fe0fbbee8 --- /dev/null +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/FallbackFontTest.kt @@ -0,0 +1,87 @@ +package chat.simplex.app + +import org.jetbrains.skia.FontMgr +import org.jetbrains.skia.paragraph.FontCollection +import org.jetbrains.skia.paragraph.ParagraphBuilder +import org.jetbrains.skia.paragraph.ParagraphStyle +import org.jetbrains.skia.paragraph.TextStyle +import org.junit.Assume.assumeNoException +import org.junit.Assume.assumeTrue +import java.io.IOException +import java.nio.file.Files +import java.nio.file.Path +import java.util.concurrent.TimeUnit +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +private const val LAYOUT_WAIT_SECONDS = 60L + +private const val SNOWMAN_BDF = """STARTFONT 2.1 +FONT -misc-snowman-medium-r-normal--8-80-75-75-c-80-iso10646-1 +SIZE 8 75 75 +FONTBOUNDINGBOX 8 8 0 0 +STARTPROPERTIES 5 +FAMILY_NAME "Snowman" +FONT_ASCENT 8 +FONT_DESCENT 0 +CHARSET_REGISTRY "ISO10646" +CHARSET_ENCODING "1" +ENDPROPERTIES +CHARS 1 +STARTCHAR snowman +ENCODING 9731 +SWIDTH 1000 0 +DWIDTH 8 0 +BBX 8 8 0 0 +BITMAP +3C +42 +3C +42 +81 +81 +42 +3C +ENDCHAR +ENDFONT +""" + +class FallbackFontTest { + @Test + fun textIsLaidOutWhenTheOnlyFallbackFontIsBitmap() = withTempDir { dir -> + assumeTrue("fontconfig selects fallback fonts only on Linux", System.getProperty("os.name") == "Linux") + Files.createDirectory(dir.resolve("fonts")) + Files.writeString(dir.resolve("fonts/snowman.bdf"), SNOWMAN_BDF) + Files.writeString(dir.resolve("fonts.conf"), "$dir/fonts$dir/cache") + val fcCache = try { + startWithFonts(dir, "fc-cache").waitFor() + } catch (e: IOException) { + assumeNoException("fc-cache is not installed", e) + return@withTempDir + } + assumeTrue("fc-cache indexes the font, as it does for installed fonts", fcCache == 0) + val java = Path.of(System.getProperty("java.home"), "bin", "java").toString() + val layout = startWithFonts(dir, java, "-cp", System.getProperty("java.class.path"), LayOutSnowman::class.java.name) + val finished = layout.waitFor(LAYOUT_WAIT_SECONDS, TimeUnit.SECONDS) + if (!finished) layout.destroyForcibly() + assertTrue(finished, "layout must end within $LAYOUT_WAIT_SECONDS s") + assertEquals(0, layout.exitValue(), Files.readString(dir.resolve("output.log"))) + } + + private fun startWithFonts(dir: Path, vararg command: String): Process = + ProcessBuilder(*command) + .directory(dir.toFile()) + .redirectErrorStream(true) + .redirectOutput(dir.resolve("output.log").toFile()) + .apply { environment()["FONTCONFIG_FILE"] = dir.resolve("fonts.conf").toString() } + .start() +} + +object LayOutSnowman { + @JvmStatic + fun main(args: Array) { + val fonts = FontCollection().setDefaultFontManager(FontMgr.default) + ParagraphBuilder(ParagraphStyle(), fonts).pushStyle(TextStyle()).addText("☃").build().layout(100f) + } +} diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/MarkdownFileViewTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/MarkdownFileViewTest.kt new file mode 100644 index 0000000000..14bb297d90 --- /dev/null +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/MarkdownFileViewTest.kt @@ -0,0 +1,134 @@ +package chat.simplex.app + +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.key.Key +import androidx.compose.ui.platform.ClipEntry +import androidx.compose.ui.platform.Clipboard +import androidx.compose.ui.platform.ClipboardManager +import androidx.compose.ui.platform.LocalClipboard +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.platform.NativeClipboard +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.onRoot +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performKeyInput +import androidx.compose.ui.test.performMouseInput +import androidx.compose.ui.test.pressKey +import androidx.compose.ui.test.runComposeUiTest +import androidx.compose.ui.text.AnnotatedString +import chat.simplex.common.model.ChatController.appPrefs +import chat.simplex.common.simplexWindowState +import chat.simplex.common.views.chat.item.MarkdownFileCopyButton +import chat.simplex.common.views.chat.item.MarkdownFileView +import chat.simplex.common.views.chat.item.markdownDocument +import chat.simplex.common.views.helpers.AlertManager +import chat.simplex.common.views.helpers.LocalAppBarHandler +import chat.simplex.common.views.helpers.rememberAppBarHandler +import kotlinx.coroutines.runBlocking +import java.awt.datatransfer.DataFlavor +import java.awt.datatransfer.Transferable +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +@OptIn(ExperimentalTestApi::class) +class MarkdownFileViewTest { + @Test + fun copiedSelectionKeepsLineBreaks() = runComposeUiTest { + val textView = appPrefs.markdownFileTextView.get() + appPrefs.markdownFileTextView.set(true) + try { + val clipboard = RecordingClipboard() + val document = runBlocking { markdownDocument("alpha\n\ngamma".toByteArray()) } + setContent { + CompositionLocalProvider(LocalClipboard provides clipboard, LocalAppBarHandler provides rememberAppBarHandler()) { + MarkdownFileView("test.md", document) + } + } + val first = onNodeWithText("alpha").fetchSemanticsNode().boundsInRoot + val last = onNodeWithText("gamma").fetchSemanticsNode().boundsInRoot + onRoot().performMouseInput { + moveTo(Offset(first.left + 1f, first.center.y)) + press() + moveTo(Offset(last.right + 10f, last.center.y)) + release() + } + onRoot().performKeyInput { pressKey(Key.Copy) } + waitForIdle() + assertEquals("alpha\n\ngamma", clipboard.text) + } finally { + appPrefs.markdownFileTextView.set(textView) + } + } + + @Test + fun copyButtonWarnsAbove128KB() = runComposeUiTest { + var copied: String? = null + val clipboard = object : ClipboardManager { + override fun setText(annotatedString: AnnotatedString) { copied = annotatedString.text } + override fun getText(): AnnotatedString? = null + } + val document = runBlocking { markdownDocument("alpha\n\ngamma".toByteArray()) } + var fileSize by mutableStateOf(131_072) + try { + setContent { + CompositionLocalProvider(LocalClipboardManager provides clipboard) { + MarkdownFileCopyButton(document.text, fileSize, null) + } + AlertManager.shared.showInView() + } + onNodeWithContentDescription("Copy").performClick() + assertEquals("alpha\n\ngamma", copied) + copied = null + fileSize = 131_073 + onNodeWithContentDescription("Copy").performClick() + onNodeWithText("Your file is 128 KB. Do you want to copy it?").assertExists() + assertNull(copied) + onNodeWithText("Copy").performClick() + assertEquals("alpha\n\ngamma", copied) + } finally { + AlertManager.shared.hideAllAlerts() + simplexWindowState.toasts.clear() + } + } + + @Test + fun copyButtonRefusesAboveHardLimit() = runComposeUiTest { + var copied: String? = null + val clipboard = object : ClipboardManager { + override fun setText(annotatedString: AnnotatedString) { copied = annotatedString.text } + override fun getText(): AnnotatedString? = null + } + try { + setContent { + CompositionLocalProvider(LocalClipboardManager provides clipboard) { + MarkdownFileCopyButton("alpha", 524_289, 524_288) + } + AlertManager.shared.showInView() + } + onNodeWithContentDescription("Copy").performClick() + onNodeWithText("Only files up to 512 KB can be copied. Save the file to open it in another app.").assertExists() + assertNull(copied) + } finally { + AlertManager.shared.hideAllAlerts() + } + } +} + +private class RecordingClipboard : Clipboard { + var text: String? = null + + override suspend fun getClipEntry(): ClipEntry? = null + + override suspend fun setClipEntry(clipEntry: ClipEntry?) { + text = (clipEntry?.nativeClipEntry as Transferable).getTransferData(DataFlavor.stringFlavor) as String + } + + override val nativeClipboard: NativeClipboard get() = this +} diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt index 486a65495f..1467582a78 100644 --- a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt @@ -246,6 +246,18 @@ class NameAlertsTest { assertLocalChats("@3") } + @Test + fun groupLinkAsAddress() = recordedAlerts("connect/group-link-as-address") { + connect("GROUP_LINK") + assertTexts("Invalid connection link", "Please check that you used the correct link or ask your contact to send you another one.", "OK") + } + + @Test + fun groupLinkAsChannel() = recordedAlerts("connect/group-link-as-channel") { + connect("GROUP_LINK") + assertTexts("Invalid connection link", "Please check that you used the correct link or ask your contact to send you another one.", "OK") + } + @Test fun connectByNameRowShowsLocalChats() = recorded("names/plan-known") { val searchText = mutableStateOf(TextFieldValue("alice")) @@ -298,6 +310,23 @@ class NameAlertsTest { onNodeWithText("Connect to team.simplex").assertExists() } + @Test + fun rejectedContactInChatList() = recorded("connect/request-rejected") { + ChatModel.chatRunning.value = true + runBlocking { + val chats = ChatController.apiGetChats(null) + withContext(Dispatchers.Main) { ChatModel.chatsContext.updateChats(chats) } + } + setContent { + CompositionLocalProvider(LocalAppBarHandler provides rememberAppBarHandler()) { + ChatListView(ChatModel, MutableStateFlow(AnimatedViewState.GONE), {}, false) + } + } + assertEquals(listOf("@2"), chatIds()) + assertFalse((chatInfo("@2") as ChatInfo.Direct).contact.active) + waitUntil(timeoutMillis = 5_000) { onAllNodesWithText("alice").fetchSemanticsNodes().isNotEmpty() } + } + @Test fun verifiedNameIsCopied() = simplexName(DomainVerification.Verified) { verifications, copied -> onNodeWithText(SIMPLEX_NAME).performClick() diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/QRCodeTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/QRCodeTest.kt new file mode 100644 index 0000000000..d5d55abf97 --- /dev/null +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/QRCodeTest.kt @@ -0,0 +1,91 @@ +package chat.simplex.app + +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.test.ComposeUiTest +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.onAllNodesWithContentDescription +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.runComposeUiTest +import boofcv.alg.fiducial.qrcode.QrCode +import chat.simplex.common.model.* +import chat.simplex.common.views.chat.ChatInfoView +import chat.simplex.common.views.helpers.LocalAppBarHandler +import chat.simplex.common.views.helpers.rememberAppBarHandler +import chat.simplex.common.views.newchat.LocalFixedQRCode +import chat.simplex.common.views.newchat.SimpleXLinkQRCode +import chat.simplex.common.views.newchat.qrCodeBitmap +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext +import kotlin.test.AfterTest +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +@OptIn(ExperimentalTestApi::class) +class QRCodeTest { + private val link = "https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2FWHV0YU1sYlU7NqiEHkHDB6gxO1ofTync%23%2F%3Fv%3D1-2%26dh%3DMCowBQYDK2VuAyEAWbebOqVYuBXaiqHcXYjEHCpYi6VzDlu6CVaijDTmsQU%253D" + + @AfterTest + fun tearDown() { + ChatModel.chatsContext.chats.value.clear() + ChatModel.currentUser.value = null + } + + @Test + fun testQRCodeBitmapOfLinkWithinCapacity() { + assertNotNull(qrCodeBitmap(link, errorLevel = QrCode.ErrorLevel.L)) + assertNotNull(qrCodeBitmap(link, errorLevel = QrCode.ErrorLevel.M)) + } + + @Test + fun testNoQRCodeBitmapOfLinkAboveCapacity() { + assertNull(qrCodeBitmap("$link&data=${"a".repeat(3000)}", errorLevel = QrCode.ErrorLevel.L)) + assertNull(qrCodeBitmap("$link&data=${"a".repeat(2400)}", errorLevel = QrCode.ErrorLevel.M)) + } + + @Test + fun testContactInfoShowsQRCodeOfAddress() = contactInfo(link) { + onNodeWithText(ADDRESS_FOOTER).assertExists() + onAllNodesWithContentDescription("QR Code").assertCountEquals(1) + } + + @Test + fun testContactInfoWithoutQRCodeOfAddressAboveCapacity() = contactInfo("$link&data=${"a".repeat(3000)}") { + onNodeWithText(ADDRESS_FOOTER).assertExists() + onAllNodesWithContentDescription("QR Code").assertCountEquals(0) + } + + @Test + fun testNoShareOfQRCodeAboveCapacity() = runComposeUiTest { + var shared = false + setContent { + CompositionLocalProvider(LocalFixedQRCode provides qrCodeBitmap(link, errorLevel = QrCode.ErrorLevel.L)) { + SimpleXLinkQRCode("$link&data=${"a".repeat(3000)}", onShare = { shared = true }) + } + } + onNodeWithContentDescription("QR Code").performClick() + waitForIdle() + assertFalse(shared) + } + + private fun contactInfo(address: String, test: ComposeUiTest.() -> Unit) = runComposeUiTest { + val contact = Contact.sampleData.copy(profile = LocalProfile.sampleData.copy(contactLink = address)) + ChatModel.currentUser.value = User.sampleData + runBlocking { withContext(Dispatchers.Main) { ChatModel.chatsContext.updateChat(null, ChatInfo.Direct(contact)) } } + setContent { + CompositionLocalProvider(LocalAppBarHandler provides rememberAppBarHandler()) { + ChatInfoView(ChatModel.chatsContext, ChatModel, contact, connectionStats = null, customUserProfile = null, localAlias = "", connectionCode = null, close = {}, onSearchClicked = {}) + } + } + test() + } + + private companion object { + const val ADDRESS_FOOTER = "You can share this address with your contacts to let them connect with alice." + } +} diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/SnapshotTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/SnapshotTest.kt index 69c657e2a7..1d4f9c7167 100644 --- a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/SnapshotTest.kt +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/SnapshotTest.kt @@ -99,6 +99,7 @@ private val previewScenes = listOf( SnapshotScene("DeletedItemView.PreviewDeletedItemView", chatItemFontScales) { PreviewDeletedItemView() }, SnapshotScene("IntegrityErrorItemView.IntegrityErrorItemViewPreview", chatItemFontScales) { IntegrityErrorItemViewPreview() }, SnapshotScene("MarkedDeletedItemView.PreviewMarkedDeletedItemView", chatItemFontScales) { PreviewMarkedDeletedItemView() }, + SnapshotScene("MarkdownFileView.PreviewMarkdownFileView") { PreviewMarkdownFileView() }, SnapshotScene("ChatHelpView.PreviewChatHelpLayout") { PreviewChatHelpLayout() }, SnapshotScene("ChatListNavLinkView.PreviewChatListNavLinkDirect") { PreviewChatListNavLinkDirect() }, SnapshotScene("ChatListNavLinkView.PreviewChatListNavLinkGroup") { PreviewChatListNavLinkGroup() }, diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-dark-font-100.png index 640a28de88..9e1e059494 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-light-font-100.png index 170b8e11a8..0a75f34763 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/AdvancedNetworkSettings.PreviewAdvancedNetworkSettingsLayout-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-dark-font-100.png index 0cccd47882..9f0918f20c 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-light-font-100.png index 782526edef..acee637fff 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.ChannelMembers-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-dark-font-100.png index 5797220b1e..3b262f9a7b 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-light-font-100.png index 3f983eeaba..855fb404d2 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.LinksAndBadge-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-dark-font-100.png index 10c8e27d87..7cdfe819fe 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-light-font-100.png index f48af72dcf..76c4bc40e8 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Lists-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-dark-font-100.png index 5226a17673..bd05ce1604 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-light-font-100.png index 6cd1632db2..bec0d5cfbb 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/Avatars.Rows-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-100.png index 55b6e928f1..19edf5d656 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-140.png index 322ace5214..83ad9260f7 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-150.png index 9b17a7bf7b..6183feca57 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-dark-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-100.png index 3a21146054..8bd97969a6 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-140.png index d97ac2e0a9..2f1363e657 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-150.png index 19448a4865..effc9febb8 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewAcceptedPreview-light-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-100.png index 98cfac9216..8207de4f47 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-140.png index a8e184b564..35544988f5 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-150.png index 31b4ed222b..2b027ff5eb 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-dark-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-100.png index 97280f9eae..cc36255dc8 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-140.png index ece28fe4f4..1b5f956260 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-150.png index 07b013065c..2a60b4ab19 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.CIGroupInvitationViewLongNamePreview-light-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-100.png index bb8e0d4f8f..40293d1136 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-140.png index 9fb09d068a..b840ea5dc7 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-150.png index 1020e11edf..b2f2fbe4bf 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-dark-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-100.png index 435c97dab7..ae1a9f96b1 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-140.png index a64fb7459d..e87949718f 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-150.png b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-150.png index 53ac5462db..8d349bd3c4 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-150.png and b/apps/multiplatform/common/src/desktopTest/snapshots/CIGroupInvitationView.PendingCIGroupInvitationViewPreview-light-font-150.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-dark-font-100.png index 129bda0cf3..4274b13b3c 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-light-font-100.png index dd1e84e4d7..634db4fae8 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatHelpView.PreviewChatHelpLayout-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewDeletedContent-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewDeletedContent-light-font-140.png index 9fe901eb6f..fe2c30f84a 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewDeletedContent-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewDeletedContent-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewEmptyLinesTerminal-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewEmptyLinesTerminal-dark-font-140.png index c7d94f2d21..5576247ddf 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewEmptyLinesTerminal-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatItemView.PreviewChatItemViewEmptyLinesTerminal-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminal-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminal-dark-font-140.png index 44c7654057..0dd50bfbfd 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminal-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminal-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalDefects-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalDefects-dark-font-140.png index bb1e2398e1..2dca985233 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalDefects-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalDefects-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-dark-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-dark-font-140.png index 2c1367c02c..93a678c18c 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-dark-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-dark-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-light-font-140.png index 49e87ea4ee..4e4e461faa 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ChatView.PreviewGroupChatLayoutTerminalMedia-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-dark-font-100.png index 1010afd3e8..74d86f3907 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-light-font-100.png index a33e3e4d7f..bc56c81aec 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/ContactConnectionInfoView.PreviewContactConnectionInfoView-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-dark-font-100.png index 9ef4fc95c3..8f3d11d2c5 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-light-font-100.png index 6d7bb7e0df..91f623b083 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/DatabaseView.PreviewDatabaseLayout-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/DeletedItemView.PreviewDeletedItemView-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/DeletedItemView.PreviewDeletedItemView-light-font-140.png index 9fe901eb6f..fe2c30f84a 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/DeletedItemView.PreviewDeletedItemView-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/DeletedItemView.PreviewDeletedItemView-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-dark-font-100.png index dcbece6adf..5e6c5220bc 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-light-font-100.png index 8cdbb18516..f01f90e282 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/HelpView.PreviewHelpView-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/IntegrityErrorItemView.IntegrityErrorItemViewPreview-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/IntegrityErrorItemView.IntegrityErrorItemViewPreview-light-font-140.png index 8011430f76..aec1e9ef5e 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/IntegrityErrorItemView.IntegrityErrorItemViewPreview-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/IntegrityErrorItemView.IntegrityErrorItemViewPreview-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-dark-font-100.png new file mode 100644 index 0000000000..1e04eb43d5 Binary files /dev/null and b/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-light-font-100.png new file mode 100644 index 0000000000..37b173d0e9 Binary files /dev/null and b/apps/multiplatform/common/src/desktopTest/snapshots/MarkdownFileView.PreviewMarkdownFileView-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/MarkedDeletedItemView.PreviewMarkedDeletedItemView-light-font-140.png b/apps/multiplatform/common/src/desktopTest/snapshots/MarkedDeletedItemView.PreviewMarkedDeletedItemView-light-font-140.png index 5c28f00714..43dad75978 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/MarkedDeletedItemView.PreviewMarkedDeletedItemView-light-font-140.png and b/apps/multiplatform/common/src/desktopTest/snapshots/MarkedDeletedItemView.PreviewMarkedDeletedItemView-light-font-140.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-dark-font-100.png index 061529ebe4..703eb6f140 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-light-font-100.png index bd48d856f0..588909d91f 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/NetworkAndServers.PreviewNetworkAndServersLayout-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-dark-font-100.png index c503ffc6b6..1119398902 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-light-font-100.png index 18e8704055..756c9f42ec 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SetNotificationsMode.PreviewSetNotificationsMode-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-dark-font-100.png index 92d0d71805..569808b38b 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-light-font-100.png index 6f2dd35320..861218f6d7 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SettingsView.PreviewSettingsLayout-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-dark-font-100.png index 5f8892e866..2ca1ff22e9 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-light-font-100.png index c881f5a126..79aee6e5e6 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/SimpleXInfo.PreviewSimpleXInfo-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-dark-font-100.png index e918b87318..22189164dc 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-light-font-100.png index 2c4fb48774..3c142ce965 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutAddressCreated-light-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-dark-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-dark-font-100.png index 866b63bea7..1ec99c3ca4 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-dark-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-dark-font-100.png differ diff --git a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-light-font-100.png b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-light-font-100.png index fb363f3c4a..6dc12e07c0 100644 Binary files a/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-light-font-100.png and b/apps/multiplatform/common/src/desktopTest/snapshots/UserAddressView.PreviewUserAddressLayoutNoAddress-light-font-100.png differ diff --git a/apps/multiplatform/spec/client/chat-view.md b/apps/multiplatform/spec/client/chat-view.md index 2f74d41332..e83ec25aa1 100644 --- a/apps/multiplatform/spec/client/chat-view.md +++ b/apps/multiplatform/spec/client/chat-view.md @@ -215,7 +215,7 @@ In chats with avatars the item is in the message column, after the avatar column When `LocalBubbleLayout.current` is true (classic chats, provided by `ChatView` with `LocalTerminalLayout`, the classic theme preview, and the chat item and chat view previews through [`BubblePreview`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt#L1506-L1509)), bubbles follow one inset (plans/2026-10-25-classic-bubbles.md). The previews of deleted and error items clip them as `ChatItemView` does (`clipChatItem`). - Texts use `chatTextStyle`, as terminal rows: message text, captions, Markdown blocks, quote text and sender (`body1`, Inter), headers, the time, event texts; the texts of `DeletedItemView` and error items through [`bubbleTextStyle(fontSize, color)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L91-L93), `chatTextStyle` in bubbles only, so the cards of terminal rows keep their style (the one-line text of `MarkedDeletedItemView` keeps its style, its line height rounded by `bubbleLineHeight`). Call items are drawn as in master: `ChatItemView` provides `LocalBubbleLayout` false for them. Markdown blocks in bubbles have the heading gaps, heading sizes and `headingBox` of terminal rows; cards and rules have `TERMINAL_BLOCK_TOP_GAP` (5.75sp) above and `TERMINAL_BLOCK_BOTTOM_GAP` (5sp) below, and each empty line typed is one line of the text style. -- On desktop, [`bubbleLineHeight(lineHeight)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L95-L101) rounds a line height in bubbles to whole pixels, with the proportional alignment of `chatTextStyle`: `chatTextStyle` applies it in bubbles, and so do the last text of a group invitation (18sp, or "Tap to join" at the line height of Inter, `INTER_LINE_HEIGHT`), "Fix connection" of decryption errors and the size line of files (the line height of Inter) and the text of `MarkedDeletedItemView` (22sp); on Android the line heights are unchanged. Skia draws the baseline of a line at its top plus the rounded ascent and reports the rounded line height less the descent, which Compose rounds into `FirstBaseline` and `LastBaseline`; both are one pixel row only when ascent and descent add up to whole pixels, so the time, placed by reported baselines, is drawn on the baseline of the text (owner report). +- On desktop, [`bubbleLineHeight(lineHeight)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L95-L101) rounds a line height in bubbles to whole pixels, with the proportional alignment of `chatTextStyle`: `chatTextStyle` applies it in bubbles, and so do the last text of a group invitation (18sp, or "Tap to join" at the line height of Inter, `INTER_LINE_HEIGHT`), "Fix connection" of decryption errors and the size line of files (the line height of Inter) and the text of `MarkedDeletedItemView` (22sp); on Android the line heights are unchanged. Skia draws the baseline of a line at its top plus the rounded ascent and reports the rounded line height less the descent, which Compose rounds into `FirstBaseline` and `LastBaseline`; both are one pixel row only when ascent and descent add up to whole pixels, so the time, placed by reported baselines, is drawn on the baseline of the text (owner report); with Skia m138 it is drawn 1 px from it at some font scales (`BubbleLayoutTest.timeOffsetFromTextBaseline`). - `BUBBLE_TEXT_INSET` (11dp, user) is the distance from a bubble or band edge to the capitals of the text under it, and from the last baseline to the edge under it; in dp, so it keeps its size at larger fonts (user). Message text, captions and an emoji under a quote or header have [`bubbleTextBoxPadding()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt#L575-L582): that inset less the space of 16sp text with the full line height above its capitals (`BUBBLE_LINE_ABOVE_CAPS`, 6sp) and under its last baseline (`BUBBLE_LINE_BELOW_BASELINE`, 4.375sp), at least 0; 5dp and 6.625dp at font scale 1. `BUBBLE_SIDE_INSET` (14dp, user) is the distance from the bubble sides to message text, captions, an emoji under a quote or header and the end of the time. Header bands, the quote band and deleted and error items use [`Modifier.bubbleTextPadding(firstLineFontSize, bottom)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt#L571-L573): `BUBBLE_SIDE_INSET` at the sides and the inset by the first and last baselines; a header followed by a quote or a forwarded header has no inset below. The header starts at `BUBBLE_SIDE_INSET` and its icon takes no height. Deleted and error items are drawn by [`ItemTextCard`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/DeletedItemView.kt#L33-L52) (`DeletedItemView`, `MarkedDeletedItemView`, `CIMsgError`) and the private `DecryptionErrorCard` (the decryption error items), each with one switch between the bubble and the rounded card of terminal rows: in bubbles they fill the shape of `clipChatItem` (`Surface` with its default `RectangleShape`, user). That shape has no tail for items without message content ([`shapeStyleWithTail`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt#L1334-L1386): `msgContent` null; user): deleted, moderated, blocked, error, decryption error and invalid JSON items. [`chatItemTailRendered(chatItem, tailVisible, revealed)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt#L1222-L1224) tells whether the tail is drawn, from the shape style of the item as `clipChatItem` computes it; `FramedItemView`, `chatItemOffset` and the sender rows of `ChatItemsList` use it. The file row ends `BUBBLE_TEXT_INSET` under the baseline of its size line; the ink bottom of the file icon is aligned to that baseline ([`fileIconOnBaseline`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIFileView.kt#L258-L262): the icon size × `FILE_ICON_INK_INSET`, the space under the ink of `ic_draft_filled`, rounded down). - The time: [`Modifier.bubbleMeta()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt#L584-L588) places the baseline of the time `BUBBLE_TEXT_INSET` above the bubble bottom, on the last baseline of the text; ticks without a time where they stand next to a time (`metaBaseline`, shared with `TerminalMetaLayout`). In deleted and error items the time follows the text on its last baseline (`bubbleMetaOnBaseline`, the text aligned by `LastBaseline`), so a wrapped text keeps the time on its last line; in group invitations [`MetaOnLastBaseline(meta, content)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt#L596-L608) places it at the end of the card on its last baseline (the card bottom without a baseline, in intrinsic measurement; user). Message text, an emoji under a quote or header, decryption errors and group invitations end with `metaReserveCopy`; after text it starts with a breaking space (`breakBefore`), so the time alone moves to the next line, except in group invitations, where the word joiner keeps the time with the last word (user); the size line of a file keeps the string of `reserveSpaceForMeta`. - Gaps between rows: `BUBBLE_CLOSE_GAP` (2sp) between close messages, `BUBBLE_FAR_GAP` (8sp) at a large gap, half above and half below each row. Event rows (`isEvent`: items without a sender, `hasTerminalSender` false, other than the chat banner: event, feature, preference and end-to-end encryption items, also collapsed) form runs (user): `eventRunLargeGap` makes the gap between two events close and the gap between an event and another row large; `ChatItemsList` applies it to the gap above a row (`eventGapAbove`) and to the separation below it (`eventGapBelow`, a large gap with the time), so a message above an event shows its tail and time. The avatar column of an event has no 8dp top padding. diff --git a/apps/simplex-broadcast-bot/Main.hs b/apps/simplex-broadcast-bot/Main.hs index 3130437e0f..8c0f60b6f6 100644 --- a/apps/simplex-broadcast-bot/Main.hs +++ b/apps/simplex-broadcast-bot/Main.hs @@ -2,10 +2,13 @@ module Main where import Broadcast.Bot import Broadcast.Options +import Control.Concurrent.Async +import Control.Monad import Simplex.Chat.Core import Simplex.Chat.Terminal (terminalChatConfig) main :: IO () main = do opts <- welcomeGetOpts - simplexChatCore terminalChatConfig (mkChatOpts opts) $ broadcastBot opts + simplexChatCore terminalChatConfig (mkChatOpts opts) $ \user cc -> + race_ (forever $ void getLine) $ broadcastBot opts user cc diff --git a/apps/simplex-broadcast-bot/src/Broadcast/Bot.hs b/apps/simplex-broadcast-bot/src/Broadcast/Bot.hs index 86f89f86e8..16b9097eee 100644 --- a/apps/simplex-broadcast-bot/src/Broadcast/Bot.hs +++ b/apps/simplex-broadcast-bot/src/Broadcast/Bot.hs @@ -8,7 +8,6 @@ module Broadcast.Bot where import Control.Concurrent (forkIO) -import Control.Concurrent.Async import Control.Concurrent.STM import Control.Monad import qualified Data.Text as T @@ -36,7 +35,7 @@ welcomeGetOpts = do broadcastBot :: BroadcastBotOpts -> User -> ChatController -> IO () broadcastBot BroadcastBotOpts {publishers, welcomeMessage, prohibitedMessage} _user cc = do initializeBotAddress cc - race_ (forever $ void getLine) . forever $ do + forever $ do (_, evt) <- atomically . readTBQueue $ outputQ cc case evt of Right (CEvtContactConnected _ ct _) -> do diff --git a/apps/simplex-directory-service/src/Directory/Service.hs b/apps/simplex-directory-service/src/Directory/Service.hs index f43f22b503..09afd6b43a 100644 --- a/apps/simplex-directory-service/src/Directory/Service.hs +++ b/apps/simplex-directory-service/src/Directory/Service.hs @@ -77,7 +77,7 @@ import Simplex.Messaging.Protocol (ErrorType (..)) import Simplex.Messaging.SimplexName (SimplexNameInfo (..), SimplexNameType (..), shortNameInfoStr) import Simplex.Messaging.TMap (TMap) import qualified Simplex.Messaging.TMap as TM -import Simplex.Messaging.Util (eitherToMaybe, raceAny_, safeDecodeUtf8, tshow, unlessM, (<$$>)) +import Simplex.Messaging.Util (catchOwn', eitherToMaybe, raceAny_, safeDecodeUtf8, tshow, unlessM, (<$$>)) import System.Directory (getAppUserDataDirectory, removeFile) import System.Exit (exitFailure) import System.Process (readProcess) @@ -341,7 +341,7 @@ directoryServiceEvent opts@DirectoryOpts {adminUsers, superUsers, serviceName, o SDRUser -> deUserCommand ct ciId cmd SDRAdmin -> deAdminCommand ct ciId cmd SDRSuperUser -> deSuperUserCommand ct ciId cmd - DEVoiceUploadEnded filePath -> void (try $ removeFile filePath :: IO (Either SomeException ())) + DEVoiceUploadEnded filePath -> removeFile filePath `catchOwn'` \_ -> pure () DELogChatResponse r -> logInfo r where groupLinkText (CCLink cReq sLnk_) = maybe (strEncodeTxt $ simplexChatContact cReq) strEncodeTxt sLnk_ diff --git a/apps/simplex-store-service/src/StoreService/Names/Chain.hs b/apps/simplex-store-service/src/StoreService/Names/Chain.hs index 98c2d37c38..118c5d9cee 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Chain.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Chain.hs @@ -63,8 +63,9 @@ import Network.HTTP.Types (hContentType, methodPost, statusCode, statusIsSuccess import Numeric (readHex, showHex) import Simplex.Messaging.Crypto (keccak256) import Simplex.Messaging.Crypto.Secp256k1 (RecoverableSignature (..)) +import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Eth.Address (Address, addressFromPrivateKey, recoverAddress) -import Simplex.Messaging.Eth.RLP (RLPItem (..), rlpEncode) +import Simplex.Messaging.Eth.RLP (RLPItem (..)) import Simplex.Messaging.Eth.Transaction (Eip1559Tx (..), signEip1559Tx) import Simplex.Messaging.Util (tshow) import StoreService.Config (ChainConfig (..)) @@ -255,7 +256,7 @@ transactionSigner raw = case signedTxItems raw of Right (fields@(chainIdItem : _), (RLPBytes yParity, RLPBytes r, RLPBytes s)) | B.length yParity <= 1, Right chainId <- scalar chainIdItem -> - fmap (chainId,) <$> recoverAddress RecoverableSignature {rsR = scalarBytes r, rsS = scalarBytes s, rsRecId = fromInteger $ os2ip yParity} (keccak256 $ B.cons eip1559TxType $ rlpEncode $ RLPList fields) + fmap (chainId,) <$> recoverAddress RecoverableSignature {rsR = scalarBytes r, rsS = scalarBytes s, rsRecId = fromInteger $ os2ip yParity} (keccak256 $ B.cons eip1559TxType $ smpEncode $ RLPList fields) Right _ -> pure $ Left "transaction: not a chain id and signature" Left e -> pure $ Left e where diff --git a/apps/simplex-store-service/src/StoreService/Names/Records.hs b/apps/simplex-store-service/src/StoreService/Names/Records.hs index 05570d29fc..0bc0aaa736 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Records.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Records.hs @@ -40,8 +40,9 @@ import Data.Word (Word64) import Simplex.Messaging.Agent.Store.Common (DBStore, withTransaction) import qualified Simplex.Messaging.Agent.Store.DB as DB import Simplex.Messaging.Crypto (sha256Hash) +import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Eth.Address (Address, recoverAddress) -import Simplex.Messaging.Eth.EIP712 (Eip712Domain, serializeSignature) +import Simplex.Messaging.Eth.EIP712 (Eip712Domain) import Simplex.Messaging.SimplexName (LabelHash, SimplexTLD) import Simplex.Messaging.Util (tshow) import StoreService.Config (ChainConfig (..)) @@ -168,7 +169,7 @@ relayEdit rs@Records {rsPendingAfter, rsEditsPerYear, rsNow} req@EditRequest {er where signed = L.map (\change -> (changeDigest rs erLabelHash change, change)) erChanges -- one change hashes as edits stored before requests took two, so their repeats still match - bodyHash = sha256Hash $ B.concat [digest <> serializeSignature scSignature | (digest, SignedChange {scSignature}) <- L.toList signed] + bodyHash = sha256Hash $ B.concat [digest <> smpEncode scSignature | (digest, SignedChange {scSignature}) <- L.toList signed] newEdit :: Records -> TVar Bool -> EditRequest -> Address -> ByteString -> IO EditAnswer newEdit rs timer req signer bodyHash = diff --git a/apps/simplex-store-service/src/StoreService/Names/Registration.hs b/apps/simplex-store-service/src/StoreService/Names/Registration.hs index 5bde1c31f4..b4eefef182 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Registration.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Registration.hs @@ -43,9 +43,10 @@ import Data.Text.Encoding (encodeUtf8) import Data.Word (Word64) import Simplex.Messaging.Crypto (keccak256) import Simplex.Messaging.Crypto.Secp256k1 (RecoverableSignature) +import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String (strEncode) import Simplex.Messaging.Eth.Address (Address, recoverAddress) -import Simplex.Messaging.Eth.EIP712 (Eip712Domain (..), Eip712Value (..), hashTypedData, serializeSignature) +import Simplex.Messaging.Eth.EIP712 (Eip712Domain (..), Eip712Value (..), hashTypedData) import Simplex.Messaging.SimplexName (LabelHash (..), SimplexTLD) import StoreService.Names.Abi (AbiValue (..), abiArray, abiBytes, abiTuple, addressWord, selector, uint256) @@ -123,7 +124,7 @@ registerWithCreditCalldata RegisterIntent {riRegistration, riNonce, riDeadline, [ Dynamic $ registrationTuple riRegistration, Static $ uint256 riNonce, Static $ uint256 riDeadline, - Dynamic $ abiBytes $ serializeSignature riSignature + Dynamic $ abiBytes $ smpEncode riSignature ] registerIntentDigest :: Eip712Domain -> Registration -> Word64 -> Word64 -> ByteString @@ -168,7 +169,7 @@ acceptCalldata TermsKind {tkRelayFunction} commitment owner deadline TermsAccept Static $ addressWord owner, Static $ uint256 taNonce, Static $ uint256 deadline, - Dynamic $ abiBytes $ serializeSignature taSignature + Dynamic $ abiBytes $ smpEncode taSignature ] setTextDigest :: Eip712Domain -> Node -> Text -> Text -> Word64 -> Word64 -> ByteString @@ -194,13 +195,13 @@ setTextWithSigCalldata (Node node) key value nonce deadline sig = Dynamic $ abiBytes $ encodeUtf8 value, Static $ uint256 nonce, Static $ uint256 deadline, - Dynamic $ abiBytes $ serializeSignature sig + Dynamic $ abiBytes $ smpEncode sig ] clearRecordsWithSigCalldata :: Node -> Word64 -> Word64 -> RecoverableSignature -> ByteString clearRecordsWithSigCalldata (Node node) nonce deadline sig = selector "clearRecordsWithSig(bytes32,uint256,uint256,bytes)" - <> abiTuple [Static node, Static $ uint256 nonce, Static $ uint256 deadline, Dynamic $ abiBytes $ serializeSignature sig] + <> abiTuple [Static node, Static $ uint256 nonce, Static $ uint256 deadline, Dynamic $ abiBytes $ smpEncode sig] -- | The resolver runs each call on itself in order, and reverts all of them when one fails. multicallCalldata :: [ByteString] -> ByteString diff --git a/apps/simplex-store-service/src/StoreService/Names/Store.hs b/apps/simplex-store-service/src/StoreService/Names/Store.hs index 6508e4e5fa..f321d2c5b7 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Store.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Store.hs @@ -128,7 +128,6 @@ import Simplex.Messaging.Crypto (sha256Hash) import Simplex.Messaging.Crypto.Secp256k1 (RecoverableSignature) import Simplex.Messaging.Encoding.String (TextEncoding (..)) import Simplex.Messaging.Eth.Address (Address, unAddress) -import Simplex.Messaging.Eth.EIP712 (serializeSignature) import Simplex.Messaging.SimplexName (LabelHash (..)) import Simplex.Messaging.Util (maybeFirstRow, tshow) import StoreService.Names.Abi (addressFromBytes, hex) @@ -791,8 +790,8 @@ updateRegistration db r now = do ))) |] ( (Binary lh, nrLength, int64 nrDuration, Binary nrCommitment, nrSealed, nrAgreedTerms, nrPhase, nrPrice) - :. (rvLabel <$> nrReveal, Binary . rvSecret <$> nrReveal, rvContactLink =<< nrReveal, rvChannelLink =<< nrReveal, int64 . rvNonce <$> nrReveal, int64 . rvDeadline <$> nrReveal, Binary . serializeSignature . rvSignature <$> nrReveal) - :. (Binary . taTermsHash <$> acceptance, int64 . taNonce <$> acceptance, Binary . serializeSignature . taSignature <$> acceptance) + :. (rvLabel <$> nrReveal, Binary . rvSecret <$> nrReveal, rvContactLink =<< nrReveal, rvChannelLink =<< nrReveal, int64 . rvNonce <$> nrReveal, int64 . rvDeadline <$> nrReveal, rvSignature <$> nrReveal) + :. (Binary . taTermsHash <$> acceptance, int64 . taNonce <$> acceptance, taSignature <$> acceptance) :. (txHashField <$> nrCommitTx, int64 <$> nrCommitBlock, txHashField <$> nrRegisterTx, int64 <$> nrRegisterBlock, int64 <$> nrRevealAfter, int64 <$> nrRevealBefore, int64 <$> nrExpiresAt) :. (truncateToSecond <$> nrRegisteredAt, truncateToSecond <$> nrFailedAt, nrError, BI live, nrMoves, truncateToSecond <$> nrLinksRefusedAt, truncateToSecond now) :. (rid, nrVersion, BI live, rid, Binary nrCommitment, Binary $ unAddress nrOwner, Binary lh) @@ -1479,7 +1478,7 @@ insertRecordEdit db NewRecordEdit {nreLabelHash = LabelHash lh, nreOwner, nreCha DB.execute db "INSERT INTO sx_badge_service_name_record_changes (name_record_edit_id, nonce, record_key, record_value, deadline, signature) VALUES (?,?,?,?,?,?)" - (editId, int64 scNonce, key, value, int64 scDeadline, Binary $ serializeSignature scSignature) + (editId, int64 scNonce, key, value, int64 scDeadline, scSignature) where (key, value) = case scChange of RCSetText k v -> (Just k, Just v) diff --git a/cabal.project b/cabal.project index 0c407f85e9..7c7fe8ac23 100644 --- a/cabal.project +++ b/cabal.project @@ -21,7 +21,7 @@ constraints: zip +disable-bzip2 +disable-zstd source-repository-package type: git location: https://github.com/simplex-chat/simplexmq.git - tag: dc118d3bcc7512398e55a1c7d7dbf87458ba0a61 + tag: d38bcf50131d59f027d170731e4ea22031650611 source-repository-package type: git @@ -36,7 +36,7 @@ source-repository-package source-repository-package type: git location: https://github.com/simplex-chat/sqlcipher-simple.git - tag: a46bd361a19376c5211f1058908fc0ae6bf42446 + tag: 6bf2796de625dca678c70e98560010c6ec7ed635 source-repository-package type: git diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 4207e62743..f20d04bdb8 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -21,6 +21,8 @@ Please discuss the problem you want to solve and your detailed implementation pl ./contributing/CODE.md has details about general requirements common for `simplexmq` and `simplex-chat` repositories. +./contributing/TESTS.md has the testing approaches of this repository: the tests required for a change, how they are written and run, and where CI runs them. + CLAUDE.md in the repository root imports these files, this guide and ../scripts/ci/README.md for Claude Code; apps/ios/CLAUDE.md and apps/multiplatform/CLAUDE.md import the README of each app. ## Compiling with SQLCipher encryption enabled @@ -87,12 +89,14 @@ For some complex features we create feature branches that will be merged once re ## Pull requests and CI -1. Open a pull request to `master` as a draft. On a draft, CI runs the reduced build: one Linux job that builds and tests the changed scopes, and one macOS job only when iOS code changed (CI guide: scripts/ci/README.md). +1. Open a pull request to `master` as a draft. On a draft, CI runs the reduced build: one Linux job that builds and tests the changed scopes, one Linux job that runs the core tests on PostgreSQL when core code changed, and one macOS job only when iOS code changed (CI guide: scripts/ci/README.md). 2. Select the core tests in a `ci-tests` block in the description, one hspec match pattern per line. `/` runs all tests; without a block, the reduced build runs no core tests. 3. Push further changes to the same branch; on a draft, each push runs the reduced build. 4. Mark the pull request ready for review once it is ready. CI then runs the full matrix on each push, and the code owners are requested for review. 5. Mark it as a draft again when more work is needed. After the approval, the pull request is merged by squash once CI passes. 6. A change to a scope without CI tests adds its build and tests to CI in the same pull request. +7. A change of the apps' code adds, in the same pull request, app tests of all its changes on the core's real responses: core tests record the responses and events in tests/fixtures/api, and the Kotlin and iOS tests run the app code on them, with any platform service the code calls mocked (CI guide: "App test fixtures"). +8. Files that tests generate (schema dumps, query plans, API docs) are committed as CI generates them: when a test changes one, the step "Check generated files" fails, and the run's artifact `generated-files-` holds the change as a patch. ## Differences between GHC 8.10.7 and GHC 9.6.3 diff --git a/docs/NAMES-CONDITIONS.md b/docs/NAMES-CONDITIONS.md index ad244fe752..7c5700eb4e 100644 --- a/docs/NAMES-CONDITIONS.md +++ b/docs/NAMES-CONDITIONS.md @@ -4,7 +4,7 @@ You accept these Conditions of Use of SimpleX Names ("Names Conditions") by regi **SimpleX names**. A name is a record controlled by your key. The record can contain links to addresses in the SimpleX Network. "Community names" are marked in the registry as referring to specific communities, usually cities or territories. -**Registry**. The .simplex names registry is a set of contracts on the Ethereum blockchain. Name registrations, records, subnames and controlling addresses are stored in immutable contracts. Other contracts may be updated during a stabilization period, expected to last 12 to 24 months from the first registration. +**Registry**. The .simplex names registry is a set of contracts on the Ethereum blockchain. The contracts may be updated during a stabilization period, expected to last 12 to 24 months from the first registration. **What the registry allows**. diff --git a/docs/contributing/TESTS.md b/docs/contributing/TESTS.md new file mode 100644 index 0000000000..acf9854076 --- /dev/null +++ b/docs/contributing/TESTS.md @@ -0,0 +1,301 @@ +# Testing + +The testing approaches of this repository: what is checked, how a test is written and run, and where CI runs it. The CI scopes, the reduced build and the `ci-tests` block of a pull request: [CI on GitHub's runners](../../scripts/ci/README.md). + +## Tests for a change + +| Change | Tests | +|---|---| +| Behaviour of the chat core: messages, groups, files, profiles, connections | [chat scenario test](#chat-scenario-tests) | +| Encoding of a protocol message or a JSON type, markdown, a pure function of the core | [unit test](#unit-tests) | +| Command, response, event or type of the core API | [Bot API docs](#checks-against-committed-files), regenerated
[app fixture](#app-fixtures), when an app processes it | +| Database migration | [schema dumps](#checks-against-committed-files) of SQLite and PostgreSQL
query plans | +| Directory service, store service, remote sessions | the [suite](#suites) of the area | +| App processing of a core response or event | [app fixture](#app-fixtures), replayed in Kotlin and iOS tests | +| App screen | a preview, rendered by the [desktop](#desktop-snapshots) and [iOS](#simplex-snapshots) snapshot tests | +| Flow across app screens | a case of an [app workflow](#app-workflows) | +| Kotlin or Swift code without views | [desktopTest or commonTest](#kotlin-apps)
[SimpleX Unit Tests](#simplex-unit-tests) | +| Package, bot, website or CI script | the tests of its [scope](#packages-and-other-scopes) | +| Scope lacking CI tests | its CI coverage, in the same pull request ([Adding CI coverage](../../scripts/ci/README.md#adding-ci-coverage)) | + +## Core + +The hspec suite `simplex-chat-test` of simplex-chat.cabal, with the entry point [tests/Test.hs](../../tests/Test.hs). Building it, running it and selecting tests by hspec match patterns: [CI guide, core](../../scripts/ci/README.md#core). A pattern is a path of `describe` and `it` names, for example `/SimpleX chat client/direct tests/`. + +- A new test module is added to `other-modules` of the test suite in simplex-chat.cabal, and its spec to `main` of Test.hs. +- `tests/tmp` contains a directory per test (`tmpBracket` in Test.hs) and is emptied at the start and the end of a run (`withTmpFiles` in ChatClient.hs). +- With `CI=true`, set on GitHub's runners, the tests marked `xdescribe''` and `xit''` are skipped, and on macOS those marked `xitMacCI` ([ChatTests/Utils.hs](../../tests/ChatTests/Utils.hs)); the tests marked `xit'` are skipped on Linux. +- [tests/fixtures](../../tests/fixtures): images and files sent in the tests, TLS credentials of the test servers, and the [app fixtures](#app-fixtures) in `api`. +- In the full matrix of build.yml, the whole suite runs on Linux x86_64, with GHC 9.6.3 and 8.10.7, and on macOS aarch64; on a draft pull request, the tests matched by its `ci-tests` block run. +- Coverage: `-fhpc` added to `ghc-options` of the test suite in simplex-chat.cabal. + +### Suites + +| Pattern | Module | Checked | +|---|---|---| +| `/SimpleX chat client/` | [ChatTests.hs](../../tests/ChatTests.hs) | [chat scenarios](#chat-scenario-tests): direct, forward, group, chat relay, local, file, profile and chat list tests | +| `/names tests/` | ChatTests/Names.hs | SimpleX names, resolved by a local resolver ([NameResolver.hs](../../tests/NameResolver.hs)); SQLite only | +| `/SimpleX chat protocol/` | ProtocolTests.hs | chat protocol messages, short link data, batch limits, preferences JSON | +| `/JSON Tests/` | JSONTests.hs, JSONFixtures.hs | conversion of the Swift JSON form to the tagged form, with QuickCheck; JSON of markdown | +| `/SimpleX chat markdown/` | MarkdownTests.hs | the markdown parser | +| `/SimpleX chat view/` | ViewTests.hs | functions of the CLI view | +| `/Mobile API Tests/` | MobileTests.hs | the API of the core library (src/Simplex/Chat/Mobile.hs) and its C functions; SQLite only | +| `/Message batching/` | MessageBatching.hs | batches of messages and of relay deliveries | +| `/Valid names/` | ValidNames.hs | display names made valid | +| `/Random servers/` | RandomServers.hs | the random choice of preset servers | +| `/Operators/` | OperatorTests.hs | server operators, usage conditions, validation of user servers | +| `/Member relations/` | MemberRelationsTests.hs | member relation vectors | +| `/Image resize/` | ImageTests.hs | image resizing | +| `/Supporter badges/` | BadgeTests.hs | badge credentials and proofs | +| `/WebRTC encryption/` | WebRTCTests.hs | encryption of call media frames; SQLite only | +| `/Remote session/` | RemoteTests.hs | a desktop controlling a mobile: handshake, messages, files | +| `/SimpleX Directory service bot/`
`/SimpleX Directory names/` | Bots/DirectoryTests.hs | the directory service with chat clients (`withDirectoryService`); names: SQLite only | +| `/SimpleX Broadcast bot/` | Bots/BroadcastTests.hs | the broadcast bot; skipped when `CI=true` | +| `/SimpleX store service/` | Bots/StoreService/*Tests.hs | configuration, web server and schema, catalog, groups, invoice waiters, payment providers, store receipts; the providers are local fakes (`Fake*.hs`) | +| `/SimpleX store service e2e/` | Bots/StoreService/BotTests.hs, GroupIntegrationTests.hs | the store service bot with chat clients | +| `/Schema dump/`
`/Postgres schema dump/`
`/Bot API docs/`
`/Save query plans/` | SchemaDump.hs, PostgresSchemaDump.hs, APIDocs.hs | [committed files](#checks-against-committed-files) | + +### Chat scenario tests + +- Checked: chat cores of several clients connected through a test SMP server, by the terminal output of each client, and by queries of a client's database for a state absent from the output. +- Pattern, registered with `it "" testDirectMessage` in the spec of its module: + + ```haskell + testDirectMessage :: HasCallStack => TestParams -> IO () + testDirectMessage = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + alice #> "@bob hello" + bob <# "alice> hello" + ``` + +- Helpers of [ChatClient.hs](../../tests/ChatClient.hs) and [ChatTests/Utils.hs](../../tests/ChatTests/Utils.hs): + + | Helper | Use | + |---|---| + | `testChat2` … `testChat5`, `testChatCfgOpts2` | clients with new databases | + | `withNewTestChat`, `withTestChat` | one client with a new database; a restart with its database | + | `withNewTestChatCfgOpts` | a client with a `ChatConfig` and `ChatOpts`, such as `chatHooks` or `markRead = False` | + | `connectUsers`, `createGroup2`, `createGroup3` | a contact; a group of 2 or 3 members | + | `##>`, `#>`, `send` | a command and its echo; a message and its sent item, time removed; a command alone | + | `<##`, `<#`, `<##.`, `.<##` | the next line; the next line, time removed; its prefix; its suffix | + | `<###`, `concurrentlyN_` | lines in any order; lines of several clients at once | + | `#$>` | a command and a function of its output line, as in `("/_get chat @2 count=100", chat, [...])` | + | `withCCTransaction`, `shouldEventuallyReturn` | a query of the client's database; a value polled for 20 s | + | `withXFTPServer`, `withSmpServer'`, `withSmpServerAndNames` | an XFTP server; another SMP server; an SMP server with a names resolver | + | `versionTestMatrix2`, `testCfgVPrev`, `testCfgV1` | clients of the previous and of the first supported versions | + | `withTestOutput` | the terminal output of the clients printed | + +- Run: `/SimpleX chat client/ tests/`, for example `/SimpleX chat client/group tests/`. +- CI: build-linux, step "Run tests". +- Pitfalls: + - The output of every client is read to its end: a test fails when a client prints a line within 0.1 s after the test (`packages/simplex-chat-client/types/typescript/src/*.ts
packages/simplex-chat-python/src/simplex_chat/types/_*.py | the API docs in bots/src/API/Docs (`testGenerate` in [APIDocs.hs](../../tests/APIDocs.hs)) | +| `/Schema dump/` | src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql | SQLite migrations, dumped with `sqlite3` | +| `/Postgres schema dump/` | src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql | PostgreSQL migrations, dumped with `pg_dump` | +| `/Save query plans/` | chat_query_plans.txt and agent_query_plans.txt in src/Simplex/Chat/Store/SQLite/Migrations | the queries recorded in the run (`chatQueryStats`, `agentQueryStats`) | +| recording tests | tests/fixtures/api | [app fixtures](#app-fixtures) | + +- Bot API docs also fail on a command, response or event of the API that is neither documented in bots/src/API/Docs nor listed in `cliCommands`, `undocumentedCommands`, `undocumentedResponses` or `undocumentedEvents`, on a type of a documented one missing from Docs/Types.hs, and on a documented command without responses. They run with GHC 9.6 and later (`MIN_VERSION_base(4,18,0)`), in SQLite builds. +- Schema dump also checks down migrations (exceptions in `skipComparisonForDownMigrations`), STRICT tables, and the output of `.lint fkey-indexes` against chat_lint.sql, an empty file, so that the test fails for a foreign key without an index. +- Save query plans is skipped when `CI=true`. The plans are of the queries of that run only, so the files are committed from a local run of the whole suite. + +### PostgreSQL + +- Run: + + ```sh + cabal test simplex-chat-test --constraint 'simplexmq +client_postgres' --constraint 'simplex-chat +client_postgres' --ghc-options=-O0 --test-option=-m --test-option='/SimpleX chat client/' + ``` + + The flags `client_postgres` of simplexmq and simplex-chat, as in scripts/desktop/build-lib-linux.sh; `dbPostgres` is defined for the tests. +- Needed: a PostgreSQL server that accepts the role `postgres` without a password, and `pg_dump`. The role `test_chat_user` and the database `test_chat_db` are created at the start of a run and dropped at its end (`withTestDB` in Test.hs); each client has its own schema, dropped after each test (`dropTestSchemas` in ChatClient.hs). +- Left out of PostgreSQL builds: Schema dump, Bot API docs, WebRTC encryption, Mobile API Tests, both names suites, Save query plans. +- CI: local runs only; build.yml builds the PostgreSQL library for releases (build-linux-postgres). +- Pitfall: the Postgres schema dump calls `sed -i ''` (BSD sed) unless `CI=true`. + +## App fixtures + +The core's responses and events are recorded by core tests in [tests/fixtures/api](../../tests/fixtures/api) and replayed by Kotlin and iOS tests in place of the core library, so that app code is tested on the output of the current core. + +```mermaid +flowchart LR + CT["core test
tests/ChatTests"] -->|"apiFixture
eventsFixture"| F["tests/fixtures/api"] + F --> T["Kotlin desktopTest
iOS SimpleX Unit Tests"] + T -->|"recorded responses
in place of the core"| V["app functions and views"] + T -->|"recorded events"| P["processReceivedMsg"] + V --> M["ChatModel, alerts, notifications"] + P --> M +``` + +### Recording + +Helpers of [ChatTests/Utils.hs](../../tests/ChatTests/Utils.hs), called in a chat scenario test: + +| Helper | Written to `tests/fixtures/api/.json` | +|---|---| +| `apiFixture fixture cc placeholders FixtureRequests {frCommands, frMarkdown, frUris}` | an object with `commands`, `markdown` and `uris`, keyed by the request: the response to each command, encoded by `chatSendCmd` of the core library's API; `chatParseMarkdown` of each text; `chatParseUri` of each link | +| `nameFixture fixture cc name` | `apiFixture` of `/_connect plan 1 ` and of the markdown of the name, in `names/` | +| `eventsFixture fixture events steps` | an array of the events appended by `recordItemEvent events`, in `eventHook` of `chatHooks`, during `steps`: `newChatItems` and `chatItemUpdated`, encoded as `chatRecvMsg` encodes them | +| `nameMovedFixture` | a `nameMoved` event, built from the IDs of the named contacts and groups | + +Examples: `testPlanKnownNameAvailable` in ChatTests/Names.hs, `testDirectMessageUpdatePrevItem` and `testMissedCall` in ChatTests/Direct.hs. + +Stable recordings: + +- Values of each run are replaced by `stableJSON`: + + | Fields | Replaced by | + |---|---| + | `createdAt`
`updatedAt`
`chatTs`
`userMemberProfileSentAt`
`itemTs` | `1970-01-01T00:00:00Z` | + | `agentConnId`
`xContactId`
`connFullLink`
`connShortLink`
`contactLink`
`groupLink`
`viaGroupLinkUri`
`simplexUri`
`memberId`
`memberPubKey`
`publicGroupId`
`businessId`
`customerId`
`itemSharedMsgId` | the field name | + | `groupRelays` | `"groupRelay"` per element | + + A field with a new value in each run is added to this list. +- Strings of the test, such as links, are replaced by the `placeholders` of `apiFixture`, in keys and values: `[(cLink, "CONTACT_LINK")]` in `testPlanAddressContactViaAddress`, so that the app test connects to `CONTACT_LINK`. +- The recorded state is awaited first: the response to an update is recorded after the item status in the database is `snd_rcvd ok complete` (`shouldEventuallyReturn` in `testDirectMessageUpdatePrevItem`), and the steps of `eventsFixture` end after the expected number of events (`testMissedCall`). +- The client whose events are recorded has `markRead = False`: the CLI marks received items read when it prints them (`runTerminalOutput` in src/Simplex/Chat/Terminal/Output.hs), while the apps receive unread items. +- Recordings are in the tagged JSON form of builds without the `swift` flag. + +### Replay + +| | Kotlin, common/src/commonMain | iOS | +|---|---|---| +| Commands | `chatSendCmdRetry`, platform/Core.kt | `sendSimpleXCmdStr`, SimpleXChat/API.swift | +| Markdown | `chatParseMarkdown`, platform/Core.kt | `parseSimpleXMarkdownText`, SimpleXChat/API.swift | +| Links | `chatParseUri`, platform/Core.kt | `parseSanitizeUri`, SimpleXChat/API.swift | +| Events | `ChatController.processReceivedMsg`, model/SimpleXAPI.kt | `processReceivedMsg`, Shared/Model/SimpleXAPI.swift | +| Notifications | `ntfManager`, platform/NtfManager.kt | `NtfManager.shared`, Shared/Model/NtfManager.swift | +| Recording read by | `fixtureText` | `fixtureJSON`, then `singleFieldJSON` to the Swift JSON form | +| Tests | [NameAlertsTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt), [ChatItemUpdateTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ChatItemUpdateTest.kt) | [NameAlertsTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/NameAlertsTests.swift), [ChatItemUpdateTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/ChatItemUpdateTests.swift) | + +- Pattern: `recorded(fixture)` in the NameAlerts tests sets the first three seams to lookups in the recording; the test fails at tear-down on a request without a recorded response, unless the request is checked with `assertRequested`. The ChatItemUpdate tests decode the recorded events, pass each to `processReceivedMsg` and compare `ChatModel`. Tear-down restores the seams and clears the model. +- Run and CI: [Kotlin apps](#kotlin-apps), [SimpleX Unit Tests](#simplex-unit-tests). CI runs the kotlin and ios scopes for a change in tests/fixtures/api (`BUILD_CHANGES` in scripts/ci/packages_release.py). The recording tests are core tests, selected in the `ci-tests` block by the patterns of the [CI guide, core](../../scripts/ci/README.md#core). +- Pitfalls: + - `singleFieldJSON` converts each object with a `type` field, except `MsgContent`, recognized by its tags. The core encodes other types with `type` in both JSON forms: the types of `taggedObjectJSON` in src, such as `MsgChatLink`, `LinkContent`, `MsgScope` and `ChatBotCommand`, and `MsgReaction`, by its own instance. A recording with them requires another conversion rule. + - The tests use the app's singletons, such as `ChatModel` and `AlertManager`: each test restores what it changes. + - The core is reached only through the replaced seams: the Kotlin test JVM does not load the core library, and the iOS app host in CI is linked with stub libraries. + +## Kotlin apps + +In apps/multiplatform: + +| Source set | Gradle task | Contents | +|---|---|---| +| common/src/commonTest | `:common:desktopTest` | tests of common code (kotlin.test) | +| common/src/desktopTest | `:common:desktopTest` | JVM tests: Compose views with `runComposeUiTest`, layout positions with `renderScene` and `Modifier.record` ([LayoutRecorder.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/LayoutRecorder.kt)), files with `withTempDir`, [app fixtures](#app-fixtures), [snapshots](#desktop-snapshots) | +| android/src/test | `:android:testFossDebugUnitTest` | a template test, `ExampleUnitTest` | +| android/src/androidTest | `connectedFossDebugAndroidTest`, with a device or an emulator | a template test, `ExampleInstrumentedTest` | + +- Run: `./gradlew :common:desktopTest`; one class: `./gradlew :common:desktopTest --tests chat.simplex.app.ChatItemUpdateTest`. The CI command: [CI guide, kotlin](../../scripts/ci/README.md#kotlin). +- CI: build.yml, step "Build and test Kotlin apps" (kotlin scope); desktop-linux, app job. +- Pitfalls: + - The working directory is apps/multiplatform/common: recordings are read from `../../../tests/fixtures/api`, sources from `src/`. + - The tests use the app's singletons, such as `ChatModel`, `appPrefs` and `simplexWindowState`: they are restored in `@AfterTest`. + - The test JVM does not load the core library: code that calls it is tested with the replaced seams of [app fixtures](#replay). + +### Desktop snapshots + +- Checked: each `@Preview` of commonMain and desktopMain, rendered in the light and dark themes by `SnapshotTest` ([SnapshotTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/SnapshotTest.kt)), equals its reference in [common/src/desktopTest/snapshots](../../apps/multiplatform/common/src/desktopTest/snapshots), within 8 of 255 per colour channel ([snapshots-compare.py](../../scripts/ci/snapshots-compare.py)). +- Write: a new `@Preview` is added to `previewScenes`, with `chatItemFontScales` for a chat item, or to `previewsCallingCore` when its layout calls the core library; `everyPreviewIsRendered` fails otherwise. A preview uses `previewDate` in place of the current time. +- Record and check: with `scripts/ci/snapshots-remote.py desktop record`, desktop-linux renders the previews of the pushed branch, and the renders replace the references, for review and commit; with `check`, the renders that differ are listed. +- Run, from apps/multiplatform, then from the repository root: + + ```sh + SNAPSHOT_DIR= ./gradlew -Psimplex.assets.dir=../../assets :common:desktopTest --tests chat.simplex.app.SnapshotTest + python3 scripts/ci/snapshots-compare.py apps/multiplatform/common/src/desktopTest/snapshots + ``` + +- CI: desktop-linux, step "Compare snapshots"; in build.yml, the previews are rendered without a comparison. +- Details: [desktop-linux README](../../scripts/ci/desktop-linux/README.md), "Snapshots". + +## iOS app + +In apps/ios, SimpleX.xcodeproj: + +| Target | Kind | Scheme | CI | +|---|---|---|---| +| SimpleX Unit Tests | unit tests hosted by the app | SimpleX Unit Tests | build.yml, build-ios, step "Run iOS unit tests" (ios scope) | +| SimpleX Snapshots | unit tests hosted by the app: preview renders and tests of a running chat | SimpleX (iOS) | ios-sim, after the smoke test | +| Tests iOS | UI tests of Xcode's template | SimpleX (iOS) | local runs only | + +A new test file is added to its target in project.pbxproj: a PBXBuildFile, a PBXFileReference, the target's group and its Sources phase. + +### SimpleX Unit Tests + +- Checked: app code on [app fixtures](#app-fixtures) and other logic of the app. +- Write: an `XCTestCase` in [apps/ios/SimpleX Unit Tests](../../apps/ios/SimpleX%20Unit%20Tests); `fixtureJSON`, `singleFieldJSON` and `waitFor` are at file scope of NameAlertsTests.swift. +- Run, on macOS: `scripts/ci/ios-stub-libs.sh`, then the `xcodebuild test` command of the step "Run iOS unit tests" of build-ios in build.yml; or Product > Test with the scheme SimpleX Unit Tests. +- Pitfalls: + - The stubs replace the libraries in apps/ios/Libraries/sim, where scripts/ios/prepare.sh puts the core built for the simulator. + - With the stubs, the app opens its database error screen and calls the core no more. + - The tests run with `-testLanguage en -testRegion US`; a test of dates sets `NSTimeZone.default` to UTC. + +### SimpleX Snapshots + +- Checked: each `PreviewProvider` of apps/ios, rendered in the light and dark themes, equals its reference in [References](../../apps/ios/SimpleX%20Snapshots/References), within 8 of 255 per colour channel; previews marked `allSizes` are rendered at three content sizes. [SnapshotTests.swift](../../apps/ios/SimpleX%20Snapshots/SnapshotTests.swift) also contains assertion tests of layout functions, calls and VoIP pushes; the VoIP push tests require a running chat (`waitUntilChatActive`). +- Write: a new `PreviewProvider` is added to `previewScenes()`, or to `EXCLUDED` of [check-previews.py](../../apps/ios/SimpleX%20Snapshots/check-previews.py) when its renders differ between runs; check-previews.py fails on a `#Preview`. A preview uses `previewDate` in place of the current time. +- Record and check: `scripts/ci/snapshots-remote.py ios record|check`, as for [desktop](#desktop-snapshots). +- Run, from the repository root, with the core in apps/ios/Libraries/sim and a simulator where the app has a running chat: `SIM_UDID= scripts/ci/ios-sim/snapshots.sh ` ([snapshots.sh](../../scripts/ci/ios-sim/snapshots.sh)). +- CI: build-ios runs check-previews.py; ios-sim renders and compares at the end of the smoke test, whose step fails on a difference. +- Details: [ios-sim README](../../scripts/ci/ios-sim/README.md), "Snapshots". + +### Tests iOS + +Xcode's UI test template: `testExample` launches the app, `testLaunchPerformance` measures its launch, `testLaunch` attaches a screenshot of the launch screen. It is in the test action of the scheme SimpleX (iOS), with SimpleX Snapshots: `xcodebuild test -scheme "SimpleX (iOS)"` of [apps/ios/README.md](../../apps/ios/README.md) runs both. + +## App workflows + +The app built from a branch, its core included, driven on a device by scripts and, on request, by Claude following a test plan, with an optional test backend (relay, directory, names server, peers). + +| Workflow | App | Smoke test | Claude plan | README | +|---|---|---|---|---| +| `ios-sim` | iOS app in an iPhone simulator | onboarding
images sent in a group
snapshots | device-test-plan.md, cases per layout in claude-scope | [ios-sim](../../scripts/ci/ios-sim/README.md) | +| `desktop-linux` | desktop app on a virtual display, Ubuntu | desktopTest with snapshots
onboarding
a local group
both layouts
images sent | claude-test.md, claude-scope | [desktop-linux](../../scripts/ci/desktop-linux/README.md) | +| `android-emu` | debug APK in an Android emulator | onboarding
a local group
both layouts
images sent | claude-test.md, claude-scope | [android](../../scripts/ci/android/README.md) | + +- Write: a scripted case in the workflow's `smoke-test.sh`, with its `ui` driver; a Claude plan in the files of the table, with `backend: yes` in claude-scope when the cases use the test backend. +- Run: by hand only, on any branch: [CI guide, Starting a run](../../scripts/ci/README.md#starting-a-run). Each run uploads the app for manual tests. +- Pitfalls: + - A run with `claude` and `backend: yes` in claude-scope also requires the input `backend`, or its plan job fails. + - A Claude run requires the branch rule of the GitHub environment `app-sim-claude` to include the branch. + - The Android app runs under ARM translation: with the input `release`, the released app runs in the same emulator, to tell an app failure from the emulator's. + +## Packages and other scopes + +| Scope | Tests | Run | +|---|---|---| +| packages: Node.js library | [packages/simplex-chat-nodejs/tests](../../packages/simplex-chat-nodejs/tests), jest:
unit tests `*.unit.test.ts`, with `core` functions mocked
tests of the add-on and of library downloads
live tests with a local smp-server (`describeIfSmpServerAvailable`: `SMP_SERVER`, or a download on Linux) | `scripts/ci/package-tests.sh build linux-x86_64`
`scripts/ci/package-tests.sh test` | +| packages: Python library | [packages/simplex-chat-python/tests](../../packages/simplex-chat-python/tests), pytest, with a fake libsimplex (`FakeLib`) | as above | +| packages: TypeScript types | generated by [Bot API docs](#checks-against-committed-files), compiled by package-tests.sh | as above | +| mcp | [packages/simplex-chat-mcp/test](../../packages/simplex-chat-mcp/test), jest:
`test/unit`
`test/e2e`, with a local smp-server and xftp-server
manual checks: [TESTING.md](../../packages/simplex-chat-mcp/TESTING.md) | `scripts/ci/scope-tests.sh mcp` | +| support-bot | [apps/simplex-support-bot/bot.test.ts](../../apps/simplex-support-bot/bot.test.ts), vitest, with `simplex-chat` and `@simplex-chat/types` replaced by test/__mocks__ | `scripts/ci/scope-tests.sh support-bot` | +| support-bot-light | [apps/simplex-support-bot-light/tests](../../apps/simplex-support-bot-light/tests), pytest, with `FakeChatApi` of conftest.py; ruff, pyright | `scripts/ci/scope-tests.sh support-bot-light` | +| website | [website/test](../../website/test), `node --test` of src/js/simplex-lib.jsc | `npm test` in website | +| badge-web | [apps/simplex-store-service/web/test](../../apps/simplex-store-service/web/test), `node --test` of the compiled tests, in UTC | `npm ci`, `npm test` in apps/simplex-store-service/web | +| ci-scripts | [scripts/ci/test_packages_release.py](../../scripts/ci/test_packages_release.py), unittest of packages_release.py | `python3 scripts/ci/test_packages_release.py` | + +CI of each scope: [CI guide, Scopes](../../scripts/ci/README.md#scopes). Scopes lacking CI tests, with tests run locally: + +| Scope | Run | Notes | +|---|---|---| +| ts-client | `npm test` in packages/simplex-chat-client/typescript | prettier, eslint and jest; client.test.ts is skipped | +| webrtc | `npm test` in packages/simplex-chat-webrtc | fullstack.test.js requires `SIMPLEX_CHAT` and `SMP_SERVER`, the paths of the chat CLI and of smp-server | +| calculator-bot | `npm test` in apps/simplex-calculator-bot | calculatorBot.test.ts: smp-server from `SMP_SERVER` or a download on Linux, and tests/fixtures/tls | diff --git a/packages/simplex-chat-mcp/.claude-plugin/plugin.json b/packages/simplex-chat-mcp/.claude-plugin/plugin.json index 848a901e13..17b10cc98e 100644 --- a/packages/simplex-chat-mcp/.claude-plugin/plugin.json +++ b/packages/simplex-chat-mcp/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "simplex", - "version": "0.3.0", + "version": "0.3.1", "description": "Each Claude Code session gets its own SimpleX group. There you prompt the session, approve its actions and tool use, and read its answers.", "author": {"name": "SimpleX Chat", "url": "https://simplex.chat"}, "homepage": "https://github.com/simplex-chat/simplex-chat/tree/stable/packages/simplex-chat-mcp#readme", diff --git a/packages/simplex-chat-mcp/README.md b/packages/simplex-chat-mcp/README.md index c855ef5a74..65864c32c9 100644 --- a/packages/simplex-chat-mcp/README.md +++ b/packages/simplex-chat-mcp/README.md @@ -10,7 +10,32 @@ With this package, Claude Code can join channels and groups, talk to bots, and e The group of a Claude Code session in the SimpleX app: a prompt, Claude's answer, and its requests to run commands, which one tap approves

-## Run Claude Code from the app +🏗️ marks what is on the [roadmap](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/ROADMAP.md). + +## Use your agents in private chats, with the full chat UX + +- No phone number, email or account. Agents have their own profile, without access to your other chats. +- Send prompts with images and files, and see answers live. Terminal prompts sent to the chat too. +- Reply and edit messages, send reactions. +- Sessions use flat layout. +- 🏗️ Voice messages, code highlighting, widgets, etc. + +## Work with others in the same session + +- Invite people to the Main group, and they join any session's group. +- Only owners and admins can approve tool calls. +- The Main group shows every session's state. +- 🏗️ Each session as a topic in one group. +- 🏗️ Agent teams: mention an agent to message it. + +## Control your agents' activity + +- Agents ask before they act in other chats or use a tool such as Bash. +- A live stream of agent's work: tasks, tool calls, etc. +- Session and machine status. +- 🏗️ Code diffs, almost every waiting state answered from the chat, etc. + +## Start You need Node.js 22 or later, Claude Code, and the [SimpleX Chat app](https://simplex.chat/downloads/) 7.1 or later. @@ -27,41 +52,25 @@ You need Node.js 22 or later, Claude Code, and the [SimpleX Chat app](https://si claude --dangerously-load-development-channels plugin:simplex@simplex-chat ``` - If you don't want to run SimpleX MCP as a channel, start `claude` without the flag to use it as an MCP server. [Read more](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/REFERENCE.md#install). + Scan the QR code with the SimpleX app and tap Join: the Main group "Claude Control" appears. The first start downloads the SimpleX core library, so the QR code can take a minute. - Scan the QR code with the SimpleX app and tap Join. The group "Claude Control" appears. At the first start the plugin downloads the SimpleX core library, so the QR code can take a minute. If you close Claude Code before then, the next start shows it. +3. Each Claude Code session gets its own group, such as "1 · my-project". Join it from the invitation in "Claude Control", and send prompts there. - On several machines or containers, set `SIMPLEX_MCP_MACHINE` on each, for example `SIMPLEX_MCP_MACHINE=laptop`, to name its group "Claude Control - laptop". - -3. Each Claude Code session gets its own group, such as "1 · my-project". Join it from the invitation in "Claude Control". A list there shows every session and its state: working, waiting for you or idle. - -4. Send prompts in the session's group, and Claude answers there, live as it writes. The answer's last message ends with a line in small print with the turn's time and tokens and the machine's free memory and disk, such as `Done in 2 min 51 s · 16K output tokens · 673K tokens in context · RAM 12 GB free · disk 3.4 GB free❗️`, with ❗️ when one runs low. A switch of the model or the effort level appears as one line. Reply to a message to show Claude which one you mean. Claude also gets your reactions, as emoji replies, and the new text of a prompt you edit. Prompts you type in the terminal appear there too, and Claude Code's own prompts, such as a finished background task, appear as one line each. Each step of Claude's work, such as running the tests, appears as one line, completed with its outcome when the step ends. A line also shows when Claude Code summarises the session's context. Before Claude acts in other chats or uses a tool such as Bash, it asks in the group, and one tap approves. Another tap approves the tool for the rest of the session. - -5. Optionally, add your plan's 5-hour and weekly usage to the last line of each answer, and get a status line in the terminal, with this setting in `~/.claude/settings.json`. It replaces a status line of your own. [Read more](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/REFERENCE.md#status-line). - - ```json - "statusLine": {"type": "command", "command": "node \"${SIMPLEX_MCP_HOME:-$HOME/.simplex-mcp}/status-line.js\""} - ``` +[REFERENCE.md](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/REFERENCE.md) covers the plugin without the channel, several machines or containers, the status line, options, recovery and security. ## Safety - Anyone in "Claude Control" can join your sessions as an admin, so only invite people you trust. -- In a session, admins and owners can prompt Claude and approve what it does. Other members can only prompt, and observers can only read. +- In a session, admins and owners can prompt the agent and approve what it does. Other members can only prompt, and observers can only read. - A tool approved for the session runs without asking until the session ends or `/revoke`. Claude Code still asks where its own rules require it, such as before a change to `.git` or `.bashrc`. - Claude Code doesn't run `!` or `/` commands sent in the group. -- Claude sends files to the group only if the group allows them. -- Claude has no SimpleX address, so nobody can contact it first. +- Agents send files to the group only if the group allows them. +- Agents have no SimpleX address, so nobody can contact them first. ## Only Claude Code, for now The agent is tested with Claude Code. Tell us which other apps and models you want to use in [an issue](https://github.com/simplex-chat/simplex-chat/issues), or contribute. -## Reference - -[REFERENCE.md](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/REFERENCE.md) covers the plugin's options, recovery and security. It also explains shared settings for several machines or containers, and running the agent as an MCP server without the channel. - -What comes next: [Roadmap](https://github.com/simplex-chat/simplex-chat/blob/master/packages/simplex-chat-mcp/ROADMAP.md). - ## Own a part of SimpleX Business is moving into messages, and AI agents follow: an agent can ask a company's agent in a chat instead of opening the company's website, and buy there too. These chats hold plans, purchases and accounts, so with AI everyone feels the need for private and secure communication. diff --git a/packages/simplex-chat-mcp/REFERENCE.md b/packages/simplex-chat-mcp/REFERENCE.md index 2a2dc02fbe..82426c5c8c 100644 --- a/packages/simplex-chat-mcp/REFERENCE.md +++ b/packages/simplex-chat-mcp/REFERENCE.md @@ -299,7 +299,7 @@ Six tools: |---|---| | `connect` | Joins a contact, bot, business, group or channel by a link or a SimpleX name, as the agent's profile or incognito. Returns the chat, its profile, welcome message, the commands a bot advertises, and the messages so far. | | `send` | Sends a message, with a file of this computer when asked, and returns every message received in that chat after it, until none arrives for `idle` seconds (30 by default). A directory bot's search results arrive this way. | -| `receive` | Returns the chat's unread messages and those that arrive while it waits, waiting for one when asked. | +| `receive` | Returns the chat's unread messages and those that arrive while it waits, waiting for one when asked. With `history`, it also returns up to 50 messages before the new ones, the agent's own included. | | `download` | Downloads the file of a received message to the data folder and returns its full path. | | `list` | Lists the agent's chats with unread counts and `approved: true` for chats approved for all messages, and its actions without a result. | | `leave` | Deletes a contact, or leaves a group, business chat or channel, and deletes the chat; the contact or the members are notified. | @@ -348,6 +348,8 @@ answer each one in that chat, and call receive again after every answer, until I Approve the connection in "My Agent", and accept the request in the app if it asks. On the card of the agent's first answer, tap `all`: its later answers to you need no approval. +In a new Claude Code session, give the same prompt again. The agent can recall the conversation: `receive` with `history` returns up to 50 earlier messages of that chat, its own answers included. + ## Several agents Each agent is its own process, with its own data folder, port, agent control chat and Claude Code server: @@ -367,6 +369,7 @@ Add an entry with the URL `http://127.0.0.1:5226/mcp` and the header `Authorizat |---|---| | The server was not running when Claude Code started | Start the server, then run `/mcp reconnect all` in Claude Code (2.1.284 or later). | | The server restarted while Claude Code was running | Claude Code reconnects up to five times within about 30 seconds. After that, in an interactive session, run `/mcp reconnect all`; `claude -p` runs and Agent SDK sessions keep retrying for about half an hour. Open calls fail, and pending actions are cancelled; the agent's repeated call creates a new request. | +| The Claude Code session ended or was compacted | Ask the agent to recall the chat: `receive` with `history` returns up to 50 messages before the new ones, the agent's own included. | | A second server was started on the same data folder | It exits with `Another server uses (PID N). If no server runs, remove /lock.` | | Every owner left the agent control chat or was removed | `connect`, `send`, `download` and `leave` fail. Without `--owners`, the server logs `No owners in the agent control chat.` and prints a new link; join with it. With an `--owners` list, the agent posts and the server logs `No owners remain: restart the server with --reset-owners --owners`. | | The agent was removed from the agent control chat, the chat was deleted, or the agent lost its owner role | `connect`, `send`, `download` and `leave` fail, and the server logs `The agent lost its control chat. Restart the server with --reset-owners.` | @@ -576,18 +579,20 @@ Only you see this link: it never enters Claude's context or tool results. Scan t After the first owner joins, Claude posts the list of sessions in the Main group, after its greeting: ``` -🟠 3 · simplex-chat: working -🔵 6 · website: waiting for you, 2 approvals -🔵 7 · docs: waiting for you in Claude Code -🟢 8 · app: idle +🟢 3 · simplex-chat: working +🟠 6 · website: waiting for you, 2 approvals +⛔️ 7 · docs: waiting for you in Claude Code +🔴 8 · app: idle +⚙️ 9 · api: working in the background ⚪ Not running: 5 · bio, 4 · notes, 2 · openclaw, 1 · first ``` -- A session is running while its Claude Code runs, or while cards wait for a decision in its group. Each running session has a line, by number: - - `🔵 N · NAME: waiting for you, K approvals`: K cards wait in the session's group. A tool-use card counts only while Claude Code shows its permission dialog, or while Claude Code's state can't be read. - - `🔵 N · NAME: waiting for you in Claude Code`: Claude Code waits for an answer in its own window, such as a dialog. - - `🟠 N · NAME: working`: Claude Code works on a turn, or a subagent works for it. - - `🟢 N · NAME: idle`: Claude Code waits for the next prompt, also while a background command runs. +- A session is running while its Claude Code runs, or while cards wait for a decision in its group. Each running session has a line, by number. Green is the state to keep: + - `🟢 N · NAME: working`: Claude Code works on a turn, or a subagent works for it. + - `🟠 N · NAME: waiting for you, K approvals`: K cards wait in the session's group, for a decision in the chat. A tool-use card counts only while Claude Code shows its permission dialog, or while Claude Code's state can't be read. + - `⛔️ N · NAME: waiting for you in Claude Code`: Claude Code waits for an answer in its own window, such as a dialog, which the chat can't give. + - `⚙️ N · NAME: working in the background`: Claude Code waits for the next prompt while a background command runs. The command's end starts a turn without a prompt. + - `🔴 N · NAME: idle`: Claude Code waits for the next prompt, and nothing runs. - `▶️ N · NAME: running`: Claude Code's state can't be read. - The last line names every other session of the data folder, newest first. Without any session, the list is `No sessions.` - The states are Claude Code's own: the plugin reads them from Claude Code's record of its process, `sessions/PID.json` in `CLAUDE_CONFIG_DIR` or `~/.claude`. diff --git a/packages/simplex-chat-mcp/ROADMAP.md b/packages/simplex-chat-mcp/ROADMAP.md index 548890807b..2cb4f4e7da 100644 --- a/packages/simplex-chat-mcp/ROADMAP.md +++ b/packages/simplex-chat-mcp/ROADMAP.md @@ -15,17 +15,21 @@ What comes next for Claude Code in SimpleX Chat. ## In your sessions -- ✅ Reply to a message, and Claude knows which one you mean. -- ✅ React to a message, and Claude sees your reaction. -- ✅ Allow a tool for the rest of a session with one tap. -- ✅ See when a session's context is summarised. - ✅ One list in the Main group shows every session and its state: working, waiting for you or idle. - See what Claude is doing while it works, with its code changes as diffs. -- ✅ The model, effort and usage of each session show in its description, updated as they change. +- ✅ React to a message, and Claude sees your reaction. +- ✅ Reply to a message, and Claude knows which one you mean. +- ✅ The model and effort of each session show in its description, updated as they change, and the usage of each turn in the last line of its answer. +- ✅ See when a session's context is summarised. +- ✅ Allow a tool for the rest of a session with one tap. - Each session is a topic inside one group, not a group of its own. - Claude can offer choices and other small interactive widgets in the chat. - Start a new session from the desktop app, in a folder you choose. +- Send voice messages to Claude. +- Delete your latest prompt, and Claude knows you withdrew it. +- Answer from the chat almost every time Claude Code waits for you. ## More agents - Codex and other agents, alongside Claude Code. +- Claude's subagents and teammates join the session's group with their own profiles, and a mention of one by name sends it a message. diff --git a/packages/simplex-chat-mcp/TESTING.md b/packages/simplex-chat-mcp/TESTING.md index b0b48d50f1..3af22f510c 100644 --- a/packages/simplex-chat-mcp/TESTING.md +++ b/packages/simplex-chat-mcp/TESTING.md @@ -64,6 +64,7 @@ The directory by its address (`docs/DIRECTORY.md`): 4. `Check for new messages from the directory, waiting up to 60 seconds.` `receive` with `wait`. 5. `List your chats and pending actions.` `list`. 6. Reject one card with its `/reject @N A`: the call returns `status: rejected`; the card ends with `Rejected by Alice.` `/pending` lists the waiting cards. +7. Start a new Claude Code session and ask: `Recall your conversation with the directory.` `receive` with `history`: the last messages of the chat, oldest first, Claude's own with the agent's name and `from_type: agent`. Approval of all messages to a chat, and leaving: @@ -245,7 +246,7 @@ In a session started as in step 2 above: - The plugin's folder had no `node_modules/.package-lock.json`. - With the same keys in `.claude/settings.json` of the folder, and without `--settings`, the run had no tool of the plugin. 19. Start Claude Code as in step 2 with an empty data folder and a machine name: `SIMPLEX_MCP_HOME=/tmp/simplex-mcp-fresh SIMPLEX_MCP_MACHINE=laptop claude --plugin-dir /tmp/simplex-plugin --dangerously-load-development-channels plugin:simplex@inline`. Exit it before the QR code shows. Start it again the same way. The QR code shows within seconds, for the group "Claude Control - laptop". Stop that service: `kill $(cat /tmp/simplex-mcp-fresh/service.lock)`. -20. With the session of step 2 running and a second session started as in step 2 in another folder, the Main group shows the list of sessions, one line for each. Ask Claude to run `sleep 20` with Bash: its line shows 🟠 working. Send `Run ls with Bash.` in its group: the line shows 🔵 waiting for you, 1 approval; tap `/approve N`, and it shows 🟠 working, then 🟢 idle when the turn ends. Press Esc during a turn: the line shows 🟢 idle within 2 seconds, although Claude Code runs no Stop hook. Ask Claude to ask you a question with AskUserQuestion: the line shows 🔵 waiting for you in Claude Code. Exit the second Claude Code: its session moves into the last line, `⚪ Not running: `. `/sessions` replies with the same text. +20. With the session of step 2 running and a second session started as in step 2 in another folder, the Main group shows the list of sessions, one line for each. Ask Claude to run `sleep 20` with Bash: its line shows 🟢 working. Send `Run ls with Bash.` in its group: the line shows 🟠 waiting for you, 1 approval; tap `/approve N`, and it shows 🟢 working, then 🔴 idle when the turn ends. Press Esc during a turn: the line shows 🔴 idle within 2 seconds, although Claude Code runs no Stop hook. Ask Claude to run `sleep 60` with Bash in the background: after its turn ends, the line shows ⚙️ working in the background until the command ends. Ask Claude to ask you a question with AskUserQuestion: the line shows ⛔️ waiting for you in Claude Code. Exit the second Claude Code: its session moves into the last line, `⚪ Not running: `. `/sessions` replies with the same text. 21. Send `Read README.md, say what you are doing before each step, and then summarize it in 30 lines.` in the group. An empty message from Claude appears at once, as a reply to your message, with typing dots. Claude's first remark or step fills it, and each later remark and the answer appear from their first line, growing by whole lines, at most every 3 seconds. The steps' lines appear between them. Each message ends without an edited mark. The answer's message ends with `Done in`, the turn's time and tokens in small print, and the chat list shows the answer. In the terminal, Claude's text appears by whole lines. 22. Send `Name a fruit.` in the group, and after the answer edit that message to `Name a vegetable.` Claude answers with a vegetable, as a reply to your message. In the transcript, the second tag has the same `item` as the first and `edited="true"`. Edit it into `/list`, and nothing happens. Turn on live mode in the app, type `Name a colour.` slowly, and send it. Claude answers once, after you send it, and the transcript has one tag with `Name a colour.` 23. Stop the service: `kill $(cat /tmp/simplex-mcp-test/service.lock)`. diff --git a/packages/simplex-chat-mcp/package-lock.json b/packages/simplex-chat-mcp/package-lock.json index 738926f8ef..618e47c008 100644 --- a/packages/simplex-chat-mcp/package-lock.json +++ b/packages/simplex-chat-mcp/package-lock.json @@ -1,12 +1,12 @@ { "name": "@simplex-chat/mcp", - "version": "0.3.0", + "version": "0.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@simplex-chat/mcp", - "version": "0.3.0", + "version": "0.3.1", "bundleDependencies": [ "@modelcontextprotocol/node", "@modelcontextprotocol/server", @@ -20,7 +20,7 @@ "@modelcontextprotocol/server": "^2.3.1", "@simplex-chat/types": "^7.1.3", "qrcode": "^1.5", - "simplex-chat": "^7.1.3" + "simplex-chat": "^7.1.4" }, "bin": { "simplex-mcp": "dist/cli.js" @@ -4319,9 +4319,9 @@ "license": "ISC" }, "node_modules/simplex-chat": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/simplex-chat/-/simplex-chat-7.1.3.tgz", - "integrity": "sha512-StC2e0qZQS/L9VfHA1oWUTh3LIYSfo3Rj5hlGRZq0z2UjkH3nkbjmHI9z56316pT2EpXugPanW396Acfx+wTRA==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/simplex-chat/-/simplex-chat-7.1.4.tgz", + "integrity": "sha512-Uc4QNCAXhlsmEvySp307t59k/ke7oAWsZqYEsM6fAcufeT4LsART2KF7vzBhJZTAZQk2JOCLjwRxfpGE31tIFA==", "inBundle": true, "license": "AGPL-3.0", "dependencies": { diff --git a/packages/simplex-chat-mcp/package.json b/packages/simplex-chat-mcp/package.json index c9b2f4b239..7264f2f20a 100644 --- a/packages/simplex-chat-mcp/package.json +++ b/packages/simplex-chat-mcp/package.json @@ -1,6 +1,6 @@ { "name": "@simplex-chat/mcp", - "version": "0.3.0", + "version": "0.3.1", "description": "MCP server and Claude Code plugin that give AI agents a SimpleX profile, approved in your app", "bin": { "simplex-mcp": "dist/cli.js" @@ -30,7 +30,7 @@ "@modelcontextprotocol/server": "^2.3.1", "@simplex-chat/types": "^7.1.3", "qrcode": "^1.5", - "simplex-chat": "^7.1.3" + "simplex-chat": "^7.1.4" }, "bundleDependencies": true, "devDependencies": { diff --git a/packages/simplex-chat-mcp/spec/README.md b/packages/simplex-chat-mcp/spec/README.md index 01d8e2c812..235df831f6 100644 --- a/packages/simplex-chat-mcp/spec/README.md +++ b/packages/simplex-chat-mcp/spec/README.md @@ -184,7 +184,7 @@ graph TD | [`tools.ts`](../src/tools.ts) | tool schemas, descriptions, handlers, connect plans, perform steps, downloads, files to send, chat owners | | [`actions.ts`](../src/actions.ts) | action records, state machine, expiry timers, per-session limits, stop | | [`control.ts`](../src/control.ts) | agent control chat and session groups: link, owners, owner commands, cards, counter | -| [`messages.ts`](../src/messages.ts) | message items and their files, item watch, waits, unread paging, display names, durations | +| [`messages.ts`](../src/messages.ts) | message items and their files, item watch, waits, unread and history paging, display names, durations | | [`core.ts`](../src/core.ts) | one SimpleX core: init, user, network config, temp folder, event buffer, profile update | | [`files.ts`](../src/files.ts) | data folders, lock, token, `headers.json`, `server.json`, session folders, socket path, service log | | [`log.ts`](../src/log.ts) | log lines, error texts, shell quoting | diff --git a/packages/simplex-chat-mcp/spec/api.md b/packages/simplex-chat-mcp/spec/api.md index 30c8a667c0..12fdeec79b 100644 --- a/packages/simplex-chat-mcp/spec/api.md +++ b/packages/simplex-chat-mcp/spec/api.md @@ -204,7 +204,7 @@ The perform fails with `file: PATH changed after the request.` when the file's r ### 1.4 `receive` -Handler: [`AgentTools.receive`](../src/tools.ts). Schemas: input [`receiveSchema`](../src/tools.ts), output [`receiveOutput`](../src/tools.ts). +Handler: [`AgentTools.receive`](../src/tools.ts). History: [`historyMessages`](../src/tools.ts), [`historyItems`](../src/messages.ts). Schemas: input [`receiveSchema`](../src/tools.ts), output [`receiveOutput`](../src/tools.ts). Input: @@ -213,14 +213,16 @@ Input: | `chat` | string | | required | `@N` or `#N` of the agent | | `wait` | number | 0 to 86400 | 0 | seconds to wait when no message is new | | `limit` | integer | 1 to 100 | 50 | most messages returned | +| `history` | integer | 1 to 50 | | most message items returned in `history` | -Output (all fields always present): +Output (`history` only with its input): | Field | Value | |---|---| | `chat` | the chat reference | | `messages` | unread received messages in chat order, then received messages that arrived during the call; live items left out; at most `limit` | | `more` | new messages not returned, overflow, and unread items left unread by the page reads | +| `history` | at most `history` message items: the last ones before the first item of `messages`, or the last ones of the chat when `messages` is empty, in chat order; sent items included; new and live items, and items with `itemDeleted` (deleted, blocked or moderated), left out; read after the wait | Tool errors: `No chat CHAT. list shows the agent's chats.` for an invalid reference, the control chat, or a store error of the first read, `initial` 1 ([`AgentTools.receive`](../src/tools.ts)); other chat errors, a store error of a later page read included, as their error text ([`errorText`, `chatErrorText`](../src/log.ts)). @@ -333,9 +335,9 @@ Tool errors: `No chat CHAT. list shows the agent's chats.` when no action with t |---|---|---|---| | `chat` | string | always | chat reference of the item | | `item` | integer | always | `meta.itemId` | -| `from` | string | always | `groupRcv`: member display name
`directRcv`: contact display name
`channelRcv`: channel display name
sent items in `connect`: the agent's name in that chat | +| `from` | string | always | `groupRcv`: member display name
`directRcv`: contact display name
`channelRcv`: channel display name
sent items in `connect` and in `history` of `receive`: the agent's name in that chat | | `from_member` | integer | `groupRcv` | `groupMemberId` | -| `from_type` | string | when the profile has a peer type | sender's `peerType`; the agent's own for its non-incognito items in `connect` | +| `from_type` | string | when the profile has a peer type | sender's `peerType`; the agent's own for its non-incognito items in `connect` and in `history` of `receive` | | `time` | string | always | `meta.itemTs` | | `text` | string | always | `msgContent.text` | | `file` | object | a received item with a file | below | @@ -366,7 +368,7 @@ Tool errors: `No chat CHAT. list shows the agent's chats.` when no action with t | `path` | `received`: the download path | | `error` | `failed`: the error text ([`fileError`, `fileStatusError`, `fileErrorText`, `srvErrorText`](../src/log.ts)) | -Only received message items (`rcvMsgContent`) are returned by `send` and `receive`; `connect` also returns sent ones (`sndMsgContent`) ([`ChatItemsWatch.collect`](../src/messages.ts), [`AgentTools.connectedChat`](../src/tools.ts)). +Only received message items (`rcvMsgContent`) are returned in `responses` of `send` and in `messages` of `receive`; `connect` and `history` of `receive` also return sent ones (`sndMsgContent`) ([`ChatItemsWatch.collect`, `historyItems`](../src/messages.ts), [`AgentTools.connectedChat`, `historyMessages`](../src/tools.ts)). Command ([`commandsOf`](../src/tools.ts), schema [`commandSchema`](../src/tools.ts)): @@ -735,10 +737,11 @@ Posts: | Part | Text | Condition | |---|---|---| -| a running session | `🔵 N · NAME: waiting for you, K approvals`, `1 approval` for one | K pending cards of the session, without those cancelled by a stop. A tool-use card counts while Claude Code's state is `waiting` or unknown | -| | `🔵 N · NAME: waiting for you in Claude Code` | no card; attached; state `waiting` | -| | `🟠 N · NAME: working` | no card; attached; state `busy` | -| | `🟢 N · NAME: idle` | no card; attached; state `idle` or `shell` | +| a running session | `🟠 N · NAME: waiting for you, K approvals`, `1 approval` for one | K pending cards of the session, without those cancelled by a stop. A tool-use card counts while Claude Code's state is `waiting` or unknown | +| | `⛔️ N · NAME: waiting for you in Claude Code` | no card; attached; state `waiting` | +| | `🟢 N · NAME: working` | no card; attached; state `busy` | +| | `🔴 N · NAME: idle` | no card; attached; state `idle` | +| | `⚙️ N · NAME: working in the background` | no card; attached; state `shell` | | | `▶️ N · NAME: running` | no card; attached; no record path, no record file, or another state | | the other sessions | `⚪ Not running: N · NAME, N · NAME, K older sessions`, newest first | sessions without a card and without an attachment, or all of them while the service stops | | no session | `No sessions.` | | diff --git a/packages/simplex-chat-mcp/spec/architecture.md b/packages/simplex-chat-mcp/spec/architecture.md index 430b7a879c..738955151f 100644 --- a/packages/simplex-chat-mcp/spec/architecture.md +++ b/packages/simplex-chat-mcp/spec/architecture.md @@ -268,6 +268,7 @@ Hooks are bound in [`startAgent`](../src/serve.ts), where `actions` is created: | `fileOffer`, `fileContent` | file fields of an item; message content of a file | | `getChat`, `receivingFiles`, `markRead` | `apiGetChat` and `apiChatItemsRead` by chat reference; the IDs of a chat's files in status `rcvAccepted`, `rcvTransfer` or `rcvWarning`, paged | | `unreadItems` | unread items of a chat after its `initial` read, paged | +| `historyItems` | message items of a chat before an item, or at its end, paged; new and live items, and items with `itemDeleted`, left out | | `reportProgress`, `nextChange`, `awaitResponses` | waits | | `duration` | a time rounded to whole milliseconds: `41 ms`, `2.0 s`, `42 s`, `4 min 12 s`, `1 h 5 min`, for the step lines and the end line of the plugin | | `validName`, `viewName` | display name rules and `@name` form | @@ -690,9 +691,10 @@ The server writes the tappable form `/'...'` only in the card's command line ([` | `wait` | 0 to 86400 s | [`connectSchema`, `sendSchema`, `receiveSchema`, `downloadSchema`](../src/tools.ts) | | `idle` | 1 to 300 s, default 30 | [`connectSchema`, `sendSchema`, `defaultIdle`](../src/tools.ts) | | `limit` | 1 to 100, default 50 | [`sendSchema`, `receiveSchema`, `defaultLimit`](../src/tools.ts) | +| `receive.history` | 1 to 50 | [`receiveSchema`](../src/tools.ts) | | `connect` snapshot | last 50 items | [`messagesOnConnect`](../src/tools.ts) | | collected items per action or call | 100, then their IDs kept as overflow until deleted | [`maxCollected`, `ChatItemsWatch.collect`](../src/messages.ts) | -| unread page | 100 items | [`pageSize`](../src/messages.ts) | +| unread and history page | 100 items | [`pageSize`](../src/messages.ts) | | chat list read | one read of 1000000 chats | [`maxChats`](../src/tools.ts) | | `download` wait, default | 60 s | [`downloadWait`](../src/tools.ts) | | download check | every 60 s | [`downloadCheck`](../src/tools.ts) | diff --git a/packages/simplex-chat-mcp/spec/flows.md b/packages/simplex-chat-mcp/spec/flows.md index afbd40e68b..a78500aa59 100644 --- a/packages/simplex-chat-mcp/spec/flows.md +++ b/packages/simplex-chat-mcp/spec/flows.md @@ -287,16 +287,17 @@ sequenceDiagram participant W as ChatItemsWatch participant C as Core participant D as Peer - A->>T: receive {chat: #35;12, wait: 3600, limit: 50} + A->>T: receive {chat: #35;12, wait: 3600, limit: 50, history: 20} T->>W: collect #35;12 into arrived T->>C: apiGetChat #35;12 initial 1 C-->>T: chatStats.unreadCount 0 T-->>A: progress: No new messages in #35;12, waiting until TIME. D->>C: post, item 40 C->>W: newChatItems: arrived + T->>C: apiGetChat #35;12 before 40 count 100 T->>C: apiChatItemsRead #35;12 [40] T->>W: stop collecting - T-->>A: {chat: #35;12, messages: [40], more: 0} + T-->>A: {chat: #35;12, messages: [40], more: 0, history} ``` Notes: @@ -306,8 +307,9 @@ Notes: - `more`: the arrived messages not returned, the overflow and the unread items not read ([`AgentTools.receive`](../src/tools.ts)). - Items received while the pages are read are returned once ([`AgentTools.receive`](../src/tools.ts)). - Exact progress text: `No new messages in CHAT; waiting until TIME.` ([`AgentTools.receive`](../src/tools.ts)). +- With `history`, after the wait the server reads pages of 100 items: `before` the first returned message, or `last` when none is returned, then `before` the first item of the previous page, until it holds `history` message items that are not new or live and have no `itemDeleted`, or a page is short; the agent's own items are named as in `connect` ([`AgentTools.receive`, `historyMessages`](../src/tools.ts), [`historyItems`](../src/messages.ts)). -Source: [`AgentTools.receive`](../src/tools.ts), [`unreadItems`, `isNewMessage`, `reportProgress`, `nextChange`, `awaitResponses`](../src/messages.ts). +Source: [`AgentTools.receive`, `historyMessages`](../src/tools.ts), [`unreadItems`, `isNewMessage`, `historyItems`, `reportProgress`, `nextChange`, `awaitResponses`](../src/messages.ts). --- @@ -1691,18 +1693,18 @@ sequenceDiagram CC->>R: status busy D->>N: every 2 s: readRecord, the session attached N->>R: read status - D->>M: showList: 🟠 N · NAME: working, then the not running line + D->>M: showList: 🟢 N · NAME: working, then the not running line M->>C: no list yet, an owner in the group: apiSendMessages #35;M, priority -1 M->>C: apiSetGroupCustomData #35;M {simplexMcpMain: true, simplexMcpList: {item, at}} C->>O: the list CC->>R: status waiting, a permission dialog CC->>S: permission_request S->>D: POST /permission - D->>M: showList: 🔵 N · NAME: waiting for you, 1 approval + D->>M: showList: 🟠 N · NAME: waiting for you, 1 approval M->>C: apiUpdateChatItem #35;M item C->>O: the list edited, no alert CC->>R: status idle - D->>M: showList: 🟢 N · NAME: idle + D->>M: showList: 🔴 N · NAME: idle M->>C: apiUpdateChatItem #35;M item Note over D,M: the list 23 hours old, or its edit refused M->>C: apiSendMessages #35;M the new list, priority -1, and its item saved diff --git a/packages/simplex-chat-mcp/src/hub.ts b/packages/simplex-chat-mcp/src/hub.ts index a072a80077..bb2f806f5a 100644 --- a/packages/simplex-chat-mcp/src/hub.ts +++ b/packages/simplex-chat-mcp/src/hub.ts @@ -65,10 +65,10 @@ const listCheckMs = 2_000 const recordReadMs = 1_000 // spec: spec/api.md#list-of-sessions const claudeStates = new Map([ - ["waiting", ["🔵", "waiting for you in Claude Code"]], - ["busy", ["🟠", "working"]], - ["idle", ["🟢", "idle"]], - ["shell", ["🟢", "idle"]], + ["waiting", ["⛔️", "waiting for you in Claude Code"]], + ["busy", ["🟢", "working"]], + ["idle", ["🔴", "idle"]], + ["shell", ["⚙️", "working in the background"]], ]) // spec: spec/api.md#list-of-sessions const unknownState: [string, string] = ["▶️", "running"] @@ -263,7 +263,7 @@ export class Session { const state = claudeStates.get(this.claudeStatus ?? "") const dialog = state === undefined || this.claudeStatus === "waiting" const cards = this.actions.pending().filter(({tool, interrupted}) => !interrupted && (dialog || tool !== "permission")).length - if (cards > 0) return `🔵 ${this.displayName}: waiting for you, ${cards} approval${cards === 1 ? "" : "s"}` + if (cards > 0) return `🟠 ${this.displayName}: waiting for you, ${cards} approval${cards === 1 ? "" : "s"}` if (!this.attached) return undefined const [emoji, text] = state ?? unknownState return `${emoji} ${this.displayName}: ${text}` diff --git a/packages/simplex-chat-mcp/src/messages.ts b/packages/simplex-chat-mcp/src/messages.ts index 37adc8898c..8eb09810a1 100644 --- a/packages/simplex-chat-mcp/src/messages.ts +++ b/packages/simplex-chat-mcp/src/messages.ts @@ -370,6 +370,17 @@ function isNewMessage(item: T.ChatItem): boolean { return item.content.type === "rcvMsgContent" && isNew(item) && !isLive(item) } +// spec: spec/architecture.md#messages-historyitems +export async function historyItems(chat: api.ChatApi, ref: string, before: number | undefined, count: number): Promise { + const items: T.ChatItem[] = [] + for (let pagination: T.ChatPagination = before === undefined ? {type: "last", count: pageSize} : {type: "before", chatItemId: before, count: pageSize}; ; ) { + const page: T.ChatItem[] = (await getChat(chat, ref, pagination)).chatItems + items.unshift(...page.filter(item => isMessageItem(item) && !isNew(item) && !isLive(item) && item.meta.itemDeleted === undefined)) + if (items.length >= count || page.length < pageSize) return items.slice(-count) + pagination = {type: "before", chatItemId: page[0].meta.itemId, count: pageSize} + } +} + // spec: spec/architecture.md#messages-reportprogress export function reportProgress(call: ToolCall, message: () => string): () => void { call.progress(message()) diff --git a/packages/simplex-chat-mcp/src/tools.ts b/packages/simplex-chat-mcp/src/tools.ts index 318eb2a995..1fbf811042 100644 --- a/packages/simplex-chat-mcp/src/tools.ts +++ b/packages/simplex-chat-mcp/src/tools.ts @@ -26,6 +26,7 @@ import { fileOffer, filePaths, getChat, + historyItems, isChatRef, isLive, isMessageItem, @@ -70,6 +71,7 @@ export interface ReceiveInput { chat: string wait?: number limit?: number + history?: number } // spec: spec/architecture.md#tools-inputs @@ -312,6 +314,7 @@ const receiveSchema: Schema = { chat: {type: "string", description: "Chat reference from connect or list: @N or #N."}, wait: {type: "number", minimum: 0, maximum: 86400, description: "Seconds to wait for a new message when none is unread. Default 0."}, limit: {type: "integer", minimum: 1, maximum: 100, description: "Most messages returned. Default 50; the rest stay unread."}, + history: {type: "integer", minimum: 1, maximum: 50, description: "Number of messages returned in history: the last ones before the new messages, yours included."}, }, required: ["chat"], additionalProperties: false, @@ -382,6 +385,7 @@ const receiveOutput: Schema = { chat: {type: "string", description: "Chat reference."}, messages: {type: "array", items: messageSchema, description: "New messages: the unread ones, then those that arrived during the call."}, more: {type: "integer", description: "New messages not returned; call receive again for them."}, + history: {type: "array", items: messageSchema, description: "With the input history: the last messages of the chat before the new ones, oldest first, yours included; not marked read."}, }, required: ["chat", "messages", "more"], } @@ -467,7 +471,8 @@ Send bot commands as text, for example /help. When a message has a file with sta // spec: spec/architecture.md#tools-instructions const receiveDescription = `Returns the new messages of a chat: the unread ones, then those that arrive during the call. With wait, it waits up to wait seconds when no message is new. -The returned messages are marked read; more counts the new ones not returned. It needs no approval. When a message has a file with status offered, call download when your user's task needs it.` +The returned messages are marked read; more counts the new ones not returned. It needs no approval. When a message has a file with status offered, call download when your user's task needs it. +With history N, it also returns the last N messages of the chat before the new ones, yours included, not marked read; at the start of a session, and after your context was compacted, call receive with history to recall the conversation.` // spec: spec/architecture.md#tools-instructions const downloadDescription = `Downloads the file of a received message to this computer and returns its full path. @@ -1344,7 +1349,7 @@ export class AgentTools { // spec: spec/api.md#tool-receive private async receive(input: ReceiveInput, call: ToolCall): Promise { - const {chat, wait = 0, limit = defaultLimit} = input + const {chat, wait = 0, limit = defaultLimit, history} = input if (!isChatRef(chat) || chat === this.agent.controlChat()) throw unknownChat(chat) const arrived = new Collected() const stop = this.agent.watch.collect(chat, arrived) @@ -1371,15 +1376,22 @@ export class AgentTools { } } const returned = fresh().slice(0, limit) + const recalled = history === undefined ? undefined : await this.historyMessages(chat, chatInfo, returned[0]?.chatItem.meta.itemId, history) if (call.signal.aborted) return undefined await markRead(this.agent.chat, chat, [...returned.map(({chatItem}) => chatItem.meta.itemId), ...skipped]) if (call.signal.aborted) return undefined - return {chat, messages: await this.toMessages(returned), more: arrived.items.length - returned.length + arrived.overflow.size + unreadRest} + return {chat, messages: await this.toMessages(returned), more: arrived.items.length - returned.length + arrived.overflow.size + unreadRest, ...defined({history: recalled})} } finally { stop() } } + // spec: spec/api.md#tool-receive + private async historyMessages(chat: string, chatInfo: T.ChatInfo, before: number | undefined, count: number): Promise { + const items = await historyItems(this.agent.chat, chat, before, count) + return this.toMessages(items.map(chatItem => ({chatInfo, chatItem}))) + } + // spec: spec/api.md#tool-list private async listChats(): Promise { const chats: object[] = [] diff --git a/packages/simplex-chat-mcp/test/e2e/service.test.ts b/packages/simplex-chat-mcp/test/e2e/service.test.ts index d2df3ee19d..f31e885c2e 100644 --- a/packages/simplex-chat-mcp/test/e2e/service.test.ts +++ b/packages/simplex-chat-mcp/test/e2e/service.test.ts @@ -255,17 +255,17 @@ test("the Main group shows every session in one list, the running ones with thei await until(() => attached.length === 1) const owner = await client.request("GET", "/link") const invitations = joinSessionGroups(alice, ["1 · one", "2 · two"]) - const working = received(alice.chat, ({chatItem}) => chatItem.meta.itemText === "🟠 1 · one: working\n⚪ Not running: 2 · two") + const working = received(alice.chat, ({chatItem}) => chatItem.meta.itemText === "🟢 1 · one: working\n⚪ Not running: 2 · two") const mainGroupId = await joinByLink(alice, owner.link!) const list = await working expect(list.chatInfo).toMatchObject({type: "group", groupInfo: {groupId: mainGroupId}}) await invitations const edited = (text: string): Promise => updated(alice.chat, inGroup(mainGroupId, ({chatItem}) => chatItem.meta.itemId === list.chatItem.meta.itemId && chatItem.meta.itemText === text)) - const waiting = edited("🔵 1 · one: waiting for you, 1 approval\n⚪ Not running: 2 · two") + const waiting = edited("🟠 1 · one: waiting for you, 1 approval\n⚪ Not running: 2 · two") writeFileSync(record, JSON.stringify({status: "waiting", waitingFor: "permission prompt"})) await client.request("POST", "/permission", {id: one, requestId: "abcde", toolName: "Bash", description: "Run shell command", inputPreview: "ls"}) await waiting - const idle = edited("🟢 1 · one: idle\n⚪ Not running: 2 · two") + const idle = edited("🔴 1 · one: idle\n⚪ Not running: 2 · two") writeFileSync(record, JSON.stringify({status: "idle"})) await idle const ended = edited("⚪ Not running: 2 · two, 1 · one") diff --git a/packages/simplex-chat-mcp/test/unit/http.test.ts b/packages/simplex-chat-mcp/test/unit/http.test.ts index a8808223de..b9deb28c45 100644 --- a/packages/simplex-chat-mcp/test/unit/http.test.ts +++ b/packages/simplex-chat-mcp/test/unit/http.test.ts @@ -165,6 +165,8 @@ describe("MCP", () => { expect(await text({chat: "@4", text: "x", wait: -1})).toMatch(/data\/wait must be >= 0$/) expect(await text({chat: "@4", text: "x", colour: "red"})).toMatch(/data must NOT have additional properties$/) expect(await text({text: "x"})).toMatch(/data must have required property 'chat'$/) + const {result} = await body(await post(modern("tools/call", {name: "receive", arguments: {chat: "@4", history: 51}}), modernHeaders("tools/call", "receive"))) + expect(result).toMatchObject({isError: true, content: [{type: "text", text: "Input validation error: Invalid arguments for tool receive: data/history must be <= 50"}]}) expect(actions.all()).toHaveLength(0) }) diff --git a/packages/simplex-chat-mcp/test/unit/messages.test.ts b/packages/simplex-chat-mcp/test/unit/messages.test.ts index 9a1b56b8ce..0f0b278337 100644 --- a/packages/simplex-chat-mcp/test/unit/messages.test.ts +++ b/packages/simplex-chat-mcp/test/unit/messages.test.ts @@ -424,6 +424,107 @@ describe("receive", () => { expect(second).toMatchObject({messages: [{item: 23}], more: 0}) }) + it("returns as history the last messages before the new ones, oldest first, yours under your name, without live, deleted and other items, and marks only the new ones read", async () => { + const chat = new FakeChat() + const fromSwitchback: T.CIDirection = {type: "groupRcv", groupMember: member(44, "Switchback")} + const read = {status: "rcvRead"} + const connected = {...item(12, "connected", fromSwitchback, read), content: {type: "rcvGroupEvent", rcvGroupEvent: {type: "memberConnected"}}} as unknown as T.ChatItem + const deleted = item(13, "removed", fromSwitchback, read) + deleted.meta.itemDeleted = {type: "deleted", chatType: T.ChatType.Group} + const items = [ + item(9, "hello", fromSwitchback, read), + item(10, "trail map?", fromSwitchback, read), + item(11, "here it is", {type: "groupSnd"}), + connected, + deleted, + item(14, "Ridge", fromSwitchback, {...read, live: true}), + item(15, "anything else?", {type: "groupSnd"}), + item(16, "size 44?", fromSwitchback), + item(17, "map updated", {type: "groupSnd"}), + item(18, "and 45?", fromSwitchback), + item(19, "and 46?", fromSwitchback), + ] + chat.chats.set("#15", {chatInfo: groupChat(group(15, "Trail", member(1, "agent"))), items}) + const {tools} = agentTools(chat) + const result = (await tools.call("receive", {chat: "#15", limit: 2, history: 3}, signal().call))!.structuredContent as {messages: {item: number}[]; more: number; history: object[]} + expect(result.messages.map(({item}) => item)).toEqual([16, 18]) + expect(result.more).toBe(1) + const sent = {chat: "#15", from: "agent", from_type: "agent", time: "2026-10-17T10:00:00Z", new: false, mentions_me: false} + expect(result.history).toEqual([ + {chat: "#15", item: 10, from: "Switchback", from_member: 44, time: "2026-10-17T10:00:00Z", text: "trail map?", new: false, mentions_me: false}, + {...sent, item: 11, text: "here it is"}, + {...sent, item: 15, text: "anything else?"}, + ]) + expect(chat.commands.filter(cmd => cmd.startsWith("/_read"))).toEqual(["/_read chat items #15 16,18"]) + }) + + it("returns as history the latest messages when none is new, and no history without the input", async () => { + const chat = new FakeChat() + chat.chats.set("@4", {chatInfo: direct(contact(4, "Switchback")), items: [item(10, "hi", {type: "directRcv"}, {status: "rcvRead"}), item(11, "hello", {type: "directSnd"})]}) + const {tools} = agentTools(chat) + expect((await tools.call("receive", {chat: "@4", history: 50}, signal().call))!.structuredContent).toEqual({ + chat: "@4", + messages: [], + more: 0, + history: [ + {chat: "@4", item: 10, from: "Switchback", time: "2026-10-17T10:00:00Z", text: "hi", new: false, mentions_me: false}, + {chat: "@4", item: 11, from: "agent", from_type: "agent", time: "2026-10-17T10:00:00Z", text: "hello", new: false, mentions_me: false}, + ], + }) + expect((await tools.call("receive", {chat: "@4"}, signal().call))!.structuredContent).not.toHaveProperty("history") + expect(chat.commands.filter(cmd => cmd.startsWith("/_read"))).toEqual([]) + }) + + it("reads history when the call returns, after the wait", async () => { + const chat = new FakeChat() + chat.chats.set("@4", {chatInfo: direct(contact(4, "Switchback")), items: [item(10, "hi", {type: "directRcv"}, {status: "rcvRead"}), item(11, "hello", {type: "directSnd"})]}) + const {tools, watch} = agentTools(chat) + const {call, progress} = signal() + const receiving = tools.call("receive", {chat: "@4", wait: 30, history: 2}, call) + await settled() + expect(progress[0]).toMatch(/^No new messages in @4; waiting until /) + watch.deliver([chat.addItem("@4", item(12, "still there?", {type: "directSnd"})), chat.addItem("@4", item(13, "yes", {type: "directRcv"}))]) + const result = (await receiving)!.structuredContent as {messages: {item: number}[]; history: {item: number}[]} + expect(result.messages.map(({item}) => item)).toEqual([13]) + expect(result.history.map(({item}) => item)).toEqual([11, 12]) + }) + + it("leaves out of history a new message whose event has not arrived, and the next call returns it", async () => { + const chat = new FakeChat() + chat.chats.set("@4", {chatInfo: direct(contact(4, "Switchback")), items: [item(10, "hi", {type: "directRcv"}, {status: "rcvRead"}), item(11, "hello", {type: "directSnd"})]}) + const {tools, watch} = agentTools(chat) + const receiving = tools.call("receive", {chat: "@4", wait: 30, history: 5}, signal().call) + await settled() + chat.addItem("@4", item(12, "still there?", {type: "directRcv"})) + watch.deliver([chat.addItem("@4", item(13, "hello?", {type: "directRcv"}))]) + const result = (await receiving)!.structuredContent as {messages: {item: number}[]; history: {item: number}[]} + expect(result.messages.map(({item}) => item)).toEqual([13]) + expect(result.history.map(({item}) => item)).toEqual([10, 11]) + const next = (await tools.call("receive", {chat: "@4"}, signal().call))!.structuredContent as {messages: {item: number}[]} + expect(next.messages.map(({item}) => item)).toEqual([12]) + }) + + it("reads history in pages of 100 items, before the first new message or from the end, until it holds the messages", async () => { + const chat = new FakeChat() + const undecrypted = Array.from({length: 150}, (_, i) => ({...item(10 + i, "", {type: "directRcv"}, {status: "rcvRead"}), content: {type: "rcvDecryptionError"}}) as unknown as T.ChatItem) + const items = [item(1, "hi", {type: "directRcv"}, {status: "rcvRead"}), item(2, "hello", {type: "directSnd"}), ...undecrypted, item(160, "still there?", {type: "directSnd"}), item(161, "yes", {type: "directRcv"})] + chat.chats.set("@4", {chatInfo: direct(contact(4, "Switchback")), items}) + const {tools} = agentTools(chat) + const first = (await tools.call("receive", {chat: "@4", history: 3}, signal().call))!.structuredContent as {history: {item: number}[]} + expect(first.history.map(({item}) => item)).toEqual([1, 2, 160]) + const second = (await tools.call("receive", {chat: "@4", history: 1}, signal().call))!.structuredContent as {history: {item: number}[]} + expect(second.history.map(({item}) => item)).toEqual([161]) + expect(chat.commands.filter(cmd => /^\/_get chat @4 (count|before)=/.test(cmd))).toEqual(["/_get chat @4 before=161 count=100", "/_get chat @4 before=61 count=100", "/_get chat @4 count=100"]) + }) + + it("returns your messages in history under your incognito name", async () => { + const chat = new FakeChat() + chat.chats.set("#15", {chatInfo: groupChat(group(15, "Trail", {...member(1, "Quiet Fox"), memberContactProfileId: 99})), items: [item(11, "here it is", {type: "groupSnd"})]}) + const {tools} = agentTools(chat) + const result = (await tools.call("receive", {chat: "#15", history: 1}, signal().call))!.structuredContent as {history: object[]} + expect(result.history).toEqual([{chat: "#15", item: 11, from: "Quiet Fox", time: "2026-10-17T10:00:00Z", text: "here it is", new: false, mentions_me: false}]) + }) + it("names the agent in a quote of its own message by its name in the chat, the incognito name included", async () => { const chat = new FakeChat() const incognito = {...contact(4, "Ridgeline"), activeConn: {connId: 204, connStatus: {type: "ready"}, customUserProfileId: 77}} as unknown as T.Contact diff --git a/packages/simplex-chat-mcp/test/unit/sessions.test.ts b/packages/simplex-chat-mcp/test/unit/sessions.test.ts index 6bc9e62fc2..61be401878 100644 --- a/packages/simplex-chat-mcp/test/unit/sessions.test.ts +++ b/packages/simplex-chat-mcp/test/unit/sessions.test.ts @@ -2606,7 +2606,7 @@ describe("Main group", () => { expect(chat.invitations.at(-1)).toEqual({groupId: 21, viaGroupId: 10, groupMemberId: 3, memberRole: T.GroupMemberRole.Owner}) }) - it("posts the list of every session after the greeting, silent, and edits it as Claude Code's records and the cards change: working, waiting for you, waiting for you in Claude Code, idle, and the ⚪ line after an exit", async () => { + it("posts the list of every session after the greeting, silent, and edits it as Claude Code's records and the cards change: working, waiting for you, waiting for you in Claude Code, idle, working in the background, and the ⚪ line after an exit", async () => { const chat = new FakeChat() const hub = await hubWith(chat, [self]) const one = await openSession(hub, id1, stored(1, "one")) @@ -2631,15 +2631,15 @@ describe("Main group", () => { await hub.showSessions() return chat.updates.length === edits ? undefined : chat.updates.at(-1)!.text } - expect(await shows("busy")).toBe("🟠 1 · one: working\n⚪ Not running: 2 · two") + expect(await shows("busy")).toBe("🟢 1 · one: working\n⚪ Not running: 2 · two") expect(chat.updates.at(-1)).toMatchObject({chatId: 10, itemId: list}) expect(await shows("busy")).toBeUndefined() - expect(await shows("waiting")).toBe("🔵 1 · one: waiting for you in Claude Code\n⚪ Not running: 2 · two") + expect(await shows("waiting")).toBe("⛔️ 1 · one: waiting for you in Claude Code\n⚪ Not running: 2 · two") one.permission({id: id1, requestId: "abcde", toolName: "Bash", description: "Run shell command", inputPreview: "ls"}) - expect(await shows("waiting")).toBe("🔵 1 · one: waiting for you, 1 approval\n⚪ Not running: 2 · two") - expect(await shows("busy")).toBe("🟠 1 · one: working\n⚪ Not running: 2 · two") - expect(await shows("idle")).toBe("🟢 1 · one: idle\n⚪ Not running: 2 · two") - expect(await shows("shell")).toBeUndefined() + expect(await shows("waiting")).toBe("🟠 1 · one: waiting for you, 1 approval\n⚪ Not running: 2 · two") + expect(await shows("busy")).toBe("🟢 1 · one: working\n⚪ Not running: 2 · two") + expect(await shows("idle")).toBe("🔴 1 · one: idle\n⚪ Not running: 2 · two") + expect(await shows("shell")).toBe("⚙️ 1 · one: working in the background\n⚪ Not running: 2 · two") one.endPermissions() one.onLine = undefined expect(await shows("idle")).toBe("⚪ Not running: 2 · two, 1 · one") @@ -2656,18 +2656,18 @@ describe("Main group", () => { one.onLine = () => undefined one.permission({id: id1, requestId: "abcde", toolName: "Bash", description: "Run shell command", inputPreview: "ls"}) two.requestMode("host") - expect(hub.sessionsText()).toBe("🔵 1 · one: waiting for you, 1 approval\n🔵 2 · two: waiting for you, 1 approval") + expect(hub.sessionsText()).toBe("🟠 1 · one: waiting for you, 1 approval\n🟠 2 · two: waiting for you, 1 approval") one.record = join(root, "claude-1.json") writeFileSync(one.record, JSON.stringify({status: "busy"})) await hub.showSessions() - expect(hub.sessionsText()).toBe("🟠 1 · one: working\n🔵 2 · two: waiting for you, 1 approval") + expect(hub.sessionsText()).toBe("🟢 1 · one: working\n🟠 2 · two: waiting for you, 1 approval") writeFileSync(one.record, JSON.stringify({status: "compacting"})) await hub.showSessions() - expect(hub.sessionsText()).toBe("🔵 1 · one: waiting for you, 1 approval\n🔵 2 · two: waiting for you, 1 approval") + expect(hub.sessionsText()).toBe("🟠 1 · one: waiting for you, 1 approval\n🟠 2 · two: waiting for you, 1 approval") one.permission({id: id1, requestId: "fghij", toolName: "Write", description: "Write a file", inputPreview: "a.txt"}) writeFileSync(one.record, JSON.stringify({status: "waiting"})) await hub.showSessions() - expect(hub.sessionsText()).toBe("🔵 1 · one: waiting for you, 2 approvals\n🔵 2 · two: waiting for you, 1 approval") + expect(hub.sessionsText()).toBe("🟠 1 · one: waiting for you, 2 approvals\n🟠 2 · two: waiting for you, 1 approval") let stopped = false const stopping = hub.stop().then(() => (stopped = true)) await until(() => chat.updates.filter(({chatId}) => chatId === 10).at(-1)?.text === "⚪ Not running: 2 · two, 1 · one") @@ -2688,10 +2688,10 @@ describe("Main group", () => { expect(hub.sessionsText()).toBe("▶️ 1 · one: running") writeFileSync(one.record, JSON.stringify({status: "busy"})) await hub.showSessions() - expect(hub.sessionsText()).toBe("🟠 1 · one: working") + expect(hub.sessionsText()).toBe("🟢 1 · one: working") writeFileSync(one.record, '{"pid": 100, "sta') await hub.showSessions() - expect(hub.sessionsText()).toBe("🟠 1 · one: working") + expect(hub.sessionsText()).toBe("🟢 1 · one: working") writeFileSync(one.record, JSON.stringify({status: "compacting"})) await hub.showSessions() expect(hub.sessionsText()).toBe("▶️ 1 · one: running") @@ -2720,7 +2720,7 @@ describe("Main group", () => { await hub.showSessions() expect(Date.now() - started).toBeLessThan(3_000) expect(opened).toHaveBeenCalledTimes(1) - expect(hub.sessionsText()).toBe("🟠 1 · one: working") + expect(hub.sessionsText()).toBe("🟢 1 · one: working") }) it("deletes a new list whose item it could not save and posts it again at the next render, and does not send a text the core refused as too large again until the text changes", async () => { diff --git a/packages/simplex-chat-nodejs/package.json b/packages/simplex-chat-nodejs/package.json index c7430c247a..25222fbfcd 100644 --- a/packages/simplex-chat-nodejs/package.json +++ b/packages/simplex-chat-nodejs/package.json @@ -1,6 +1,6 @@ { "name": "simplex-chat", - "version": "7.1.3", + "version": "7.1.4", "main": "dist/index.js", "types": "dist/index.d.ts", "gypfile": false, diff --git a/packages/simplex-chat-nodejs/src/release.ts b/packages/simplex-chat-nodejs/src/release.ts index 7587633550..a9dd64788a 100644 --- a/packages/simplex-chat-nodejs/src/release.ts +++ b/packages/simplex-chat-nodejs/src/release.ts @@ -1,16 +1,16 @@ // Written by scripts/ci/packages_release.py from the simplex-chat-libs releases. -export const LIBS_RELEASE = "core-7.1.3.0" +export const LIBS_RELEASE = "core-7.1.4.0" export const ADDON_RELEASE: string | undefined = "nodejs-addon-cce06d8" export const SHA256: {readonly [asset: string]: string} = { - "simplex-chat-libs-linux-aarch64.zip": "46e296417de8cddc0d6f800d7c634dec410a1af20ea38ff31f224ef388aaeb00", - "simplex-chat-libs-linux-x86_64-postgres.zip": "ea89b4e95836c79c887cc13a2dc9fc66e319b21ee4148ca38817539657601050", - "simplex-chat-libs-linux-x86_64.zip": "12b6ea97c64a5ea53a66f47e827dc8c0d6bc767fd44b22aab47786ac90e91d01", - "simplex-chat-libs-macos-aarch64.zip": "b7612b05cd17267f4e24efacfd16fa4a9f9b0c39b34c2f52465e34395492a452", - "simplex-chat-libs-macos-x86_64.zip": "ce7a9a2be0cd0e6782902d8ce4420e8660e4e2360d7fc0248584a0163f1a236d", - "simplex-chat-libs-windows-x86_64.zip": "a9ed55c82753d57cfddaddee78cc989b0edf3fe5fe08d7214e6f84ab43609999", + "simplex-chat-libs-linux-aarch64.zip": "5ab4be63353e49b0d24b70b154745d2e45c288903e0c17078b8f957e3633ca6b", + "simplex-chat-libs-linux-x86_64-postgres.zip": "77cf1e2c9a75b723ce18abc5c02873dbe08d37dca069a0d815dca3095143439a", + "simplex-chat-libs-linux-x86_64.zip": "d4888149b29fd9d4ca690d2a8f3763dde477b77fe1ea6927d5990137bceeab6b", + "simplex-chat-libs-macos-aarch64.zip": "32450fef49e2e38db33783fe0761f4af16463a5cd7a204f8c41875909db60b56", + "simplex-chat-libs-macos-x86_64.zip": "3ab5efc5bbc5b8ddfa6a24a4d79e318fff3df0dd4c3334c5cd9acb1b0288101c", + "simplex-chat-libs-windows-x86_64.zip": "c88e185442cb738d53d2dc2d5408c4cb9efedaa910c677ec10e8dd74c12b0223", "simplex-chat-nodejs-linux-aarch64.node": "de09cf5653772370fbd1ab2b046a9a2b68f3d2a078103befb2d4eb3e11748ebb", "simplex-chat-nodejs-linux-x86_64.node": "fda77e39a5d38b1132a6a04ef9f9cd2c939a429e709f28c81c3777684ba73603", "simplex-chat-nodejs-macos-aarch64.node": "3da7ae0064c151a0508d3f0a208a9af5647a8113df8d9164f76c786a882d68df", diff --git a/packages/simplex-chat-nodejs/tests/live.test.ts b/packages/simplex-chat-nodejs/tests/live.test.ts index 526e230c51..beb80fa445 100644 --- a/packages/simplex-chat-nodejs/tests/live.test.ts +++ b/packages/simplex-chat-nodejs/tests/live.test.ts @@ -39,8 +39,13 @@ describeIfSmpServerAvailable("Live message tests (use local SMP server)", () => const timeout = 10000 const received = (check: (meta: T.CIMeta) => boolean) => bob.wait("newChatItems", ({chatItems}) => chatItems.some(({chatItem: {meta}}) => check(meta)), timeout) + const updatedItem = (event: {chatItemUpdate?: {chatItem: T.ChatItem}; chatItem?: {chatItem: T.ChatItem}}) => + (event.chatItemUpdate ?? event.chatItem)?.chatItem const updated = (check: (meta: T.CIMeta) => boolean) => - bob.wait("chatItemUpdated", ({chatItemUpdate: {chatItem: {meta}}}) => check(meta), timeout) + bob.wait("chatItemUpdated", event => { + const item = updatedItem(event) + return item !== undefined && check(item.meta) + }, timeout) const live = new api.LiveMessage(alice, CT.Direct, bobContact.contactId, 500) const started = received(meta => meta.itemLive === true && meta.itemText === "") @@ -52,7 +57,7 @@ describeIfSmpServerAvailable("Live message tests (use local SMP server)", () => expect(await updatedLive).toBeDefined() const finalized = updated(meta => meta.itemId === itemId && meta.itemLive === false && meta.itemText === "Hello world") await live.end("Hello world") - expect((await finalized)?.chatItemUpdate.chatItem.meta.itemEdited).toBe(false) + expect(updatedItem((await finalized)!)?.meta.itemEdited).toBe(false) const emptyStarted = received(meta => meta.itemLive === true && meta.itemText === "") live.update("") diff --git a/plans/2026-10-19-mcp-server.md b/plans/2026-10-19-mcp-server.md index 94a80058a1..0c18f2d64b 100644 --- a/plans/2026-10-19-mcp-server.md +++ b/plans/2026-10-19-mcp-server.md @@ -1,6 +1,6 @@ # SimpleX MCP server 0.2: plan -Status: draft · 2026-10-17, files and leave 2026-10-30 (`plans/2026-10-30-mcp-files-and-leave.md`) · person-facing manual: `REFERENCE.md`, the plugin in short in `README.md`. Code references: master `139ce5f8c` (`/code/simplex-chat-6`), unless marked `9711dcfc9` (core 7.1.0.11); `simplex-chat` 7.1.0-beta.10.2 loads core 7.1.0.20. Pending decisions: section Open. +Status: draft · 2026-10-17, files and leave 2026-10-30 (`plans/2026-10-30-mcp-files-and-leave.md`), history 2026-11-12 (`plans/2026-11-12-mcp-history.md`) · person-facing manual: `REFERENCE.md`, the plugin in short in `README.md`. Code references: master `139ce5f8c` (`/code/simplex-chat-6`), unless marked `9711dcfc9` (core 7.1.0.11); `simplex-chat` 7.1.0-beta.10.2 loads core 7.1.0.20. Pending decisions: section Open. ## Scope @@ -705,6 +705,7 @@ input field type rule chat string required; a chat of the agent wait number optional; seconds to wait when no message is new; 0 to 86400; default 0 limit number optional; 1 to 100; default 50 +history number optional; 1 to 50; most message items returned in history ``` ``` @@ -712,6 +713,7 @@ result field type present chat string always messages Message[] always; the new messages, up to limit: the unread ones in chat order, then those that arrive during the call more number always; new messages not returned +history Message[] with history; up to history message items: the last ones before the first of messages, or the last ones of the chat when messages is empty, in chat order; sent items included; new and live items, and items with itemDeleted (deleted, blocked or moderated), left out ``` - New: a received message that is unread when the call reads its page, or that arrives during the call. The returned ones are marked read; another call marking one read after this call collected it does not remove it. @@ -1360,8 +1362,11 @@ receive(input, ctx): none new and wait > 0: wait for newChatItems of chat until one is new | wait | signal progress at once and every 60 s: "No new messages in ; waiting until