mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
fix(cli): point wmill.yaml schema header at an absolute, release-pinned URL (#12367)
`wmill init` wrote `# yaml-language-server: $schema=wmill.schema.json`, a path relative to the user's wmill.yaml where no schema file exists, so the YAML language server loaded nothing. The header now names cli/wmill.schema.json at the CLI's own release tag on raw.githubusercontent.com. The committed schema had drifted since v1.834.0 (it lacked includeDatatablePermissions); regenerate it and add a unit test that fails while it is stale. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9477036c2a
commit
9eb3d2e7d4
@@ -1,3 +1,5 @@
|
||||
import { VERSION } from "../../core/constants.ts";
|
||||
|
||||
/**
|
||||
* Configuration option descriptor — each entry IS a JSON Schema property
|
||||
* with extra metadata for template rendering and reference table display.
|
||||
@@ -10,7 +12,8 @@
|
||||
* Adding a new option:
|
||||
* 1. Add an entry to CONFIG_REFERENCE with JSON Schema type fields + description
|
||||
* 2. Add template rendering hints (section, commented, templateValue, etc.)
|
||||
* 3. `wmill init` (YAML template), `wmill config` (table), and wmill.schema.json all update automatically
|
||||
* 3. `wmill init` (YAML template) and `wmill config` (table) update automatically
|
||||
* 4. Regenerate wmill.schema.json: `bun generate-schema.ts`
|
||||
*/
|
||||
export interface ConfigOption {
|
||||
// --- JSON Schema fields (kept when generating schema) ---
|
||||
@@ -259,10 +262,16 @@ function yamlKey(s: string): string {
|
||||
return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
||||
}
|
||||
|
||||
// Absolute and pinned to this CLI's release tag: nothing copies the schema next
|
||||
// to the user's wmill.yaml (nor into the npm package), and the tag's schema lists
|
||||
// exactly the options this CLI version accepts.
|
||||
export const WMILL_SCHEMA_URL =
|
||||
`https://raw.githubusercontent.com/windmill-labs/windmill/v${VERSION}/cli/wmill.schema.json`;
|
||||
|
||||
export function generateCommentedTemplate(branchName?: string, binding?: BranchBinding, bindings?: WorkspaceBinding[]): string {
|
||||
const branch = yamlKey(branchName ?? "main");
|
||||
const lines: string[] = [
|
||||
"# yaml-language-server: $schema=wmill.schema.json",
|
||||
`# yaml-language-server: $schema=${WMILL_SCHEMA_URL}`,
|
||||
"# wmill.yaml — Windmill CLI configuration",
|
||||
'# Full reference: run "wmill config"',
|
||||
"",
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
*/
|
||||
|
||||
import { expect, test, describe } from "bun:test";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { parse } from "yaml";
|
||||
import Ajv from "ajv";
|
||||
import { VERSION } from "../src/core/constants.ts";
|
||||
import {
|
||||
generateCommentedTemplate,
|
||||
generateJsonSchema,
|
||||
@@ -65,9 +68,13 @@ describe("generateCommentedTemplate", () => {
|
||||
expect(config.workspaces["prod"].workspaceId).toBe("prod-ws");
|
||||
});
|
||||
|
||||
test("contains yaml-language-server schema directive", () => {
|
||||
// The header must be an absolute URL: a relative path resolves next to the
|
||||
// user's wmill.yaml, where no schema file exists.
|
||||
test("first line points the YAML language server at the schema of this CLI's release tag", () => {
|
||||
const yaml = generateCommentedTemplate("main");
|
||||
expect(yaml.startsWith("# yaml-language-server: $schema=wmill.schema.json")).toBe(true);
|
||||
expect(yaml.split("\n")[0]).toBe(
|
||||
`# yaml-language-server: $schema=https://raw.githubusercontent.com/windmill-labs/windmill/v${VERSION}/cli/wmill.schema.json`,
|
||||
);
|
||||
});
|
||||
|
||||
test("includes all non-commented, non-skipped CONFIG_REFERENCE entries as active YAML keys", () => {
|
||||
@@ -105,6 +112,14 @@ describe("generateCommentedTemplate", () => {
|
||||
describe("generateJsonSchema", () => {
|
||||
const schema = generateJsonSchema();
|
||||
|
||||
// wmill.yaml headers fetch cli/wmill.schema.json from the release tag, so the
|
||||
// committed file is what users validate against. Regenerate: `bun generate-schema.ts`.
|
||||
test("matches the committed cli/wmill.schema.json", () => {
|
||||
const committed = readFileSync(join(import.meta.dir, "..", "wmill.schema.json"), "utf-8")
|
||||
.replace(/\r\n/g, "\n");
|
||||
expect(committed).toBe(JSON.stringify(schema, null, 2) + "\n");
|
||||
});
|
||||
|
||||
test("is a valid JSON Schema draft-07", () => {
|
||||
expect(schema.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
||||
expect(schema.type).toBe("object");
|
||||
|
||||
@@ -93,6 +93,10 @@
|
||||
"type": "boolean",
|
||||
"description": "Include workspace settings in sync"
|
||||
},
|
||||
"includeDatatablePermissions": {
|
||||
"type": "boolean",
|
||||
"description": "With includeSettings, also sync each data table's roles and who may connect as them"
|
||||
},
|
||||
"includeKey": {
|
||||
"type": "boolean",
|
||||
"description": "Include encryption key in sync"
|
||||
|
||||
Reference in New Issue
Block a user