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
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@
Notable changes, newest first. Release notes on GitHub list every commit;
this file collects what users and scripts need to know.

## Unreleased

### New

- `norcube cms validate [path]` checks a Norcube CMS site from its
repository, offline and without a sign-in: the schema in `.norcube/cms/`
(YAML, `$ref`, field types and knobs, options, bounds, regexes,
`visibleIf` paths, storages, preview), every content file against its
collection (the editor's rules: required, shapes, array item kinds and
bounds, regex, length, uniqueness, custom validators, out-of-schema
keys) and the links between files (two files at one URL, links no page
produces, missing images, dangling references). `--only
schema|content|links` narrows the run, `--collection` limits it to one
collection, `--fail-on warning|error|none` picks what fails the exit
code. The checks come from the public
[cms-schema](https://github.com/norcubeplatform/cms-schema) module, so a
site's CI runs exactly what the editor runs.

### Changes

- Built with Go 1.26.11, which fixes GO-2026-6859 in the standard library.

### Changes for scripts

- New error code `invalid` (exit 1): `cms validate` found findings at the
severity `--fail-on` asks it to fail on; `details` holds the counts and
stdout the report.
- `cms validate -o json` prints `{schemaVersion, path, findings[],
summary{files, schemaFiles, errors, warnings}}`; each finding has `file`,
`path`, `severity`, `rule`, `message` and optionally `hint`. Rule ids
are frozen in the cms-schema module.

## 0.26.0 (2026-11-07)

### New
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ norcube langsync namespaces list # LangSync namespaces
norcube domainradar check acme.dev # is a domain free?
norcube monitor status # open incidents and monitors that need attention
norcube billing usage estimate # this month's charges so far
norcube cms validate ./site # check a CMS site's schema and content, offline
norcube doctor # something not working? start here
```

Expand Down
5 changes: 3 additions & 2 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ exit codes may not.
| Exit | Codes | Meaning |
| --- | --- | --- |
| 0 | | Success |
| 1 | `error`, `server_error`, `job_failed`, `unhealthy` | General failure; a waited-for job ended unsuccessfully (`details` holds the job); a `--fail-on` state was found (`monitor status`, `details` holds the report) |
| 1 | `error`, `server_error`, `job_failed`, `unhealthy`, `invalid` | General failure; a waited-for job ended unsuccessfully (`details` holds the job); a `--fail-on` state was found (`monitor status`, `details` holds the report); a local check found findings at the `--fail-on` severity (`cms validate`, `details` holds the counts, stdout the report) |
| 2 | `usage_error`, `validation_failed`, `org_not_found` | Fix the command line or input; also any prompt without a terminal |
| 3 | `not_found` | The API answered 404 |
| 4 | `login_required` | Not signed in, session expired or revoked, CI token expired, revoked or unknown |
Expand Down Expand Up @@ -732,7 +732,7 @@ flag; [CHANGELOG.md](../CHANGELOG.md) says when each arrived.
| `billing` | `status`; `subscriptions list`; `usage estimate | metrics`; `invoices list | download`; `budget get | set` |
| `monitor` | `status` (`--fail-on`); `monitors list | get | create | update | delete | pause | resume | run` (`--wait`), `monitors bulk pause | resume | delete`, `monitors results list`, `monitors status-changes list`, `monitors stats get`, `monitors availability get`, `monitors certificate get`, `monitors alerts get | set`; `incidents list | get | acknowledge | summary`; `channels list | get | create | update | delete | test | verify`, `channels deliveries list`; `status-pages list | get | create | update | delete | publish | unpublish | preview-link`, `status-pages layout get | set`, `status-pages incidents list | get | create | update`, `status-pages incidents updates create`, `status-pages subscribers list | delete`; `maintenance list | get | create | update | cancel | finish` |
| PromptHub | No command group; `nrc api prompthub ...` |
| CMS | None (CMS has no public API) |
| `cms` | `validate` (`--only schema|content|links`, `--collection`, `--fail-on`), offline on a site checkout; the CMS has no public API, so there are no resource commands |

CI token scopes, as defined by Norcube Auth and listed by
`nrc auth ci-token scopes`: `backup.read`, `backup.write` (run backups
Expand Down Expand Up @@ -800,6 +800,7 @@ changelog, and the owner's decisions in the planning sessions of
| 2026-11-06 | Maintenance windows in the CLI: `monitor maintenance`. The resource is a mass noun, an exception to the plural rule of P1, because "maintenances" isn't a word and "maintenance windows" is long to type for something used in deploy scripts; `maintenance-windows` is an alias. A window is named by id only: titles repeat by design. `--state` filters on the field the result calls `state` (the API's query parameter is `status`), with the API's values. There is no `delete`: the API deletes only a cancelled window, a completed one explains a gap in uptime and goes by itself after two years, and `cancel` already takes a window out of everything people see; `nrc api` reaches the endpoint. `finish` is a new verb, because `cancel` would say the work didn't happen. `cancel` confirms, since it mails whoever was told; `finish` doesn't and has no `--yes`, because ending a silence is the safe direction and it must run unattended at the end of a deploy. Notifications are explicit in the request, because the API takes no defaults: the flags default to on, as the owner decided, and `--no-notify` turns off all three. `monitor status` keeps a monitor among `problems` when what is wrong is a calendar condition or a watched aspect, because a window doesn't hold those | Owner's brief. Rejected: a bare `2h` meaning two hours ahead, since `ParseTimeArg` reads the same spelling as two hours ago | owner |
| 2026-11-06 | `-o id` prints only the result's id. Deploy scripts capture what they create with `id=$(... -o id)`, and `-o text` prints the state as well, so it would need `cut`. It is a global output value rather than a flag of one command, so it means the same everywhere (P1, P13) | Named in the owner's maintenance windows plan. Rejected: `--query id -o text` as the documented form, which still works but is too long for the one thing every script needs | owner |
| 2026-11-05 | `--auto-post` is the one page setting `create` doesn't require: the flag came after 0.23.0, so requiring it would break scripts that create pages, and the API keeps it off unless asked. `--notify` is sent only when given, and exists only on writes that add an update | Compatibility rule P10; owner's brief | owner |
| 2026-11-15 | `cms validate`: a `cms` group whose first command works on a site checkout, offline, with no sign-in. The checks live in the public `github.com/norcubeplatform/cms-schema` module, which the CMS service and the dashboard's fixtures share, so the CLI is a thin wrapper and cannot drift from the editor. `--fail-on` defaults to `error` (unlike `monitor status`, whose default is `none`) because a validator that exits 0 on errors would be useless in CI; findings keep their severity whatever `--fail-on` says. A failed run uses the new code `invalid`, not `unhealthy`: `unhealthy` describes a service's state, `invalid` what the command checked. The report is printed before the error so CI keeps it. The path argument completes directories only | Owner's brief: validate a whole site against every page, locally and in CI, with the rules the editor runs. Rejected: putting the checks in the CLI module (the private backend would then depend on the CLI's releases and dependency graph); a `--strict` flag (the tree already has `--fail-on` for this); naming the command `cms schema validate` (content and links are checked too) | owner |

---

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/norcubeplatform/cli

go 1.26.1

toolchain go1.26.10
toolchain go1.26.11

require (
github.com/charmbracelet/huh v1.0.0
Expand All @@ -12,6 +12,7 @@ require (
github.com/gofrs/flock v0.13.0
github.com/google/uuid v1.6.0
github.com/jmespath-community/go-jmespath v1.1.1
github.com/norcubeplatform/cms-schema v0.1.1
github.com/oapi-codegen/runtime v1.4.0
github.com/pelletier/go-toml/v2 v2.3.1
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/norcubeplatform/cms-schema v0.1.1 h1:19HHWyqDrTGG2THK54TvzngCdhUNxWFywsuUrhLzAbU=
github.com/norcubeplatform/cms-schema v0.1.1/go.mod h1:fY05NpvoygKgMBZjj3+R6KI1vko9CSJPJKS02n6WRh0=
github.com/oapi-codegen/runtime v1.4.0 h1:KLOSFOp7UzkbS7Cs1ms6NBEKYr0WmH2wZG0KKbd2er4=
github.com/oapi-codegen/runtime v1.4.0/go.mod h1:5sw5fxCDmnOzKNYmkVNF8d34kyUeejJEY8HNT2WaPec=
github.com/oasdiff/yaml v0.1.1 h1:6nHx+pn9gBRM6YpBlFZFQGCCd1nuvqOBtTD3KKTgGxY=
Expand Down
23 changes: 23 additions & 0 deletions internal/cli/cms/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Package cms implements the `norcube cms ...` command tree. Norcube CMS
// edits content that lives in the site's own git repository, so these
// commands work on a checkout of the site, offline: no sign-in, no
// organization, no network. The checks are the ones the editor runs,
// shared through the public cms-schema module, so a site that passes here
// opens cleanly in the CMS.
package cms

import "github.com/spf13/cobra"

// NewCmd returns the `cms` parent command with all subcommands.
func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cms",
Short: "Check a Norcube CMS site's schema and content from its repository",
Long: `Norcube CMS keeps a site's schema in .norcube/cms/ and its content in the
site's own repository. These commands read a checkout of that repository
and need no sign-in: run them on your machine before you push, or in the
site's CI to block a change that breaks the content model.`,
}
cmd.AddCommand(newValidateCmd())
return cmd
}
198 changes: 198 additions & 0 deletions internal/cli/cms/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package cms

import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

"github.com/norcubeplatform/cms-schema/load"
"github.com/norcubeplatform/cms-schema/report"
"github.com/norcubeplatform/cms-schema/validate"

"github.com/norcubeplatform/cli/internal/clierr"
"github.com/norcubeplatform/cli/internal/cmdutil"
"github.com/norcubeplatform/cli/internal/output"
)

// What `validate --fail-on` accepts, from the strictest to none.
var validateFailOn = []string{failOnWarning, failOnError, failOnNone}

const (
failOnError = "error"
failOnWarning = "warning"
failOnNone = "none"
)

// validateScopes are the values of --only, in the order the checks run.
var validateScopes = []string{validate.ScopeSchema, validate.ScopeContent, validate.ScopeLinks}

// validateReportVersion is the version of the `cms validate -o json`
// document. Within a version changes are additive only.
const validateReportVersion = 1

// validateReport is what `cms validate -o json` prints.
type validateReport struct {
SchemaVersion int `json:"schemaVersion" yaml:"schemaVersion"`
// Path is the site directory as given on the command line.
Path string `json:"path" yaml:"path"`
// Findings are sorted by file, path and severity. Each names a rule
// from the frozen list in the cms-schema module.
Findings []report.Finding `json:"findings" yaml:"findings"`
Summary validateSummary `json:"summary" yaml:"summary"`
}

// validateSummary counts what the run looked at and found.
type validateSummary struct {
// Files is the number of content files checked, SchemaFiles the
// number of schema files loaded.
Files int `json:"files" yaml:"files"`
SchemaFiles int `json:"schemaFiles" yaml:"schemaFiles"`
Errors int `json:"errors" yaml:"errors"`
Warnings int `json:"warnings" yaml:"warnings"`
}

func newValidateCmd() *cobra.Command {
var (
only []string
collection string
failOn string
)
cmd := &cobra.Command{
Use: "validate [path]",
Annotations: cmdutil.Reads(),
Short: "Check a site's CMS schema and content the way the editor does",
Long: `Reads the site checkout at path (default: the current directory) and
reports what the Norcube CMS editor would: schema files that do not load
or contradict themselves, content that breaks a field's rules, and links,
images and references that point at nothing. Nothing is sent anywhere;
the command needs no sign-in.

Three groups of checks run, selectable with --only:
schema .norcube/cms/ loads: YAML, $ref, field types and knobs, select
options, bounds, regexes, visibleIf paths, storages, preview
content every content file against its collection: required, value
shapes, array item kinds and bounds, regex, length, uniqueness,
custom validators, out-of-schema keys
links the site as a whole: two files at one URL, links no page
produces, missing images and files, dangling references

Each finding names the file, the field path inside it, a severity and a
rule id (schema.unresolved_ref, content.required, links.missing_asset…).
Rule ids are stable; match on them in scripts.

The exit code follows --fail-on: with "error" (the default) the command
exits 1 when any finding is an error, with "warning" when any finding
exists, with "none" it always exits 0 and only reports. A path that is
not a CMS site exits 3.`,
Example: ` norcube cms validate
norcube cms validate ./site --fail-on warning
norcube cms validate --only schema
# In CI, keep the report as an artifact
norcube cms validate -o json > cms-validate.json
norcube cms validate -o json --query "findings[?rule=='links.missing_asset'].file"`,
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(*cobra.Command, []string, string) ([]cobra.Completion, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveFilterDirs
},
RunE: cmdutil.Run(func(cmd *cobra.Command, args []string) (any, error) {
for _, o := range only {
if err := oneOf("--only", o, validateScopes); err != nil {
return nil, err
}
}
if err := oneOf("--fail-on", failOn, validateFailOn); err != nil {
return nil, err
}
path := "."
if len(args) == 1 {
path = args[0]
}
info, err := os.Stat(path)
switch {
case errors.Is(err, os.ErrNotExist):
return nil, clierr.Usage(fmt.Errorf("%s: no such directory", path))
case err != nil:
return nil, err
case !info.IsDir():
return nil, clierr.Usage(fmt.Errorf("%s is a file; pass the site's directory", path))
}

res, err := validate.Site(os.DirFS(path), validate.Options{Only: only, Collection: collection})
if errors.Is(err, load.ErrNotASite) {
return nil, &clierr.Error{
Code: clierr.CodeNotFound,
Message: fmt.Sprintf("%s holds no Norcube CMS site: no %s and no %s", path, load.ConfigFile, load.LegacyConfigFile),
Hint: "Run the command from the site's root, or pass its path.",
Err: err,
}
}
if err != nil {
return nil, err
}

rep := validateReport{
SchemaVersion: validateReportVersion,
Path: path,
Findings: res.Findings,
Summary: validateSummary{Files: res.Files, SchemaFiles: res.SchemaFiles, Errors: res.Errors, Warnings: res.Warnings},
}
if rep.Findings == nil {
rep.Findings = []report.Finding{}
}
view := output.View[report.Finding]{
Value: rep,
Table: output.Table[report.Finding]{
Headers: []string{"SEVERITY", "FILE", "PATH", "RULE", "MESSAGE"},
Rows: func(f report.Finding) []string {
return []string{string(f.Severity), f.File, f.Path, string(f.Rule), f.Message}
},
Items: rep.Findings,
},
}
fmt.Fprintf(cmd.ErrOrStderr(), "%d content %s, %d schema %s: %d %s, %d %s\n",
res.Files, plural(res.Files, "file"), res.SchemaFiles, plural(res.SchemaFiles, "file"),
res.Errors, plural(res.Errors, "error"), res.Warnings, plural(res.Warnings, "warning"))

fail := (failOn == failOnError && res.Errors > 0) ||
(failOn == failOnWarning && (res.Errors > 0 || res.Warnings > 0))
if !fail {
return view, nil
}
if err := cmdutil.Print(cmd, view); err != nil {
return nil, err
}
return nil, &clierr.Error{
Code: clierr.CodeInvalid,
Message: fmt.Sprintf("%s does not pass: %d %s, %d %s", path, res.Errors, plural(res.Errors, "error"), res.Warnings, plural(res.Warnings, "warning")),
Hint: "Fix the findings above, or pass --fail-on none to report without failing.",
Details: rep.Summary,
}
}),
}
cmd.Flags().StringSliceVar(&only, "only", nil, "Run only these checks: schema, content, links (repeatable or comma-separated; default all)")
cmd.Flags().StringVar(&collection, "collection", "", "Check the content and links of one collection only, by its key")
cmd.Flags().StringVar(&failOn, "fail-on", failOnError, "Exit 1 on findings of this severity or worse: warning, error or none")
cmdutil.FlagEnum(cmd, "only", validateScopes...)
cmdutil.FlagEnum(cmd, "fail-on", validateFailOn...)
return cmd
}

// oneOf rejects a flag value outside its allowed list before any work.
func oneOf(flag, v string, allowed []string) error {
for _, a := range allowed {
if v == a {
return nil
}
}
return clierr.Usage(fmt.Errorf("%s %q: one of %s", flag, v, strings.Join(allowed, ", ")))
}

func plural(n int, word string) string {
if n == 1 {
return word
}
return word + "s"
}
Loading
Loading