@asterxsk/kiln 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -155
- package/agent/AGENTS.md +67 -67
- package/agent/README.md +5 -5
- package/agent/extensions/ask-user/index.ts +418 -418
- package/agent/extensions/ask-user/install.ps1 +27 -27
- package/agent/extensions/ask-user/install.sh +24 -24
- package/agent/extensions/ask-user/package-lock.json +769 -769
- package/agent/extensions/ask-user/package.json +19 -19
- package/agent/extensions/ask-user/prompt.ts +45 -45
- package/agent/extensions/ask-user/tsconfig.json +7 -7
- package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -942
- package/agent/extensions/background-terminals/index.ts +627 -627
- package/agent/extensions/background-terminals/install.ps1 +27 -27
- package/agent/extensions/background-terminals/install.sh +24 -24
- package/agent/extensions/background-terminals/manager.test.ts +735 -735
- package/agent/extensions/background-terminals/output.test.ts +109 -109
- package/agent/extensions/background-terminals/package-lock.json +769 -769
- package/agent/extensions/background-terminals/package.json +17 -17
- package/agent/extensions/background-terminals/prompt.test.ts +125 -125
- package/agent/extensions/background-terminals/ps.test.ts +82 -82
- package/agent/extensions/background-terminals/result-delivery.test.ts +44 -44
- package/agent/extensions/background-terminals/src/domain.ts +87 -87
- package/agent/extensions/background-terminals/src/manager.ts +907 -907
- package/agent/extensions/background-terminals/src/output.ts +84 -84
- package/agent/extensions/background-terminals/src/prompt.ts +142 -142
- package/agent/extensions/background-terminals/src/result-delivery.ts +27 -27
- package/agent/extensions/background-terminals/src/runtime.ts +36 -36
- package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -79
- package/agent/extensions/background-terminals/src/ui/ps.ts +621 -621
- package/agent/extensions/background-terminals/tsconfig.json +7 -7
- package/agent/extensions/destructive/README.md +31 -31
- package/agent/extensions/destructive/index.ts +88 -88
- package/agent/extensions/destructive/install.ps1 +27 -27
- package/agent/extensions/destructive/install.sh +24 -24
- package/agent/extensions/file-search/index.spec.ts +443 -443
- package/agent/extensions/file-search/index.ts +459 -459
- package/agent/extensions/file-search/install.ps1 +27 -27
- package/agent/extensions/file-search/install.sh +24 -24
- package/agent/extensions/file-search/package-lock.json +2253 -2253
- package/agent/extensions/file-search/package.json +23 -23
- package/agent/extensions/file-search/src/args.ts +122 -122
- package/agent/extensions/file-search/src/binaries.ts +422 -422
- package/agent/extensions/file-search/src/output.ts +126 -126
- package/agent/extensions/file-search/src/process.ts +146 -146
- package/agent/extensions/file-search/src/prompt.ts +52 -52
- package/agent/extensions/file-search/tsconfig.json +7 -7
- package/agent/extensions/goal/README.md +50 -50
- package/agent/extensions/goal/index.ts +155 -155
- package/agent/extensions/goal/install.ps1 +27 -27
- package/agent/extensions/goal/install.sh +24 -24
- package/agent/extensions/kiln-update/README.md +38 -25
- package/agent/extensions/kiln-update/index.ts +177 -99
- package/agent/extensions/modelconf/PLAN.md +915 -915
- package/agent/extensions/modelconf/README.md +66 -66
- package/agent/extensions/modelconf/index.ts +296 -296
- package/agent/extensions/modelconf/install.ps1 +27 -27
- package/agent/extensions/modelconf/install.sh +24 -24
- package/agent/extensions/modelconf/package-lock.json +1809 -1809
- package/agent/extensions/modelconf/package.json +13 -13
- package/agent/extensions/modelconf/src/fuzzy.ts +26 -26
- package/agent/extensions/modelconf/src/glob.ts +13 -13
- package/agent/extensions/modelconf/src/persistence.test.ts +46 -46
- package/agent/extensions/modelconf/src/persistence.ts +164 -164
- package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -75
- package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -1101
- package/agent/extensions/modelconf/tsconfig.json +15 -15
- package/agent/extensions/pi-web-access/CHANGELOG.md +690 -690
- package/agent/extensions/pi-web-access/LICENSE +21 -21
- package/agent/extensions/pi-web-access/README.md +470 -470
- package/agent/extensions/pi-web-access/SECURITY.md +5 -5
- package/agent/extensions/pi-web-access/activity.ts +101 -101
- package/agent/extensions/pi-web-access/auth-fetch.ts +148 -148
- package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -272
- package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -669
- package/agent/extensions/pi-web-access/content-find.ts +139 -139
- package/agent/extensions/pi-web-access/credential-source.ts +191 -191
- package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -406
- package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -568
- package/agent/extensions/pi-web-access/declared-web-links.ts +173 -173
- package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -496
- package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -140
- package/agent/extensions/pi-web-access/exa.ts +526 -526
- package/agent/extensions/pi-web-access/extract.ts +1196 -1196
- package/agent/extensions/pi-web-access/feature-config.ts +29 -29
- package/agent/extensions/pi-web-access/fetch-params.ts +111 -111
- package/agent/extensions/pi-web-access/gemini-adc.ts +298 -298
- package/agent/extensions/pi-web-access/gemini-api.ts +353 -353
- package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -108
- package/agent/extensions/pi-web-access/gemini-search.ts +21 -21
- package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -128
- package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -101
- package/agent/extensions/pi-web-access/gemini-web.ts +487 -487
- package/agent/extensions/pi-web-access/github-api.ts +197 -197
- package/agent/extensions/pi-web-access/github-extract.ts +746 -746
- package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -700
- package/agent/extensions/pi-web-access/index.ts +1737 -1737
- package/agent/extensions/pi-web-access/package-lock.json +5808 -5808
- package/agent/extensions/pi-web-access/package.json +64 -64
- package/agent/extensions/pi-web-access/page-query.ts +96 -96
- package/agent/extensions/pi-web-access/pdf-extract.ts +409 -409
- package/agent/extensions/pi-web-access/promise-try.d.ts +7 -7
- package/agent/extensions/pi-web-access/query-rewrite.ts +51 -51
- package/agent/extensions/pi-web-access/render-search-error.ts +170 -170
- package/agent/extensions/pi-web-access/rsc-extract.ts +338 -338
- package/agent/extensions/pi-web-access/search-types.ts +20 -20
- package/agent/extensions/pi-web-access/source-check.ts +282 -282
- package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -526
- package/agent/extensions/pi-web-access/storage.ts +521 -521
- package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -125
- package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -208
- package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -840
- package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -441
- package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -283
- package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -25
- package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -118
- package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -210
- package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -552
- package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -212
- package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -40
- package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -334
- package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -95
- package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -53
- package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -92
- package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -86
- package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -34
- package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -173
- package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -257
- package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -170
- package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -133
- package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -178
- package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -148
- package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -223
- package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -378
- package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -565
- package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -99
- package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -118
- package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -52
- package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -50
- package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -51
- package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -140
- package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -500
- package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -286
- package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -52
- package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -102
- package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -152
- package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -274
- package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -179
- package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -205
- package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -456
- package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -106
- package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -182
- package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -66
- package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -64
- package/agent/extensions/pi-web-access/tsconfig.json +11 -11
- package/agent/extensions/pi-web-access/utils.ts +451 -451
- package/agent/extensions/pi-web-access/video-extract.ts +392 -392
- package/agent/extensions/pi-web-access/youtube-extract.ts +328 -328
- package/agent/extensions/shared/activity-status.ts +31 -31
- package/agent/extensions/shared/child-session.test.ts +270 -270
- package/agent/extensions/shared/child-session.ts +148 -148
- package/agent/extensions/shared/context-utilization.test.ts +48 -48
- package/agent/extensions/shared/context-utilization.ts +47 -47
- package/agent/extensions/shared/dashboard-state.ts +99 -99
- package/agent/extensions/shared/install.ps1 +27 -27
- package/agent/extensions/shared/install.sh +24 -24
- package/agent/extensions/shared/tool-call-timeout.test.ts +117 -117
- package/agent/extensions/shared/tool-call-timeout.ts +104 -104
- package/agent/extensions/skillsconf/README.md +74 -74
- package/agent/extensions/skillsconf/index.ts +92 -92
- package/agent/extensions/skillsconf/install.ps1 +27 -27
- package/agent/extensions/skillsconf/install.sh +24 -24
- package/agent/extensions/skillsconf/package-lock.json +1809 -1809
- package/agent/extensions/skillsconf/package.json +18 -18
- package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -64
- package/agent/extensions/skillsconf/src/delete-skill.ts +45 -45
- package/agent/extensions/skillsconf/src/filter.test.ts +80 -80
- package/agent/extensions/skillsconf/src/filter.ts +74 -74
- package/agent/extensions/skillsconf/src/fuzzy.ts +26 -26
- package/agent/extensions/skillsconf/src/persistence.test.ts +72 -72
- package/agent/extensions/skillsconf/src/persistence.ts +169 -169
- package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -337
- package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -758
- package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -91
- package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -144
- package/agent/extensions/skillsconf/tsconfig.json +15 -15
- package/agent/extensions/statusline/index.ts +273 -282
- package/agent/extensions/statusline/install.ps1 +27 -27
- package/agent/extensions/statusline/install.sh +24 -24
- package/agent/extensions/subagents/by-the-way.test.ts +29 -29
- package/agent/extensions/subagents/claude.test.ts +119 -119
- package/agent/extensions/subagents/codex.test.ts +102 -102
- package/agent/extensions/subagents/context-usage.test.ts +107 -107
- package/agent/extensions/subagents/docs/design-plan.md +568 -568
- package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -354
- package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -571
- package/agent/extensions/subagents/index.ts +779 -779
- package/agent/extensions/subagents/install.ps1 +27 -27
- package/agent/extensions/subagents/install.sh +24 -24
- package/agent/extensions/subagents/manager.test.ts +276 -276
- package/agent/extensions/subagents/package-lock.json +2244 -2244
- package/agent/extensions/subagents/package.json +19 -19
- package/agent/extensions/subagents/result-delivery.test.ts +27 -27
- package/agent/extensions/subagents/src/backend.ts +73 -73
- package/agent/extensions/subagents/src/backends/claude.ts +701 -701
- package/agent/extensions/subagents/src/backends/codex.ts +1060 -1060
- package/agent/extensions/subagents/src/backends/pi.ts +575 -575
- package/agent/extensions/subagents/src/backends/stub.ts +300 -300
- package/agent/extensions/subagents/src/by-the-way.ts +21 -21
- package/agent/extensions/subagents/src/domain.ts +253 -253
- package/agent/extensions/subagents/src/format.ts +74 -74
- package/agent/extensions/subagents/src/manager.ts +736 -736
- package/agent/extensions/subagents/src/prompt.ts +92 -92
- package/agent/extensions/subagents/src/result-delivery.ts +20 -20
- package/agent/extensions/subagents/src/runtime.ts +53 -53
- package/agent/extensions/subagents/src/ui/takeover.ts +583 -583
- package/agent/extensions/subagents/src/ui/transcript.ts +201 -201
- package/agent/extensions/subagents/takeover.test.ts +29 -29
- package/agent/extensions/subagents/tsconfig.json +7 -7
- package/agent/extensions/todo/AGENTS.md +38 -38
- package/agent/extensions/todo/LICENSE +21 -21
- package/agent/extensions/todo/config.ts +55 -55
- package/agent/extensions/todo/index.ts +151 -151
- package/agent/extensions/todo/install.ps1 +27 -27
- package/agent/extensions/todo/install.sh +24 -24
- package/agent/extensions/todo/locales/de.json +17 -17
- package/agent/extensions/todo/locales/en.json +15 -15
- package/agent/extensions/todo/locales/es.json +17 -17
- package/agent/extensions/todo/locales/fr.json +17 -17
- package/agent/extensions/todo/locales/pt-BR.json +17 -17
- package/agent/extensions/todo/locales/pt.json +17 -17
- package/agent/extensions/todo/locales/ru.json +17 -17
- package/agent/extensions/todo/locales/uk.json +17 -17
- package/agent/extensions/todo/locales/zh.json +17 -17
- package/agent/extensions/todo/package-lock.json +3358 -3358
- package/agent/extensions/todo/package.json +67 -67
- package/agent/extensions/todo/state/i18n-bridge.ts +64 -64
- package/agent/extensions/todo/state/invariants.ts +20 -20
- package/agent/extensions/todo/state/replay.ts +38 -38
- package/agent/extensions/todo/state/selectors.ts +107 -107
- package/agent/extensions/todo/state/state-reducer.ts +326 -326
- package/agent/extensions/todo/state/state.ts +18 -18
- package/agent/extensions/todo/state/store.ts +82 -82
- package/agent/extensions/todo/state/task-graph.ts +57 -57
- package/agent/extensions/todo/todo-overlay.ts +200 -200
- package/agent/extensions/todo/todo.ts +155 -155
- package/agent/extensions/todo/tool/response-envelope.ts +109 -109
- package/agent/extensions/todo/tool/types.ts +206 -206
- package/agent/extensions/todo/view/format.ts +177 -177
- package/agent/extensions/trim-context/README.md +54 -54
- package/agent/extensions/trim-context/index.ts +487 -487
- package/agent/extensions/trim-context/install.ps1 +27 -27
- package/agent/extensions/trim-context/install.sh +24 -24
- package/agent/keybindings.json +7 -7
- package/agent/version.txt +1 -1
- package/bin/kiln.js +20 -13
- package/package.json +1 -1
- package/agent/extensions/taste/index.ts +0 -443
- package/agent/extensions/taste/install.ps1 +0 -27
- package/agent/extensions/taste/install.sh +0 -24
|
@@ -1,257 +1,257 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { spawnSync } from "node:child_process";
|
|
3
|
-
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { test } from "node:test";
|
|
7
|
-
|
|
8
|
-
const geminiApiModuleUrl = new URL("../gemini-api.ts", import.meta.url).href;
|
|
9
|
-
const geminiAdcModuleUrl = new URL("../gemini-adc.ts", import.meta.url).href;
|
|
10
|
-
|
|
11
|
-
function runChild(script, env) {
|
|
12
|
-
const childEnv = { ...process.env };
|
|
13
|
-
for (const key of [
|
|
14
|
-
"PI_CODING_AGENT_DIR",
|
|
15
|
-
"XDG_CONFIG_HOME",
|
|
16
|
-
"GEMINI_API_KEY",
|
|
17
|
-
"GOOGLE_GEMINI_BASE_URL",
|
|
18
|
-
"CLOUDFLARE_API_KEY",
|
|
19
|
-
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
20
|
-
"GOOGLE_CLOUD_PROJECT",
|
|
21
|
-
"GOOGLE_CLOUD_LOCATION",
|
|
22
|
-
"GCLOUD_PROJECT",
|
|
23
|
-
]) {
|
|
24
|
-
delete childEnv[key];
|
|
25
|
-
}
|
|
26
|
-
// macOS homedir() ignores HOME, so pin the ADC file explicitly so tests are hermetic.
|
|
27
|
-
Object.assign(childEnv, env);
|
|
28
|
-
return spawnSync(process.execPath, ["--input-type=module"], {
|
|
29
|
-
input: script,
|
|
30
|
-
encoding: "utf8",
|
|
31
|
-
env: childEnv,
|
|
32
|
-
maxBuffer: 2 * 1024 * 1024,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function writeAdc(root, extra = {}) {
|
|
37
|
-
return writeFile(
|
|
38
|
-
join(root, "adc.json"),
|
|
39
|
-
JSON.stringify({
|
|
40
|
-
client_id: "synthetic-client-id",
|
|
41
|
-
client_secret: "synthetic-client-secret",
|
|
42
|
-
refresh_token: "synthetic-refresh-token",
|
|
43
|
-
type: "authorized_user",
|
|
44
|
-
universe_domain: "googleapis.com",
|
|
45
|
-
...extra,
|
|
46
|
-
}) + "\n",
|
|
47
|
-
"utf8",
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
test("Gemini ADC availability requires geminiAuth adc, project, location, and an ADC file", async () => {
|
|
52
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-avail-"));
|
|
53
|
-
await writeFile(join(root, "web-search.json"), JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l" }) + "\n", "utf8");
|
|
54
|
-
|
|
55
|
-
// ADC file does not exist yet -> not available.
|
|
56
|
-
const child = runChild(`
|
|
57
|
-
const { isGeminiApiAvailable } = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
58
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
59
|
-
console.log(JSON.stringify({ adcAvail: adc.isGeminiAdcAvailable(), apiAvail: isGeminiApiAvailable() }));
|
|
60
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
61
|
-
assert.equal(child.status, 0, child.stderr);
|
|
62
|
-
assert.deepEqual(JSON.parse(child.stdout.trim()), { adcAvail: false, apiAvail: false });
|
|
63
|
-
|
|
64
|
-
// Now write an ADC file; availability should flip on.
|
|
65
|
-
await writeAdc(root);
|
|
66
|
-
const child2 = runChild(`
|
|
67
|
-
const { isGeminiApiAvailable } = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
68
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
69
|
-
console.log(JSON.stringify({ adcAvail: adc.isGeminiAdcAvailable(), apiAvail: isGeminiApiAvailable(), missingProject: (await import(${JSON.stringify(geminiAdcModuleUrl)})).getAdcProject() }));
|
|
70
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
71
|
-
assert.equal(child2.status, 0, child2.stderr);
|
|
72
|
-
const avail = JSON.parse(child2.stdout.trim());
|
|
73
|
-
assert.equal(avail.adcAvail, true);
|
|
74
|
-
assert.equal(avail.apiAvail, true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("Gemini ADC config parse errors stay visible", async () => {
|
|
78
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-config-"));
|
|
79
|
-
await writeFile(join(root, "web-search.json"), "not valid JSON", "utf8");
|
|
80
|
-
|
|
81
|
-
const child = runChild(`
|
|
82
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
83
|
-
let error = null;
|
|
84
|
-
try {
|
|
85
|
-
adc.isGeminiAdcAvailable();
|
|
86
|
-
} catch (err) {
|
|
87
|
-
error = err.message;
|
|
88
|
-
}
|
|
89
|
-
console.log(JSON.stringify({ error }));
|
|
90
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
91
|
-
|
|
92
|
-
assert.equal(child.status, 0, child.stderr);
|
|
93
|
-
const { error } = JSON.parse(child.stdout.trim());
|
|
94
|
-
assert.match(error, /Failed to parse .*web-search\.json/);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("Gemini ADC credential parse errors include the file path", async () => {
|
|
98
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-file-"));
|
|
99
|
-
const adcPath = join(root, "adc.json");
|
|
100
|
-
await writeFile(adcPath, "not valid JSON", "utf8");
|
|
101
|
-
|
|
102
|
-
const child = runChild(`
|
|
103
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
104
|
-
let error = null;
|
|
105
|
-
try {
|
|
106
|
-
await adc.getAdcAccessToken();
|
|
107
|
-
} catch (err) {
|
|
108
|
-
error = err.message;
|
|
109
|
-
}
|
|
110
|
-
console.log(JSON.stringify({ error }));
|
|
111
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: adcPath });
|
|
112
|
-
|
|
113
|
-
assert.equal(child.status, 0, child.stderr);
|
|
114
|
-
const { error } = JSON.parse(child.stdout.trim());
|
|
115
|
-
assert.match(error, /Failed to parse Google Application Default Credentials file at /);
|
|
116
|
-
assert.match(error, /adc\.json/);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test("Gemini ADC credential shape errors include the file path", async () => {
|
|
120
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-shape-"));
|
|
121
|
-
const adcPath = join(root, "adc.json");
|
|
122
|
-
await writeFile(adcPath, JSON.stringify({ type: "authorized_user", client_id: "id", client_secret: "secret" }) + "\n", "utf8");
|
|
123
|
-
|
|
124
|
-
const child = runChild(`
|
|
125
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
126
|
-
let error = null;
|
|
127
|
-
try {
|
|
128
|
-
await adc.getAdcAccessToken();
|
|
129
|
-
} catch (err) {
|
|
130
|
-
error = err.message;
|
|
131
|
-
}
|
|
132
|
-
console.log(JSON.stringify({ error }));
|
|
133
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: adcPath });
|
|
134
|
-
|
|
135
|
-
assert.equal(child.status, 0, child.stderr);
|
|
136
|
-
const { error } = JSON.parse(child.stdout.trim());
|
|
137
|
-
assert.match(error, /Failed to parse Google Application Default Credentials file at /);
|
|
138
|
-
assert.match(error, /authorized_user file is missing refresh_token/);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("Gemini ADC rejects malformed token success responses", async () => {
|
|
142
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-token-shape-"));
|
|
143
|
-
await writeAdc(root);
|
|
144
|
-
const env = { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") };
|
|
145
|
-
|
|
146
|
-
const child = runChild(`
|
|
147
|
-
globalThis.fetch = async () => new Response(JSON.stringify({ access_token: true, expires_in: "bad" }), { status: 200 });
|
|
148
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
149
|
-
let error = null;
|
|
150
|
-
try {
|
|
151
|
-
await adc.getAdcAccessToken();
|
|
152
|
-
} catch (err) {
|
|
153
|
-
error = err.message;
|
|
154
|
-
}
|
|
155
|
-
console.log(JSON.stringify({ error }));
|
|
156
|
-
`, env);
|
|
157
|
-
|
|
158
|
-
assert.equal(child.status, 0, child.stderr);
|
|
159
|
-
const { error } = JSON.parse(child.stdout.trim());
|
|
160
|
-
assert.match(error, /Gemini ADC token exchange returned no access_token/);
|
|
161
|
-
|
|
162
|
-
const expires = runChild(`
|
|
163
|
-
globalThis.fetch = async () => new Response(JSON.stringify({ access_token: "token", expires_in: "bad" }), { status: 200 });
|
|
164
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
165
|
-
let error = null;
|
|
166
|
-
try {
|
|
167
|
-
await adc.getAdcAccessToken();
|
|
168
|
-
} catch (err) {
|
|
169
|
-
error = err.message;
|
|
170
|
-
}
|
|
171
|
-
console.log(JSON.stringify({ error }));
|
|
172
|
-
`, env);
|
|
173
|
-
|
|
174
|
-
assert.equal(expires.status, 0, expires.stderr);
|
|
175
|
-
assert.match(JSON.parse(expires.stdout.trim()).error, /Gemini ADC token exchange returned invalid expires_in/);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("Gemini ADC classifies only credential rejections as CredentialResolutionError", async () => {
|
|
179
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-classify-"));
|
|
180
|
-
await writeAdc(root);
|
|
181
|
-
const env = { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") };
|
|
182
|
-
|
|
183
|
-
const classify = (status, body) => runChild(`
|
|
184
|
-
globalThis.fetch = async () => new Response(${JSON.stringify(body)}, { status: ${status} });
|
|
185
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
186
|
-
let threw = null;
|
|
187
|
-
try {
|
|
188
|
-
await adc.getAdcAccessToken();
|
|
189
|
-
} catch (err) {
|
|
190
|
-
threw = { name: err.name, category: err.category, message: err.message };
|
|
191
|
-
}
|
|
192
|
-
console.log(JSON.stringify({ threw }));
|
|
193
|
-
`, env);
|
|
194
|
-
|
|
195
|
-
// Credential rejections -> CredentialResolutionError.
|
|
196
|
-
for (const status of [400, 401, 403]) {
|
|
197
|
-
const out = classify(status, JSON.stringify({ error: "denied" }));
|
|
198
|
-
assert.equal(out.status, 0, out.stderr);
|
|
199
|
-
const { threw } = JSON.parse(out.stdout.trim());
|
|
200
|
-
assert.equal(threw.name, "CredentialResolutionError", `status ${status}`);
|
|
201
|
-
assert.equal(threw.category, "oauth-credential-rejected", `status ${status}`);
|
|
202
|
-
assert.match(threw.message, /OAuth token exchange rejected/, `status ${status}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Transient failures stay plain Errors so fallbacks still run.
|
|
206
|
-
for (const status of [429, 404, 500, 502, 503]) {
|
|
207
|
-
const out = classify(status, "upstream boom");
|
|
208
|
-
assert.equal(out.status, 0, out.stderr);
|
|
209
|
-
const { threw } = JSON.parse(out.stdout.trim());
|
|
210
|
-
assert.equal(threw.name, "Error", `status ${status}`);
|
|
211
|
-
assert.equal(threw.category, undefined, `status ${status}`);
|
|
212
|
-
assert.match(threw.message, new RegExp(`token exchange failed \\(${status}\\)`), `status ${status}`);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("Gemini ADC does not advertise the Files-API (YouTube/video) path", async () => {
|
|
217
|
-
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-video-"));
|
|
218
|
-
await writeAdc(root);
|
|
219
|
-
await writeFile(
|
|
220
|
-
join(root, "web-search.json"),
|
|
221
|
-
JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l" }) + "\n",
|
|
222
|
-
"utf8",
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
// ADC only: generate-content paths are available, the Files-API path is not.
|
|
226
|
-
const adcOnly = runChild(`
|
|
227
|
-
const api = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
228
|
-
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
229
|
-
console.log(JSON.stringify({
|
|
230
|
-
adcAvail: adc.isGeminiAdcAvailable(),
|
|
231
|
-
apiAvail: api.isGeminiApiAvailable(),
|
|
232
|
-
videoAvail: api.isGeminiApiAvailableWithVideo(),
|
|
233
|
-
}));
|
|
234
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
235
|
-
assert.equal(adcOnly.status, 0, adcOnly.stderr);
|
|
236
|
-
assert.deepEqual(JSON.parse(adcOnly.stdout.trim()), {
|
|
237
|
-
adcAvail: true,
|
|
238
|
-
apiAvail: true,
|
|
239
|
-
videoAvail: false,
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// ADC + API key: the Files-API path becomes available again.
|
|
243
|
-
await writeFile(
|
|
244
|
-
join(root, "web-search.json"),
|
|
245
|
-
JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l", geminiApiKey: "synthetic-key" }) + "\n",
|
|
246
|
-
"utf8",
|
|
247
|
-
);
|
|
248
|
-
const withKey = runChild(`
|
|
249
|
-
const api = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
250
|
-
console.log(JSON.stringify({
|
|
251
|
-
apiAvail: api.isGeminiApiAvailable(),
|
|
252
|
-
videoAvail: api.isGeminiApiAvailableWithVideo(),
|
|
253
|
-
}));
|
|
254
|
-
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
255
|
-
assert.equal(withKey.status, 0, withKey.stderr);
|
|
256
|
-
assert.deepEqual(JSON.parse(withKey.stdout.trim()), { apiAvail: true, videoAvail: true });
|
|
257
|
-
});
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
|
|
8
|
+
const geminiApiModuleUrl = new URL("../gemini-api.ts", import.meta.url).href;
|
|
9
|
+
const geminiAdcModuleUrl = new URL("../gemini-adc.ts", import.meta.url).href;
|
|
10
|
+
|
|
11
|
+
function runChild(script, env) {
|
|
12
|
+
const childEnv = { ...process.env };
|
|
13
|
+
for (const key of [
|
|
14
|
+
"PI_CODING_AGENT_DIR",
|
|
15
|
+
"XDG_CONFIG_HOME",
|
|
16
|
+
"GEMINI_API_KEY",
|
|
17
|
+
"GOOGLE_GEMINI_BASE_URL",
|
|
18
|
+
"CLOUDFLARE_API_KEY",
|
|
19
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
20
|
+
"GOOGLE_CLOUD_PROJECT",
|
|
21
|
+
"GOOGLE_CLOUD_LOCATION",
|
|
22
|
+
"GCLOUD_PROJECT",
|
|
23
|
+
]) {
|
|
24
|
+
delete childEnv[key];
|
|
25
|
+
}
|
|
26
|
+
// macOS homedir() ignores HOME, so pin the ADC file explicitly so tests are hermetic.
|
|
27
|
+
Object.assign(childEnv, env);
|
|
28
|
+
return spawnSync(process.execPath, ["--input-type=module"], {
|
|
29
|
+
input: script,
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
env: childEnv,
|
|
32
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function writeAdc(root, extra = {}) {
|
|
37
|
+
return writeFile(
|
|
38
|
+
join(root, "adc.json"),
|
|
39
|
+
JSON.stringify({
|
|
40
|
+
client_id: "synthetic-client-id",
|
|
41
|
+
client_secret: "synthetic-client-secret",
|
|
42
|
+
refresh_token: "synthetic-refresh-token",
|
|
43
|
+
type: "authorized_user",
|
|
44
|
+
universe_domain: "googleapis.com",
|
|
45
|
+
...extra,
|
|
46
|
+
}) + "\n",
|
|
47
|
+
"utf8",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
test("Gemini ADC availability requires geminiAuth adc, project, location, and an ADC file", async () => {
|
|
52
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-avail-"));
|
|
53
|
+
await writeFile(join(root, "web-search.json"), JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l" }) + "\n", "utf8");
|
|
54
|
+
|
|
55
|
+
// ADC file does not exist yet -> not available.
|
|
56
|
+
const child = runChild(`
|
|
57
|
+
const { isGeminiApiAvailable } = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
58
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
59
|
+
console.log(JSON.stringify({ adcAvail: adc.isGeminiAdcAvailable(), apiAvail: isGeminiApiAvailable() }));
|
|
60
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
61
|
+
assert.equal(child.status, 0, child.stderr);
|
|
62
|
+
assert.deepEqual(JSON.parse(child.stdout.trim()), { adcAvail: false, apiAvail: false });
|
|
63
|
+
|
|
64
|
+
// Now write an ADC file; availability should flip on.
|
|
65
|
+
await writeAdc(root);
|
|
66
|
+
const child2 = runChild(`
|
|
67
|
+
const { isGeminiApiAvailable } = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
68
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
69
|
+
console.log(JSON.stringify({ adcAvail: adc.isGeminiAdcAvailable(), apiAvail: isGeminiApiAvailable(), missingProject: (await import(${JSON.stringify(geminiAdcModuleUrl)})).getAdcProject() }));
|
|
70
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
71
|
+
assert.equal(child2.status, 0, child2.stderr);
|
|
72
|
+
const avail = JSON.parse(child2.stdout.trim());
|
|
73
|
+
assert.equal(avail.adcAvail, true);
|
|
74
|
+
assert.equal(avail.apiAvail, true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("Gemini ADC config parse errors stay visible", async () => {
|
|
78
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-config-"));
|
|
79
|
+
await writeFile(join(root, "web-search.json"), "not valid JSON", "utf8");
|
|
80
|
+
|
|
81
|
+
const child = runChild(`
|
|
82
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
83
|
+
let error = null;
|
|
84
|
+
try {
|
|
85
|
+
adc.isGeminiAdcAvailable();
|
|
86
|
+
} catch (err) {
|
|
87
|
+
error = err.message;
|
|
88
|
+
}
|
|
89
|
+
console.log(JSON.stringify({ error }));
|
|
90
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
91
|
+
|
|
92
|
+
assert.equal(child.status, 0, child.stderr);
|
|
93
|
+
const { error } = JSON.parse(child.stdout.trim());
|
|
94
|
+
assert.match(error, /Failed to parse .*web-search\.json/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("Gemini ADC credential parse errors include the file path", async () => {
|
|
98
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-file-"));
|
|
99
|
+
const adcPath = join(root, "adc.json");
|
|
100
|
+
await writeFile(adcPath, "not valid JSON", "utf8");
|
|
101
|
+
|
|
102
|
+
const child = runChild(`
|
|
103
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
104
|
+
let error = null;
|
|
105
|
+
try {
|
|
106
|
+
await adc.getAdcAccessToken();
|
|
107
|
+
} catch (err) {
|
|
108
|
+
error = err.message;
|
|
109
|
+
}
|
|
110
|
+
console.log(JSON.stringify({ error }));
|
|
111
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: adcPath });
|
|
112
|
+
|
|
113
|
+
assert.equal(child.status, 0, child.stderr);
|
|
114
|
+
const { error } = JSON.parse(child.stdout.trim());
|
|
115
|
+
assert.match(error, /Failed to parse Google Application Default Credentials file at /);
|
|
116
|
+
assert.match(error, /adc\.json/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("Gemini ADC credential shape errors include the file path", async () => {
|
|
120
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-shape-"));
|
|
121
|
+
const adcPath = join(root, "adc.json");
|
|
122
|
+
await writeFile(adcPath, JSON.stringify({ type: "authorized_user", client_id: "id", client_secret: "secret" }) + "\n", "utf8");
|
|
123
|
+
|
|
124
|
+
const child = runChild(`
|
|
125
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
126
|
+
let error = null;
|
|
127
|
+
try {
|
|
128
|
+
await adc.getAdcAccessToken();
|
|
129
|
+
} catch (err) {
|
|
130
|
+
error = err.message;
|
|
131
|
+
}
|
|
132
|
+
console.log(JSON.stringify({ error }));
|
|
133
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: adcPath });
|
|
134
|
+
|
|
135
|
+
assert.equal(child.status, 0, child.stderr);
|
|
136
|
+
const { error } = JSON.parse(child.stdout.trim());
|
|
137
|
+
assert.match(error, /Failed to parse Google Application Default Credentials file at /);
|
|
138
|
+
assert.match(error, /authorized_user file is missing refresh_token/);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("Gemini ADC rejects malformed token success responses", async () => {
|
|
142
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-token-shape-"));
|
|
143
|
+
await writeAdc(root);
|
|
144
|
+
const env = { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") };
|
|
145
|
+
|
|
146
|
+
const child = runChild(`
|
|
147
|
+
globalThis.fetch = async () => new Response(JSON.stringify({ access_token: true, expires_in: "bad" }), { status: 200 });
|
|
148
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
149
|
+
let error = null;
|
|
150
|
+
try {
|
|
151
|
+
await adc.getAdcAccessToken();
|
|
152
|
+
} catch (err) {
|
|
153
|
+
error = err.message;
|
|
154
|
+
}
|
|
155
|
+
console.log(JSON.stringify({ error }));
|
|
156
|
+
`, env);
|
|
157
|
+
|
|
158
|
+
assert.equal(child.status, 0, child.stderr);
|
|
159
|
+
const { error } = JSON.parse(child.stdout.trim());
|
|
160
|
+
assert.match(error, /Gemini ADC token exchange returned no access_token/);
|
|
161
|
+
|
|
162
|
+
const expires = runChild(`
|
|
163
|
+
globalThis.fetch = async () => new Response(JSON.stringify({ access_token: "token", expires_in: "bad" }), { status: 200 });
|
|
164
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
165
|
+
let error = null;
|
|
166
|
+
try {
|
|
167
|
+
await adc.getAdcAccessToken();
|
|
168
|
+
} catch (err) {
|
|
169
|
+
error = err.message;
|
|
170
|
+
}
|
|
171
|
+
console.log(JSON.stringify({ error }));
|
|
172
|
+
`, env);
|
|
173
|
+
|
|
174
|
+
assert.equal(expires.status, 0, expires.stderr);
|
|
175
|
+
assert.match(JSON.parse(expires.stdout.trim()).error, /Gemini ADC token exchange returned invalid expires_in/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("Gemini ADC classifies only credential rejections as CredentialResolutionError", async () => {
|
|
179
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-classify-"));
|
|
180
|
+
await writeAdc(root);
|
|
181
|
+
const env = { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") };
|
|
182
|
+
|
|
183
|
+
const classify = (status, body) => runChild(`
|
|
184
|
+
globalThis.fetch = async () => new Response(${JSON.stringify(body)}, { status: ${status} });
|
|
185
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
186
|
+
let threw = null;
|
|
187
|
+
try {
|
|
188
|
+
await adc.getAdcAccessToken();
|
|
189
|
+
} catch (err) {
|
|
190
|
+
threw = { name: err.name, category: err.category, message: err.message };
|
|
191
|
+
}
|
|
192
|
+
console.log(JSON.stringify({ threw }));
|
|
193
|
+
`, env);
|
|
194
|
+
|
|
195
|
+
// Credential rejections -> CredentialResolutionError.
|
|
196
|
+
for (const status of [400, 401, 403]) {
|
|
197
|
+
const out = classify(status, JSON.stringify({ error: "denied" }));
|
|
198
|
+
assert.equal(out.status, 0, out.stderr);
|
|
199
|
+
const { threw } = JSON.parse(out.stdout.trim());
|
|
200
|
+
assert.equal(threw.name, "CredentialResolutionError", `status ${status}`);
|
|
201
|
+
assert.equal(threw.category, "oauth-credential-rejected", `status ${status}`);
|
|
202
|
+
assert.match(threw.message, /OAuth token exchange rejected/, `status ${status}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Transient failures stay plain Errors so fallbacks still run.
|
|
206
|
+
for (const status of [429, 404, 500, 502, 503]) {
|
|
207
|
+
const out = classify(status, "upstream boom");
|
|
208
|
+
assert.equal(out.status, 0, out.stderr);
|
|
209
|
+
const { threw } = JSON.parse(out.stdout.trim());
|
|
210
|
+
assert.equal(threw.name, "Error", `status ${status}`);
|
|
211
|
+
assert.equal(threw.category, undefined, `status ${status}`);
|
|
212
|
+
assert.match(threw.message, new RegExp(`token exchange failed \\(${status}\\)`), `status ${status}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("Gemini ADC does not advertise the Files-API (YouTube/video) path", async () => {
|
|
217
|
+
const root = await mkdtemp(join(tmpdir(), "pi-web-access-gemini-adc-video-"));
|
|
218
|
+
await writeAdc(root);
|
|
219
|
+
await writeFile(
|
|
220
|
+
join(root, "web-search.json"),
|
|
221
|
+
JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l" }) + "\n",
|
|
222
|
+
"utf8",
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// ADC only: generate-content paths are available, the Files-API path is not.
|
|
226
|
+
const adcOnly = runChild(`
|
|
227
|
+
const api = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
228
|
+
const adc = await import(${JSON.stringify(geminiAdcModuleUrl)});
|
|
229
|
+
console.log(JSON.stringify({
|
|
230
|
+
adcAvail: adc.isGeminiAdcAvailable(),
|
|
231
|
+
apiAvail: api.isGeminiApiAvailable(),
|
|
232
|
+
videoAvail: api.isGeminiApiAvailableWithVideo(),
|
|
233
|
+
}));
|
|
234
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
235
|
+
assert.equal(adcOnly.status, 0, adcOnly.stderr);
|
|
236
|
+
assert.deepEqual(JSON.parse(adcOnly.stdout.trim()), {
|
|
237
|
+
adcAvail: true,
|
|
238
|
+
apiAvail: true,
|
|
239
|
+
videoAvail: false,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// ADC + API key: the Files-API path becomes available again.
|
|
243
|
+
await writeFile(
|
|
244
|
+
join(root, "web-search.json"),
|
|
245
|
+
JSON.stringify({ geminiAuth: "adc", geminiProject: "p", geminiLocation: "l", geminiApiKey: "synthetic-key" }) + "\n",
|
|
246
|
+
"utf8",
|
|
247
|
+
);
|
|
248
|
+
const withKey = runChild(`
|
|
249
|
+
const api = await import(${JSON.stringify(geminiApiModuleUrl)});
|
|
250
|
+
console.log(JSON.stringify({
|
|
251
|
+
apiAvail: api.isGeminiApiAvailable(),
|
|
252
|
+
videoAvail: api.isGeminiApiAvailableWithVideo(),
|
|
253
|
+
}));
|
|
254
|
+
`, { HOME: root, USERPROFILE: root, PI_CODING_AGENT_DIR: root, GOOGLE_APPLICATION_CREDENTIALS: join(root, "adc.json") });
|
|
255
|
+
assert.equal(withKey.status, 0, withKey.stderr);
|
|
256
|
+
assert.deepEqual(JSON.parse(withKey.stdout.trim()), { apiAvail: true, videoAvail: true });
|
|
257
|
+
});
|