feat(controlplane): serve the step vocabulary in the workflow-definitions schema; the editor checks step types against it
This commit is contained in:
1 parent
c885eb5bec
commit
a5279bb187
8 files changed
+98
-28
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, onScopeDispose, reactive, ref, watch } from "vue";
|
||||
import { useLiveUpdatesStore } from "./live-updates.ts";
|
||||
import type { StepTypeInfo } from "../workflows/workflow-yaml.ts";
|
||||
|
||||
import { diffValues, saveInOrder, type Change } from "../settings/changes.ts";
|
||||
import {
|
||||
@@ -486,7 +487,21 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** The registered workflow step types, served in the definitions schema. */
|
||||
function stepTypes(): StepTypeInfo[] {
|
||||
const schema = catalog.value.find(
|
||||
(resource) => resource.kind === "workflow-definitions",
|
||||
)?.schema_json;
|
||||
if (!schema) return [];
|
||||
try {
|
||||
return (JSON.parse(schema)["x-step-types"] ?? []) as StepTypeInfo[];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stepTypes,
|
||||
applyStatusFor,
|
||||
changesFor,
|
||||
changeFor,
|
||||
|
||||
@@ -99,12 +99,12 @@ async function restoreOne(): Promise<void> {
|
||||
);
|
||||
}
|
||||
|
||||
// What is typed, read by the rules this page can answer (workflow-yaml.ts). The
|
||||
// Steps preview, the gutter and the validity indicator are three readings of
|
||||
// one parse, so they cannot disagree about the same text. The server remains
|
||||
// the authority: step types and their settings are not served to the dashboard,
|
||||
// so a save it refuses still reports its own reason below.
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value));
|
||||
// What is typed, read against the served step vocabulary (workflow-yaml.ts).
|
||||
// The Steps preview, the gutter and the validity indicator are three readings
|
||||
// of one parse, so they cannot disagree about the same text. Step settings are
|
||||
// not served, so a save the server refuses still reports its own reason below.
|
||||
const vocabulary = computed(() => store.stepTypes());
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value));
|
||||
const steps = computed(() => (parsed.value.ok ? parsed.value.steps : []));
|
||||
const lines = computed(() => yamlLines(yaml.value));
|
||||
|
||||
@@ -153,9 +153,7 @@ function syncScroll(event: Event): void {
|
||||
<div class="space-y-1.5">
|
||||
<div class="flex items-baseline gap-2">
|
||||
<Label for="workflow-yaml">YAML</Label>
|
||||
<!-- What the page can check: the YAML parses, it carries an id, and it
|
||||
names at least one step with a type. Step types and settings are
|
||||
the server's to check, on save. -->
|
||||
<!-- Step settings are the server's to check, on save. -->
|
||||
<span
|
||||
class="ml-auto text-xs"
|
||||
:class="parsed.ok ? 'text-ok' : 'text-danger'"
|
||||
@@ -212,6 +210,17 @@ function syncScroll(event: Event): void {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<details v-if="vocabulary.length" class="text-sm">
|
||||
<summary class="cursor-pointer text-fg-subtle">Step types ({{ vocabulary.length }})</summary>
|
||||
<ul class="mt-2 flex flex-wrap gap-1.5" aria-label="Step types">
|
||||
<li
|
||||
v-for="info in vocabulary"
|
||||
:key="info.name"
|
||||
class="rounded border border-border bg-secondary px-2 py-0.5 font-mono text-xs"
|
||||
:title="info.needs_repository ? 'Needs a repository' : 'Runs without a repository'"
|
||||
>{{ info.name }}<span v-if="!info.needs_repository" class="text-fg-subtle"> · no repo</span></li>
|
||||
</ul>
|
||||
</details>
|
||||
<p v-if="localError || state.error" class="text-sm text-danger" role="alert">
|
||||
{{ localError || state.error }}
|
||||
</p>
|
||||
|
||||
@@ -3,17 +3,20 @@ import { parseDocument } from "yaml";
|
||||
/**
|
||||
* The workflow YAML editor's reading of what is typed.
|
||||
*
|
||||
* The server is the authority on a definition: `workflow.ParseDefinition`
|
||||
* parses with known fields, requires an id and at least one step, and checks
|
||||
* every step type against its registry and every step's settings against that
|
||||
* type's own rules. The registry is not served to the dashboard, so this module
|
||||
* answers the part the page can answer without inventing a second vocabulary:
|
||||
* does the YAML parse, does it carry an id, and does it name at least one step
|
||||
* that has a type. "Valid" here means exactly those three things -- a save the
|
||||
* server refuses still reports the server's own reason, and that path is
|
||||
* unchanged.
|
||||
* The server is the authority on a definition. The page checks what it can
|
||||
* from the served step vocabulary: the YAML parses, carries an id, names at
|
||||
* least one step, every step type is registered, and a workflow whose
|
||||
* repository is not required uses only steps that run without one. Step
|
||||
* settings stay the server's to check, so a save it refuses still reports the
|
||||
* server's own reason.
|
||||
*/
|
||||
|
||||
/** One registered step type, as the control-plane catalog serves it. */
|
||||
export interface StepTypeInfo {
|
||||
name: string;
|
||||
needs_repository: boolean;
|
||||
}
|
||||
|
||||
/** One chip in the read-only Steps preview. */
|
||||
export interface WorkflowStepChip {
|
||||
/** 1-based, the position the server's own errors use. */
|
||||
@@ -31,7 +34,10 @@ export function validationLabel(parsed: WorkflowParse): string {
|
||||
return parsed.line ? `Line ${parsed.line}: ${parsed.message}` : parsed.message;
|
||||
}
|
||||
|
||||
export function parseWorkflowYaml(source: string): WorkflowParse {
|
||||
export function parseWorkflowYaml(
|
||||
source: string,
|
||||
vocabulary: StepTypeInfo[] = [],
|
||||
): WorkflowParse {
|
||||
const document = parseDocument(source);
|
||||
const problem = document.errors[0];
|
||||
if (problem) {
|
||||
@@ -58,6 +64,11 @@ export function parseWorkflowYaml(source: string): WorkflowParse {
|
||||
if (!steps.length)
|
||||
return { ok: false, message: `workflow ${id} has no steps` };
|
||||
|
||||
const known = new Map(vocabulary.map((info) => [info.name, info]));
|
||||
const repository =
|
||||
typeof value.repository === "string" && value.repository.trim()
|
||||
? value.repository.trim()
|
||||
: "required";
|
||||
const chips: WorkflowStepChip[] = [];
|
||||
for (const [i, step] of steps.entries()) {
|
||||
if (!isMapping(step) || !isNonEmptyString(step.type)) {
|
||||
@@ -66,7 +77,21 @@ export function parseWorkflowYaml(source: string): WorkflowParse {
|
||||
message: `workflow ${id} step ${i + 1} needs a type`,
|
||||
};
|
||||
}
|
||||
chips.push({ index: i + 1, type: step.type.trim() });
|
||||
const type = step.type.trim();
|
||||
const info = known.get(type);
|
||||
if (known.size && !info) {
|
||||
return {
|
||||
ok: false,
|
||||
message: `workflow ${id} step ${i + 1}: unknown step type "${type}"`,
|
||||
};
|
||||
}
|
||||
if (info?.needs_repository && repository !== "required") {
|
||||
return {
|
||||
ok: false,
|
||||
message: `workflow ${id} step ${i + 1}: "${type}" needs a repository, but the workflow's repository is ${repository}`,
|
||||
};
|
||||
}
|
||||
chips.push({ index: i + 1, type });
|
||||
}
|
||||
return { ok: true, id, steps: chips };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user