Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Pin real image digests into the published CLI package (#15)

Joshua Franced98a91427cf0
diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml
index 495900ddd..ad5ae3355 100644
--- a/.github/workflows/publish-cli.yml
+++ b/.github/workflows/publish-cli.yml
@@ -2,6 +2,10 @@ name: Publish the QM CLI
on:
workflow_dispatch:
+ inputs:
+ images_ref:
+ description: Commit SHA whose published images the package should pin
+ required: false
permissions:
contents: read
@@ -27,6 +31,36 @@ jobs:
npm ci
npm run typecheck
npm run test:pack
+ - name: Pin published image digests
+ env:
+ IMAGES_REF: ${{ inputs.images_ref || github.sha }}
+ run: |
+ set -euo pipefail
+ out=$(jq -n '{sandboxBase: "", services: {}}')
+ for service in core web-ui admin portal auth sandbox-base; do
+ repo="yc-software/qm/$service"
+ token=$(curl -fsS "https://ghcr.io/token?scope=repository:$repo:pull&service=ghcr.io" | jq -r .token)
+ digest=$(curl -fsS -o /dev/null -D - -H "Authorization: Bearer $token" \
+ -H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json' \
+ "https://ghcr.io/v2/$repo/manifests/$IMAGES_REF" \
+ | tr -d '\r' | awk 'tolower($1) == "docker-content-digest:" { print $2 }')
+ if [ -z "$digest" ]; then
+ echo "no published image for $repo at $IMAGES_REF" >&2
+ exit 1
+ fi
+ ref="ghcr.io/$repo@$digest"
+ if [ "$service" = sandbox-base ]; then
+ out=$(printf '%s' "$out" | jq --arg r "$ref" '.sandboxBase = $r')
+ else
+ out=$(printf '%s' "$out" | jq --arg k "$service" --arg r "$ref" '.services[$k] = $r')
+ fi
+ done
+ printf '%s\n' "$out" > cli/manifest.json
+ cat cli/manifest.json
+ jq -e '[.sandboxBase] + [.services[]]
+ | length == 6
+ and all(test("^ghcr\\.io/yc-software/qm/[a-z-]+@sha256:[0-9a-f]{64}$"))
+ and all(test("@sha256:(.)\\1{63}$") | not)' cli/manifest.json > /dev/null
- name: Publish
working-directory: cli
run: npm publish --provenance --access public
diff --git a/cli/package.json b/cli/package.json
index ac84bbca3..11c6a4573 100644
--- a/cli/package.json
+++ b/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@yc-software/qm",
- "version": "0.1.0",
+ "version": "0.1.1",
"license": "MIT",
"description": "Control-plane CLI for portable QM deployments on Docker, Fly, and AWS.",
"type": "module",
diff --git a/cli/test/init.test.ts b/cli/test/init.test.ts
index d5cafd4e4..79f40918d 100644
--- a/cli/test/init.test.ts
+++ b/cli/test/init.test.ts
@@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { runInit } from "../src/commands/init.ts";
import { CONFIG_FILENAME, loadConfigInDir } from "../src/config.ts";
+import { cliVersion } from "../src/manifest.ts";
import { parseToolDescriptor, validateSandboxLayer } from "../src/sandbox-layer.ts";
import { SERVICE_NAMES, VIRTUAL_SERVICE_NAMES } from "../src/services.ts";
import { renderEnvExample } from "../src/secrets.ts";
@@ -427,7 +428,7 @@ test("init preflights package.json and completes an install-first package manife
assert.equal(manifest.private, true);
assert.equal(manifest.engines?.node, ">=24.0.0");
assert.equal(manifest.scripts?.deploy, "qm up");
- assert.equal(manifest.dependencies?.["@yc-software/qm"], "0.1.0");
+ assert.equal(manifest.dependencies?.["@yc-software/qm"], cliVersion());
assert.equal(manifest.dependencies?.["qm-cli"], undefined);
assert.equal(manifest.dependencies?.other, "1.0.0");
} finally {
@@ -512,7 +513,7 @@ test("the scaffold is an npm-backed deployment repository with no CI coupling an
scripts?: Record<string, string>;
};
assert.equal(packageJson.private, true);
- assert.equal(packageJson.dependencies?.["@yc-software/qm"], "0.1.0");
+ assert.equal(packageJson.dependencies?.["@yc-software/qm"], cliVersion());
assert.equal(packageJson.scripts?.check, "qm check");
assert.ok(existsSync(join(dir, "deployment.md")));
assert.ok(existsSync(join(dir, ".codex", "skills", "deploy-qm", "SKILL.md")));
diff --git a/cli/test/package.test.ts b/cli/test/package.test.ts
index 93e9311c8..e4b9c0e06 100644
--- a/cli/test/package.test.ts
+++ b/cli/test/package.test.ts
@@ -49,6 +49,7 @@ test(
const awsDeployment = join(dir, "aws-deployment");
const tarballBytes = readFileSync(tarball);
const packageManifest = JSON.parse(readFileSync(join(cliDir, "package.json"), "utf8")) as Record<string, unknown>;
+ const version = packageManifest["version"] as string;
registry = createServer((request, response) => {
const origin = `http://${request.headers.host}`;
if (request.url && decodeURIComponent(request.url) === "/@yc-software/qm") {
@@ -56,12 +57,12 @@ test(
response.end(
JSON.stringify({
name: "@yc-software/qm",
- "dist-tags": { latest: "0.1.0" },
+ "dist-tags": { latest: version },
versions: {
- "0.1.0": {
+ [version]: {
...packageManifest,
dist: {
- tarball: `${origin}/@yc-software/qm/-/qm-0.1.0.tgz`,
+ tarball: `${origin}/@yc-software/qm/-/qm-${version}.tgz`,
shasum: createHash("sha1").update(tarballBytes).digest("hex"),
integrity: `sha512-${createHash("sha512").update(tarballBytes).digest("base64")}`,
},
@@ -71,7 +72,7 @@ test(
);
return;
}
- if (request.url === "/@yc-software/qm/-/qm-0.1.0.tgz") {
+ if (request.url === `/@yc-software/qm/-/qm-${version}.tgz`) {
response.setHeader("content-type", "application/octet-stream");
response.end(tarballBytes);
return;
@@ -93,7 +94,7 @@ test(
[
"exec",
"--yes",
- "--package=@yc-software/[email protected]",
+ `--package=@yc-software/qm@${version}`,
"--",
"qm",
"init",
@@ -134,7 +135,7 @@ test(
};
assert.equal(consumerPackage.private, true);
assert.equal(consumerPackage.scripts?.deploy, "qm up");
- assert.equal(consumerPackage.dependencies?.["@yc-software/qm"], "0.1.0");
+ assert.equal(consumerPackage.dependencies?.["@yc-software/qm"], version);
}
await new Promise<void>((resolve, reject) => registry!.close((error) => (error ? reject(error) : resolve())));
registry = undefined;
diff --git a/test/release-workflows.test.ts b/test/release-workflows.test.ts
index f7eaea747..b9027e25b 100644
--- a/test/release-workflows.test.ts
+++ b/test/release-workflows.test.ts
@@ -73,3 +73,27 @@ test("publishing the CLI is a separate, attested, main-only operation", () => {
assert.match(workflow, /NODE_AUTH_TOKEN: \$\{\{ secrets\.NPM_TOKEN \}\}/);
assert.doesNotMatch(workflow, /packages: write/);
});
+
+test("the published package pins real image digests, never the checked-in sentinel", () => {
+ const workflow = readFileSync(".github/workflows/publish-cli.yml", "utf8");
+
+ assert.ok(
+ workflow.indexOf("Pin published image digests") < workflow.indexOf("npm publish"),
+ "digests are resolved before the package is published",
+ );
+ assert.match(workflow, /for service in core web-ui admin portal auth sandbox-base; do/);
+ assert.match(workflow, /printf '%s\\n' "\$out" > cli\/manifest\.json/);
+ assert.match(workflow, /no published image for \$repo at \$IMAGES_REF/);
+ assert.match(workflow, /\{63\}\$"\) \| not\)/);
+
+ const sentinel = JSON.parse(readFileSync("cli/manifest.json", "utf8")) as {
+ sandboxBase: string;
+ services: Record<string, string>;
+ };
+ const refs = [sentinel.sandboxBase, ...Object.values(sentinel.services)];
+ assert.equal(refs.length, 6);
+ assert.ok(
+ refs.every((ref) => ref.startsWith("registry.invalid/")),
+ "the checked-in manifest stays a sentinel so a source checkout never pulls a stale digest",
+ );
+});