test: handle legacy cron swift path
This commit is contained in:
parent
8d07955f2c
commit
4aa2f24af3
@ -1,7 +1,7 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
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";
|
import { CronPayloadSchema } from "../gateway/protocol/schema.js";
|
||||||
|
|
||||||
type SchemaLike = {
|
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 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", () => {
|
describe("cron protocol conformance", () => {
|
||||||
it("ui + swift include all cron providers from gateway schema", async () => {
|
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");
|
const content = await fs.readFile(path.join(cwd, relPath), "utf-8");
|
||||||
for (const channel of channels) {
|
for (const channel of channels) {
|
||||||
const pattern = new RegExp(`\\bcase\\s+${channel}\\b`);
|
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("jobs:")).toBe(true);
|
||||||
expect(uiTypes.includes("jobCount")).toBe(false);
|
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");
|
const swift = await fs.readFile(swiftPath, "utf-8");
|
||||||
expect(swift.includes("struct CronSchedulerStatus")).toBe(true);
|
expect(swift.includes("struct CronSchedulerStatus")).toBe(true);
|
||||||
expect(swift.includes("let jobs:")).toBe(true);
|
expect(swift.includes("let jobs:")).toBe(true);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user