Commit e3a5cab
python: decode boolean-discriminated unions (#2123)
* python: decode boolean-discriminated unions
The Python generator captured a union discriminator's JSON Schema `const`
with `String()`, so a boolean const became the string "true"/"false" and the
emitted dispatcher matched `case "true":`. A JSON boolean decodes to Python
`True`, which never equals `"true"`, so every boolean-discriminated union
fell through to `raise ValueError`.
Two unions are affected. `sessions.list()` raised
`ValueError: Unknown SessionListEntry isRemote: False` for any non-empty
session list, and `QueuedCommandHandled.to_dict()` put the string `"true"` on
the wire where the schema declares `{"type": "boolean", "const": true}`.
Keep the const's JSON type through codegen and render it as a Python literal
(`True`/`False`), annotating the discriminator `ClassVar` as `bool`. This
mirrors how `go.ts` already models discriminator values. Regenerating changes
six lines of `python/copilot/generated/rpc.py`; no other language changes.
* python: strengthen sessions.list e2e discriminator coverage
Ensure the rpc sessions.list e2e test persists at least one session entry and asserts the matching session decodes to LocalSessionMetadataValue with is_remote=False, exercising the boolean discriminator path end-to-end.
Use an authed client token from GITHUB_TOKEN (default fakevalue) and enqueue a user turn before save/list so the entry is present without depending on full model completion.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* python: document intentional ExceptionGroup swallow in sessions.list e2e
CodeQL flagged the new `except ExceptionGroup: pass` in the sessions.list
teardown as an empty except clause with no explanation. Add the same
explanatory comment the four other identical teardowns in this file already
carry.
Also wrap the enqueue `session.send(...)` call, which was 104 characters and
failed the repo's 100-column ruff lint.
* python: wait for the saved session instead of a fixed sleep in sessions.list e2e
The sessions.list e2e test enqueued a turn, slept 200ms, then saved and listed
once. On the Windows runners the enqueued turn was not recorded yet when save
ran, so sessions.list came back empty and `assert len(listed.sessions) >= 1`
failed with `assert 0 >= 1`. Linux and macOS happened to win the race.
Replace the fixed sleep with the existing `wait_for_condition` harness helper,
re-saving on each attempt until the session actually appears in sessions.list.
All discriminator assertions are unchanged, so the boolean-discriminator path
this PR fixes is still exercised end-to-end.
`asyncio` was imported only for the removed sleep, so drop the import.
---------
Co-authored-by: examon <examon@users.noreply.github.com>
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 3186a84 commit e3a5cab
4 files changed
Lines changed: 197 additions & 40 deletions
File tree
- python
- copilot/generated
- e2e
- scripts/codegen
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
286 | 292 | | |
287 | | - | |
| 293 | + | |
288 | 294 | | |
289 | 295 | | |
290 | 296 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 297 | + | |
297 | 298 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
306 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
307 | 333 | | |
| 334 | + | |
| 335 | + | |
308 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
309 | 342 | | |
310 | 343 | | |
311 | 344 | | |
312 | 345 | | |
313 | 346 | | |
314 | 347 | | |
315 | 348 | | |
316 | | - | |
| 349 | + | |
317 | 350 | | |
318 | 351 | | |
319 | 352 | | |
320 | 353 | | |
321 | | - | |
| 354 | + | |
322 | 355 | | |
323 | 356 | | |
324 | 357 | | |
325 | 358 | | |
326 | | - | |
| 359 | + | |
327 | 360 | | |
328 | 361 | | |
329 | 362 | | |
330 | 363 | | |
331 | | - | |
| 364 | + | |
332 | 365 | | |
333 | 366 | | |
334 | 367 | | |
335 | 368 | | |
336 | | - | |
| 369 | + | |
337 | 370 | | |
338 | 371 | | |
339 | 372 | | |
340 | 373 | | |
341 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
342 | 383 | | |
343 | 384 | | |
344 | 385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 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 | + | |
0 commit comments