|
| 1 | +# oc-chef-pedant Testing Guide |
| 2 | + |
| 3 | +This guide standardizes how to run the oc-chef-pedant suite across environments (chef-server vs chef-zero) and documents recent helper scope changes, risk notes, and the validation matrix post ActiveSupport removal. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Supported Execution Modes |
| 8 | + |
| 9 | +| Mode | Target | Purpose | Invocation Summary | |
| 10 | +|------|--------|---------|--------------------| |
| 11 | +| Server (Embedded) | Full Chef Server (dev VM / omnibus install) | Primary regression signal | `chef-server-ctl test` (inside VM) or `bin/oc-chef-pedant -c pedant_config.rb` | |
| 12 | +| chef-zero (Released Gem) | Upstream chef-zero gem matching Chef 18 baseline | Fast API contract smoke, isolate server-side regressions | Rake task / direct script (see below) | |
| 13 | +| chef-zero (Branch Override) | Branch removing legacy Chef::VERSION references | Validate removal of ActiveSupport & version coupling | Export `CHEF_VERSION` or Bundler override Gemfile | |
| 14 | + |
| 15 | +> Ruby 3.1.7 is the reference version (Chef 18 parity). Avoid 3.4+ until broader compatibility is validated. |
| 16 | +
|
| 17 | +--- |
| 18 | + |
| 19 | +## 2. Quick Commands |
| 20 | + |
| 21 | +### 2.1 Inside Dev VM (full server) |
| 22 | + |
| 23 | +```bash |
| 24 | +chef-server-ctl test --all # Full pedant + internal org tests |
| 25 | +chef-server-ctl test # Default subset |
| 26 | +chef-server-ctl test --all --exclude-internal-orgs |
| 27 | +``` |
| 28 | + |
| 29 | +### 2.2 Local (without full server) using chef-zero |
| 30 | + |
| 31 | +From `oc-chef-pedant/`: |
| 32 | + |
| 33 | +```bash |
| 34 | +# Ensure bundle resolves to the released chef-zero |
| 35 | +bundle install |
| 36 | +rake chef_zero_spec |
| 37 | +``` |
| 38 | + |
| 39 | +### 2.3 Using Branch Override of chef-zero |
| 40 | + |
| 41 | +Use a dedicated Gemfile (example: `scripts/bk_tests/chef_zero-Gemfile`) or add a block like: |
| 42 | + |
| 43 | +```ruby |
| 44 | +# Gemfile.local snippet |
| 45 | +# gem 'chef-zero', git: 'https://github.com/chef/chef-zero', branch: 'remove-chef-version' |
| 46 | +``` |
| 47 | + |
| 48 | +Then: |
| 49 | + |
| 50 | +```bash |
| 51 | +BUNDLE_GEMFILE=scripts/bk_tests/chef_zero-Gemfile bundle install |
| 52 | +BUNDLE_GEMFILE=scripts/bk_tests/chef_zero-Gemfile rake chef_zero_spec |
| 53 | +``` |
| 54 | + |
| 55 | +### 2.4 Focused Spec Samples |
| 56 | + |
| 57 | +```bash |
| 58 | +bundle exec rspec spec/api/keys/user_keys_spec.rb:930-970 |
| 59 | +bundle exec rspec spec/api/server_api_version_spec.rb |
| 60 | +``` |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 3. Helper Scope Changes (IMPORTANT) |
| 65 | + |
| 66 | +Removed class-level singleton helpers: |
| 67 | + |
| 68 | +- `platform` |
| 69 | +- `api_url` |
| 70 | + |
| 71 | +Rationale: They caused large clusters of WrongScope failures when indirectly invoked in `before(:all)` and polluted example group scope. Use patterns below: |
| 72 | + |
| 73 | +| Context | Old (removed) | New (explicit) | |
| 74 | +|---------|---------------|----------------| |
| 75 | +| before(:all)/after(:all) | `platform.create_user(name)` | `Pedant::Config.pedant_platform.create_user(name)` | |
| 76 | +| Example / let / before(:each) | `platform` (still OK via instance helper) | `platform` | |
| 77 | +| Building URLs (group scope) | `api_url("/nodes")` | `Pedant::Config.pedant_platform.api_url("/nodes")` | |
| 78 | + |
| 79 | +Instance helpers remain: `platform`, `api_url(path)` inside example scope only. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 4. Validation Matrix |
| 84 | + |
| 85 | +| Dimension | Set | Notes | |
| 86 | +|-----------|-----|-------| |
| 87 | +| Ruby | 3.1.7 | Canonical; matches Chef 18 runtime | |
| 88 | +| Platform Mode | Full Server, chef-zero (released), chef-zero (branch) | Branch mode only when validating coupling removal | |
| 89 | +| Spec Slice | Smoke (server_api_version_spec + a CRUD resource), Core (default), Full (`--all`) | Smoke runs should complete < 2 min on typical dev hardware | |
| 90 | +| Headers | `X-Chef-Version` hardcoded KNIFE_VERSION | No dynamic Chef::VERSION dependency | |
| 91 | +| API Versions | v0 (legacy), negotiation path (`/server_api_version`) | Ensure `server_api_version_spec` passes in all modes | |
| 92 | + |
| 93 | +Minimum CI gates after recent changes: |
| 94 | + |
| 95 | +1. Server Mode Core suite: PASS |
| 96 | +2. chef-zero Released Smoke suite: PASS (server_api_version + basic ACL or keys spec subset) |
| 97 | +3. Branch Override (only while feature branch active): Smoke suite PASS |
| 98 | +4. Full Server `--all` (nightly) PASS |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## 5. Risk & Compatibility Notes |
| 103 | + |
| 104 | +| Area | Risk | Mitigation | |
| 105 | +|------|------|------------| |
| 106 | +| Helper Scope Removal | Hidden reliance on class-level `platform` in `before(:all)` blocks causing NameError later | Grep for `before(:all)` + `platform.`; replace with explicit config reference | |
| 107 | +| ActiveSupport Removal | Missed implicit inflector / Hash key conversions | Added targeted replacements (`pedant/concern`, `stringify_keys` shim) & core suite green before broader matrix | |
| 108 | +| Version Decoupling | Tools expecting dynamic Chef::VERSION in headers | Hardcoded `KNIFE_VERSION` unchanged; document expectation | |
| 109 | +| chef-zero Branch Divergence | Drift from released gem causing false positives | Keep branch usage confined to feature PR validation; do not gate merges on branch-only passes | |
| 110 | +| Ruby Version Skew | Newer Ruby 3.3/3.4 differences (warning categories, RSpec timing) | Pin CI to 3.1.7; add optional future lane once core stabilized | |
| 111 | + |
| 112 | +Rollback Strategy: Re-introducing class-level helpers is low complexity but discouraged; prefer updating any lingering specs. ActiveSupport dependency should not be restored—issues should be fixed by adding narrowly scoped utilities. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 6. Troubleshooting Quick Table |
| 117 | + |
| 118 | +| Symptom | Likely Cause | Action | |
| 119 | +|---------|--------------|--------| |
| 120 | +| 1000+ WrongScope / method missing `platform` failures | A `before(:all)` still calling instance helper | Replace with `Pedant::Config.pedant_platform` | |
| 121 | +| 401/403 explosion under chef-zero only | Org/user provisioning order or missing association | Re-run single spec with `--backtrace`, inspect platform creation logs | |
| 122 | +| All requests 500 in chef-zero mode | Wrong chef-zero branch / dependency mismatch | Confirm Gemfile lock; run `ruby -v`; re-bundle with released gem | |
| 123 | +| Version negotiation failures | Header mismatch / test expecting dynamic version | Inspect `X-Chef-Version` in captured request log | |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 7. Adding New Tests – Best Practices |
| 128 | + |
| 129 | +- Use `let` for per-example dynamic data; use `shared(:symbol)` only when a value must be accessible inside `before(:all)`. |
| 130 | +- Avoid creating real users/orgs in `before(:all)` unless they are immutable and shared; prefer `before(:each)` for mutable objects. |
| 131 | +- Always clean up with explicit `Pedant::Config.pedant_platform.delete_*` calls in `after(:all)` for created actors. |
| 132 | +- For new endpoints: add smoke coverage to the Smoke slice (small curated set) to keep early failures tight. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## 8. Future Enhancements (Optional Backlog) |
| 137 | + |
| 138 | +- Introduce a tagged `:smoke` subset with < 50 examples for <60s validation. |
| 139 | +- Add script to auto-rewrite lingering `platform.` calls in group hooks. |
| 140 | +- Parameterize KNIFE_VERSION via env var for experimental clients. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## 9. At-a-Glance Checklist (PR Author) |
| 145 | + |
| 146 | +- [ ] Core suite passes locally (server mode) |
| 147 | +- [ ] Smoke suite passes with released chef-zero |
| 148 | +- [ ] No new `before(:all)` using instance helpers |
| 149 | +- [ ] Added/updated docs if new config flags introduced |
| 150 | + |
| 151 | +--- |
| 152 | +Last updated: 2025-11-06 |
0 commit comments