mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-11-29 15:51:52 +00:00
Some checks failed
CI / build (push) Has been cancelled
Deploy to dev2 / deploy (push) Has been cancelled
test / test (push) Has been cancelled
* OpenTask 0.1 + OpenWorkflow 0.1: specs, schemas, fixtures, validators docs/opentask.md mints OpenTask: one task a person does on a computer, written down as meaning (goal, apps, parameters with a sensitivity class and never a value, semantic steps with no coordinates, capture gaps, stop conditions, approvals, a success check, provenance, runners with digests) so an agent can do it again. docs/openworkflow.md mints OpenWorkflow: a collection of OpenTasks inline or by URL + sha256, in sequence or any order respecting after, with a publisher index at /.well-known/openworkflow.json. - @logicsrc/schemas 0.6.0: opentask, openworkflow, openworkflow-index - @logicsrc/validators 0.6.0: step numbering, placeholders, apps, no example on personal/secret parameters, after references Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * logicsrc-web: register OpenTask and OpenWorkflow Registry entries (process family, status 0.1) after OpenErrand, with the family blurb updated; /opentask and /openworkflow landing pages naming w3bs.org/tasks and w3bs.org/workflows as the reference publisher and moshscript (moshcode run) as one runner; the worked examples served under /examples and a logicsrc.com workflow index at /.well-known/openworkflow.json; contract tests holding the pages' lists and the served files against the docs and fixtures, and both specs added to spec discovery. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.8 KiB
TypeScript
106 lines
4.8 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { readDoc } from "../src/lib/docs";
|
|
import { ACTIONS, RULES as TASK_RULES, SENSITIVITY } from "../src/app/opentask/data";
|
|
import { ORDERS, RULES as WORKFLOW_RULES } from "../src/app/openworkflow/data";
|
|
|
|
// The /opentask and /openworkflow landing pages restate the specs' lists, and
|
|
// the site serves the worked examples and a workflow index. These tests keep
|
|
// all of them in step with docs/opentask.md, docs/openworkflow.md and the
|
|
// schema fixtures.
|
|
|
|
const task = readDoc("opentask") ?? "";
|
|
const workflow = readDoc("openworkflow") ?? "";
|
|
const root = resolve(__dirname, "../../..");
|
|
const json = (path: string) => JSON.parse(readFileSync(resolve(root, path), "utf8"));
|
|
|
|
/** The text of a section, from its heading to the next heading of level 2 or 3. */
|
|
function section(doc: string, heading: string): string {
|
|
const start = doc.indexOf(`\n${heading}\n`);
|
|
expect(start, `the doc has a ${heading} section`).toBeGreaterThan(-1);
|
|
const next = doc.slice(start + 1).search(/\n#{2,3} /);
|
|
return doc.slice(start, next === -1 ? undefined : start + 1 + next);
|
|
}
|
|
|
|
/** The bold titles of a numbered rule list, without their closing period. */
|
|
function ruleTitles(doc: string): string[] {
|
|
return [...section(doc, "## Runner rules").matchAll(/^(\d+)\. \*\*(.+?)\.\*\*/gm)].map((m) => m[2]);
|
|
}
|
|
|
|
/** The first JSON block in a section. */
|
|
function firstJson(doc: string, heading: string): unknown {
|
|
const m = section(doc, heading).match(/```json\n([\s\S]*?)\n```/);
|
|
expect(m, `${heading} has a JSON block`).not.toBeNull();
|
|
return JSON.parse(m![1]);
|
|
}
|
|
|
|
describe("OpenTask: the spec, its landing page and its published files agree", () => {
|
|
it("lists the same step actions, in the same order", () => {
|
|
const row = section(task, "## Steps")
|
|
.split("\n")
|
|
.find((line) => line.startsWith("| `action` |"));
|
|
expect(row, "the Steps table has an action row").toBeDefined();
|
|
expect([...row!.split("|")[3].matchAll(/`([^`]+)`/g)].map((m) => m[1])).toEqual([...ACTIONS]);
|
|
});
|
|
|
|
it("lists the same sensitivity classes, in the same order", () => {
|
|
const line = section(task, "## Parameters")
|
|
.split("\n")
|
|
.find((l) => l.startsWith("- `sensitivity`"));
|
|
expect(line).toBeDefined();
|
|
expect([...line!.matchAll(/`(public|personal|secret)`/g)].map((m) => m[1])).toEqual(SENSITIVITY.map(([name]) => name));
|
|
});
|
|
|
|
it("shows the seven runner rules under the spec's own titles", () => {
|
|
expect(TASK_RULES.map(([title]) => title)).toEqual(ruleTitles(task));
|
|
expect(TASK_RULES.length).toBe(7);
|
|
});
|
|
|
|
it("prints the fixture as the worked example, and the site serves the same bytes", () => {
|
|
const fixture = json("packages/schemas/fixtures/opentask/export-a-task-as-moshscript.json");
|
|
expect(firstJson(task, "## Worked example")).toEqual(fixture);
|
|
expect(json("apps/logicsrc-web/public/examples/opentask/export-a-task-as-moshscript.json")).toEqual(fixture);
|
|
});
|
|
|
|
it("has no em dashes", () => {
|
|
expect(task).not.toContain(String.fromCharCode(0x2014));
|
|
});
|
|
});
|
|
|
|
describe("OpenWorkflow: the spec, its landing page and its published files agree", () => {
|
|
it("lists the same orders", () => {
|
|
const row = section(workflow, "## The workflow file")
|
|
.split("\n")
|
|
.find((line) => line.startsWith("| `order` |"));
|
|
expect(row).toBeDefined();
|
|
for (const [name] of ORDERS) expect(row).toContain(`\`${name}\``);
|
|
});
|
|
|
|
it("shows the five runner rules under the spec's own titles", () => {
|
|
expect(WORKFLOW_RULES.map(([title]) => title)).toEqual(ruleTitles(workflow));
|
|
expect(WORKFLOW_RULES.length).toBe(5);
|
|
});
|
|
|
|
it("prints the fixtures as its examples, and the site serves the same bytes", () => {
|
|
const fixture = json("packages/schemas/fixtures/openworkflow/release-a-package.json");
|
|
expect(firstJson(workflow, "## The workflow file")).toEqual(fixture);
|
|
expect(firstJson(workflow, "## The index")).toEqual(json("packages/schemas/fixtures/openworkflow/index.json"));
|
|
expect(json("apps/logicsrc-web/public/examples/openworkflow/release-a-package.json")).toEqual(fixture);
|
|
});
|
|
|
|
it("serves a publisher index that lists the example from this site", () => {
|
|
const index = json("apps/logicsrc-web/public/.well-known/openworkflow.json");
|
|
const fixtureIndex = json("packages/schemas/fixtures/openworkflow/index.json");
|
|
expect(index.type).toBe(fixtureIndex.type);
|
|
expect(index.version).toBe(fixtureIndex.version);
|
|
expect(index.publisher).toBe("https://logicsrc.com");
|
|
expect(index.workflows).toEqual([
|
|
{ ...fixtureIndex.workflows[0], url: "https://logicsrc.com/examples/openworkflow/release-a-package.json" }
|
|
]);
|
|
});
|
|
|
|
it("has no em dashes", () => {
|
|
expect(workflow).not.toContain(String.fromCharCode(0x2014));
|
|
});
|
|
});
|