Generate Puppet resource types natively before the env swap #2

Merged
benvin merged 13 commits from benvin/generate-types into main 2026-11-08 21:42:12 +11:00
Member

Puppet servers need .resource_types to isolate custom types per environment; puppet generate types needs a Ruby toolchain on the deploy host and runs outside the atomic swap.

  • add internal/gentypes, a static Go port of puppet generate types (classic DSL + Resource API)
  • skip any type whose output w10k cannot prove matches puppet, logging file and line and keeping prior output
  • fail the env on I/O errors, path-confinement violations, parser limits, panics or a committed .resource_types symlink
  • generate before the swap when w10k.generate_types: true; print skipped-type counts per env
  • key worktrees on generate_types and the generator version
  • check fixtures against real openvox 9.3.0 output and fuzz the parser
Puppet servers need `.resource_types` to isolate custom types per environment; `puppet generate types` needs a Ruby toolchain on the deploy host and runs outside the atomic swap. - add `internal/gentypes`, a static Go port of `puppet generate types` (classic DSL + Resource API) - skip any type whose output w10k cannot prove matches puppet, logging file and line and keeping prior output - fail the env on I/O errors, path-confinement violations, parser limits, panics or a committed `.resource_types` symlink - generate before the swap when `w10k.generate_types: true`; print skipped-type counts per env - key worktrees on `generate_types` and the generator version - check fixtures against real openvox 9.3.0 output and fuzz the parser
Author
Member
  • internal/gentypes/parse.go:213 — a stray ), ], } or end makes skipStatement return without advancing; parseFile(")\n") loops forever and hangs the deploy → always consume at least one token, or error at depth 0 closers
  • internal/gentypes/parse.go:942 — unbounded recursion in expr/primary ([, {, #{); 4 MiB of [ in a branch type file is a fatal stack overflow that kills w10k → cap nesting depth and return an error
  • internal/gentypes/parse.go:475 — non-DSL type-body statements are skipped, so include PuppetX::Foo::Params (an included hook calling base.newparam), extend, instance_eval, Foo.add_params(self) silently drop attributes puppet emits; contradicts "unknown constructs fail" → allowlist harmless calls (validate, autorequire, feature, def, ...) and fail on the rest
  • internal/gentypes/parse.go:100 — def exists?/create/destroy in the type body make puppet add an implicit ensure (metatype/manager.rb:121); output has no ensure → detect the three public defs and add default ensure, or fail
  • internal/gentypes/parse.go:1073 — Resource API accepts behavior: as an alias of behaviour: (type_definition.rb); behavior: :namevar renders as a property with title pattern [\x27\x27] → read both keys
  • internal/gentypes/lexer.go:192 — 0x1f/1_000 render as 0x1f/1_000 (puppet 31/1000); lexer.go:483 "\101" → 101 (puppet A); render.go:142 /é/ → /é/ (puppet /(?-mix:é)/) → normalise or fail on these literals
  • nit: internal/gentypes/generate.go:89 — committed symlinks in .resource_types survive cleanup (puppet unlinks every stale child) → remove non-directories too
  • nit: internal/gentypes/generate.go:278 — $basemodulepath modules are dropped; puppet generates their types too → state it in the PR body or error when basemodulepath has types
  • nit: internal/gentypes/testdata/env/external_modules//lib/puppet/provider/**/.rb — empty provider files would give no provider param under real puppet, so fixtures and golden disagree → keep a minimal provide call in each
  • nit: internal/deploy/deploy.go:268 — turning generate_types on leaves unchanged complete envs without .resource_types until their next commit → note the forced redeploy in the PR body
- internal/gentypes/parse.go:213 — a stray `)`, `]`, `}` or `end` makes skipStatement return without advancing; `parseFile(")\n")` loops forever and hangs the deploy → always consume at least one token, or error at depth 0 closers - internal/gentypes/parse.go:942 — unbounded recursion in expr/primary (`[`, `{`, `#{`); 4 MiB of `[` in a branch type file is a fatal stack overflow that kills w10k → cap nesting depth and return an error - internal/gentypes/parse.go:475 — non-DSL type-body statements are skipped, so `include PuppetX::Foo::Params` (an `included` hook calling `base.newparam`), `extend`, `instance_eval`, `Foo.add_params(self)` silently drop attributes puppet emits; contradicts "unknown constructs fail" → allowlist harmless calls (validate, autorequire, feature, def, ...) and fail on the rest - internal/gentypes/parse.go:100 — `def exists?`/`create`/`destroy` in the type body make puppet add an implicit `ensure` (metatype/manager.rb:121); output has no ensure → detect the three public defs and add default ensure, or fail - internal/gentypes/parse.go:1073 — Resource API accepts `behavior:` as an alias of `behaviour:` (type_definition.rb); `behavior: :namevar` renders as a property with title pattern `[\x27\x27]` → read both keys - internal/gentypes/lexer.go:192 — `0x1f`/`1_000` render as `0x1f`/`1_000` (puppet `31`/`1000`); lexer.go:483 `"\101"` → `101` (puppet `A`); render.go:142 `/é/` → `/é/` (puppet `/(?-mix:é)/`) → normalise or fail on these literals - nit: internal/gentypes/generate.go:89 — committed symlinks in `.resource_types` survive cleanup (puppet unlinks every stale child) → remove non-directories too - nit: internal/gentypes/generate.go:278 — `$basemodulepath` modules are dropped; puppet generates their types too → state it in the PR body or error when basemodulepath has types - nit: internal/gentypes/testdata/env/external_modules/*/lib/puppet/provider/**/*.rb — empty provider files would give no provider param under real puppet, so fixtures and golden disagree → keep a minimal `provide` call in each - nit: internal/deploy/deploy.go:268 — turning `generate_types` on leaves unchanged complete envs without `.resource_types` until their next commit → note the forced redeploy in the PR body
Author
Member
  • internal/gentypes/lexer.go case c == '@' || c == '$' — a type/mixin file ending in $ panics (slice out of range); prepare has no recover, so one file kills w10k → bounds-check before advancing past $
  • internal/gentypes/generate.go providers loop — provider is emitted for any provider//*.rb; puppet adds it only when a file calls provide (empty or class-only file → none); deploy_test's empty posix.rb asserts the wrong output → skip unless every provider file is a recognised provide, fix the fixture
  • internal/gentypes/parse.go topStmt — unrecognised top-level statements are skipped unchecked; Puppet::Type.type(:a).send(:newparam, :extra), H.add(Puppet::Type.type(:a)) or .provide(:x) {} change puppet's output, not ours → allowlist top-level statements, skip the rest
  • internal/gentypes/parse.go rval.get — string keys match symbol options: 'namevar' => true makes a namevar, 'parent' => Puppet::Parameter::Boolean adds values, string-keyed register_type emits; puppet ignores/rejects all three. features: [:custom_insync] adds the trigger, puppet matches strings only → symbol keys only, string-only features
  • internal/gentypes/parse.go rsapiValues — prefix match diverges from TypeParser: Variant[String] → Pattern[//], Optional[Variant[Integer]] → Pattern[/^-?\d+$/] in puppet, Any here; unparseable 'string' fails in puppet, emits here → skip anything outside a strict grammar
  • internal/gentypes/parse.go newattr — duplicate newproperty/newparam names raise in puppet (type skipped); we emit both → skip on duplicates
  • nit: internal/gentypes/parse.go methodCall — bare Type.newtype outside module Puppet, and parents/Puppet::ResourceApi used without their require, NameError in puppet but emit here → skip when scope/require is missing
- internal/gentypes/lexer.go `case c == '@' || c == '$'` — a type/mixin file ending in `$` panics (slice out of range); prepare has no recover, so one file kills w10k → bounds-check before advancing past `$` - internal/gentypes/generate.go providers loop — `provider` is emitted for any provider/<type>/*.rb; puppet adds it only when a file calls `provide` (empty or class-only file → none); deploy_test's empty posix.rb asserts the wrong output → skip unless every provider file is a recognised `provide`, fix the fixture - internal/gentypes/parse.go topStmt — unrecognised top-level statements are skipped unchecked; `Puppet::Type.type(:a).send(:newparam, :extra)`, `H.add(Puppet::Type.type(:a))` or `.provide(:x) {}` change puppet's output, not ours → allowlist top-level statements, skip the rest - internal/gentypes/parse.go rval.get — string keys match symbol options: `'namevar' => true` makes a namevar, `'parent' => Puppet::Parameter::Boolean` adds values, string-keyed register_type emits; puppet ignores/rejects all three. `features: [:custom_insync]` adds the trigger, puppet matches strings only → symbol keys only, string-only features - internal/gentypes/parse.go rsapiValues — prefix match diverges from TypeParser: `Variant[String]` → `Pattern[//]`, `Optional[Variant[Integer]]` → `Pattern[/^-?\d+$/]` in puppet, `Any` here; unparseable `'string'` fails in puppet, emits here → skip anything outside a strict grammar - internal/gentypes/parse.go newattr — duplicate newproperty/newparam names raise in puppet (type skipped); we emit both → skip on duplicates - nit: internal/gentypes/parse.go methodCall — bare `Type.newtype` outside `module Puppet`, and parents/`Puppet::ResourceApi` used without their `require`, NameError in puppet but emit here → skip when scope/require is missing
Author
Member
  • internal/gentypes/parse.go:1811 — providerOf ignores non-Puppet::Type statements, the provide block and any const parent: (:1844); providers load inside newtype, so require 'missing_gem', raise, undefined consts or parent: Puppet::Provider::Nope make puppet drop the type while w10k writes it → analyse provider files with the type-file allowlist (block body included) or skip.
  • internal/gentypes/parse.go:1645 — missing resource_api validate_schema DevErrors: reserved attrs (title provider alias audit before consume export loglevel noop notify require schedule stage subscribe tag), desc+docs, ensure not Enum[present, absent], attr rsapi_custom_insync_trigger; puppet emits nothing, w10k emits → skip these.
  • internal/gentypes/ptype.go:87 — bare Variant member not flattened: Variant[Variant, String] is String in puppet (Pattern[//]), w10k emits Any → drop kid-less Variants when flattening.
  • internal/gentypes/ptype.go:27 — floatLit accepts 1.0e+5, 0e0, 1e400, which TypeParser rejects (puppet emits nothing) → match puppet's float lexing and reject float64 overflow.
  • internal/gentypes/parse.go:870 — include reads the camel-cased path, not the required file, and unions methods over every module's copy (:880); an unrequired puppet_x/a/mix.rb or a second module's copy adds an implicit ensure puppet lacks → use only the required file; skip if >1 module provides it.
  • internal/gentypes/parse.go:468 — module libs sit after puppet core/gems on $LOAD_PATH; require 'puppet/util/execution' loads core but w10k analyses the module copy (puppet: uninitialized constant, w10k: emits) → only resolve module requires for paths core/gems can't provide (e.g. puppet_x/), else skip.
  • internal/gentypes/parse.go:392 — flat const map ignores lexical scope: top-level VALS='a' + module Puppet; VALS='b'; end + top-level newtype gives puppet Enum['a'], w10k Enum['b'] → scope consts or skip on multi-scope assignment.
  • internal/deploy/deploy_test.go:649 — asserts a skipped type's .pp is absent from the new worktree, contradicting the body's "keeping prior output" → carry the live env's .pp for skipped types, or fix body+test.
- internal/gentypes/parse.go:1811 — providerOf ignores non-`Puppet::Type` statements, the provide block and any const `parent:` (:1844); providers load inside `newtype`, so `require 'missing_gem'`, `raise`, undefined consts or `parent: Puppet::Provider::Nope` make puppet drop the type while w10k writes it → analyse provider files with the type-file allowlist (block body included) or skip. - internal/gentypes/parse.go:1645 — missing resource_api validate_schema DevErrors: reserved attrs (`title provider alias audit before consume export loglevel noop notify require schedule stage subscribe tag`), `desc`+`docs`, `ensure` not `Enum[present, absent]`, attr `rsapi_custom_insync_trigger`; puppet emits nothing, w10k emits → skip these. - internal/gentypes/ptype.go:87 — bare `Variant` member not flattened: `Variant[Variant, String]` is String in puppet (`Pattern[//]`), w10k emits `Any` → drop kid-less Variants when flattening. - internal/gentypes/ptype.go:27 — floatLit accepts `1.0e+5`, `0e0`, `1e400`, which TypeParser rejects (puppet emits nothing) → match puppet's float lexing and reject float64 overflow. - internal/gentypes/parse.go:870 — include reads the camel-cased path, not the required file, and unions methods over every module's copy (:880); an unrequired `puppet_x/a/mix.rb` or a second module's copy adds an implicit `ensure` puppet lacks → use only the required file; skip if >1 module provides it. - internal/gentypes/parse.go:468 — module libs sit after puppet core/gems on `$LOAD_PATH`; `require 'puppet/util/execution'` loads core but w10k analyses the module copy (puppet: uninitialized constant, w10k: emits) → only resolve module requires for paths core/gems can't provide (e.g. `puppet_x/`), else skip. - internal/gentypes/parse.go:392 — flat const map ignores lexical scope: top-level `VALS='a'` + `module Puppet; VALS='b'; end` + top-level newtype gives puppet `Enum['a']`, w10k `Enum['b']` → scope consts or skip on multi-scope assignment. - internal/deploy/deploy_test.go:649 — asserts a skipped type's .pp is absent from the new worktree, contradicting the body's "keeping prior output" → carry the live env's .pp for skipped types, or fix body+test.
benvin changed target branch from benvin/scaffold to main 2026-11-08 21:41:24 +11:00
benvin added 13 commits 2026-11-08 21:41:24 +11:00
Generate Puppet resource types natively before the env swap
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline failed
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/pr/lint Pipeline was successful
dfb5fa021f
- add gentypes: a static Go port of `puppet generate types` for classic and Resource API types
- run it in prepare when w10k.generate_types is set; a failure fails the env and keeps the old link
- confine reads to the worktree and module cache, refuse a committed .resource_types symlink
- test against real puppet output for a vendored Apache-2.0 type set
Give the failing-input fixture a stale output mtime
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
893da512f1
Write .resource_types through an os.Root on the worktree
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ac24c66924
Merge remote-tracking branch 'origin/benvin/scaffold' into benvin/generate-types
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
e2bd36c8d9
# Conflicts:
#	internal/deploy/config.go
#	internal/deploy/deploy_test.go
- error on stray closers, deep nesting and runaway parses
- allow only inert statements in type and attribute bodies, resolving included mixins
- add the implicit ensure puppet gives types defining exists?, create and destroy
- accept behavior: as the Resource API alias of behaviour:
- normalise Ruby integer, float, string escape and regex literals, failing on forms that cannot be reproduced
- unlink stale symlinks in .resource_types
- verify fixtures, with real providers, against real puppet output
Key typed worktrees on generate_types and the generator version
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline failed
0edce80e2c
Cap tokens per Ruby file
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
71425b58c8
Skip unparseable types instead of failing the environment
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
d570c98fea
Parse failures are logged per file and counted per env; I/O, confinement and parser-limit errors still fail the deploy.
Merge remote-tracking branch 'origin/benvin/scaffold' into benvin/generate-types
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
a152bb57a0
# Conflicts:
#	internal/deploy/deploy.go
Merge remote-tracking branch 'origin/benvin/scaffold' into benvin/generate-types
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
0112806a21
# Conflicts:
#	internal/deploy/deploy.go
- bound-check a trailing $ in the lexer and turn a per-file panic into an env error
- allowlist top-level statements: requires, literal constants, module Puppet, begin/rescue requires
- require the require that defines Puppet::ResourceApi, Boolean and File parents and included mixins
- name providers by their provide call; skip types whose provider files are not one recognised provide
- read symbol option keys only, as newparam, newproperty and register_type do
- parse Resource API types with a TypeParser-compatible grammar
- skip duplicate properties and parameters
- add a parseFile fuzz target and real-puppet golden fixtures for each case
Merge remote-tracking branch 'origin/benvin/scaffold' into benvin/generate-types
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
8ea6aacd3f
# Conflicts:
#	internal/deploy/deploy.go
Merge remote-tracking branch 'origin/benvin/scaffold' into benvin/generate-types
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
1130645dd3
# Conflicts:
#	internal/deploy/deploy.go
benvin merged commit 1bb175c92c into main 2026-11-08 21:42:12 +11:00
benvin deleted branch benvin/generate-types 2026-11-08 21:42:13 +11:00
This repo is archived. You cannot comment on pull requests.