|
| 1 | +# Lab content checks |
| 2 | + |
| 3 | +Automated checks that catch problems in the lab content before a learner hits |
| 4 | +them. They are deliberately cheap: **no Azure resources, no credentials, and no |
| 5 | +spend**, so they can run on every pull request. |
| 6 | + |
| 7 | +## Running them locally |
| 8 | + |
| 9 | +``` |
| 10 | +pip install -r tools/checks/requirements.txt |
| 11 | +python tools/checks/check_frontmatter.py |
| 12 | +python tools/checks/check_code_blocks.py |
| 13 | +python tools/checks/check_links.py |
| 14 | +python tools/checks/check_line_endings.py |
| 15 | +``` |
| 16 | + |
| 17 | +Each script exits non-zero when it finds a problem and prints the file and line. |
| 18 | +In GitHub Actions the same output becomes an inline annotation on the pull |
| 19 | +request diff. |
| 20 | + |
| 21 | +## Tier 0 — content checks (every pull request, and every push to `main`) |
| 22 | + |
| 23 | +| Check | What it catches | |
| 24 | +| --- | --- | |
| 25 | +| `check_frontmatter.py` | YAML that won't parse, which breaks the site build. The usual cause is an unescaped apostrophe inside a single-quoted value, such as `verify: 'you don't have access'`. | |
| 26 | +| `check_code_blocks.py` | A ```` ```python ```` block that isn't valid Python. Learners paste these straight into a file, so a bad indent breaks the lab. | |
| 27 | +| `check_links.py` | A link to a page that was renamed or moved, or a screenshot that no longer exists. | |
| 28 | +| `check_line_endings.py` | Text files drifting back to CRLF in the index, against the `.gitattributes` policy. | |
| 29 | + |
| 30 | +### Why the code block check normalizes first |
| 31 | + |
| 32 | +The blocks are snippets, not programs, so parsing them as-is is useless — 134 of |
| 33 | +148 blocks in this repo would report a false positive. The check therefore: |
| 34 | + |
| 35 | +1. **Dedents** the block, because snippets are indented to sit inside a function |
| 36 | + body. |
| 37 | +2. **Closes a trailing open block** if parsing failed *only* because a `with` or |
| 38 | + `def` has no body — the lab adds that body in a later step. |
| 39 | + |
| 40 | +A genuine syntax error — a typo, an unbalanced bracket, or a bad indent *within* |
| 41 | +the snippet — still fails. That is the class of bug behind the `fix fence |
| 42 | +indentation` and `fix code sample indentation` fixes on `main`. |
| 43 | + |
| 44 | +## Tier 1 — SDK contract (nightly) |
| 45 | + |
| 46 | +`check_sdk_contract.py` installs each lab's pinned requirements, then checks that |
| 47 | +every module and symbol the lab imports still resolves — both in the Python |
| 48 | +files the lab ships **and in the code blocks the instructions tell learners to |
| 49 | +paste**. |
| 50 | + |
| 51 | +It runs nightly, and on any pull request that touches a `requirements.txt`, the |
| 52 | +check itself, or its workflow — the changes most likely to break it. It is |
| 53 | +path-filtered because it installs dependencies across a matrix of every lab, |
| 54 | +which is too slow to run on unrelated pull requests. |
| 55 | + |
| 56 | +This targets the breakages this repo actually hits, which are import- and |
| 57 | +signature-level: |
| 58 | + |
| 59 | +- *Fix Exercise 3: Update FastMCP import to standalone package* |
| 60 | +- *Update labs 02 and 03 to `azure-ai-projects==2.0.0b4`* |
| 61 | +- *Revert agent-framework bump on legacy labs 07/08* |
| 62 | + |
| 63 | +Each would have been caught here, without any Azure resources, before reaching a |
| 64 | +learner. |
| 65 | + |
| 66 | +It runs twice per lab. **Pinned** uses the versions in `requirements.txt`; a |
| 67 | +failure means something was yanked or a transitive dependency broke. **Latest** |
| 68 | +strips the pins; a failure there is early warning for the next version bump and |
| 69 | +does not fail the job. |
| 70 | + |
| 71 | +Because these labs are maintained asynchronously, a scheduled failure opens a |
| 72 | +GitHub issue rather than relying on someone noticing a red badge. |
| 73 | + |
| 74 | +### The import contract maintains itself |
| 75 | + |
| 76 | +There is no hand-written list of expected symbols. The contract is derived from |
| 77 | +the content, so it cannot drift: add an import to a lab or an instruction code |
| 78 | +block and it is checked automatically. |
| 79 | + |
| 80 | +Only **keyword arguments** are pinned by hand, in `KWARG_CONTRACTS`, because |
| 81 | +they can't be derived reliably. If you change a code block to pass a new |
| 82 | +argument, add it there so a future SDK rename fails loudly instead of silently |
| 83 | +breaking the lab. |
| 84 | + |
| 85 | +Starter files are expected to be incomplete — a `def` whose body the learner |
| 86 | +fills in later is a syntax error by design — so a parse failure with that |
| 87 | +signature is ignored outside `Solution/`. |
| 88 | + |
| 89 | +## Not yet covered |
| 90 | + |
| 91 | +These need groundwork that doesn't exist yet: |
| 92 | + |
| 93 | +| Check | Blocked on | |
| 94 | +| --- | --- | |
| 95 | +| Strict frontmatter schema (`type`, `section`, `difficulty`, `order`) | The consolidated labs carrying that metadata. | |
| 96 | +| Generated task tables match frontmatter | The same metadata, plus the table include. | |
| 97 | +| Instructions match the `Solution/` code | A convention for mapping a code block to its solution file, e.g. an HTML comment above each block. | |
| 98 | +| Shared infrastructure hasn't drifted between labs | A canonical `Labfiles/_shared/` with a sync script. | |
0 commit comments