Commit e005cc1
fix(node): tighten StateSelector to typed behavior keys (#3683)
* fix(node): tighten StateSelector to typed behavior keys
Resolves the TODO from 2d9d35f. The previous comment claimed the
SupportedBehaviors index signature blocked tightening, but concrete
EndpointType.For<T> already preserves the literal MapOf<> shape with
narrow keys. Use a `string extends K` discriminator inside StateSelector
so concrete typed endpoints get BehaviorSelection<BehaviorAt<T,K>>
(typed attribute keys, autocomplete, rejection of unknown keys), and
unbound `T extends EndpointType` falls back to RawBehaviorSelection.
Adds a @ts-expect-error type-level test asserting unknown attribute
keys are rejected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(node): assert StateSelector fallback for unbound generic endpoints
Adds a type-level equality assertion that the `string extends K`
fallback branch of `StateSelector<T>` resolves to `RawBehaviorSelection`
for unbound `T extends EndpointType`, plus a runtime-shape assertion
that arbitrary string-keyed attribute lists remain assignable. Closes
the regression gap noted by Copilot review on PR #3683 — without this,
a refactor that drops or reorders the fallback branch could silently
break generic callers that relied on raw string selections.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(node): exercise real EndpointType()/SupportedBehaviors() factory path
Adds a type-level regression test that builds an endpoint via the actual
`EndpointType(...)` + `SupportedBehaviors(...)` + `MapOf<>` pipeline and
asserts: (a) `keyof behaviors` stays narrow to the literal id rather than
widening to `string`, and (b) `StateSelector<T>` accepts known State keys
and rejects unknown ones. Closes the gap noted by Copilot review on
PR #3683 — the previous tests only used a hand-built intersection
(`EndpointType & { behaviors: { fake: ... } }`) that would still pass
even if `EndpointType.For<T>` or `MapOf<T>` regressed for real, factory-
constructed endpoints.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5aca7b8 commit e005cc1
2 files changed
Lines changed: 54 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1347 | 1347 | | |
1348 | 1348 | | |
1349 | 1349 | | |
1350 | | - | |
1351 | | - | |
1352 | 1350 | | |
1353 | | - | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
1354 | 1356 | | |
1355 | 1357 | | |
1356 | 1358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
65 | 112 | | |
66 | 113 | | |
67 | 114 | | |
| |||
0 commit comments