@intentius/chant 0.124.63 → 0.124.65
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/dist/cli/handlers/approve.d.ts +8 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +27 -4
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +2 -1
- package/dist/cli/handlers/release.d.ts +6 -4
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +101 -16
- package/dist/cli/handlers/run.d.ts +30 -1
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +108 -7
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +34 -7
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +19 -0
- package/dist/cli/registry.d.ts +10 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/cli-support.d.ts +19 -1
- package/dist/components/cli-support.d.ts.map +1 -1
- package/dist/components/cli-support.js +11 -3
- package/dist/components/component.d.ts +19 -0
- package/dist/components/component.d.ts.map +1 -1
- package/dist/components/component.schema.json +17 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/release-run.d.ts +48 -0
- package/dist/components/release-run.d.ts.map +1 -0
- package/dist/components/release-run.js +166 -0
- package/dist/components/starter-plugin.d.ts +1 -0
- package/dist/components/starter-plugin.d.ts.map +1 -1
- package/dist/components/starter-plugin.js +5 -1
- package/dist/components/unchanged-inputs.d.ts +81 -0
- package/dist/components/unchanged-inputs.d.ts.map +1 -0
- package/dist/components/unchanged-inputs.js +122 -0
- package/dist/components/verbs/index.d.ts +1 -0
- package/dist/components/verbs/index.d.ts.map +1 -1
- package/dist/components/verbs/index.js +1 -0
- package/dist/components/verbs/release-image.d.ts +36 -0
- package/dist/components/verbs/release-image.d.ts.map +1 -0
- package/dist/components/verbs/release-image.js +33 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/gate-statement.schema.json +4 -2
- package/dist/lifecycle/delivery-metrics.d.ts.map +1 -1
- package/dist/lifecycle/delivery-metrics.js +4 -2
- package/dist/lifecycle/gate-ledger.d.ts +11 -2
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +6 -0
- package/dist/lifecycle/gate-seal.d.ts +20 -4
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +18 -5
- package/dist/lifecycle/gate-statement.d.ts +27 -2
- package/dist/lifecycle/gate-statement.d.ts.map +1 -1
- package/dist/lifecycle/gate-statement.js +37 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +6 -1
- package/dist/lifecycle/ledger-read.js +1 -1
- package/dist/lifecycle/plan-stale.d.ts.map +1 -1
- package/dist/lifecycle/plan-stale.js +1 -2
- package/dist/lifecycle/publish-declaration.d.ts +20 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +24 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +1 -2
- package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
- package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
- package/dist/lifecycle/publish-git-ssh.js +180 -0
- package/dist/lifecycle/publish-homebrew.d.ts +11 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -1
- package/dist/lifecycle/publish-homebrew.js +96 -5
- package/dist/lifecycle/publish-marketplace.d.ts +36 -2
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -1
- package/dist/lifecycle/publish-marketplace.js +173 -30
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -1
- package/dist/lifecycle/publish-tauri.js +1 -2
- package/dist/lifecycle/query.d.ts +2 -2
- package/dist/lifecycle/query.d.ts.map +1 -1
- package/dist/lifecycle/query.js +3 -3
- package/dist/lifecycle/release-cut.d.ts +82 -6
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +209 -20
- package/dist/lifecycle/release-ledger.d.ts +11 -0
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.d.ts +13 -0
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.js +5 -0
- package/dist/lifecycle/release-revocation.d.ts +4 -3
- package/dist/lifecycle/release-revocation.d.ts.map +1 -1
- package/dist/lifecycle/release-revocation.js +5 -4
- package/dist/lifecycle/release-store.d.ts +49 -3
- package/dist/lifecycle/release-store.d.ts.map +1 -1
- package/dist/lifecycle/release-store.js +22 -3
- package/dist/op/gate.d.ts +1 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +2 -1
- package/dist/op/op-waves-run.js +5 -3
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +26 -6
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +284 -283
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +1 -2
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -1
- package/dist/workspace/ci-quarantine-report.js +1 -2
- package/dist/workspace/ci-quarantine.d.ts.map +1 -1
- package/dist/workspace/ci-quarantine.js +1 -2
- package/dist/workspace/delivery-metrics.schema.json +1 -1
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +1 -2
- package/dist/workspace/release-candidates.d.ts +9 -1
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +16 -5
- package/dist/workspace/release-candidates.schema.json +7 -0
- package/dist/workspace/releases.schema.json +54 -2
- package/package.json +1 -1
- package/src/cli/handlers/approve-external-signature.test.ts +105 -3
- package/src/cli/handlers/approve.ts +34 -4
- package/src/cli/handlers/pr.ts +2 -1
- package/src/cli/handlers/release.ts +91 -16
- package/src/cli/handlers/run-unchanged.e2e.test.ts +112 -0
- package/src/cli/handlers/run.ts +117 -7
- package/src/cli/main.ts +34 -7
- package/src/cli/parse-args.ts +15 -0
- package/src/cli/registry.ts +10 -2
- package/src/components/cli-support.test.ts +53 -0
- package/src/components/cli-support.ts +26 -4
- package/src/components/component.schema.json +17 -0
- package/src/components/component.ts +20 -0
- package/src/components/index.ts +1 -0
- package/src/components/registry.test.ts +1 -1
- package/src/components/release-run.test.ts +127 -0
- package/src/components/release-run.ts +188 -0
- package/src/components/starter-plugin.ts +5 -0
- package/src/components/unchanged-inputs.test.ts +98 -0
- package/src/components/unchanged-inputs.ts +151 -0
- package/src/components/verbs/index.ts +1 -0
- package/src/components/verbs/release-image.ts +52 -0
- package/src/config.ts +8 -0
- package/src/gate-statement.schema.json +4 -2
- package/src/lifecycle/delivery-metrics.ts +4 -2
- package/src/lifecycle/gate-ledger.ts +17 -2
- package/src/lifecycle/gate-seal.ts +24 -6
- package/src/lifecycle/gate-statement.ts +40 -4
- package/src/lifecycle/git.test.ts +15 -0
- package/src/lifecycle/git.ts +5 -1
- package/src/lifecycle/ledger-read.ts +1 -1
- package/src/lifecycle/plan-stale.test.ts +3 -4
- package/src/lifecycle/plan-stale.ts +1 -2
- package/src/lifecycle/publish-declaration.ts +24 -1
- package/src/lifecycle/publish-forge.ts +1 -2
- package/src/lifecycle/publish-git-ssh.ts +202 -0
- package/src/lifecycle/publish-homebrew.test.ts +181 -2
- package/src/lifecycle/publish-homebrew.ts +101 -6
- package/src/lifecycle/publish-marketplace.test.ts +158 -6
- package/src/lifecycle/publish-marketplace.ts +192 -31
- package/src/lifecycle/publish-resume.test.ts +40 -0
- package/src/lifecycle/publish-tauri.ts +1 -2
- package/src/lifecycle/query.ts +3 -3
- package/src/lifecycle/release-cut-lane.test.ts +195 -0
- package/src/lifecycle/release-cut-override.test.ts +225 -0
- package/src/lifecycle/release-cut.test.ts +45 -0
- package/src/lifecycle/release-cut.ts +262 -21
- package/src/lifecycle/release-ledger.ts +11 -0
- package/src/lifecycle/release-publish.ts +18 -0
- package/src/lifecycle/release-revocation.ts +5 -4
- package/src/lifecycle/release-store.ts +73 -5
- package/src/op/gate.ts +2 -1
- package/src/op/op-waves-run.ts +4 -2
- package/src/pr-forge.ts +25 -6
- package/src/pr-requires.test.ts +9 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/ci-green.ts +1 -2
- package/src/workspace/ci-quarantine-report.test.ts +2 -3
- package/src/workspace/ci-quarantine-report.ts +1 -2
- package/src/workspace/ci-quarantine.test.ts +2 -3
- package/src/workspace/ci-quarantine.ts +1 -2
- package/src/workspace/delivery-metrics.schema.json +1 -1
- package/src/workspace/delivery-metrics.test.ts +8 -0
- package/src/workspace/intent.ts +1 -2
- package/src/workspace/release-candidates.schema.json +7 -0
- package/src/workspace/release-candidates.ts +19 -5
- package/src/workspace/releases.schema.json +54 -2
- package/src/workspace/trust/gate-seal.test.ts +44 -0
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* #4676: the Homebrew tap target against a GitHub repository fake. The stage
|
|
3
3
|
* commits the rendered formula to a staging branch that brew does not read,
|
|
4
|
-
* and the tap branch moves only at the reveal. Nothing reaches a network
|
|
4
|
+
* and the tap branch moves only at the reveal. Nothing reaches a network:
|
|
5
|
+
* over SSH (#4699), git pushes to a bare repository through a fake ssh.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { afterAll, describe, expect, test } from "vitest";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
|
-
import {
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
12
|
import { tmpdir } from "node:os";
|
|
11
13
|
import { join } from "node:path";
|
|
12
14
|
import { createRedactor } from "./publish-credentials";
|
|
13
15
|
import { PublishDeclarationSchema } from "./publish-declaration";
|
|
16
|
+
import { githubSshHost } from "./publish-git-ssh";
|
|
14
17
|
import { fillUrl, releaseVersion, renderFormula } from "./publish-homebrew";
|
|
15
18
|
import { createPublishTargets } from "./publish-targets";
|
|
16
19
|
import { PublishTargetError, type PublishContext } from "./release-publish";
|
|
@@ -177,3 +180,179 @@ describe("homebrew tap (#4676)", () => {
|
|
|
177
180
|
expect(renderFormula('version "{{ version }}" # #{bin}', { version: "1.0", label: "v1.0", tag: "t" }, new Map())).toBe('version "1.0" # #{bin}');
|
|
178
181
|
});
|
|
179
182
|
});
|
|
183
|
+
|
|
184
|
+
describe("homebrew tap over SSH with a deploy key (#4699)", () => {
|
|
185
|
+
const KEY = "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAAfakedeploykeymaterial\n-----END OPENSSH PRIVATE KEY-----\n";
|
|
186
|
+
const HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
|
|
187
|
+
const git = (cwd: string, args: string[]) =>
|
|
188
|
+
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
189
|
+
|
|
190
|
+
/** A bare tap under `root`, as `git@github.com:<repo>.git` reaches it through the fake ssh, with one commit on main. */
|
|
191
|
+
function bareTap(files: Record<string, string>) {
|
|
192
|
+
const root = mkdtempSync(join(tmpdir(), "chant-tap-ssh-"));
|
|
193
|
+
dirs.push(root);
|
|
194
|
+
const bare = join(root, "arugula-salad", "homebrew-tap.git");
|
|
195
|
+
mkdirSync(bare, { recursive: true });
|
|
196
|
+
git(bare, ["init", "-q", "--bare", "-b", "main"]);
|
|
197
|
+
const work = join(root, "work");
|
|
198
|
+
mkdirSync(work);
|
|
199
|
+
git(work, ["init", "-q", "-b", "main"]);
|
|
200
|
+
const commit = (message: string, more: Record<string, string>) => {
|
|
201
|
+
for (const [p, text] of Object.entries(more)) {
|
|
202
|
+
mkdirSync(join(work, p, ".."), { recursive: true });
|
|
203
|
+
writeFileSync(join(work, p), text);
|
|
204
|
+
}
|
|
205
|
+
git(work, ["add", "-A"]);
|
|
206
|
+
git(work, ["commit", "-q", "-m", message]);
|
|
207
|
+
git(work, ["push", "-q", bare, "HEAD:refs/heads/main"]);
|
|
208
|
+
};
|
|
209
|
+
commit("init", files);
|
|
210
|
+
return {
|
|
211
|
+
root,
|
|
212
|
+
bare,
|
|
213
|
+
push: (more: Record<string, string>) => commit("someone else", more),
|
|
214
|
+
log: (branch: string) => git(bare, ["log", "--format=%s", branch]).split("\n").reverse(),
|
|
215
|
+
read: (branch: string, path: string) => git(bare, ["show", `${branch}:${path}`]) + "\n",
|
|
216
|
+
head: (branch: string) => git(bare, ["rev-parse", branch]),
|
|
217
|
+
branches: () => git(bare, ["for-each-ref", "--format=%(refname:short)", "refs/heads"]).split("\n").filter(Boolean),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* An ssh that serves the bare taps under `root` when it is handed `KEY`
|
|
223
|
+
* and a known-hosts file holding `HOST_KEY` for the host, and logs each
|
|
224
|
+
* call's host and options.
|
|
225
|
+
*/
|
|
226
|
+
function fakeSsh(root: string) {
|
|
227
|
+
const bin = join(root, "ssh");
|
|
228
|
+
const log = join(root, "ssh.log");
|
|
229
|
+
writeFileSync(
|
|
230
|
+
bin,
|
|
231
|
+
`#!${process.execPath}
|
|
232
|
+
const fs = require("fs");
|
|
233
|
+
const { spawnSync } = require("child_process");
|
|
234
|
+
const args = process.argv.slice(2);
|
|
235
|
+
const opts = [];
|
|
236
|
+
let key = "";
|
|
237
|
+
for (let i = 0; i < args.length - 2; i++) {
|
|
238
|
+
if (args[i] === "-o") opts.push(args[++i]);
|
|
239
|
+
else if (args[i] === "-i") key = fs.readFileSync(args[++i], "utf-8");
|
|
240
|
+
else if (args[i] === "-F") i++;
|
|
241
|
+
}
|
|
242
|
+
const host = args[args.length - 2].replace(/^git@/, "");
|
|
243
|
+
const known = opts.find((o) => o.startsWith("UserKnownHostsFile="));
|
|
244
|
+
const hosts = known ? fs.readFileSync(known.slice("UserKnownHostsFile=".length), "utf-8") : "";
|
|
245
|
+
fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ host, opts, mode: (fs.statSync(args[args.indexOf("-i") + 1]).mode & 0o777).toString(8) }) + "\\n");
|
|
246
|
+
if (!opts.includes("StrictHostKeyChecking=yes") || !hosts.split("\\n").includes(host + " " + ${JSON.stringify(HOST_KEY)})) { console.error("Host key verification failed."); process.exit(255); }
|
|
247
|
+
if (key !== ${JSON.stringify(KEY)}) { console.error("git@" + host + ": Permission denied (publickey)."); process.exit(255); }
|
|
248
|
+
const cmd = args[args.length - 1].replace(/'([^']+\\.git)'/, (_, p) => "'" + ${JSON.stringify(root)} + "/" + p + "'");
|
|
249
|
+
const r = spawnSync("sh", ["-c", cmd], { stdio: "inherit" });
|
|
250
|
+
process.exit(r.status === null ? 1 : r.status);
|
|
251
|
+
`,
|
|
252
|
+
);
|
|
253
|
+
chmodSync(bin, 0o755);
|
|
254
|
+
const calls = () => (existsSync(log) ? readFileSync(log, "utf-8").trim().split("\n").filter(Boolean).map((l) => JSON.parse(l) as { host: string; opts: string[]; mode: string }) : []);
|
|
255
|
+
return { bin, calls };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The API's /meta, which lists the host keys; nothing else is asked of it. */
|
|
259
|
+
function fakeMeta(keys: string[] = [HOST_KEY]) {
|
|
260
|
+
const calls: Array<{ url: string; headers: Record<string, string> }> = [];
|
|
261
|
+
const fetch = async (url: string, init: { method: string; headers: Record<string, string> }) => {
|
|
262
|
+
calls.push({ url, headers: init.headers });
|
|
263
|
+
const body = url === `${API}/meta` ? JSON.stringify({ ssh_keys: keys }) : "";
|
|
264
|
+
return { ok: body !== "", status: body ? 200 : 404, headers: { get: () => null }, text: async () => body };
|
|
265
|
+
};
|
|
266
|
+
return { fetch, calls };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const sshCtx = (dir: string, env: NodeJS.ProcessEnv = { HOMEBREW_TAP_KEY: KEY, PATH: process.env.PATH }) => context(dir, { env });
|
|
270
|
+
|
|
271
|
+
test("stages the formula on a branch over SSH, and fast-forwards the tap branch at the reveal, with no token", async () => {
|
|
272
|
+
const dir = member();
|
|
273
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n", "README.md": "tap\n" });
|
|
274
|
+
const ssh = fakeSsh(tap.root);
|
|
275
|
+
const meta = fakeMeta();
|
|
276
|
+
const [target] = await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY" })], { fetch: meta.fetch, ssh: ssh.bin });
|
|
277
|
+
expect(target!.credentialEnv).toEqual(["HOMEBREW_TAP_KEY"]);
|
|
278
|
+
const ctx = sshCtx(dir);
|
|
279
|
+
await target!.plan(ctx);
|
|
280
|
+
expect(ssh.calls()).toEqual([]);
|
|
281
|
+
|
|
282
|
+
const main = tap.head("main");
|
|
283
|
+
const staged = await target!.stage(ctx);
|
|
284
|
+
expect(staged.state).toMatchObject({ branch: "main", staging: "chant-publish/arugula-1.4.0" });
|
|
285
|
+
expect(staged.state.commit).toBe(tap.head("chant-publish/arugula-1.4.0"));
|
|
286
|
+
expect(tap.head("main")).toBe(main);
|
|
287
|
+
expect(tap.read("main", "Formula/arugula.rb")).toBe("old formula\n");
|
|
288
|
+
expect(tap.read("chant-publish/arugula-1.4.0", "Formula/arugula.rb")).toContain('version "1.4.0"');
|
|
289
|
+
expect(new Set(ssh.calls().map((c) => c.host))).toEqual(new Set(["api.github.test"]));
|
|
290
|
+
expect(ssh.calls()[0]!.opts).toEqual(expect.arrayContaining(["IdentitiesOnly=yes", "StrictHostKeyChecking=yes", "BatchMode=yes"]));
|
|
291
|
+
expect(ssh.calls()[0]!.mode).toBe("600");
|
|
292
|
+
// The API is asked for the host keys only, without a token.
|
|
293
|
+
expect(meta.calls.map((c) => c.url)).toEqual([`${API}/meta`]);
|
|
294
|
+
expect(meta.calls[0]!.headers.authorization).toBeUndefined();
|
|
295
|
+
|
|
296
|
+
// A stage run again finds the staging branch holding the formula and pushes nothing.
|
|
297
|
+
const again = await target!.stage(ctx);
|
|
298
|
+
expect(again.state).toEqual(staged.state);
|
|
299
|
+
expect(tap.log("chant-publish/arugula-1.4.0")).toEqual(["init", "arugula 1.4.0"]);
|
|
300
|
+
|
|
301
|
+
// The reveal is a fast-forward to the staged commit, from a session of its own, as on a fresh clone.
|
|
302
|
+
await target!.reveal(ctx, staged);
|
|
303
|
+
expect(tap.head("main")).toBe(staged.state.commit);
|
|
304
|
+
expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
|
|
305
|
+
expect(tap.read("main", "README.md")).toBe("tap\n");
|
|
306
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
307
|
+
expect(ctx.lines.join("\n")).not.toContain("fakedeploykeymaterial");
|
|
308
|
+
|
|
309
|
+
const done = await target!.stage(ctx);
|
|
310
|
+
expect(done.state).toEqual({ branch: "main", present: "true" });
|
|
311
|
+
expect(await target!.reveal(ctx, done)).toMatchObject({ items: [{ present: true }] });
|
|
312
|
+
expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("a tap branch that moved since the stage gets the formula as one commit on top", async () => {
|
|
316
|
+
const dir = member();
|
|
317
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n" });
|
|
318
|
+
const [target] = await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY", branch: "main" })], { fetch: fakeMeta().fetch, ssh: fakeSsh(tap.root).bin });
|
|
319
|
+
const ctx = sshCtx(dir);
|
|
320
|
+
const staged = await target!.stage(ctx);
|
|
321
|
+
tap.push({ "Formula/other.rb": "other\n" });
|
|
322
|
+
await target!.reveal(ctx, staged);
|
|
323
|
+
expect(tap.log("main")).toEqual(["init", "someone else", "arugula 1.4.0"]);
|
|
324
|
+
expect(tap.read("main", "Formula/other.rb")).toBe("other\n");
|
|
325
|
+
expect(tap.read("main", "Formula/arugula.rb")).toContain('version "1.4.0"');
|
|
326
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("refuses a missing key, a key beside a token, a key the remote refuses, and a host whose key the API doesn't list", async () => {
|
|
330
|
+
const dir = member();
|
|
331
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n" });
|
|
332
|
+
const ssh = fakeSsh(tap.root);
|
|
333
|
+
const make = async (fetch = fakeMeta().fetch) => (await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY" })], { fetch, ssh: ssh.bin }))[0]!;
|
|
334
|
+
|
|
335
|
+
const missing = await refused((await make()).plan(sshCtx(dir, { HOMEBREW_TAP_TOKEN: "ghp_not_read" })));
|
|
336
|
+
expect(missing.code).toBe("publish-credentials-missing");
|
|
337
|
+
expect(missing.message).toContain("SSH key from HOMEBREW_TAP_KEY");
|
|
338
|
+
|
|
339
|
+
expect((await refused(createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY", tokenEnv: "HOMEBREW_TAP_TOKEN" })]))).code).toBe("publish-homebrew-auth-invalid");
|
|
340
|
+
|
|
341
|
+
const wrongKey = await refused((await make()).stage(sshCtx(dir, { HOMEBREW_TAP_KEY: KEY.replace("fake", "other"), PATH: process.env.PATH })));
|
|
342
|
+
expect(wrongKey.code).toBe("publish-homebrew-failed");
|
|
343
|
+
expect(wrongKey.message).toContain("Permission denied (publickey)");
|
|
344
|
+
expect(wrongKey.message).not.toContain("otherdeploykeymaterial");
|
|
345
|
+
|
|
346
|
+
const otherHost = await refused((await make(fakeMeta(["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIsomeoneelse"]).fetch)).stage(sshCtx(dir)));
|
|
347
|
+
expect(otherHost.message).toContain("Host key verification failed");
|
|
348
|
+
|
|
349
|
+
const noMeta = await refused((await make(fakeMeta([]).fetch)).stage(sshCtx(dir)));
|
|
350
|
+
expect(noMeta.message).toContain("gave no SSH host keys");
|
|
351
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("the SSH host is github.com for api.github.com and the API's own host for GitHub Enterprise Server", () => {
|
|
355
|
+
expect(githubSshHost("https://api.github.com")).toBe("github.com");
|
|
356
|
+
expect(githubSshHost("https://ghe.acme.test/api/v3")).toBe("ghe.acme.test");
|
|
357
|
+
});
|
|
358
|
+
});
|
|
@@ -34,6 +34,15 @@
|
|
|
34
34
|
* the reveal commits the formula onto it instead, one commit either way,
|
|
35
35
|
* unless it already holds the formula as rendered.
|
|
36
36
|
*
|
|
37
|
+
* With `sshKeyEnv` (#4699), the same two steps run with git over SSH and the
|
|
38
|
+
* private key in that variable, such as a deploy key limited to the tap, in
|
|
39
|
+
* place of the API and a token (./publish-git-ssh.ts). The stage fetches the
|
|
40
|
+
* tap branch, commits the formula on its head and force-pushes that commit
|
|
41
|
+
* to the staging branch. The reveal fetches the staging branch and pushes
|
|
42
|
+
* its commit to the tap branch without force, which the remote takes only
|
|
43
|
+
* as a fast-forward; when the tap branch moved, it commits the formula onto
|
|
44
|
+
* the new head instead and pushes that, then deletes the staging branch.
|
|
45
|
+
*
|
|
37
46
|
* The asset URLs are the declaration's `url` pattern, so the files must be
|
|
38
47
|
* downloadable there by the time the formula is: declare the `forge` target
|
|
39
48
|
* that attaches them before this one, and its reveal runs first.
|
|
@@ -41,15 +50,18 @@
|
|
|
41
50
|
|
|
42
51
|
import { readFileSync } from "node:fs";
|
|
43
52
|
import { basename } from "node:path";
|
|
44
|
-
import { readCredential } from "./publish-credentials";
|
|
53
|
+
import { readCredential, type Credential } from "./publish-credentials";
|
|
45
54
|
import type { HomebrewPublishDeclaration } from "./publish-declaration";
|
|
55
|
+
import { SshGitRepo } from "./publish-git-ssh";
|
|
46
56
|
import { GitHubRepo, githubApi } from "./publish-github";
|
|
47
57
|
import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
|
|
48
58
|
import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget } from "./release-publish";
|
|
49
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
50
59
|
|
|
51
60
|
/** The first chant that publishes a `homebrew` target (#4676). */
|
|
52
|
-
export const PUBLISH_HOMEBREW_FLOOR =
|
|
61
|
+
export const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
|
|
62
|
+
|
|
63
|
+
/** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
|
|
64
|
+
export const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = "0.124.64";
|
|
53
65
|
|
|
54
66
|
/** The variable the tap token is read from when the declaration names none. */
|
|
55
67
|
export const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
|
|
@@ -88,7 +100,11 @@ export function renderFormula(
|
|
|
88
100
|
|
|
89
101
|
export function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDeps): PublishTarget {
|
|
90
102
|
const fetchImpl: PublishFetch = deps.fetch ?? ((url, init) => fetch(url, init as RequestInit));
|
|
91
|
-
|
|
103
|
+
if (decl.sshKeyEnv && decl.tokenEnv) {
|
|
104
|
+
throw new PublishTargetError("publish-homebrew-auth-invalid", `the homebrew target for ${decl.tap} names both tokenEnv and sshKeyEnv`, "Keep one: sshKeyEnv pushes with git over SSH, tokenEnv commits through the API.");
|
|
105
|
+
}
|
|
106
|
+
const ssh = decl.sshKeyEnv !== undefined;
|
|
107
|
+
const tokenNames = [decl.sshKeyEnv ?? decl.tokenEnv ?? HOMEBREW_TOKEN_ENV];
|
|
92
108
|
const formulaName = basename(decl.formula).replace(/\.rb$/, "");
|
|
93
109
|
const setup = (ctx: PublishContext) => {
|
|
94
110
|
const version = releaseVersion(ctx.label);
|
|
@@ -101,7 +117,11 @@ export function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDe
|
|
|
101
117
|
}
|
|
102
118
|
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
103
119
|
if (!token) {
|
|
104
|
-
throw new PublishTargetError(
|
|
120
|
+
throw new PublishTargetError(
|
|
121
|
+
"publish-credentials-missing",
|
|
122
|
+
`the homebrew target reads its ${ssh ? "SSH key" : "token"} from ${tokenNames[0]}, and it is not set`,
|
|
123
|
+
ssh ? `Set ${tokenNames[0]} to a private key that may push to ${decl.tap}, such as a deploy key with write access.` : `Set ${tokenNames[0]} to a token that may push to ${decl.tap}.`,
|
|
124
|
+
);
|
|
105
125
|
}
|
|
106
126
|
const assets = new Map<string, { url: string; sha256: string }>();
|
|
107
127
|
for (const p of decl.assets) {
|
|
@@ -130,8 +150,9 @@ export function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDe
|
|
|
130
150
|
},
|
|
131
151
|
async stage(ctx) {
|
|
132
152
|
const { version, token, assets, bytes, digest } = setup(ctx);
|
|
133
|
-
ctx.log(`using the token from ${token.from}`);
|
|
153
|
+
ctx.log(`using the ${ssh ? "SSH key" : "token"} from ${token.from}`);
|
|
134
154
|
for (const [name, a] of assets) ctx.log(`${name}: ${a.url} sha256 ${a.sha256}`);
|
|
155
|
+
if (ssh) return withSsh(ctx, token, (tap) => stageOverSsh(ctx, tap, version, bytes, digest));
|
|
135
156
|
const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
|
|
136
157
|
const branch = decl.branch ?? (await tap.defaultBranch());
|
|
137
158
|
const head = await tap.branchHead(branch);
|
|
@@ -167,6 +188,10 @@ export function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDe
|
|
|
167
188
|
const { version, token, bytes } = setup(ctx);
|
|
168
189
|
const { branch, staging, commit } = staged.state;
|
|
169
190
|
if (!branch || !staging || !commit) throw new PublishTargetError("publish-homebrew-failed", `the staged formula for ${decl.tap} has no staging commit to reveal`);
|
|
191
|
+
if (ssh) {
|
|
192
|
+
await withSsh(ctx, token, (tap) => revealOverSsh(ctx, tap, { branch, staging, commit }, version, bytes));
|
|
193
|
+
return published;
|
|
194
|
+
}
|
|
170
195
|
const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
|
|
171
196
|
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)}`);
|
|
172
197
|
if (!(await tap.moveRef(`heads/${branch}`, commit, false))) {
|
|
@@ -183,5 +208,75 @@ export function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDe
|
|
|
183
208
|
return published;
|
|
184
209
|
},
|
|
185
210
|
};
|
|
211
|
+
|
|
212
|
+
async function withSsh<T>(ctx: PublishContext, key: Credential, step: (tap: SshGitRepo) => Promise<T>): Promise<T> {
|
|
213
|
+
const tap = await SshGitRepo.open({ api: githubApi(decl.api, ctx.env), repo: decl.tap, key, ctx, fetch: fetchImpl, code: "publish-homebrew-failed", git: deps.git, ssh: deps.ssh });
|
|
214
|
+
try {
|
|
215
|
+
return await step(tap);
|
|
216
|
+
} finally {
|
|
217
|
+
tap.close();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function stageOverSsh(ctx: PublishContext, tap: SshGitRepo, version: string, bytes: Uint8Array, digest: string) {
|
|
222
|
+
const { defaultBranch, heads } = await tap.heads();
|
|
223
|
+
const branch = decl.branch ?? defaultBranch;
|
|
224
|
+
const head = branch ? heads.get(branch) : undefined;
|
|
225
|
+
if (!branch || !head) throw new PublishTargetError("publish-homebrew-failed", `${tap.remote} has no branch ${branch ?? "HEAD points at"}`, "Set branch to the branch brew installs from.");
|
|
226
|
+
const item: PublishItem = { name: decl.formula, destination: where(branch), digest };
|
|
227
|
+
const done = (state: Record<string, string>, present: boolean) => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: { branch, ...state } });
|
|
228
|
+
ctx.log(`reading ${branch} of ${tap.remote} over SSH`);
|
|
229
|
+
await tap.fetch(branch);
|
|
230
|
+
const onTap = await tap.file(head, decl.formula);
|
|
231
|
+
if (onTap && onTap.equals(Buffer.from(bytes))) {
|
|
232
|
+
ctx.log(`${branch} already has ${decl.formula} for ${version}`);
|
|
233
|
+
return done({ present: "true" }, true);
|
|
234
|
+
}
|
|
235
|
+
const staging = `chant-publish/${formulaName}-${version}`;
|
|
236
|
+
const stagingHead = heads.get(staging);
|
|
237
|
+
if (stagingHead) {
|
|
238
|
+
await tap.fetch(staging);
|
|
239
|
+
const onStaging = await tap.file(stagingHead, decl.formula);
|
|
240
|
+
if (onStaging && onStaging.equals(Buffer.from(bytes))) {
|
|
241
|
+
ctx.log(`${staging} already has ${decl.formula} for ${version}`);
|
|
242
|
+
return done({ staging, commit: stagingHead }, true);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
ctx.log(`committing ${decl.formula} for ${version} to ${staging}, at ${branch}'s head ${head.slice(0, 12)}, and pushing it over SSH`);
|
|
246
|
+
const commit = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
|
|
247
|
+
await tap.push(commit, staging, true);
|
|
248
|
+
return done({ staging, commit }, false);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function revealOverSsh(ctx: PublishContext, tap: SshGitRepo, state: { branch: string; staging: string; commit: string }, version: string, bytes: Uint8Array): Promise<void> {
|
|
252
|
+
const { branch, staging, commit } = state;
|
|
253
|
+
const { heads } = await tap.heads();
|
|
254
|
+
// The staged commit is on the staging branch: fetch it, since this run may be a resume on a fresh clone.
|
|
255
|
+
// Depth 2: the staged commit and the head it was made on, so git sees the push as a fast-forward.
|
|
256
|
+
const stagingHead = heads.get(staging) === commit ? await tap.fetch(staging, 2) : null;
|
|
257
|
+
let moved = true;
|
|
258
|
+
if (stagingHead === commit) {
|
|
259
|
+
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)} over SSH`);
|
|
260
|
+
moved = (await tap.push(commit, branch, false)) === "rejected";
|
|
261
|
+
} else {
|
|
262
|
+
ctx.log(`${staging} is not at the staged commit ${commit.slice(0, 12)} any more`);
|
|
263
|
+
}
|
|
264
|
+
if (moved) {
|
|
265
|
+
// The tap moved since the stage, or the staged commit is gone: one commit of the formula onto it, unless it already holds it.
|
|
266
|
+
const head = await tap.fetch(branch);
|
|
267
|
+
const onTap = await tap.file(head, decl.formula);
|
|
268
|
+
if (onTap && onTap.equals(Buffer.from(bytes))) {
|
|
269
|
+
ctx.log(`${branch} already has ${decl.formula} for ${version}`);
|
|
270
|
+
} else {
|
|
271
|
+
ctx.log(`committing ${decl.formula} for ${version} onto ${branch}'s head ${head.slice(0, 12)}`);
|
|
272
|
+
const onto = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
|
|
273
|
+
if ((await tap.push(onto, branch, false)) === "rejected") {
|
|
274
|
+
throw new PublishTargetError("publish-homebrew-failed", `${branch} of ${tap.remote} moved again while ${decl.formula} was committed onto it`, "Run the same publish again: it commits the formula onto the branch's new head.");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
await tap.deleteBranch(staging);
|
|
279
|
+
}
|
|
280
|
+
|
|
186
281
|
return target;
|
|
187
282
|
}
|
|
@@ -107,14 +107,33 @@ const reply = (status: number, body: string | Uint8Array = "") => ({
|
|
|
107
107
|
},
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
/**
|
|
111
|
+
* An Open VSX fake: namespaces, and the versions published to it by
|
|
112
|
+
* `POST /api/-/publish`. `trusted` lists the extensions whose trusted
|
|
113
|
+
* publisher is a GitHub Actions ID token with the registry as its audience
|
|
114
|
+
* (`gha-id-token`) or `ovsx-id-token`; `refuse` is a status every upload gets.
|
|
115
|
+
*/
|
|
116
|
+
function fakeOpenVsx(root: string, namespaces: string[], versions = new Map<string, Uint8Array>(), opts: { trusted?: string[]; refuse?: number } = {}) {
|
|
117
|
+
const calls: Array<{ method: string; url: string; headers?: Record<string, string>; body?: string }> = [];
|
|
118
|
+
let issued = 0;
|
|
113
119
|
const fetch = async (url: string, init: { method: string; headers: Record<string, string>; body?: Uint8Array | string }) => {
|
|
114
|
-
calls.push({ method: init.method, url });
|
|
120
|
+
calls.push({ method: init.method, url, headers: init.headers, ...(typeof init.body === "string" ? { body: init.body } : {}) });
|
|
115
121
|
const u = new URL(url);
|
|
122
|
+
if (u.host === "token.actions.test") {
|
|
123
|
+
if (init.headers.authorization !== "Bearer gha-request-token") return reply(401);
|
|
124
|
+
return reply(200, JSON.stringify({ value: u.searchParams.get("audience") === root ? "gha-id-token" : "gha-id-token-for-another-audience" }));
|
|
125
|
+
}
|
|
126
|
+
if (init.method === "POST" && u.pathname === "/api/-/trusted-publishing/token") {
|
|
127
|
+
const req = JSON.parse(init.body as string) as { namespace: string; extension: string; token: string };
|
|
128
|
+
if (!["gha-id-token", "ovsx-id-token"].includes(req.token) || !(opts.trusted ?? []).includes(`${req.namespace}.${req.extension}`)) {
|
|
129
|
+
return reply(400, JSON.stringify({ error: `No trusted publisher matches this token for ${req.namespace}.${req.extension}.` }));
|
|
130
|
+
}
|
|
131
|
+
return reply(201, JSON.stringify({ value: `tp-token-${++issued}`, expiresTimestamp: "2026-11-01T00:10:00Z" }));
|
|
132
|
+
}
|
|
116
133
|
if (init.method === "POST" && u.pathname === "/api/-/publish") {
|
|
117
|
-
if (
|
|
134
|
+
if (opts.refuse) return reply(opts.refuse);
|
|
135
|
+
const token = u.searchParams.get("token") ?? "";
|
|
136
|
+
if (token !== "ovsx-token-1" && token !== `tp-token-${issued}`) return reply(403, '{"error":"Invalid access token."}');
|
|
118
137
|
const id = vsixIdentity(Buffer.from(init.body as Uint8Array), "upload");
|
|
119
138
|
const key = `${id.publisher}/${id.name}/${id.version}`;
|
|
120
139
|
if (versions.has(key)) return reply(400, '{"error":"already published"}');
|
|
@@ -130,7 +149,7 @@ function fakeOpenVsx(root: string, namespaces: string[], versions = new Map<stri
|
|
|
130
149
|
}
|
|
131
150
|
return reply(404);
|
|
132
151
|
};
|
|
133
|
-
return { fetch, calls, versions };
|
|
152
|
+
return { fetch, calls, versions, issued: () => issued };
|
|
134
153
|
}
|
|
135
154
|
|
|
136
155
|
/** A fake `vsce` that logs each run and its VSCE_PAT, and a gallery fake that lists the versions it published. */
|
|
@@ -142,6 +161,11 @@ function fakeVsce(dir: string) {
|
|
|
142
161
|
`#!${process.execPath}
|
|
143
162
|
const fs = require("fs");
|
|
144
163
|
fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ args: process.argv.slice(2), pat: process.env.VSCE_PAT || "" }) + "\\n");
|
|
164
|
+
if (process.argv[2] === "verify-pat") {
|
|
165
|
+
if (process.env.FAKE_VSCE_VERIFY_FAIL) { console.error("ERROR Can not acquire a Microsoft Entra ID access token."); process.exit(1); }
|
|
166
|
+
console.log("DONE The Personal Access Token verification succeeded for the publisher '" + process.argv[3] + "'.");
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}
|
|
145
169
|
console.log("Publishing with " + process.env.VSCE_PAT);
|
|
146
170
|
if (process.env.FAKE_VSCE_FAIL) { console.error("ERROR Access Denied"); process.exit(1); }
|
|
147
171
|
console.log("DONE Published arugula.arugula-vscode v1.2.0.");
|
|
@@ -252,3 +276,131 @@ describe("editor marketplaces (#4676)", () => {
|
|
|
252
276
|
expect(() => readZipEntry(Buffer.from("not a zip at all, long enough to scan"), "a")).toThrow(/not a zip/);
|
|
253
277
|
});
|
|
254
278
|
});
|
|
279
|
+
|
|
280
|
+
describe("marketplaces with the run's identity, and a refusal as a warning (#4698)", () => {
|
|
281
|
+
const GHA = { GITHUB_ACTIONS: "true", ACTIONS_ID_TOKEN_REQUEST_URL: "https://token.actions.test/idtoken?api-version=2.0", ACTIONS_ID_TOKEN_REQUEST_TOKEN: "gha-request-token" };
|
|
282
|
+
|
|
283
|
+
test("VS Code Marketplace, azure-credential: the stage runs vsce verify-pat and the reveal vsce publish, both with --azure-credential and no VSCE_PAT", async () => {
|
|
284
|
+
const { dir } = member();
|
|
285
|
+
const vsce = fakeVsce(temp());
|
|
286
|
+
const [target] = await createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "vscode", vsix: "dist/arugula.vsix", registry: "https://marketplace.test", auth: "azure-credential" })], {
|
|
287
|
+
fetch: vsce.fetch,
|
|
288
|
+
vsce: vsce.bin,
|
|
289
|
+
});
|
|
290
|
+
// A PAT left in the environment is not passed on: vsce prefers it to --azure-credential.
|
|
291
|
+
const ctx = context(dir, { VSCE_PAT: "stray-pat", PATH: process.env.PATH });
|
|
292
|
+
expect(target!.credentialEnv).toEqual(["AZURE_CLIENT_SECRET"]);
|
|
293
|
+
await target!.plan(ctx);
|
|
294
|
+
expect(vsce.runs()).toEqual([]);
|
|
295
|
+
|
|
296
|
+
const staged = await target!.stage(ctx);
|
|
297
|
+
expect(vsce.runs()).toEqual([{ args: ["verify-pat", "arugula", "--azure-credential"], pat: "" }]);
|
|
298
|
+
expect(staged.state).toEqual({});
|
|
299
|
+
|
|
300
|
+
await target!.reveal(ctx, staged);
|
|
301
|
+
expect(vsce.runs()[1]).toEqual({ args: ["publish", "--packagePath", join(dir, "dist/arugula.vsix"), "--azure-credential"], pat: "" });
|
|
302
|
+
expect(ctx.lines.join("\n")).not.toContain("using the token");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test("VS Code Marketplace, azure-credential: an identity vsce can't sign in with is refused at the stage, before anything reveals", async () => {
|
|
306
|
+
const { dir } = member();
|
|
307
|
+
const vsce = fakeVsce(temp());
|
|
308
|
+
const [target] = await createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "vscode", vsix: "dist/arugula.vsix", registry: "https://marketplace.test", auth: "azure-credential" })], {
|
|
309
|
+
fetch: vsce.fetch,
|
|
310
|
+
vsce: vsce.bin,
|
|
311
|
+
});
|
|
312
|
+
const err = await refused(target!.stage(context(dir, { FAKE_VSCE_VERIFY_FAIL: "1", PATH: process.env.PATH })));
|
|
313
|
+
expect(err.code).toBe("publish-marketplace-azure-credential");
|
|
314
|
+
expect(err.message).toContain("Microsoft Entra");
|
|
315
|
+
expect(vsce.runs().map((r) => r.args[0])).toEqual(["verify-pat"]);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("Open VSX, trusted-publishing: the stage exchanges the GitHub Actions ID token to check the registration, and the reveal exchanges again to upload", async () => {
|
|
319
|
+
const { dir, bytes } = member();
|
|
320
|
+
const ovsx = fakeOpenVsx("https://open-vsx.test", ["arugula"], new Map(), { trusted: ["arugula.arugula-vscode"] });
|
|
321
|
+
const [target] = await createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "openvsx", vsix: "dist/arugula.vsix", registry: "https://open-vsx.test", auth: "trusted-publishing" })], { fetch: ovsx.fetch });
|
|
322
|
+
const ctx = context(dir, GHA);
|
|
323
|
+
expect(target!.credentialEnv).toEqual(["OVSX_ID_TOKEN"]);
|
|
324
|
+
await target!.plan(ctx);
|
|
325
|
+
expect(ovsx.calls).toEqual([]);
|
|
326
|
+
|
|
327
|
+
const staged = await target!.stage(ctx);
|
|
328
|
+
expect(ovsx.issued()).toBe(1);
|
|
329
|
+
const idRequest = ovsx.calls.find((c) => c.url.startsWith("https://token.actions.test/"))!;
|
|
330
|
+
expect(new URL(idRequest.url).searchParams.get("audience")).toBe("https://open-vsx.test");
|
|
331
|
+
expect(new URL(idRequest.url).searchParams.get("api-version")).toBe("2.0");
|
|
332
|
+
expect(JSON.parse(ovsx.calls.find((c) => c.url.endsWith("/trusted-publishing/token"))!.body!)).toEqual({ namespace: "arugula", extension: "arugula-vscode", token: "gha-id-token" });
|
|
333
|
+
expect(ovsx.versions.size).toBe(0);
|
|
334
|
+
|
|
335
|
+
await target!.reveal(ctx, staged);
|
|
336
|
+
expect(ovsx.issued()).toBe(2);
|
|
337
|
+
expect(Buffer.from(ovsx.versions.get("arugula/arugula-vscode/1.2.0")!).equals(bytes)).toBe(true);
|
|
338
|
+
expect(ovsx.calls.find((c) => c.url.includes("/api/-/publish"))!.url).toContain("token=tp-token-2");
|
|
339
|
+
const out = ctx.lines.join("\n");
|
|
340
|
+
for (const secret of ["gha-id-token", "tp-token-1", "tp-token-2", "gha-request-token"]) expect(out).not.toContain(secret);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("Open VSX, trusted-publishing: reads an ID token from OVSX_ID_TOKEN outside GitHub Actions; refuses a run with none, and an extension with no trusted publisher", async () => {
|
|
344
|
+
const { dir } = member();
|
|
345
|
+
const make = async (ovsx: ReturnType<typeof fakeOpenVsx>) =>
|
|
346
|
+
(await createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "openvsx", vsix: "dist/arugula.vsix", registry: "https://open-vsx.test", auth: "trusted-publishing" })], { fetch: ovsx.fetch }))[0]!;
|
|
347
|
+
const trusted = fakeOpenVsx("https://open-vsx.test", ["arugula"], new Map(), { trusted: ["arugula.arugula-vscode"] });
|
|
348
|
+
await (await make(trusted)).stage(context(dir, { OVSX_ID_TOKEN: "ovsx-id-token" }));
|
|
349
|
+
expect(trusted.issued()).toBe(1);
|
|
350
|
+
expect(trusted.calls.some((c) => c.url.startsWith("https://token.actions.test/"))).toBe(false);
|
|
351
|
+
|
|
352
|
+
const none = await refused((await make(trusted)).plan(context(dir, { OVSX_PAT: "a-pat-is-not-read" })));
|
|
353
|
+
expect(none.code).toBe("publish-credentials-missing");
|
|
354
|
+
expect(none.fix).toContain("id-token: write");
|
|
355
|
+
|
|
356
|
+
const unregistered = fakeOpenVsx("https://open-vsx.test", ["arugula"]);
|
|
357
|
+
const err = await refused((await make(unregistered)).stage(context(dir, GHA)));
|
|
358
|
+
expect(err.code).toBe("publish-marketplace-trusted-publishing");
|
|
359
|
+
expect(err.message).toContain("No trusted publisher matches");
|
|
360
|
+
expect(err.fix).toContain("https://open-vsx.test/user-settings/trusted-publishers");
|
|
361
|
+
expect(unregistered.calls.some((c) => c.url.includes("/api/-/publish"))).toBe(false);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("an auth the marketplace does not take, or tokenEnv beside an identity, is refused when the targets are made", async () => {
|
|
365
|
+
const make = (d: Record<string, unknown>) => createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", vsix: "x.vsix", ...d })]);
|
|
366
|
+
expect((await refused(make({ marketplace: "openvsx", auth: "azure-credential" }))).code).toBe("publish-marketplace-auth-invalid");
|
|
367
|
+
expect((await refused(make({ marketplace: "vscode", auth: "trusted-publishing" }))).code).toBe("publish-marketplace-auth-invalid");
|
|
368
|
+
expect((await refused(make({ marketplace: "vscode", auth: "azure-credential", tokenEnv: "VSCE_PAT" }))).code).toBe("publish-marketplace-auth-invalid");
|
|
369
|
+
expect(() => PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "openvsx", vsix: "x.vsix", onRefusal: "ignore" })).toThrow();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("onRefusal warn: an upload Open VSX refuses comes back refused with a warning; without it the reveal fails", async () => {
|
|
373
|
+
const { dir } = member();
|
|
374
|
+
const make = async (ovsx: ReturnType<typeof fakeOpenVsx>, onRefusal?: "warn") =>
|
|
375
|
+
(await createPublishTargets([PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "openvsx", vsix: "dist/arugula.vsix", registry: "https://open-vsx.test", ...(onRefusal ? { onRefusal } : {}) })], { fetch: ovsx.fetch }))[0]!;
|
|
376
|
+
const ctx = context(dir, { OVSX_PAT: "ovsx-token-1" });
|
|
377
|
+
|
|
378
|
+
const strict = await make(fakeOpenVsx("https://open-vsx.test", ["arugula"], new Map(), { refuse: 406 }));
|
|
379
|
+
expect((await refused(strict.reveal(ctx, await strict.stage(ctx)))).code).toBe("publish-marketplace-failed");
|
|
380
|
+
|
|
381
|
+
const lenient = await make(fakeOpenVsx("https://open-vsx.test", ["arugula"], new Map(), { refuse: 406 }), "warn");
|
|
382
|
+
const out = await lenient.reveal(ctx, await lenient.stage(ctx));
|
|
383
|
+
expect(out.items).toEqual([expect.objectContaining({ name: "arugula.arugula-vscode@1.2.0", refused: true })]);
|
|
384
|
+
expect(out.warning).toContain("Open VSX refused arugula.arugula-vscode@1.2.0");
|
|
385
|
+
expect(out.warning).toContain("answered 406");
|
|
386
|
+
expect(out.warning).not.toContain("ovsx-token-1");
|
|
387
|
+
|
|
388
|
+
// The stage's checks still refuse under warn.
|
|
389
|
+
expect((await refused((await make(fakeOpenVsx("https://open-vsx.test", []), "warn")).stage(ctx))).code).toBe("publish-marketplace-no-namespace");
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("onRefusal warn: a vsce publish that fails comes back refused; vsce missing from PATH still fails", async () => {
|
|
393
|
+
const { dir } = member();
|
|
394
|
+
const vsce = fakeVsce(temp());
|
|
395
|
+
const decl = PublishDeclarationSchema.parse({ type: "marketplace", marketplace: "vscode", vsix: "dist/arugula.vsix", registry: "https://marketplace.test", onRefusal: "warn" });
|
|
396
|
+
const [target] = await createPublishTargets([decl], { fetch: vsce.fetch, vsce: vsce.bin });
|
|
397
|
+
const ctx = context(dir, { VSCE_PAT: "vsce-pat-secret", FAKE_VSCE_FAIL: "1", PATH: process.env.PATH });
|
|
398
|
+
const out = await target!.reveal(ctx, await target!.stage(ctx));
|
|
399
|
+
expect(out.items[0]!.refused).toBe(true);
|
|
400
|
+
expect(out.warning).toContain("Access Denied");
|
|
401
|
+
expect(out.warning).not.toContain("vsce-pat-secret");
|
|
402
|
+
|
|
403
|
+
const [missing] = await createPublishTargets([decl], { fetch: fakeVsce(temp()).fetch, vsce: join(temp(), "no-vsce") });
|
|
404
|
+
expect((await refused(missing!.reveal(ctx, await missing!.stage(ctx)))).code).toBe("publish-marketplace-vsce-missing");
|
|
405
|
+
});
|
|
406
|
+
});
|