qwen-code/integration-tests/sdk-typescript
Shaojin Wen d40f3e975e
Some checks are pending
Qwen Code CI / Lint (push) Waiting to run
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Test-1 (push) Blocked by required conditions
Qwen Code CI / Test-2 (push) Blocked by required conditions
Qwen Code CI / Test-3 (push) Blocked by required conditions
Qwen Code CI / Test-4 (push) Blocked by required conditions
Qwen Code CI / Test-5 (push) Blocked by required conditions
Qwen Code CI / Test-6 (push) Blocked by required conditions
Qwen Code CI / Test-7 (push) Blocked by required conditions
Qwen Code CI / Test-8 (push) Blocked by required conditions
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
Qwen Code CI / CodeQL (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
fix(test): restore abort-and-lifecycle stdin-close test to pre-#3723 version (#3777)
* fix(test): restore abort-and-lifecycle stdin-close test to pre-#3723 version

#3723 rewrote `should handle control responses when stdin closes
before replies` in a way that flipped its semantics:

- Old: canUseTool sleeps 1s before allowing; asyncGenerator awaits
  `inputStreamDonePromise` so stdin closes WHILE the control reply
  is still in flight; expects `original content` (the in-flight
  tool must NOT execute). Tests CLI robustness when stdin closes
  before replies — matching the test name.

- New: canUseTool returns `allow` immediately; stdin stays open
  until the second result arrives; expects `updated`. Requires
  the LLM to actually call write_file → receive tool result →
  reply 'done'. The test name still says "stdin closes before
  replies", but it no longer tests that.

The new version times out (testTimeout 5min, retry x2 = 900s) on
both macOS and Linux on every push since #3723, because it depends
on LLM tool-calling behavior that isn't deterministic on the CI
endpoint. CI history shows the pre-#3723 version was stable across
30+ runs.

This restores only the test file. The shared permissionFlow,
coreToolScheduler/Session wiring, and e2e workflow `npm run bundle`
step from #3723 are kept intact.

* test(integration): add timeout and unify loop into race chain

Address review feedback on the restored test:

- firstResultPromise / secondResultPromise now have a 30s setTimeout
  reject path, matching the pattern used by canUseToolCalledPromise
  and inputStreamDonePromise (15s). Without these, a hang in the
  result stream falls back to the global Vitest testTimeout (5min)
  with no useful diagnostic.

- loop() is now retained as `loopPromise` and joined into the await
  chain via `Promise.race`. If the iterator throws or the consumer
  exits unexpectedly, the failure surfaces directly to the test
  instead of becoming an unhandled rejection while the test waits
  on side-channel promises.

* test(integration): close pseudo-pass paths in stdin-close lifecycle test

Address review feedback. Each change maps to a specific finding:

- Guard canUseTool by toolName === 'write_file' AND file_path against
  the target absolute path. The model may issue read_file or call
  write_file with an unexpected path; those must not satisfy the
  permission-control timing harness, otherwise the test could pass
  without exercising the intended path.

- Capture the second SDK result and assert it's defined, so the
  Promise.race below can no longer short-circuit silently.

- Replace `Promise.race([..., loopPromise])` with a rejection-only
  loopError partner. Loop completion alone (e.g. iterator ends before
  canUseTool is invoked) must not short-circuit the awaited
  milestones; only loop errors should fail the test.

- Restore absolute path via `helper.getPath('test.txt')` and embed it
  in the prompt, so the file the test asserts on is unambiguously
  the same one the model is asked to write.

- Wrap timing promises in a `boundedPromise` helper that clears its
  timeout on resolve, eliminating dangling timers on success runs.

- Drop the unconditional `console.log(JSON.stringify(...))` in the
  consumer loop to reduce CI retry noise.

Out of scope (acknowledged but deferred): the test still requires
the model to actually emit a write_file tool call; with the new
15s/30s bounded timeouts, an LLM that fails to call write_file now
fails fast with a labeled error ("canUseTool callback not called
timeout after 15000ms") instead of hanging to the global 5-min
testTimeout. Making the test fully model-independent would require
a control-only path that doesn't go through tool dispatch — out of
scope for this regression fix.

* test(integration): defer phase timers in stdin-close lifecycle test

Address review suggestion: the 15s budgets on canUseToolCalled and
inputStreamDone started counting at promise creation, but those phases
only begin after firstResult (30s budget) resolves. On a slow CI run
where the first LLM round-trip exceeds 15s, those timers would reject
before their phase even starts, surfacing a misleading
"canUseTool callback not called" error when the actual cause was
first-result latency.

Add an explicit `startTimer()` to boundedPromise and arm each timer
only when its phase actually begins:

- firstResult: armed immediately (begins with the query).
- canUseToolCalled / inputStreamDone / secondResult: armed inside
  createPrompt right after firstResult resolves, so first-turn latency
  cannot eat into their budgets.

This also makes timeout errors point at the correct phase if any of
them does fire.
2026-05-02 21:39:43 +08:00
..
abort-and-lifecycle.test.ts fix(test): restore abort-and-lifecycle stdin-close test to pre-#3723 version (#3777) 2026-05-02 21:39:43 +08:00
configuration-options.test.ts Add chat recording toggle (CLI + settings) and disable recording in tests 2025-12-15 13:48:38 +08:00
mcp-server.test.ts fix: sdk mcp tests 2026-02-09 11:54:20 +08:00
message-event-pairing.test.ts Fix SDK message event pairing and improve content block handling 2026-03-18 18:10:23 +08:00
multi-turn.test.ts test(sdk): simplify integration tests for reliability 2026-03-16 11:23:57 +08:00
permission-control.test.ts feat(web-search): remove built-in web_search tool, replace with MCP-based approach (#3502) 2026-04-24 11:29:02 +08:00
sdk-mcp-server.test.ts fix: sdk mcp tests 2026-02-09 11:54:20 +08:00
session-id.test.ts fix: sandbox user permission in integration tests 2026-02-15 11:02:32 +08:00
single-turn.test.ts chore: rename @qwen-code/sdk-typescript to @qwen-code/sdk 2025-12-05 21:47:26 +08:00
subagents.test.ts feat: simplify subagent model configuration with model selector 2026-03-27 11:49:45 +08:00
system-control.test.ts test: improve sdk integration tests 2026-01-27 17:10:36 +08:00
test-helper.ts test(sdk): add tool control pattern matching tests 2026-03-24 22:31:59 +08:00
tool-control.test.ts test(sdk): improve permission message pattern matching 2026-03-27 16:36:06 +08:00