Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ writes.

## Status

Phase 3 is implemented in source. The repository contains
Phase 4 is implemented in source. The repository contains
`@pegma/scheduler` (contracts, durable runner), `@pegma/scheduler-cloudflare`
(explicit Cron Trigger dispatch), Memory Store / Azurite / local D1 tests, and
design documentation. No package has been published.
(explicit Cron Trigger dispatch), independent consumer fixtures under
`fixtures/`, Memory Store / Azurite / local D1 tests, and design documentation.
No package has been published.

The first consumers are:

Expand All @@ -25,8 +26,8 @@ The first consumers are:

| Package | Status | Responsibility |
| ----------------------------- | -------------- | ------------------------------------------- |
| `@pegma/scheduler` | Phase 3 source | Contracts, durable task state, and runner |
| `@pegma/scheduler-cloudflare` | Phase 3 source | Thin explicit Cron Trigger dispatch adapter |
| `@pegma/scheduler` | Phase 4 source | Contracts, durable task state, and runner |
| `@pegma/scheduler-cloudflare` | Phase 4 source | Thin explicit Cron Trigger dispatch adapter |

## Development

Expand All @@ -40,4 +41,7 @@ npm run test:node
npm run test:d1
```

Consumer fixtures (Ops Hub, Support Desk, Azure Functions shapes) live under
[fixtures/](fixtures/) and run as part of `npm test`.

See [docs/PROJECT_PLAN.md](docs/PROJECT_PLAN.md) for the delivery sequence.
5 changes: 3 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ into the core invocation contract and routes `controller.cron` through an
explicit host-supplied map. It does not own D1, Wrangler configuration, or
task discovery.

Azure begins as a tested composition example. A package is justified only
after repeated adapter behavior appears in a second Azure consumer.
Azure begins as a tested composition example under
`fixtures/azure-functions`. A package is justified only after repeated adapter
behavior appears in a second Azure consumer.

## Static task registry

Expand Down
6 changes: 4 additions & 2 deletions docs/CLOUDFLARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ survive restarts. Do not treat Memory Store as durability evidence.
2. Adapter unit tests construct scheduled controller inputs without a network.
3. Cloudflare Vitest pool tests run against real local D1
(`packages/scheduler-cloudflare/src/fixture.d1.test.ts`).
4. A green Ops Hub fixture (Phase 4) proves Docker volume and repeated trigger
behavior.
4. The Ops Hub-shaped fixture under `fixtures/ops-hub` proves Cron route
composition and scheduled work against Memory Store. Docker volume
durability and repeated `/__scheduled` triggers remain host/Worker concerns
once Ops Hub is more than bootstrap.

Run the D1 suite alone:

Expand Down
6 changes: 4 additions & 2 deletions docs/CONSUMER_REQUIREMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@ Both consumers need:
- manual/local invocation;
- safe operational telemetry.

This closes requirements Phase 0. It does not claim the integration phase is
complete: both consumer fixtures must still compile and run before release.
This closes requirements Phase 0. Phase 4 consumer fixtures under `fixtures/`
compile against exact workspace package pins and prove real scheduled work for
the Ops Hub and Support Desk task shapes. Full host applications still pin the
first advertised release after Phase 5 publishes.
14 changes: 11 additions & 3 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Status

**Stage:** Phases 0–3 are complete in source (contracts, durable runner, and
Cloudflare Cron Trigger adapter with local D1 tests). No package is published
**Stage:** Phases 0–4 are complete in source (contracts, durable runner,
Cloudflare adapter, and independent consumer fixtures). No package is published
or production-usable.

**Trigger:** Ops Hub and Support Desk independently need the same explicit,
Expand Down Expand Up @@ -91,7 +91,7 @@ tests pass against Memory Store and Azurite.
**Exit criterion:** a synthetic Worker fixture survives restart, repeated
events, overlap, and a complete checkpoint cycle against persistent local D1.

### Phase 4 — consumer integration
### Phase 4 — consumer integration (complete)

- Compose Ops Hub health probing and GitHub synchronization.
- Compose Support Desk mail send/reconciliation/retention and queue repair.
Expand All @@ -102,6 +102,14 @@ events, overlap, and a complete checkpoint cycle against persistent local D1.
**Exit criterion:** both independent consumers compile against exact package
pins and their integration tests prove real scheduled work.

**Phase 4 evidence:** workspace packages under `fixtures/*` each declare exact
dependency pins in their own `package.json` (`@pegma/scheduler@0.0.0`; Ops Hub
also pins `@pegma/scheduler-cloudflare@0.0.0`) and prove scheduled work with
independent task state. Ops Hub remains bootstrap-only as a host application;
the fixture is the integration bar until that host lands Worker phases.
Support Desk domain packages stay outside this repository; the fixture mirrors
`HOST_COMPOSITION.md` loop names without inventing per-bucket tasks.

### Phase 5 — first advertised release

- Complete focused security review and package inventory verification.
Expand Down
4 changes: 3 additions & 1 deletion docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Before adding release automation:

1. Complete the Phase 2 runner and adversarial tests.
2. Complete real Azurite and D1 verification.
3. Complete Ops Hub and Support Desk consumer fixtures.
3. Complete Ops Hub and Support Desk consumer fixtures
(`fixtures/ops-hub`, `fixtures/support-desk`, plus Azure reference under
`fixtures/azure-functions`).
4. Complete a focused security review.
5. Refresh exact Pegma dependency pins from `https://pegma.dev/catalog.json`.

Expand Down
16 changes: 12 additions & 4 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,20 @@ Real local D1 tests (`npm run test:d1`) through
- concurrent claim fencing on the same task;
- `waitUntil` wiring on the execution context.

## Phase 4 consumer fixture coverage

Independent fixtures under `fixtures/` pin workspace package versions and prove:

- Ops Hub: health + GitHub routes, independent checkpoints, live-lease overlap;
- Support Desk: five direct loops, independent checkpoints, no dynamic
receipt-bucket tasks, failure retains checkpoints without secrets;
- Azure Functions: timer entry point, checkpoint cycle, stale redelivery.

## Adapter and consumer matrix

Before publication, also run:
Before publication, also run full host applications when they exist:

- an Ops Hub health and GitHub-sync fixture (Phase 4);
- Support Desk mail-send, reconciliation, terminal sweep, queue repair, and
inactive-sweep fixtures (Phase 4).
- Ops Hub Worker + Docker volume story (host still bootstrap-only);
- Support Desk production host wiring after `@pegma/scheduler@0.1.0` publishes.

Memory tests are never a production durability claim.
21 changes: 21 additions & 0 deletions fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Consumer fixtures

Independent host compositions that declare exact dependency pins in each
fixture `package.json` (`@pegma/scheduler@0.0.0`, and for Ops Hub also
`@pegma/scheduler-cloudflare@0.0.0`) against the monorepo workspaces and prove
real scheduled work before any npm publish.

These fixtures are the Phase 4 integration bar described in
`docs/RELEASING.md`. They deliberately do **not** import Ops Hub or Support
Desk application packages: Ops Hub is still bootstrap-only, and Support Desk
domain APIs stay outside this repository. Each fixture mirrors the host task
names and bounded-page shapes documented in those consumers.

| Fixture | Mirrors |
| ----------------- | ------------------------------------------------------------- |
| `ops-hub` | Health probes + GitHub org sync on Cloudflare Cron routes |
| `support-desk` | Mail send/reconcile/sweep + queue repair/inactive-sweep loops |
| `azure-functions` | Timer-trigger composition for a RetireGolden-style Azure host |

Run with the repository gate (`npm test`). External consumers should pin the
first advertised release (`0.1.0`) after Phase 5 publishes.
41 changes: 41 additions & 0 deletions fixtures/azure-functions/composition.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";

import {
createAzureFunctionsComposition,
createFakeAzureDomain,
} from "./composition.js";

const T0 = "2026-07-31T12:00:00.000Z";
const T1 = "2026-07-31T13:00:00.000Z";

describe("azure-functions consumer fixture", () => {
it("runs a timer occurrence and advances the projection checkpoint", async () => {
const domain = createFakeAzureDomain();
const composition = createAzureFunctionsComposition({ domain });

const first = await composition.onTimer(T0);
expect(first.outcome).toBe("succeeded");
if (first.outcome === "succeeded") {
expect(first.state.checkpoint).toBe("proj:25");
}

const second = await composition.onTimer(T1);
expect(second.outcome).toBe("succeeded");
if (second.outcome === "succeeded") {
expect(second.state.checkpoint).toBeUndefined();
expect(second.state.lastScheduledFor).toBe(T1);
}

expect(domain.refreshes).toBe(2);
});

it("suppresses a stale timer redelivery", async () => {
const composition = createAzureFunctionsComposition();
await composition.onTimer(T1);
const stale = await composition.onTimer(T0);
expect(stale).toMatchObject({
outcome: "skipped",
reason: "stale_occurrence",
});
});
});
105 changes: 105 additions & 0 deletions fixtures/azure-functions/composition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* RetireGolden-shaped Azure Functions timer composition fixture.
*
* Azure owns the timer trigger wakeup. This fixture shows how a host would
* call createScheduler.runScheduled from a timer function without a dedicated
* Azure adapter package (none is justified until a second Azure consumer
* appears — see docs/ARCHITECTURE.md).
*/
import {
createScheduler,
defineScheduledTasks,
type Scheduler,
type SchedulerRunResult,
} from "@pegma/scheduler";
import {
fixedClock,
noopLogger,
type Clock,
type IsoTimestamp,
} from "@pegma/spine";
import { createMemoryStore, type Store } from "@pegma/storage-core";

export interface AzureTimerDomain {
refreshProjection(input: {
readonly cursor?: string;
}): Promise<{ readonly nextCursor: string | null; readonly rows: number }>;
}

export interface AzureTimerComposition {
readonly store: Store;
readonly scheduler: Scheduler<{
"retiregolden.projection.refresh": (
context: import("@pegma/scheduler").ScheduledTaskContext,
) => Promise<import("@pegma/scheduler").ScheduledTaskResult>;
}>;
/**
* Host timer entry point. `scheduledFor` is the trusted occurrence time the
* Azure Functions host supplies (not provider time).
*/
onTimer(scheduledFor: IsoTimestamp): Promise<SchedulerRunResult>;
}

export function createFakeAzureDomain(): AzureTimerDomain & {
readonly refreshes: number;
} {
let refreshes = 0;
return {
get refreshes() {
return refreshes;
},
async refreshProjection({ cursor }) {
refreshes += 1;
if (cursor === undefined) {
return { rows: 25, nextCursor: "proj:25" };
}
return { rows: 10, nextCursor: null };
},
};
}

export function createAzureFunctionsComposition(options?: {
readonly store?: Store;
readonly clock?: Clock;
readonly workerId?: string;
readonly domain?: AzureTimerDomain;
}): AzureTimerComposition {
const store = options?.store ?? createMemoryStore();
const clock = options?.clock ?? fixedClock("2026-07-31T12:00:00.000Z");
const domain = options?.domain ?? createFakeAzureDomain();

const tasks = defineScheduledTasks({
"retiregolden.projection.refresh": async ({ checkpoint }) => {
const page = await domain.refreshProjection({
...(checkpoint === undefined ? {} : { cursor: checkpoint }),
});
return {
nextCheckpoint: page.nextCursor,
summary: { rows: page.rows },
more: page.nextCursor !== null,
};
},
});

const scheduler = createScheduler({
store,
clock,
logger: noopLogger,
instanceId: "retiregolden-azure",
workerId: options?.workerId ?? "azure-func-instance",
tasks,
leaseMilliseconds: 60_000,
handlerTimeoutMilliseconds: 55_000,
});

return {
store,
scheduler,
onTimer(scheduledFor) {
return scheduler.runScheduled("retiregolden.projection.refresh", {
scheduledFor,
invocationId: `timer:${scheduledFor}`,
});
},
};
}
12 changes: 12 additions & 0 deletions fixtures/azure-functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@pegma/fixture-azure-functions",
"version": "0.0.0",
"private": true,
"description": "Azure Functions timer composition fixture for @pegma/scheduler.",
"type": "module",
"dependencies": {
"@pegma/scheduler": "0.0.0",
"@pegma/spine": "0.1.2",
"@pegma/storage-core": "0.4.0"
}
}
Loading