Commit fc0e709
fix: correct buggy example code in skills, standardize CLI command form (#55)
* fix: correct buggy example code in skill references
Several reference examples contain code an agent would copy verbatim but
that doesn't behave as intended:
content-experimentation-best-practices/references/cms-integration.md
- assignVariant drew Math.random() * 100 without normalizing against the
sum of variant weights, so weights that don't total 100 skew the split
- it reused a cached cookie value without checking it's still a valid
variant, leaving users bucketed to removed/renamed IDs
- it assumed a non-empty variants array (variants[length - 1] throws on [])
- the GROQ example filtered experimentVariants only by experiment status,
so the first running experiment won regardless of the user's assignment;
now scoped by experimentId plus the assigned variantId
sanity-best-practices/references/migration-html-import.md
- the custom <a> deserializer returned a top-level _type: 'link' block;
htmlToBlocks expects an __annotation with a markDef and children from
next(), matching portable-text-conversion/rules/html-to-pt.md
sanity-best-practices/references/functions.md
- the auto-tag function listened on create/update and wrote to tags with
no guard, re-triggering itself in a loop; added !defined(tags) to the
filter, mirroring the recursion guard in the translation example
* fix: more buggy example code in skill references
Second batch of fixes from automated review (Cursor Bugbot):
- cms-integration.md: the assignVariant fallback returned the last variant
without calling setCookie, so visitors who hit that path (stale/invalid
cookie, zero total weight) were re-bucketed on every request; persist it
- functions.md: the step-by-step 'Creating a Function' tutorial filtered on
_type == "post" while its handler patches the same document — add the
!defined(firstPublished) recursion guard the file itself prescribes
- angular.md: the Transfer State snippet had literal '+' diff markers pasted
in, making it invalid TypeScript; strip them and hoist the imports
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix: address Copilot review findings in skill examples
- migration-html-import: guard `el.tagName` with optional chaining so the
custom rules fall through for non-element nodes (text nodes) instead of
throwing, matching portable-text-conversion/rules/html-to-pt.md.
- angular: widen the TransferState key to `ClientReturn<Query> | null` so
`get(key, null)` type-checks against Angular's
`get<T>(key: StateKey<T>, defaultValue: T): T`.
* fix: guard null href/src in htmlToBlocks deserializer examples
`getAttribute` returns null for a missing attribute, so the examples could
emit `href: null` markDefs and the literal string `image@null` — the latter
only fails later at asset-upload time, with no pointer back to the bad node.
Both rules now read the attribute once and fall through when it is absent,
so the surrounding text is still deserialized by the default handling.
Applies the same fix to portable-text-conversion/rules/html-to-pt.md, which
carried the identical `image@null` bug.
* docs: scope _sanityAsset examples to the NDJSON import path
`_sanityAsset` is resolved by the CLI importer, which fetches each `image@<url>`
and swaps in a real asset reference. The mutation API does not interpret it, so
the same blocks written via @sanity/client, `sanity exec`, or `defineMigration`
are stored verbatim, leaving an image field with no `asset` reference.
Neither example said so, and migration-html-import.md labelled the directive
"Upload image separately, store reference" — a description of the client-upload
path it is not. It then went on to demonstrate `defineMigration`, the very path
where the directive is inert. Name the supported path at both call sites, add a
note pointing at the upload-first alternative, and flag the constraint in the
`defineMigration` section.
Refs: https://www.sanity.io/docs/content-lake/importing-data
* docs: use canonical plural CLI topics throughout
The skills used both forms: `sanity dataset import` / `schema deploy` /
`migration run` alongside `blueprints *` / `functions *`. Standardize on the
plural form.
Plural is the canonical topic in @sanity/cli 7.x — registered in oclif.config.js
and backed by dist/commands/<topic>/, so oclif dispatches it directly. Singular
resolves only by missing oclif lookup and landing in the command_not_found hook,
which rewrites it via topicAliases. That shim works today and is silent, but it
is a compatibility path, and it is not what the docs show.
Covers dataset -> datasets, schema -> schemas, migration -> migrations.
`blueprints` and `functions` were already plural.
---------
Co-authored-by: Rune Botten <rbotten@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent fc8116b commit fc0e709
15 files changed
Lines changed: 133 additions & 70 deletions
File tree
- commands
- skills
- content-experimentation-best-practices/references
- portable-text-conversion/rules
- sanity-best-practices/references
- sanity-migration
- references
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 37 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
138 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
139 | 144 | | |
140 | 145 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
145 | 158 | | |
146 | 159 | | |
147 | 160 | | |
148 | | - | |
| 161 | + | |
149 | 162 | | |
150 | 163 | | |
151 | 164 | | |
152 | 165 | | |
153 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
154 | 171 | | |
155 | 172 | | |
156 | 173 | | |
157 | 174 | | |
158 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
159 | 182 | | |
160 | 183 | | |
161 | 184 | | |
162 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
163 | 190 | | |
164 | 191 | | |
165 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
124 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| |||
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
236 | | - | |
| 241 | + | |
237 | 242 | | |
238 | 243 | | |
239 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
| 445 | + | |
| 446 | + | |
454 | 447 | | |
455 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
456 | 455 | | |
457 | 456 | | |
458 | | - | |
459 | | - | |
| 457 | + | |
| 458 | + | |
460 | 459 | | |
461 | 460 | | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
472 | 473 | | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
478 | 479 | | |
479 | 480 | | |
480 | 481 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
460 | 463 | | |
461 | 464 | | |
462 | 465 | | |
463 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
464 | 470 | | |
465 | 471 | | |
466 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| |||
Lines changed: 37 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
51 | 65 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
| |||
60 | 74 | | |
61 | 75 | | |
62 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
63 | 85 | | |
64 | 86 | | |
65 | 87 | | |
| |||
105 | 127 | | |
106 | 128 | | |
107 | 129 | | |
108 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
109 | 133 | | |
110 | 134 | | |
111 | 135 | | |
| |||
136 | 160 | | |
137 | 161 | | |
138 | 162 | | |
139 | | - | |
| 163 | + | |
140 | 164 | | |
141 | 165 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
| 319 | + | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| |||
0 commit comments