Repository navigation
Commit 9420afa
authored
test: accept native Vertex malformed-function terminal with empty content (#524)
## Problem
The Drift Tests run
[38104122278](https://github.com/CopilotKit/aimock/actions/runs/38104122278)
on `main` @ b9cff07 failed the live Vertex case `k5-object` (`expected
[ 'TARGET_COMPARED', 'NOT_TRIGGERED' ] to include 'FAILURE'`). Because
of that, `k5-stream`, `k9-object` and `k9-stream` were not attempted
(`earlier-case-failed`).
Vertex returned HTTP 200 from `gemini-2.5-flash`:
```
"candidates":[{"content":{},"finishReason":"MALFORMED_FUNCTION_CALL","finishMessage":"Malformed function call: print(default_api.archive(cities=['Tokyo"}]
```
The comparator already approves a `MALFORMED_FUNCTION_CALL` terminal as
`NOT_TRIGGERED` (reason `malformed-function-terminal`). The retained
`k5-stream` capture passes this way. The difference is the shape: in
object mode Vertex sent an **empty** `content: {}` object, while the
stream capture has no `content` key. Any `content` present had to have
`role: "model"` plus a `parts` array, so the check threw `invalid
content`. This is a deterministic shape-handling bug in the test
comparator, not a new upstream behavior class.
## Change (test-only; no `src/` change)
`src/__tests__/drift/vertex-misbehavior.drift.ts`:
- On the **native** leg only, when the candidate's `finishReason` is
`MALFORMED_FUNCTION_CALL`, an empty `content` object (no keys) is
treated the same as absent content.
- This covers **object and stream mode on purpose**: an empty `content`
means no content in either mode.
- Any other content still needs `role: "model"` plus a `parts` array.
The modeled (aimock) leg stays strict.
- The CI capture is retained byte-exact as a fixture with its sha256
(`4c38ba91…477eb`), with the same request hash as the existing k5
captures.
- `withVertexSequence` takes an optional list of served captures, so the
recurrence test can serve the CI capture first.
## Local red/green
Real surface: the captured raw bytes are replayed through the actual
`@google/genai` SDK over an owned localhost HTTP server, then through
`compareVertexObservation`. Separately, the CI capture runs through
`runVertexRecurrence`, the live path that failed in run 38104122278,
against a localhost origin.
**RED** (new tests, with the comparator's content check restored to the
b9cff07 line):
```
× ... classifies the captured empty-content object as an approved non-trigger AssertionError: invalid content
× ... rejects the captured malformed-function terminal without a finish message (got 'invalid content' before reaching the terminal check)
× ... accepts empty content with a malformed-function terminal in stream mode AssertionError: invalid content
× Vertex recurrence continues past the captured empty-content malformed-function terminal
→ expected [ … ] to have a length of 4 but got 1 (k5-object FAILURE; later cases earlier-case-failed)
Tests 4 failed | 6 passed | 72 skipped (82)
```
**GREEN** (after fix):
```
✓ Vertex retained native dispositions > 'k5-object' | 'k5-stream' | 'k9-object' | 'k9-stream' preserve genuine wire bytes and approved non-trigger
✓ ... classifies the captured empty-content object as an approved non-trigger (NOT_TRIGGERED / malformed-function-terminal)
✓ ... accepts empty content with a malformed-function terminal in stream mode (NOT_TRIGGERED / malformed-function-terminal)
✓ ... rejects the same empty content on the modeled leg
✓ ... rejects malformed-function content with 'non-model role' ({role:"user"})
✓ ... rejects malformed-function content with 'non-array parts' ({role:"model", parts:"x"})
✓ ... rejects malformed-function content with 'missing parts' ({role:"model"})
✓ ... rejects empty content with a STOP terminal
✓ ... rejects empty content with a MAX_TOKENS terminal
✓ ... rejects the captured malformed-function terminal without a finish message (invalid malformed-function terminal)
✓ Vertex recurrence continues past the captured empty-content malformed-function terminal
(4 requests; all four NOT_TRIGGERED; no earlier-case-failed)
Whole file: Tests 78 passed | 4 skipped (82) (the 4 skipped are the live-gated cases)
```
**Mutation check:** I replaced each guard clause with `true`, one at a
time, and each mutant was caught:
- dropping `origin === "native"` fails the modeled-leg test
- dropping the `MALFORMED_FUNCTION_CALL` check fails the STOP and
MAX_TOKENS tests
- dropping the empty-object check fails the role and parts tests
- dropping the existing `Array.isArray(content.parts)` check fails the
'non-array parts' and 'missing parts' tests
## Live verification: not run locally
**I could not run Vertex live locally.** CI gets its token through
GitHub workload identity for the `main` schedule/dispatch runs only. The
local gcloud credentials need interactive re-authentication, and no
Vertex credential is in the local secret store. The live confirmation is
a manual Drift Tests run on `main` after merge.
## Gates
`pnpm typecheck`, `pnpm lint`, `pnpm format:check`, `pnpm build`: pass.
`pnpm test`: 377 files / 14073 passed, 3 skipped.1 file changed
Lines changed: 118 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
172 | 180 | | |
173 | 181 | | |
174 | 182 | | |
| |||
389 | 397 | | |
390 | 398 | | |
391 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
392 | 480 | | |
393 | 481 | | |
394 | 482 | | |
| |||
1247 | 1335 | | |
1248 | 1336 | | |
1249 | 1337 | | |
| 1338 | + | |
1250 | 1339 | | |
1251 | 1340 | | |
1252 | 1341 | | |
1253 | 1342 | | |
1254 | 1343 | | |
1255 | 1344 | | |
1256 | 1345 | | |
1257 | | - | |
| 1346 | + | |
1258 | 1347 | | |
1259 | 1348 | | |
1260 | 1349 | | |
| |||
1571 | 1660 | | |
1572 | 1661 | | |
1573 | 1662 | | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
0 commit comments