This commit is contained in:
Eva Ho 2026-04-22 15:00:09 -04:00
parent 001f50e117
commit eb48bee816
5 changed files with 134 additions and 18 deletions

View file

@ -6,6 +6,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
)
@ -16,20 +17,46 @@ type appLaunchIntegration struct {
func loadAppLaunchManifest(t *testing.T) []appLaunchIntegration {
t.Helper()
path := filepath.Join("..", "ui", "app", "src", "data", "launch-integrations.json")
path := filepath.Join("..", "ui", "app", "src", "data", "launch-integrations.ts")
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read app launch manifest: %v", err)
}
jsonData := extractJSONArray(t, string(data))
var manifest []appLaunchIntegration
if err := json.Unmarshal(data, &manifest); err != nil {
if err := json.Unmarshal([]byte(jsonData), &manifest); err != nil {
t.Fatalf("parse app launch manifest: %v", err)
}
return manifest
}
func extractJSONArray(t *testing.T, src string) string {
t.Helper()
assign := strings.Index(src, "= [")
if assign == -1 {
t.Fatal("launch manifest assignment not found")
}
start := strings.Index(src[assign:], "[")
end := strings.Index(src[assign:], "] satisfies")
if end != -1 {
end += assign
} else {
end = strings.LastIndex(src, "]")
}
if start == -1 || end == -1 || end < start {
t.Fatal("launch manifest array not found")
}
start += assign
return src[start : end+1]
}
func TestStore(t *testing.T) {
s, cleanup := setupTestStore(t)
defer cleanup()

View file

@ -1,19 +1,10 @@
import CopyButton from "@/components/CopyButton";
import launchIntegrations, { type LaunchIntegration } from "@/data/launch-integrations";
import { useSettings } from "@/hooks/useSettings";
import launchIntegrations from "@/data/launch-integrations.json";
interface LaunchCommand {
id: string;
name: string;
command: string;
description: string;
icon?: string;
darkIcon?: string;
iconClassName?: string;
}
const LAUNCH_COMMANDS: LaunchCommand[] = launchIntegrations;
const LAUNCH_COMMANDS: LaunchIntegration[] = launchIntegrations;
function LaunchIcon({ item }: { item: LaunchCommand }) {
function LaunchIcon({ item }: { item: LaunchIntegration }) {
if (item.icon) {
if (item.darkIcon) {
return (
@ -47,7 +38,7 @@ export default function LaunchCommands() {
const isWindows = navigator.platform.toLowerCase().includes("win");
const { setSettings } = useSettings();
const renderCommandCard = (item: LaunchCommand) => (
const renderCommandCard = (item: LaunchIntegration) => (
<div key={item.command} className="w-full text-left">
<div className="flex items-start gap-4 sm:gap-5">
<div

View file

@ -1,4 +1,14 @@
[
export interface LaunchIntegration {
id: string;
name: string;
command: string;
description: string;
icon?: string;
darkIcon?: string;
iconClassName?: string;
}
const launchIntegrations = [
{
"id": "openclaw",
"name": "OpenClaw",
@ -63,4 +73,6 @@
"darkIcon": "/launch-icons/pi-dark.svg",
"iconClassName": "h-7 w-7"
}
]
] satisfies LaunchIntegration[];
export default launchIntegrations;

View file

@ -11,7 +11,6 @@
/* Bundler mode */
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",

View file

@ -0,0 +1,87 @@
package launch
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
)
type appLaunchIntegration struct {
ID string `json:"id"`
Name string `json:"name"`
Command string `json:"command"`
Description string `json:"description"`
}
func loadAppLaunchManifest(t *testing.T) []appLaunchIntegration {
t.Helper()
path := filepath.Join("..", "..", "app", "ui", "app", "src", "data", "launch-integrations.ts")
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read app launch manifest: %v", err)
}
jsonData := extractJSONArray(t, string(data))
var manifest []appLaunchIntegration
if err := json.Unmarshal([]byte(jsonData), &manifest); err != nil {
t.Fatalf("parse app launch manifest: %v", err)
}
return manifest
}
func extractJSONArray(t *testing.T, src string) string {
t.Helper()
assign := strings.Index(src, "= [")
if assign == -1 {
t.Fatal("launch manifest assignment not found")
}
start := strings.Index(src[assign:], "[")
end := strings.Index(src[assign:], "] satisfies")
if end != -1 {
end += assign
} else {
end = strings.LastIndex(src, "]")
}
if start == -1 || end == -1 || end < start {
t.Fatal("launch manifest array not found")
}
start += assign
return src[start : end+1]
}
func TestAppLaunchManifestMatchesLauncherRegistry(t *testing.T) {
manifest := loadAppLaunchManifest(t)
infos := ListIntegrationInfos()
if len(manifest) != len(infos) {
t.Fatalf("manifest integration count = %d, want %d", len(manifest), len(infos))
}
for i, info := range infos {
entry := manifest[i]
if entry.ID != info.Name {
t.Fatalf("manifest[%d].id = %q, want %q", i, entry.ID, info.Name)
}
if entry.Name != info.DisplayName {
t.Fatalf("manifest[%d].name = %q, want %q", i, entry.Name, info.DisplayName)
}
if entry.Description != info.Description {
t.Fatalf("manifest[%d].description = %q, want %q", i, entry.Description, info.Description)
}
wantCommand := "ollama launch " + info.Name
if entry.Command != wantCommand {
t.Fatalf("manifest[%d].command = %q, want %q", i, entry.Command, wantCommand)
}
}
}