New package gcp-ai (Yaka88): Vertex models and Google Cloud credits through the user's own gcloud ADC, with multiple accounts, a signed-in model list, and a pipe-only Chrome for the credits read.
Reviewed at 8989b58 against the 10-24 review at 4586c99. I read the whole incremental diff (index.mjs, lib/browser, lib/credentials, lib/lock, test/*). Earlier rounds had already reviewed the rest.
- Tests reaching the network: fixed. test/network.mjs replaces fetch and blocks non-local net/tls/http/dns. `bun test` (40 pass, 1 skip [Linux-only lock test], 0 fail, 106s) ran in a sandbox HOME/TMPDIR behind a dead HTTPS_PROXY, with a preload that logged non-local fetch and connect calls: 0 lines logged. Broken by hand: with the fetch stub removed from "already filed", the guard prints "Unexpected network fetch … userinfo" and bun exits 1. Restored, it exits 0.
- Chrome background traffic: lsof on the test Chrome processes (56 samples during browser.test.mjs, 5 pass) found no inet sockets at all.
- Leftover work after a test: close() now awaits settled, and every sign-in test closes in finally before restoring fetch.
- Smaller points: the lock's age ceiling now comes after the Linux /proc check; settings() is auth > options > env for every field; resolveAdcDirectory and authorizeAdc are removed.
- `bun scripts/check.mjs gcp-ai`: ok. The merge onto main 98985a2 is clean. Loaded into magpie's plugin host (origin/main 4dfd88206) with scripts/try.sh in a sandbox HOME: gcp-ai, 12 models, not signed in.
Not tried: a real Google account or gcloud sign-in, Windows, Linux (the lock test is skipped on macOS). The headless Console credits scrape still runs for every signed-in account, cached on failure, as noted in the earlier review.
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import test from "node:test"
|
|
import { mkdtemp, rm } from "node:fs/promises"
|
|
import { tmpdir } from "node:os"
|
|
import { join } from "node:path"
|
|
import { take, wanted } from "../lib/lock.mjs"
|
|
|
|
// A browser kept between reads still holds the profile's lock. Another process
|
|
// that wants the profile must not have to wait out the whole idle window, so
|
|
// the waiter says so on disk and the holder steps aside.
|
|
|
|
test("a waiter is visible to the holder, and taking the lock clears it", async () => {
|
|
const directory = await mkdtemp(join(tmpdir(), "vertex-want-"))
|
|
try {
|
|
const file = join(directory, "profile")
|
|
const release = await take(file)
|
|
const takenAt = Date.now()
|
|
assert.equal(await wanted(file), 0)
|
|
|
|
// A second taker cannot have the lock, and leaves a mark that it is waiting.
|
|
const waiter = take(file, { timeout: 5000, poll: 20 })
|
|
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
assert.ok((await wanted(file)) > takenAt, "the wait is not visible to the holder")
|
|
|
|
await release()
|
|
const second = await waiter
|
|
// The waiter now holds it, so nobody is waiting any more.
|
|
assert.equal(await wanted(file), 0)
|
|
await second()
|
|
} finally { await rm(directory, { recursive: true, force: true }) }
|
|
})
|