@@ -5,6 +5,44 @@ import os from "node:os";
55import path from "node:path" ;
66import { afterEach } from "vitest" ;
77
8+ export function writeNodeBackedJq ( binDir : string ) : void {
9+ const jqPath = path . join ( binDir , "jq" ) ;
10+ fs . writeFileSync (
11+ jqPath ,
12+ `#!/usr/bin/env node
13+ const fs = require("node:fs");
14+ const args = process.argv.slice(2);
15+ const query = args.at(-1) ?? "";
16+ const input = JSON.parse(fs.readFileSync(0, "utf8"));
17+ const print = (value) => process.stdout.write(String(value ?? "") + "\\n");
18+
19+ if (query === ".login") print(input.login);
20+ else if (query === ".name // empty") print(input.name ?? "");
21+ else if (query === ".created_at") print(input.created_at);
22+ else if (query === ".type") print(input.type);
23+ else if (query === ".totalCommitContributions") print(input.totalCommitContributions);
24+ else if (query === ".totalIssueContributions") print(input.totalIssueContributions);
25+ else if (query === ".totalPullRequestContributions") print(input.totalPullRequestContributions);
26+ else if (query === ".totalPullRequestReviewContributions") print(input.totalPullRequestReviewContributions);
27+ else if (query.includes("{id: .profileId")) {
28+ const profiles = input.auth?.oauth?.profiles ?? [];
29+ const profile = profiles.filter((item) => item.provider === "anthropic" && item.type === "oauth").sort((a, b) => (b.expiresAt ?? 0) - (a.expiresAt ?? 0))[0];
30+ print(profile?.profileId ?? "none");
31+ } else if (query.includes(".auth.providers[]")) {
32+ const counts = (input.auth?.providers ?? []).filter((item) => item.provider === "anthropic").map((item) => item.profiles?.apiKey ?? 0);
33+ print(Math.max(0, ...counts));
34+ } else if (query.includes(".auth.oauth.profiles[]")) {
35+ const profiles = (input.auth?.oauth?.profiles ?? []).filter((item) => item.provider === "anthropic" && item.type === "oauth");
36+ print(Math.max(0, ...profiles.map((item) => item.expiresAt ?? 0)));
37+ } else {
38+ process.stderr.write("unsupported jq query: " + query + "\\n");
39+ process.exit(2);
40+ }
41+ ` ,
42+ ) ;
43+ fs . chmodSync ( jqPath , 0o755 ) ;
44+ }
45+
846export function createScriptTestHarness ( ) {
947 const tempDirs : string [ ] = [ ] ;
1048
0 commit comments