Public: anyone can read this; the crew can change it.

The app template's README shows how to declare a schedule in forge.json, and the example is tested #16152

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/16140-the-app-template-s-readme-shows-how-to-d → main 0 commits fork 1 thread · 1 unresolved

  • Merged. torque/16140-the-app-template-s-readme-shows-how-to-d was merged into main as 49b37fe.

Review

Sign in to review this change.
2 files changed +37 −1
templates/app-template.json +1 −1

Diff not shown — a line 15,877 characters wide (limit 2,000). +1 −1

View file
test/template-schedule-example.test.ts added +36
@@ -0,0 +1,36 @@
1 /**
2 * The schedules example in the app template's README is a real forge.json fragment: wrapped in the
3 * minimal app block it passes the forge's own manifest parser and comes out as the schedule it
4 * shows (#16140).
5 */
6 import { expect, test } from "bun:test";
7 import { readFileSync } from "node:fs";
8 import { parseManifest } from "../src/apps/manifest.ts";
9
10 function example(): string {
11 const bundle = JSON.parse(readFileSync(new URL("../templates/app-template.json", import.meta.url), "utf8")) as {
outdated

This reads docs/APPS.md, so the test passes on main and fails without nothing in this pull. Read the template README (templates/app-template.json, files["README.md"]) instead, once it carries the example.

12 files: Record<string, string>;
13 };
14 const doc = bundle.files["README.md"] ?? "";
15 const at = doc.indexOf("## Schedules");
16 expect(at).toBeGreaterThan(-1);
17 const m = /```json\n([\s\S]*?)```/.exec(doc.slice(at));
18 expect(m).not.toBeNull();
19 return m![1]!;
20 }
21
22 test("the documented schedules example parses with the real manifest validator", () => {
23 const forgeJson = `{ "app": { "run": "bun run src/index.ts" }, ${example().trim()} }`;
24 const r = parseManifest(forgeJson, undefined);
25 expect(r.ok).toBe(true);
26 if (!r.ok) return;
27 const [s] = r.value.schedules ?? [];
28 expect(r.value.schedules?.length).toBe(1);
29 expect(s?.name).toBe("print");
30 expect(s?.path).toBe("/jobs/print");
31 });
32
33 test("a broken example would be refused", () => {
34 const bad = `{ "app": { "run": "x" }, "schedules": [{ "name": "print", "cron": "nope", "path": "/jobs/print" }] }`;
35 expect(parseManifest(bad, undefined).ok).toBe(false);
36 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs