Skip to content

Commit 95ede3d

Browse files
committed
chore: improve test and build facilities
1 parent 1c80947 commit 95ede3d

File tree

14 files changed

+199
-143
lines changed

14 files changed

+199
-143
lines changed

.github/scripts/check.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Validate the registry model.
3+
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
project_root="$(cd "${SCRIPT_DIR}/../.." && pwd)"
8+
weaver_image="$(cat "${SCRIPT_DIR}/../weaver.image")"
9+
10+
docker run --rm \
11+
-v "${project_root}/model:/model" \
12+
"$weaver_image" \
13+
registry check -r /model

.github/scripts/resolve.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# Resolve the full registry (including OTel dependencies).
3+
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
project_root="$(cd "${SCRIPT_DIR}/../.." && pwd)"
8+
weaver_image="$(cat "${SCRIPT_DIR}/../weaver.image")"
9+
10+
docker run --rm \
11+
-v "${project_root}/model:/model" \
12+
-v "${project_root}:/out" \
13+
"$weaver_image" \
14+
registry resolve -r /model -o /out/resolved.json
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
# Run Weaver live-check tests against JSON test payloads.
3+
#
4+
# Usage:
5+
# run-live-check-tests.sh <valid|invalid>
6+
#
7+
# The argument selects the test suite (valid or invalid).
8+
9+
set -euo pipefail
10+
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
project_root="$(cd "${SCRIPT_DIR}/../.." && pwd)"
13+
weaver_image="$(cat "${SCRIPT_DIR}/../weaver.image")"
14+
15+
suite="${1:?Usage: $0 <valid|invalid>}"
16+
17+
if [[ "$suite" != "valid" && "$suite" != "invalid" ]]; then
18+
echo "ERROR: first argument must be 'valid' or 'invalid', got '$suite'" >&2
19+
exit 2
20+
fi
21+
22+
test_dir="${project_root}/tests/${suite}"
23+
failed=0
24+
count=0
25+
26+
for file in $(find "$test_dir" -name '*.json' | sort); do
27+
count=$((count + 1))
28+
rel_path="${file#"$project_root"/}"
29+
echo "--- ${rel_path} ---"
30+
31+
if docker run --rm \
32+
-v "${project_root}/model:/model" \
33+
-v "${file}:/test.json" \
34+
"$weaver_image" \
35+
registry live-check -r /model --input-source /test.json --input-format json --no-stream; then
36+
if [[ "$suite" == "valid" ]]; then
37+
echo "PASS: ${rel_path}"
38+
else
39+
echo "FAIL: ${rel_path} (should fail but passed)"
40+
failed=1
41+
fi
42+
else
43+
if [[ "$suite" == "invalid" ]]; then
44+
echo "PASS: ${rel_path} (correctly rejected)"
45+
else
46+
echo "FAIL: ${rel_path} (should pass but didn't)"
47+
failed=1
48+
fi
49+
fi
50+
done
51+
52+
if [[ "$count" -eq 0 ]]; then
53+
echo "ERROR: no ${suite} test files found"
54+
exit 1
55+
fi
56+
57+
exit $failed

.github/weaver.image

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
otel/weaver:v0.21.2

.github/workflows/validate-pr.yml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,20 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1616

17-
- name: Setup Weaver
18-
uses: open-telemetry/weaver/.github/actions/setup-weaver@6efae3022af925deab04aa70924cd501443fb7f9 # v0.21.2
19-
2017
- name: Check model
21-
run: weaver registry check -r ./model
18+
run: make check
2219

2320
- name: Resolve registry
24-
run: weaver registry resolve -r ./model -o resolved.json
21+
run: make resolve
2522

2623
live-check-tests:
2724
name: Live-Check Tests
2825
runs-on: ubuntu-latest
2926
steps:
3027
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3128

32-
- name: Setup Node.js
33-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
34-
with:
35-
node-version: 'lts/*'
36-
37-
- name: Setup Weaver
38-
uses: open-telemetry/weaver/.github/actions/setup-weaver@6efae3022af925deab04aa70924cd501443fb7f9 # v0.21.2
39-
40-
- name: Run valid live-check tests
41-
run: |
42-
failed=0
43-
count=$(find tests/valid -name '*.json5' | wc -l)
44-
if [ "$count" -eq 0 ]; then
45-
echo "::error::No valid test files found"
46-
exit 1
47-
fi
48-
for file in $(find tests/valid -name '*.json5' | sort); do
49-
echo "::group::Checking: $file"
50-
tmpfile=$(mktemp --suffix=.json)
51-
npx json5 "$file" > "$tmpfile"
52-
if weaver registry live-check -r ./model \
53-
--input-source "$tmpfile" --input-format json \
54-
--diagnostic-format gh_workflow_command; then
55-
echo "PASS: $file"
56-
else
57-
echo "::error::FAIL: $file should pass but didn't"
58-
failed=1
59-
fi
60-
rm "$tmpfile"
61-
echo "::endgroup::"
62-
done
63-
exit $failed
64-
65-
- name: Run invalid live-check tests
66-
run: |
67-
failed=0
68-
count=$(find tests/invalid -name '*.json5' | wc -l)
69-
if [ "$count" -eq 0 ]; then
70-
echo "::error::No invalid test files found"
71-
exit 1
72-
fi
73-
for file in $(find tests/invalid -name '*.json5' | sort); do
74-
echo "::group::Checking: $file"
75-
tmpfile=$(mktemp --suffix=.json)
76-
npx json5 "$file" > "$tmpfile"
77-
if weaver registry live-check -r ./model \
78-
--input-source "$tmpfile" --input-format json; then
79-
echo "::error::FAIL: $file should fail but passed"
80-
failed=1
81-
else
82-
echo "PASS: $file (correctly rejected)"
83-
fi
84-
rm "$tmpfile"
85-
echo "::endgroup::"
86-
done
87-
exit $failed
29+
- name: Run live-check tests
30+
run: make test
8831

8932
generate-docs:
9033
name: Generate Documentation

CLAUDE.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ model/
1212
registry_manifest.yaml # Registry manifest with OTel semconv dependency
1313
<namespace> # Different folders, organize by functional area
1414
tests/
15-
valid/ # JSON5 test data expected to pass validation
16-
invalid/ # JSON5 test data expected to fail validation
15+
valid/ # JSON test data expected to pass validation
16+
invalid/ # JSON test data expected to fail validation
1717
```
1818

1919
## Validation
2020

21-
Validate the registry model using dockerized Weaver:
21+
All validation and testing runs via Docker through the `Makefile`.
2222

2323
```sh
24-
docker run --rm -v "$(pwd)/model:/model" fa4f1c6954ec registry check -r /model
25-
```
26-
27-
Or if Weaver is installed locally:
28-
29-
```sh
30-
weaver registry check -r ./model
24+
make check # validate the registry model
25+
make test # run all live-check tests
26+
make test-valid # run only valid test cases
27+
make test-invalid # run only invalid test cases
3128
```
3229

3330
## Metric documentation workflow
@@ -45,6 +42,13 @@ The metric definitions were produced by:
4542
- Deprecated Prometheus aliases (e.g., `dash0_spans_total`) get their own metric group entry with `deprecated: { reason: renamed, renamed_to: <otel_name> }`.
4643
- Every metric **must** have a `unit` field compliant with [UCUM](https://ucum.org/).
4744

45+
## Test data maintenance
46+
47+
When adding, removing, or renaming test files under `tests/valid/` or `tests/invalid/`, update `tests/README.md`:
48+
49+
- Each test file must have a row in the README table for its domain section.
50+
- The description should explain what the test exercises and why it is expected to pass or fail.
51+
4852
## Prose rules
4953

5054
Follow these rules when writing or editing prose in this project.

CONTRIBUTING.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
## Prerequisites
44

55
- Signing the [Contributor License Agreement](https://github.com/cla-assistant/cla-assistant)
6-
- [OTel Weaver](https://github.com/open-telemetry/weaver) (v0.21.2+)
7-
- Node.js (LTS) — used for converting JSON5 test data
6+
- Docker
87

98
## Making changes to the model
109

@@ -18,12 +17,13 @@ They use the [OpenTelemetry Weaver](https://github.com/open-telemetry/weaver) re
1817
When adding or modifying conventions:
1918

2019
1. Edit or create the relevant YAML files under `model/`.
21-
2. Run `weaver registry check -r ./model` to validate the model.
20+
2. Run `make check` to validate the model.
2221
3. Add or update test data under `tests/`.
22+
4. Run `make test` to verify all test data.
2323

2424
## Test data
2525

26-
Test data lives under the `tests/` directory as [JSON5](https://json5.org/) files:
26+
Test data lives under the `tests/` directory as plain JSON files:
2727

2828
- `tests/valid/` — Samples that must pass validation.
2929
- `tests/invalid/` — Samples that must fail validation.
@@ -32,38 +32,31 @@ When adding a new event or entity, add at least one valid and one invalid test c
3232

3333
## Validating locally
3434

35+
All validation runs via Docker through the provided `Makefile`.
36+
3537
Check the registry model for correctness:
3638

3739
```sh
38-
weaver registry check -r ./model
40+
make check
3941
```
4042

41-
Resolve the full registry (including OTel dependencies):
43+
Resolve the full registry (including OTel dependencies) into `resolved.json`:
4244

4345
```sh
44-
weaver registry resolve -r ./model -o resolved.json
46+
make resolve
4547
```
4648

47-
Run the live-check tests against valid test data:
49+
Run all live-check tests (valid and invalid):
4850

4951
```sh
50-
for file in $(find tests/valid -name '*.json5' | sort); do
51-
tmpfile=$(mktemp --suffix=.json)
52-
npx json5 "$file" > "$tmpfile"
53-
weaver registry live-check -r ./model --input-source "$tmpfile" --input-format json
54-
rm "$tmpfile"
55-
done
52+
make test
5653
```
5754

58-
Run the live-check tests against invalid test data (each file should be rejected):
55+
You can also run only the valid or invalid suite:
5956

6057
```sh
61-
for file in $(find tests/invalid -name '*.json5' | sort); do
62-
tmpfile=$(mktemp --suffix=.json)
63-
npx json5 "$file" > "$tmpfile"
64-
weaver registry live-check -r ./model --input-source "$tmpfile" --input-format json
65-
rm "$tmpfile"
66-
done
58+
make test-valid
59+
make test-invalid
6760
```
6861

6962
## Pull requests

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: check resolve test test-valid test-invalid
2+
3+
## Validate the registry model.
4+
check:
5+
@.github/scripts/check.sh
6+
7+
## Resolve the full registry (including OTel dependencies).
8+
resolve:
9+
@.github/scripts/resolve.sh
10+
11+
## Run all live-check tests.
12+
test: test-valid test-invalid
13+
14+
## Run valid live-check tests (each file must pass).
15+
test-valid:
16+
@.github/scripts/run-live-check-tests.sh valid
17+
18+
## Run invalid live-check tests (each file must be rejected).
19+
test-invalid:
20+
@.github/scripts/run-live-check-tests.sh invalid

tests/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Test payloads
2+
3+
This directory contains [Weaver live-check](https://github.com/open-telemetry/weaver) sample payloads used to validate the registry model.
4+
5+
- `valid/` — Samples that **must pass** validation.
6+
- `invalid/` — Samples that **must fail** validation.
7+
8+
## deployment
9+
10+
### Valid
11+
12+
| File | Description |
13+
|------|-------------|
14+
| `valid/deployment/full-deployment-event.json` | A `dash0.deployment` event with all supported resource and event attributes populated. |
15+
| `valid/deployment/minimal-deployment-event.json` | A `dash0.deployment` event with only the required resource attribute (`service.name`). All optional attributes are omitted to test the baseline case. |
16+
17+
### Invalid
18+
19+
| File | Description |
20+
|------|-------------|
21+
| `invalid/deployment/wrong-type-service-name.json` | A `dash0.deployment` event where `service.name` has the wrong type (`int` instead of `string`). Verifies that type mismatches are rejected. |

tests/invalid/deployment/missing-required-attrs.json5

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)