From d7adec8f746b04d78183701923a94572b32ac286 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 8 Nov 2026 05:39:42 +0800 Subject: [PATCH] gcp-ai: the fake gcloud in the ADC consent test exits only after its ADC write lands The "ADC setup reads gcloud's complete consent URL ..." test's writesThenFails fake started the ADC write on one 5ms timer (void, not awaited) and exited on another 40ms timer. beginAdcLogin stats the ADC file on a non-zero exit to tell "saved, then the quota probe failed" from a failed consent, so when the write took more than ~35ms on a busy machine the exit was read before the file existed and the test saw "gcloud could not set up ADC". Real gcloud has written the file before it exits, so the plugin is right and the race was the test's: the fake now emits exit only once its write has resolved. Run on mote (Bun 1.4.2, TMPDIR and HOME inside the run dir): - reproduced: the write's timer moved 5ms -> 60ms on the old test: red ("gcloud could not set up ADC") every run. - fixed, with a 100ms sleep injected into fixture.setAdc: green. - broken by hand (the fake's exit no longer awaits the write), same 100ms injection: red. Injection removed afterwards. - bun test packages/gcp-ai: 95 pass, 14 skip, 0 fail. - bun scripts/check.mjs gcp-ai: ok. - repo-root bun test: 6867 pass, 0 fail (499 files). Only a test changed, so no version bump. Fixes #835 --- packages/gcp-ai/test/plugin.test.mjs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/gcp-ai/test/plugin.test.mjs b/packages/gcp-ai/test/plugin.test.mjs index 525b64f..eabc156 100644 --- a/packages/gcp-ai/test/plugin.test.mjs +++ b/packages/gcp-ai/test/plugin.test.mjs @@ -475,9 +475,17 @@ test("ADC setup reads gcloud's complete consent URL and distinguishes saved ADC // ADC written before gcloud's own quota-project probe failed: the sign-in // worked, so the exit code is not the answer. await fixture.clearAdc() + // Real gcloud has saved the file before it exits, so the fake exits only + // once its write has landed: two independent timers raced on a busy + // machine, and the exit could be read before the file was there (#835). const writesThenFails = () => { - const child = split(["https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=x&state=y\n"], 1) - setTimeout(() => { void fixture.setAdc({ quota_project_id: "adc-project" }) }, 5) + const child = new EventEmitter() + child.stdout = new EventEmitter(); child.stderr = new EventEmitter(); child.kill = () => {} + setTimeout(async () => { + child.stderr.emit("data", "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=x&state=y\n") + await fixture.setAdc({ quota_project_id: "adc-project" }) + child.emit("exit", 1) + }, 5) return child } await (await beginAdcLogin({}, writesThenFails)).done