fix(tsgo): align cron contract and secrets test helper

This commit is contained in:
Vincent Koc
2026-04-12 03:57:46 +01:00
parent 90db90fdc5
commit 7204d490aa
3 changed files with 18 additions and 6 deletions

View File

@@ -37,6 +37,8 @@ export type CronListPageResult = {
export type CronWakeResult = { ok: true } | { ok: false };
export type CronServiceRunResult = CronRunResult | { ok: true; ran: false; reason: "invalid-spec" };
export interface CronServiceContract {
start(): Promise<void>;
stop(): void;
@@ -46,8 +48,8 @@ export interface CronServiceContract {
add(input: CronAddInput): Promise<CronAddResult>;
update(id: string, patch: CronUpdateInput): Promise<CronUpdateResult>;
remove(id: string): Promise<CronRemoveResult>;
run(id: string, mode?: CronRunMode): Promise<CronRunResult>;
enqueueRun(id: string, mode?: CronRunMode): Promise<CronRunResult>;
run(id: string, mode?: CronRunMode): Promise<CronServiceRunResult>;
enqueueRun(id: string, mode?: CronRunMode): Promise<CronServiceRunResult>;
getJob(id: string): CronJob | undefined;
wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult;
}

View File

@@ -1,4 +1,8 @@
import type { CronListPageOptions, CronServiceContract } from "./service-contract.js";
import type {
CronListPageOptions,
CronServiceContract,
CronServiceRunResult,
} from "./service-contract.js";
import * as ops from "./service/ops.js";
import { type CronServiceDeps, createCronServiceState } from "./service/state.js";
import type { CronJob, CronJobCreate, CronJobPatch } from "./types.js";
@@ -8,6 +12,7 @@ export type {
CronListPageOptions,
CronListPageResult,
CronServiceContract,
CronServiceRunResult,
CronWakeResult,
} from "./service-contract.js";
@@ -49,12 +54,16 @@ export class CronService implements CronServiceContract {
return await ops.remove(this.state, id);
}
async run(id: string, mode?: "due" | "force") {
async run(id: string, mode?: "due" | "force"): Promise<CronServiceRunResult> {
return await ops.run(this.state, id, mode);
}
async enqueueRun(id: string, mode?: "due" | "force") {
return await ops.enqueueRun(this.state, id, mode);
async enqueueRun(id: string, mode?: "due" | "force"): Promise<CronServiceRunResult> {
const result = await ops.enqueueRun(this.state, id, mode);
if (result.ok && "runnable" in result) {
throw new Error("cron enqueueRun returned unresolved runnable disposition");
}
return result;
}
getJob(id: string): CronJob | undefined {

View File

@@ -11,6 +11,7 @@ import {
} from "./runtime.js";
import {
asConfig,
buildTestWebSearchProviders,
loadAuthStoreWithProfiles,
resetPluginWebSearchProvidersMock,
} from "./runtime.test-support.ts";