Skip to content

Commit

Permalink
feat: add bug reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jun 9, 2024
1 parent 36a4700 commit 030b807
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 39 deletions.
31 changes: 28 additions & 3 deletions xcode/FuegoTestApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
F7A4061D2C134233008FBC77 /* Fuego.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7A4061C2C134233008FBC77 /* Fuego.xcframework */; };
F7A4061E2C134233008FBC77 /* Fuego.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F7A4061C2C134233008FBC77 /* Fuego.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F7A406442C1347D7008FBC77 /* book.dat in Resources */ = {isa = PBXBuildFile; fileRef = F7A406432C1347D6008FBC77 /* book.dat */; };
F7F406092C136F1E000DCDAD /* FuegoCBridge in Frameworks */ = {isa = PBXBuildFile; productRef = F7F406082C136F1E000DCDAD /* FuegoCBridge */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -45,13 +46,16 @@
F7A4061C2C134233008FBC77 /* Fuego.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Fuego.xcframework; path = ../build/Fuego.xcframework; sourceTree = "<group>"; };
F7A406422C134536008FBC77 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.4.sdk/usr/lib/libc++.tbd"; sourceTree = DEVELOPER_DIR; };
F7A406432C1347D6008FBC77 /* book.dat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = book.dat; path = ../../book/book.dat; sourceTree = "<group>"; };
F7F406062C136E71000DCDAD /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Package.swift; sourceTree = "<group>"; };
F7F406072C136F09000DCDAD /* FuegoCBridge */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = FuegoCBridge; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
F7A406062C13418E008FBC77 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F7F406092C136F1E000DCDAD /* FuegoCBridge in Frameworks */,
F7A4061D2C134233008FBC77 /* Fuego.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -114,6 +118,7 @@
F7A4060B2C13418E008FBC77 /* FuegoTestApp */ = {
isa = PBXGroup;
children = (
F7F406072C136F09000DCDAD /* FuegoCBridge */,
F71F4F0F2C135C7400B5D0FE /* FuegoOnAppleSilicon */,
F7A4060C2C13418E008FBC77 /* FuegoTestAppApp.swift */,
F7A4060E2C13418E008FBC77 /* ContentView.swift */,
Expand All @@ -136,6 +141,7 @@
F7A4061B2C134233008FBC77 /* Frameworks */ = {
isa = PBXGroup;
children = (
F7F406062C136E71000DCDAD /* Package.swift */,
F7A406422C134536008FBC77 /* libc++.tbd */,
F7A4061C2C134233008FBC77 /* Fuego.xcframework */,
);
Expand All @@ -159,6 +165,9 @@
dependencies = (
);
name = FuegoTestApp;
packageProductDependencies = (
F7F406082C136F1E000DCDAD /* FuegoCBridge */,
);
productName = FuegoTestApp;
productReference = F7A406092C13418E008FBC77 /* FuegoTestApp.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -344,13 +353,17 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = FuegoTestApp/FuegoTestApp.entitlements;
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"FuegoTestApp/Preview Content\"";
DEVELOPMENT_TEAM = 8ZRM3D7KC6;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 8ZRM3D7KC6;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = FuegoTestApp;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
Expand All @@ -368,6 +381,7 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = mesqueeb.FuegoTestApp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
Expand All @@ -384,13 +398,16 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = FuegoTestApp/FuegoTestApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"FuegoTestApp/Preview Content\"";
DEVELOPMENT_TEAM = 8ZRM3D7KC6;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = FuegoTestApp;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
Expand All @@ -408,6 +425,7 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = mesqueeb.FuegoTestApp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
Expand Down Expand Up @@ -440,6 +458,13 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
F7F406082C136F1E000DCDAD /* FuegoCBridge */ = {
isa = XCSwiftPackageProductDependency;
productName = FuegoCBridge;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = F7A406012C13418E008FBC77 /* Project object */;
}
93 changes: 57 additions & 36 deletions xcode/FuegoTestApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ let testCommands = [
"clear_board",
"komi 6.5",
"play b D4",
"showboard",
"genmove w",
"showboard",
"play b E4",
"showboard",
"genmove w",
"showboard",
// "set_free_handicap d16 q16 d4 q4",
// "genmove w"
]
Expand All @@ -20,7 +24,7 @@ struct ContentView: View {
@State private var fuegoError: String = ""

@State var fuegoBridge: FuegoBridge? = nil

init() {
guard let bundleBookUrl = Bundle.main.url(forResource: "book", withExtension: "dat") else {
fatalError("can't retrieve bundle path")
Expand All @@ -32,6 +36,27 @@ struct ContentView: View {
fatalError("can't set book directory directory")
}
}

func startEngine() async {
if fuegoBridge == nil {
fuegoBridge = FuegoBridge()
print("AI connecting...")
do {
try await fuegoBridge!.startEngine()
print("AI connected")
} catch {
print("AI didn't connect, error: \(error)")
fuegoError = "\(error)"
}
}
}

func stopEngine() async {
print("stopping AI")
await fuegoBridge?.stopEngine()
fuegoBridge = nil
print("stopped AI")
}

func handleResponse(_ response: String) {
print("response →", response)
Expand Down Expand Up @@ -65,44 +90,40 @@ struct ContentView: View {

var body: some View {
VStack(spacing: 16) {
TextField("Enter text here", text: $inputText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button("Submit") { submitCommand() }
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(10)

VStack {
ForEach(sentCommands, id: \.self) { command in
Text(command).font(.caption)
}
}

Text("Fuego Response: \(fuegoResponse)")

Text("Error: \(fuegoError)")
}
.padding()
.task {
if fuegoBridge == nil {
fuegoBridge = FuegoBridge()
print("AI connecting...")
do {
try await fuegoBridge!.startEngine()
print("AI connected")
} catch {
print("AI didn't connect, error: \(error)")
fuegoError = "\(error)"
}
Button("Start Engine") { Task { await startEngine() } }
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(10)
}
}
.onDisappear {
Task {
await fuegoBridge?.stopEngine()

if fuegoBridge != nil {
TextField("Enter text here", text: $inputText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button("Submit") { submitCommand() }
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(10)

VStack {
ForEach(sentCommands, id: \.self) { command in
Text(command).font(.caption)
}
}

Text("Fuego Response: \(fuegoResponse)")

Text("Error: \(fuegoError)")

Button("Stop Engine") { Task { await stopEngine() } }
.padding()
}
}
.padding()
.onDisappear { Task { await stopEngine() }}
}
}
8 changes: 8 additions & 0 deletions xcode/FuegoTestApp/FuegoCBridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
26 changes: 26 additions & 0 deletions xcode/FuegoTestApp/FuegoCBridge/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

/// This package is a stub. It's created just so when referencing the source code of the `FuegoOnAppleSilicon` folder
/// In the FuegoTestApp, that it will compile because otherwise it complains about not finding FuegoCBridge.
///
/// With FuegoTestApp we can develop the source code of `FuegoOnAppleSilicon` live without needing to redeploy.
let package = Package(
name: "FuegoCBridge",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "FuegoCBridge",
targets: ["FuegoCBridge"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "FuegoCBridge"),
.testTarget(
name: "FuegoCBridgeTests",
dependencies: ["FuegoCBridge"]),
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
@testable import FuegoCBridge

final class FuegoCBridgeTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}

0 comments on commit 030b807

Please sign in to comment.