mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: handle legacy cron swift path
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { MACOS_APP_SOURCES_DIR } from "../compat/legacy-names.js";
|
||||
import { LEGACY_MACOS_APP_SOURCES_DIR, MACOS_APP_SOURCES_DIR } from "../compat/legacy-names.js";
|
||||
import { CronPayloadSchema } from "../gateway/protocol/schema.js";
|
||||
|
||||
type SchemaLike = {
|
||||
@@ -30,7 +30,26 @@ function extractCronChannels(schema: SchemaLike): string[] {
|
||||
|
||||
const UI_FILES = ["ui/src/ui/types.ts", "ui/src/ui/ui-types.ts", "ui/src/ui/views/cron.ts"];
|
||||
|
||||
const SWIFT_FILES = [`${MACOS_APP_SOURCES_DIR}/GatewayConnection.swift`];
|
||||
const SWIFT_FILE_CANDIDATES = [
|
||||
`${MACOS_APP_SOURCES_DIR}/GatewayConnection.swift`,
|
||||
`${LEGACY_MACOS_APP_SOURCES_DIR}/GatewayConnection.swift`,
|
||||
];
|
||||
|
||||
async function resolveSwiftFiles(cwd: string): Promise<string[]> {
|
||||
const matches: string[] = [];
|
||||
for (const relPath of SWIFT_FILE_CANDIDATES) {
|
||||
try {
|
||||
await fs.access(path.join(cwd, relPath));
|
||||
matches.push(relPath);
|
||||
} catch {
|
||||
// ignore missing path
|
||||
}
|
||||
}
|
||||
if (matches.length === 0) {
|
||||
throw new Error(`Missing Swift cron definition. Tried: ${SWIFT_FILE_CANDIDATES.join(", ")}`);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
describe("cron protocol conformance", () => {
|
||||
it("ui + swift include all cron providers from gateway schema", async () => {
|
||||
@@ -45,7 +64,8 @@ describe("cron protocol conformance", () => {
|
||||
}
|
||||
}
|
||||
|
||||
for (const relPath of SWIFT_FILES) {
|
||||
const swiftFiles = await resolveSwiftFiles(cwd);
|
||||
for (const relPath of swiftFiles) {
|
||||
const content = await fs.readFile(path.join(cwd, relPath), "utf-8");
|
||||
for (const channel of channels) {
|
||||
const pattern = new RegExp(`\\bcase\\s+${channel}\\b`);
|
||||
@@ -61,7 +81,8 @@ describe("cron protocol conformance", () => {
|
||||
expect(uiTypes.includes("jobs:")).toBe(true);
|
||||
expect(uiTypes.includes("jobCount")).toBe(false);
|
||||
|
||||
const swiftPath = path.join(cwd, SWIFT_FILES[0]);
|
||||
const [swiftRelPath] = await resolveSwiftFiles(cwd);
|
||||
const swiftPath = path.join(cwd, swiftRelPath);
|
||||
const swift = await fs.readFile(swiftPath, "utf-8");
|
||||
expect(swift.includes("struct CronSchedulerStatus")).toBe(true);
|
||||
expect(swift.includes("let jobs:")).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user