|
| 1 | +# Golden Templates |
| 2 | + |
| 3 | +Pinned outputs of `sam build` and `sam package` for representative templates. |
| 4 | +Catches output-shape regressions in SAM-CLI's local pipeline. See |
| 5 | +[`designs/golden-templates-and-semver-check.md`](../../designs/golden-templates-and-semver-check.md) |
| 6 | +for the full design. |
| 7 | + |
| 8 | +## Layout |
| 9 | + |
| 10 | +``` |
| 11 | +tests/golden/ |
| 12 | +├── templates/ |
| 13 | +│ ├── sam_resources/<case>/ # AWS::Serverless::* coverage |
| 14 | +│ ├── packageable_resources/<case>/ # Raw CFN resource coverage |
| 15 | +│ ├── language_extensions/<case>/ # Fn::ForEach et al |
| 16 | +│ └── cross_cutting/<case>/ # Nested stacks, AWS::Include, etc. |
| 17 | +└── ... (harness code) |
| 18 | +``` |
| 19 | + |
| 20 | +Each case directory contains: |
| 21 | +- `template.yaml` — the input template. |
| 22 | +- `metadata.yaml` — `language_extensions: bool`, `description`, `issue_refs`. |
| 23 | +- `src/` — any source files referenced by `CodeUri` etc. |
| 24 | +- `expected.build.yaml` — pinned post-build template (regenerated by harness). |
| 25 | +- `expected.package.yaml` — pinned post-package template. |
| 26 | +- `README.md` — what this case covers and why it's pinned. |
| 27 | + |
| 28 | +## Adding a new case |
| 29 | + |
| 30 | +1. Create the case directory and author `template.yaml`, `metadata.yaml`, `src/`, `README.md`. |
| 31 | +2. Generate the pinned outputs: |
| 32 | + ``` |
| 33 | + python tests/golden/update_goldens.py --new --filter '<axis>/<case-name>' |
| 34 | + ``` |
| 35 | +3. Eyeball `expected.{build,package}.yaml`. Confirm the shape is what you expect. |
| 36 | +4. Commit everything together. |
| 37 | + |
| 38 | +The semver gate treats new cases as additions and does not require a version bump. |
| 39 | + |
| 40 | +## Re-pinning an existing case |
| 41 | + |
| 42 | +If a SAM-CLI behavior change intentionally alters the expanded output: |
| 43 | + |
| 44 | +``` |
| 45 | +python tests/golden/update_goldens.py --filter '<axis>/<case-name>' |
| 46 | +``` |
| 47 | + |
| 48 | +Review the diff in your IDE before committing. **Modifying or deleting an |
| 49 | +existing pin requires a major version bump in `samcli/__init__.py` in the |
| 50 | +same PR**, enforced by `.github/workflows/golden-semver-gate.yml`. |
| 51 | + |
| 52 | +## Inspecting differences |
| 53 | + |
| 54 | +``` |
| 55 | +python tests/golden/update_goldens.py --diff --filter '<glob>' # show would-be changes |
| 56 | +python tests/golden/update_goldens.py --check # exit 1 if anything would change |
| 57 | +``` |
| 58 | + |
| 59 | +## Running the suite |
| 60 | + |
| 61 | +``` |
| 62 | +pytest tests/golden # all cases |
| 63 | +pytest tests/golden -k foreach_static # one case |
| 64 | +make test-all # part of make pr |
| 65 | +``` |
0 commit comments