Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

3.3 KB
Raw Blame
import Foundation
import Testing
@testable import CodyncKit

@Test func activityErrorAndUnknownStatusNeverLookCompleted() {
    let error = BotActivityPresentation(status: "error", activity: "")
    #expect(error.phase == .failed)
    #expect(error.title == "Failed")
    #expect(error.symbol != "checkmark")
    #expect(error.progressStep == 4)
    let unknown = BotActivityPresentation(status: "new-host-status", activity: "")
    #expect(unknown.phase == .waiting)
    #expect(unknown.symbol != "checkmark")
    #expect(unknown.progressStep < 4)
}

@Test func staleActivityStopsPresentingLiveProgress() {
    for status in ["working", "needsInput"] {
        let stale = BotActivityPresentation(status: status, activity: "Old step", isStale: true)
        #expect(stale.phase == .stale)
        #expect(!stale.caption.contains("Old step"))
    }
    let done = BotActivityPresentation(status: "idle", activity: "Old step", isStale: true)
    #expect(done.phase == .completed)
    #expect(done.symbol == "checkmark")
}

@Test func activityCaptionIsTheStepWhileLive() {
    #expect(BotActivityPresentation(status: "needsInput", activity: "Choose a branch").caption == "Choose a branch")
    #expect(BotActivityPresentation(status: "working", activity: "").caption == "Working")
    #expect(BotActivityPresentation(status: "idle", activity: "Old step").caption == "Done")
}

@MainActor @Test func teamWidgetKeepsPicksAndFillsTheRestByUrgency() {
    let bots = Bot.widgetPreview  // review: needs you, build: working, docs: idle
    #expect(BotsTeamCard.slots(bots: bots, picks: []).map { $0?.id } == ["preview-review", "preview-build", "preview-docs", nil])
    let picked = BotsTeamCard.slots(bots: bots, picks: [nil, "preview-docs", nil, nil]).map { $0?.id }
    #expect(picked == ["preview-review", "preview-docs", "preview-build", nil])
    // A deleted pick falls back to automatic.
    #expect(BotsTeamCard.slots(bots: bots, picks: ["gone"]).first??.id == "preview-review")
}

@Test func aCallShowsOnTheActivityInsteadOfDone() throws {
    let idle = BotActivityPresentation(status: "idle", activity: "Old step", call: .listening)
    #expect(idle.phase == .onCall(.listening))
    #expect(idle.caption == "On a call · Listening")
    #expect(idle.symbol == "waveform")
    #expect(BotActivityPresentation(status: "idle", activity: "", call: .connecting).caption == "Connecting the call")
    #expect(BotActivityPresentation(status: "working", activity: "", isStale: true, call: .paused).title == "Call paused")
    // While the bot works, its progress is the line; a waiting approval and a failure stay visible.
    #expect(BotActivityPresentation(status: "working", activity: "Running the tests", call: .speaking).caption == "Running the tests")
    #expect(BotActivityPresentation(status: "needsInput", activity: "Choose", call: .listening).phase == .needsInput)
    #expect(BotActivityPresentation(status: "error", activity: "", call: .listening).phase == .failed)
    #expect(BotActivityPresentation(status: "idle", activity: "").title == "Done")
    // The app writes the call as its raw value (the widget decodes it).
    let state = BotActivityAttributes.ContentState(status: "idle", activity: "", startedAt: nil, call: .speaking)
    let json = try #require(String(data: try JSONEncoder().encode(state), encoding: .utf8))
    #expect(json.contains(#""call":"speaking""#))
}