diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb8ee8a..f397fd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,6 +72,9 @@ jobs: node-version: 22 cache: pnpm + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + - name: Install website dependencies run: pnpm install --frozen-lockfile @@ -92,8 +95,16 @@ jobs: MDBASE_RS_DIR: .sources/mdbase-rs MDBASE_TS_DIR: .sources/mdbase + - name: Reject stale Connect release updates + if: github.event_name == 'pull_request' + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: | + git fetch --no-tags --depth=1 origin "$BASE_SHA" + pnpm check:release-order "$BASE_SHA" + - name: Type and content checks - run: pnpm test:deploy:dev && pnpm check:release && pnpm check + run: pnpm test:deploy:dev && pnpm test:release-update && pnpm check:release && pnpm check env: GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index bb486bb..c9c0383 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -79,6 +79,9 @@ jobs: node-version: 22 cache: pnpm + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + - name: Install website dependencies run: pnpm install --frozen-lockfile diff --git a/.github/workflows/update-connect-release.yml b/.github/workflows/update-connect-release.yml new file mode 100644 index 0000000..16940ce --- /dev/null +++ b/.github/workflows/update-connect-release.yml @@ -0,0 +1,150 @@ +name: Update Connect release + +on: + repository_dispatch: + types: [connect-client-release-published] + workflow_dispatch: + inputs: + tag: + description: Published mdbase Connect release tag + required: true + type: string + +permissions: + contents: read + +concurrency: + group: connect-release-update + cancel-in-progress: false + +jobs: + update: + name: Verify release and open pull request + runs-on: ubuntu-24.04 + steps: + - name: Select release tag + id: release + env: + DISPATCH_TAG: ${{ github.event.client_payload.tag }} + MANUAL_TAG: ${{ inputs.tag }} + run: | + tag="${DISPATCH_TAG:-$MANUAL_TAG}" + if [[ ! "$tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then + echo "Invalid Connect release tag." >&2 + exit 1 + fi + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "branch=automation/connect-release-$tag" >> "$GITHUB_OUTPUT" + + - name: Check out website + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + persist-credentials: false + + - name: Read specification source identity + id: specification + run: | + echo "repository=$(jq -r '.specification.repository' site-sources.json)" >> "$GITHUB_OUTPUT" + echo "ref=$(jq -r '.specification.ref' site-sources.json)" >> "$GITHUB_OUTPUT" + + - name: Check out specification + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ steps.specification.outputs.repository }} + ref: ${{ steps.specification.outputs.ref }} + path: .sources/mdbase-spec + persist-credentials: false + + - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 + with: + version: 10 + + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 22 + cache: pnpm + + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + + - name: Install website dependencies + run: pnpm install --frozen-lockfile + + - name: Build specification artifact + working-directory: .sources/mdbase-spec/site + run: npm ci && npm run build + + - name: Verify public evidence and generate release record + env: + GH_TOKEN: ${{ github.token }} + MDBASE_RELEASE_NPM_ATTEMPTS: "15" + MDBASE_RELEASE_NPM_DELAY_MS: "60000" + run: node scripts/update-connect-release.mjs '${{ steps.release.outputs.tag }}' + + - name: Validate generated website + env: + GH_TOKEN: ${{ github.token }} + MDBASE_SPEC_DIR: .sources/mdbase-spec + run: pnpm test + + - name: Require a release-only change + id: changes + run: | + mapfile -t changed < <(git diff --name-only) + if [ "${#changed[@]}" -eq 0 ]; then + echo "present=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + printf '%s\n' "${changed[@]}" | sort > "$RUNNER_TEMP/changed" + printf '%s\n' site-sources.json src/data/connect-release.json | sort > "$RUNNER_TEMP/expected" + diff -u "$RUNNER_TEMP/expected" "$RUNNER_TEMP/changed" + echo "present=true" >> "$GITHUB_OUTPUT" + + - name: Create website automation token + if: steps.changes.outputs.present == 'true' + id: app-token + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 + with: + app-id: ${{ vars.RELEASE_AUTOMATION_APP_ID }} + private-key: ${{ secrets.RELEASE_AUTOMATION_APP_PRIVATE_KEY }} + owner: mdbase-dev + repositories: mdbase.dev + permission-contents: write + permission-pull-requests: write + + - name: Open release update pull request + if: steps.changes.outputs.present == 'true' + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + BRANCH: ${{ steps.release.outputs.branch }} + TAG: ${{ steps.release.outputs.tag }} + run: | + existing="$(gh pr list --repo "$GITHUB_REPOSITORY" --state all --head "$BRANCH" --json url,state --jq '.[0] // empty')" + if [ -n "$existing" ]; then + state="$(jq -r .state <<<"$existing")" + url="$(jq -r .url <<<"$existing")" + if [ "$state" = "OPEN" ] || [ "$state" = "MERGED" ]; then + echo "Release update already represented by $url" + exit 0 + fi + echo "The deterministic release PR was closed without merging: $url" >&2 + exit 1 + fi + if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then + echo "Remote branch $BRANCH exists without a pull request; refusing to overwrite it." >&2 + exit 1 + fi + git switch -c "$BRANCH" + git config user.name "mdbase release automation[bot]" + git config user.email "mdbase-release-automation[bot]@users.noreply.github.com" + git add site-sources.json src/data/connect-release.json + git commit -m "Update Connect downloads to $TAG" + git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git push --set-upstream origin "$BRANCH" + gh pr create \ + --repo "$GITHUB_REPOSITORY" \ + --base main \ + --head "$BRANCH" \ + --title "Update Connect downloads to $TAG" \ + --body "Updates the Downloads release record from the published, Sigstore-verified mdbase Connect channel for [$TAG](https://github.com/mdbase-dev/mdbase-connect/releases/tag/$TAG).\n\nThe website release checks and full test suite passed before this PR was opened." diff --git a/README.md b/README.md index 1e3503e..439528a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Override their paths with `MDBASE_SPEC_DIR`, `MDBASE_CONNECT_DIR`, ## Production build +Release checks require `gh` authentication and `cosign`; CI installs the pinned +Cosign version used by the Connect release workflow. + ```sh pnpm sync:sources pnpm check @@ -36,6 +39,22 @@ remain traceable to the release artifacts they document. The first-party contract catalog is built from the commit pinned in `site-sources.json`, then published as static files under `/contracts/`. +## Connect release updates + +A published Connect desktop release dispatches its immutable tag to +`.github/workflows/update-connect-release.yml`. The workflow verifies the +GitHub release, Sigstore-signed channel manifest, tag commit, matching npm SDK, +and release assets; regenerates `src/data/connect-release.json` and the Connect +pin in `site-sources.json`; runs the complete website test suite; and opens a +normal pull request. It never deploys or pushes `main` directly. The same +workflow can be run manually with a tag to recover from a delayed npm +publication or failed dispatch. + +The workflow uses a GitHub App configured as `RELEASE_AUTOMATION_APP_ID` and +`RELEASE_AUTOMATION_APP_PRIVATE_KEY`. Its installation on this repository needs +only `contents: write` and `pull requests: write`. The App token ensures the +resulting pull request triggers the ordinary protected `Site checks` workflow. + ## Development deployment ```sh diff --git a/package.json b/package.json index 108e4f8..f825227 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,10 @@ "import:spec": "node scripts/import-spec.mjs", "check:links": "node scripts/check-links.mjs", "check:release": "node scripts/check-connect-release.mjs", + "check:release-order": "node scripts/check-connect-release-order.mjs", "test:deploy:dev": "node --test scripts/deploy-pages-dev.test.mjs", - "test": "pnpm test:deploy:dev && pnpm check:release && pnpm check && pnpm build && pnpm import:spec && pnpm check:links" + "test:release-update": "node --test scripts/connect-release-record.test.mjs", + "test": "pnpm test:deploy:dev && pnpm test:release-update && pnpm check:release && pnpm check && pnpm build && pnpm import:spec && pnpm check:links" }, "dependencies": { "@astrojs/sitemap": "^3.7.3", diff --git a/public/mdbase-murmuration.js b/public/mdbase-murmuration.js index c3a0deb..ba07068 100644 --- a/public/mdbase-murmuration.js +++ b/public/mdbase-murmuration.js @@ -800,7 +800,7 @@ particle.vx += accelerationX * step; particle.vy += accelerationY * step; const speed = Math.hypot(particle.vx, particle.vy); - const maximum = 2.5 + index % 5 * 0.08; + const maximum = 1.7 + index % 5 * 0.06; if (speed > maximum) { particle.vx = particle.vx / speed * maximum; particle.vy = particle.vy / speed * maximum; @@ -854,9 +854,9 @@ context.save(); context.strokeStyle = palette.muted; - context.globalAlpha = 0.88; + context.globalAlpha = 0.52; context.lineWidth = 1; - context.setLineDash(edge.dashed ? [4, 5] : []); + context.setLineDash(edge.dashed ? [3, 5] : []); context.beginPath(); context.moveTo(points[0].x, points[0].y); points.slice(1).forEach((point) => context.lineTo(point.x, point.y)); @@ -867,16 +867,16 @@ const previousPoint = points[points.length - 2]; const angle = Math.atan2(finalPoint.y - previousPoint.y, finalPoint.x - previousPoint.x); context.fillStyle = palette.muted; - context.globalAlpha = 0.95; + context.globalAlpha = 0.62; context.beginPath(); context.moveTo(finalPoint.x, finalPoint.y); context.lineTo( - finalPoint.x - Math.cos(angle - 0.48) * 6, - finalPoint.y - Math.sin(angle - 0.48) * 6 + finalPoint.x - Math.cos(angle - 0.48) * 5, + finalPoint.y - Math.sin(angle - 0.48) * 5 ); context.lineTo( - finalPoint.x - Math.cos(angle + 0.48) * 6, - finalPoint.y - Math.sin(angle + 0.48) * 6 + finalPoint.x - Math.cos(angle + 0.48) * 5, + finalPoint.y - Math.sin(angle + 0.48) * 5 ); context.closePath(); context.fill(); @@ -906,26 +906,15 @@ function drawNodeSurface(node, compact) { const { x, y, w, h } = node.box; context.save(); - - if (node.kind === "boundary") { - context.fillStyle = palette.surface; - context.strokeStyle = palette.line; - context.setLineDash([5, 5]); - } else if (node.kind === "authority") { - context.fillStyle = palette.surfaceSubtle; - context.strokeStyle = palette.accent; - context.setLineDash([]); - } else { - context.fillStyle = - node.kind === "service" ? palette.surfaceSubtle : palette.surface; - context.strokeStyle = - node.kind === "replica" ? palette.muted : palette.line; - context.setLineDash(node.kind === "replica" ? [4, 4] : []); - } - - context.lineWidth = node.kind === "authority" ? 1.25 : 1; + context.fillStyle = palette.surface; + context.strokeStyle = node.kind === "authority" ? palette.muted : palette.lineSoft; + context.globalAlpha = node.kind === "authority" ? 0.78 : 0.64; + context.lineWidth = 1; + context.setLineDash( + node.kind === "boundary" || node.kind === "replica" ? [3, 5] : [] + ); context.beginPath(); - context.roundRect(x, y, w, h, compact ? 3 : 5); + context.rect(x, y, w, h); context.fill(); context.stroke(); context.setLineDash([]); @@ -933,31 +922,23 @@ } function drawNodeLabel(node, compact) { - const { x, y, h } = node.box; + const { x, y } = node.box; context.save(); const labelX = x + (compact ? 7 : 10); - const labelY = y + (compact ? 12 : 15); + const labelY = y + (compact ? 14 : 16); context.textAlign = "left"; - context.fillStyle = - node.kind === "authority" ? palette.accent : palette.ink; - context.font = - `600 ${compact ? 8.5 : 10}px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`; + context.fillStyle = palette.ink; + context.globalAlpha = 0.78; + context.font = '17px "Atkinson Hyperlegible", sans-serif'; context.fillText(node.label, labelX, labelY); - - if (node.detail && h > (compact ? 42 : 52)) { - context.fillStyle = palette.muted; - context.font = - `${compact ? 7.5 : 8.5}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`; - context.fillText(node.detail, labelX, labelY + (compact ? 10 : 12)); - } context.restore(); } function drawNote(note, compact) { context.save(); context.fillStyle = palette.muted; - context.font = - `600 ${compact ? 9 : 10}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`; + context.globalAlpha = 0.68; + context.font = '17px "Atkinson Hyperlegible", sans-serif'; context.textAlign = "center"; context.fillText(note.text, note.x, note.y); context.restore(); @@ -986,22 +967,25 @@ } function drawParticle(particle, compact) { - const baseSize = compact ? 2.5 : 3.25; + const baseSize = compact ? 1.8 : 2.25; const size = particle.role === "packet" - ? baseSize * 1.5 + ? baseSize * 1.35 : baseSize * particle.scale; const x = Math.round(particle.x - size / 2); const y = Math.round(particle.y - size / 2); + context.save(); + context.globalAlpha = particle.role === "packet" ? 0.82 : 0.62; if (particle.role === "replica") { context.strokeStyle = palette.replica; - context.lineWidth = 0.9; - context.strokeRect(x, y, Math.max(1.75, size), Math.max(1.75, size)); + context.lineWidth = 0.8; + context.strokeRect(x, y, Math.max(1.5, size), Math.max(1.5, size)); } else { context.fillStyle = particleFill(particle); - context.fillRect(x, y, Math.max(1.75, size), Math.max(1.75, size)); + context.fillRect(x, y, Math.max(1.5, size), Math.max(1.5, size)); } + context.restore(); } function draw(now) { @@ -1021,7 +1005,6 @@ if (activeScene !== "intro") { context.save(); context.globalAlpha = diagramAlpha; - diagram.edges.forEach((edge) => drawEdgeLabel(edge, compact)); diagram.nodes.forEach((node) => drawNodeLabel(node, compact)); diagram.notes.forEach((note) => drawNote(note, compact)); context.restore(); diff --git a/public/mdbase-shell.css b/public/mdbase-shell.css index 9ee4e0b..c5071ab 100644 --- a/public/mdbase-shell.css +++ b/public/mdbase-shell.css @@ -1,383 +1,396 @@ :root { --sans: "Atkinson Hyperlegible", "Segoe UI", sans-serif; --mono: "Azeret Mono", "SFMono-Regular", "Cascadia Code", monospace; - --header: 4rem; - --site-width: 78rem; + --site-left: clamp(24px, 8vw, 120px); + --shell-width: 1080px; } -.site-header, -.spec-header { - position: fixed; - z-index: 100; - top: 0; - right: 0; - left: 0; - height: var(--header); - padding: 0; - color: var(--color-text); - background: var(--color-surface); - border-bottom: 1px solid var(--color-border); +body { + margin: 0; + font-family: var(--sans); + font-size: 1rem; + line-height: 1.5; } .spec-header { - display: flex; - padding-inline: clamp(1rem, 3vw, 2.25rem); - align-items: center; - justify-content: space-between; - gap: 1.5rem; -} - -.site-header__inner { - display: flex; - width: 100%; - height: 100%; - padding-inline: clamp(1rem, 3vw, 2.25rem); - align-items: center; - justify-content: space-between; - gap: 1.5rem; + position: relative; + z-index: 100; + top: auto; + right: auto; + left: auto; + display: block; + width: min(calc(100% - 48px), var(--shell-width)); + height: auto; + margin-left: var(--site-left); + padding: 22px 0 0; + color: var(--color-text); + background: var(--color-canvas); + border: 0; } -.site-brand, .spec-brand { - display: flex; - min-width: 0; - align-items: center; - gap: 0.75rem; + min-height: 0; + margin-bottom: 18px; + gap: 8px; } -.wordmark, .landing-logo { - display: inline-flex; - flex: 0 0 auto; - align-items: center; - gap: 0.5rem; + gap: 0; color: var(--color-text); - font: 600 0.8125rem/1 var(--mono); - letter-spacing: -0.01em; - text-decoration: none; -} - -.brand-mark, -.mdbase-mark { - display: block; - width: 1.25rem; - height: 1.25rem; - overflow: visible; + font: 400 1rem/1.5 var(--sans); + letter-spacing: 0; } -.brand-mark--compact { - width: 1.25rem; - height: 1.25rem; +.landing-logo .mdbase-mark { + display: none; } -.brand-mark__ink, -.mdbase-mark-ink { - fill: var(--color-text); +.spec-version { + color: var(--color-text-muted); + font: 400 1rem/1.5 var(--sans); } -.brand-mark__accent, -.mdbase-mark-accent { - fill: var(--color-accent); +.spec-header-actions { + display: flex; + width: 100%; + height: auto; + min-height: 0; + margin: 0; + padding: 10px 0; + align-items: center; + gap: 22px; + border-top: 1px solid var(--color-text); + border-bottom: 1px solid var(--color-text); } -.desktop-nav, .landing-nav { display: flex; - height: 100%; - align-items: stretch; - gap: 0; + height: auto; + flex-wrap: wrap; + align-items: center; + gap: 6px 22px; } -.desktop-nav a, .landing-nav a { - position: relative; - display: flex; - padding: 0 0.75rem; - align-items: center; - color: var(--color-text-muted); - font: 400 0.75rem/1 var(--sans); - text-decoration: none; + display: inline; + min-height: 0; + padding: 0; + color: var(--color-text); + font: 400 1rem/1.5 var(--sans); + text-decoration: underline; + text-underline-offset: 0.2em; } -.desktop-nav a::after, .landing-nav a::after { - position: absolute; - right: 0.75rem; - bottom: -1px; - left: 0.75rem; - height: 2px; - content: ""; - background: transparent; -} - -.desktop-nav a:hover, -.desktop-nav a[aria-current="page"], -.landing-nav a:hover, -.landing-nav a[aria-current="page"], -.landing-nav a.nav-active { - color: var(--color-text); + display: none; } -.desktop-nav a[aria-current="page"]::after, -.landing-nav a[aria-current="page"]::after, -.landing-nav a.nav-active::after { - background: var(--color-accent); +.landing-nav a:hover { + color: var(--color-text-soft); } -.header-actions, -.spec-header-actions { - display: flex; - height: 100%; - margin-left: auto; - align-items: center; - gap: 0.35rem; +.landing-nav a.nav-active { + color: var(--color-text); + font-weight: 400; + text-decoration: none; } .theme-menu { - position: relative; - flex: 0 0 auto; + margin-left: auto; } .theme-menu > summary { - display: grid; - width: 2.75rem; - height: 2.75rem; - padding: 0; - place-items: center; - color: var(--color-text-faint); - background: transparent; - border: 0; - border-radius: var(--radius); - list-style: none; - cursor: pointer; -} - -.theme-menu > summary::-webkit-details-marker { - display: none; + width: auto; + height: auto; + min-height: 0; + color: var(--color-text); + border-radius: 0; } .theme-menu > summary:hover, .theme-menu[open] > summary { - color: var(--color-text); - background: var(--color-surface-subtle); -} - -.theme-menu > summary:focus-visible { - outline: 2px solid var(--color-accent); - outline-offset: 2px; -} - -.theme-menu__icon { - display: block; - width: 0.875rem; - height: 0.875rem; -} - -.theme-menu__icon circle { - fill: none; - stroke: currentColor; - stroke-width: 1.25; -} - -.theme-menu__icon path { - fill: currentColor; + color: var(--color-text-soft); + background: transparent; } .theme-menu__options { - position: absolute; - z-index: 110; - top: calc(100% + 0.4rem); - right: 0; - display: grid; - width: 7.5rem; - padding: 0.3rem; - background: var(--color-surface); - border: 1px solid var(--color-border-strong); - border-radius: var(--radius); + border-radius: 0; + background: var(--color-canvas); } .theme-menu__options button { + min-height: 2rem; + border-radius: 0; + font: 400 1rem/1.5 var(--sans); +} + +.spec-layout { display: grid; - width: 100%; - min-height: 2.75rem; - padding: 0 0.5rem; - align-items: center; - grid-template-columns: 1fr auto; - color: var(--color-text-soft); + width: min(calc(100vw - var(--site-left) - 24px), var(--shell-width)); + min-height: 0; + margin: 64px 0 0 var(--site-left); + padding: 0; + grid-template-columns: 180px minmax(0, 660px) minmax(0, 1fr); + gap: 32px; +} + +.spec-sidebar { + position: sticky; + z-index: 20; + inset: auto; + top: 32px; + width: auto; + max-height: calc(100vh - 64px); + align-self: start; + overflow-y: auto; + padding: 0 0 0 16px; background: transparent; border: 0; - border-radius: var(--radius); - font: 400 0.66rem/1 var(--mono); - text-align: left; - cursor: pointer; -} - -.theme-menu__options button::after { - width: 0.3rem; - height: 0.3rem; - content: ""; - background: var(--color-accent); - border-radius: 50%; - opacity: 0; + border-left: 1px solid var(--color-text); } -.theme-menu__options button:hover { - color: var(--color-text); - background: var(--color-surface-subtle); +.sidebar-group { + margin: 0; } -.theme-menu__options button[aria-pressed="true"] { +.sidebar-group-label { + margin: 0 0 10px; + padding: 0; color: var(--color-text); + font: 400 1rem/1.5 var(--sans); } -.theme-menu__options button[aria-pressed="true"]::after { - opacity: 1; -} - -.theme-menu__options button:focus-visible { - outline: 2px solid var(--color-accent); - outline-offset: -2px; +.sidebar-link { + display: grid; + min-height: 0; + padding: 3px 0; + grid-template-columns: minmax(0, 1fr); + color: var(--color-text-soft); + border-radius: 0; + font: 400 1rem/1.4 var(--sans); + text-decoration: none; } -.mobile-nav { - position: relative; +.sidebar-link .num { display: none; } -.mobile-nav summary { - display: flex; - min-height: 2.75rem; - padding: 0.35rem 0.25rem; - align-items: center; - color: var(--color-text-soft); - font-size: 0.78rem; - list-style: none; - cursor: pointer; +.sidebar-link:hover, +.sidebar-link.active { + color: var(--color-text); + background: transparent; + font-weight: 400; + text-decoration: none; } -.mobile-nav summary::-webkit-details-marker { - display: none; +.spec-content { + width: auto; + min-width: 0; + padding: 0 0 96px; + grid-column: 2; + justify-self: stretch; } -.mobile-nav nav { - position: absolute; - top: 2.15rem; - right: 0; - width: min(18rem, calc(100vw - 2rem)); - padding: 0.5rem; - background: var(--color-surface); - border: 1px solid var(--color-border-strong); +.spec-section { + margin-bottom: 64px; } -.mobile-nav nav a { - display: block; - padding: 0.7rem; +.spec-section > h1:first-child, +.spec-section h1, +.spec-section h2, +.spec-section h3, +.spec-section h4, +.spec-section h5, +.spec-section h6, +.spec-content strong { color: var(--color-text); - font-size: 0.82rem; - text-decoration: none; + font-family: var(--sans); + font-size: 1rem; + font-weight: 400; + line-height: 1.35; + letter-spacing: 0; + text-wrap: pretty; } -.mobile-nav nav a[aria-current="page"] { - color: var(--color-accent-strong); +.spec-section > h1:first-child { + margin: 0 0 24px; + padding: 0; + border: 0; } -.site-footer { - position: relative; - z-index: 2; - display: block; - min-height: 0; - margin-top: 5rem; - padding: 0; - color: var(--color-text-muted); - background: var(--color-surface); +.spec-section h2 { + margin: 40px 0 16px; + padding-top: 16px; border-top: 1px solid var(--color-border); - font: inherit; } -.site-footer__inner { - display: grid; - width: min(100% - 2rem, var(--site-width)); - min-height: 8rem; - margin-inline: auto; - padding-block: 2rem; - align-items: start; - grid-template-columns: minmax(14rem, 0.72fr) minmax(0, 1.28fr); - gap: 2rem; +.spec-section h3, +.spec-section h4, +.spec-section h5, +.spec-section h6 { + margin: 28px 0 12px; } -.site-footer strong { +.spec-content p, +.spec-content li { + max-width: 660px; +} + +.spec-content a { color: var(--color-text); - font: 600 0.75rem/1 var(--mono); + text-decoration-color: currentColor; } -.site-footer p { - margin: 0.3rem 0 0; - color: var(--color-text-muted); - font-size: 0.78rem; +.spec-content a:hover { + color: var(--color-text-soft); } -.site-footer .site-footer__nav { - display: grid; - grid-template-columns: repeat(3, minmax(0, 1fr)); - gap: 1.5rem; +.spec-content code { + color: var(--color-text); + border-radius: 0; } -.site-footer__nav > div { - display: grid; - align-content: start; - gap: 0.5rem; +.spec-content pre, +.spec-content blockquote, +.spec-content table { + border-radius: 0; + box-shadow: none; } -.site-footer__nav > div > strong { - margin-bottom: 0.15rem; - color: var(--color-text-muted); - font-size: 0.625rem; +.spec-content pre, +.spec-content blockquote { + background: var(--color-canvas); + border: 1px solid var(--color-text); } -.site-footer nav a { - color: var(--color-text-soft); - font-size: 0.75rem; - text-decoration: none; +.anchor { + color: var(--color-text-muted); + font-weight: 400; } -.site-footer nav a:hover { +.sidebar-toggle { + min-height: 0; + padding: 0; color: var(--color-text); + background: transparent; + border: 0; + border-radius: 0; + font: 400 1rem/1.5 var(--sans); text-decoration: underline; - text-underline-offset: 0.3rem; -} + text-underline-offset: 0.2em; +} + +@media (max-width: 1024px) { + .spec-header { + display: flex; + width: calc(100% - 32px); + margin-left: 16px; + padding: 16px 0 10px; + align-items: center; + gap: 12px; + border-bottom: 1px solid var(--color-text); + } + + .spec-brand { + display: flex; + flex: 1; + margin: 0; + } + + .sidebar-toggle { + display: inline-flex; + order: 3; + margin-left: auto; + } -@media (max-width: 60rem) { - .desktop-nav, - .landing-nav { + .spec-header .landing-nav { display: none; } - .mobile-nav { + .spec-header-actions { + width: auto; + margin: 0; + padding: 0; + justify-content: flex-end; + border: 0; + } + + .theme-menu { + margin: 0; + } + + .spec-layout { + display: block; + width: calc(100% - 32px); + margin: 48px 0 0 16px; + } + + .spec-sidebar { + position: fixed; + z-index: 120; + inset: 0 auto 0 0; + width: min(320px, calc(100vw - 48px)); + max-height: none; + padding: 24px 18px; + background: var(--color-canvas); + border: 0; + border-right: 1px solid var(--color-text); + transform: translateX(-105%); + } + + .spec-sidebar.open { + transform: translateX(0); + } + + .sidebar-scrim { + inset: 0; + z-index: 110; + } + + .spec-mobile-links { display: block; } + + .spec-content { + width: min(660px, 100%); + padding-bottom: 72px; + } } -@media (max-width: 42rem) { - .site-header__inner { - padding-inline: 0.625rem; +@media (max-width: 560px) { + .spec-version { + display: none; + } + + .spec-header-actions { + gap: 12px; } - .site-footer__inner { - width: min(100% - 1.25rem, var(--site-width)); + .spec-content { + width: 100%; } - .site-footer__inner { - grid-template-columns: 1fr; - gap: 1.5rem; + .spec-section { + margin-bottom: 48px; } - .site-footer .site-footer__nav { - grid-template-columns: repeat(2, minmax(0, 1fr)); + .anchor { + display: none; } } -@media (max-width: 30rem) { - .site-footer .site-footer__nav { - grid-template-columns: 1fr; +@media print { + .spec-header, + .spec-sidebar, + .sidebar-scrim { + display: none !important; + } + + .spec-layout, + .spec-content { + display: block; + width: auto; + margin: 0; + padding: 0; } } diff --git a/public/mdbase-theme.css b/public/mdbase-theme.css index b70e4ad..cd6b4e7 100644 --- a/public/mdbase-theme.css +++ b/public/mdbase-theme.css @@ -1,25 +1,25 @@ :root { color-scheme: light; - color: var(--ink); - background: var(--paper); + color: var(--color-text); + background: var(--color-canvas); font-family: "Atkinson Hyperlegible", "Segoe UI", sans-serif; font-synthesis: none; - --color-canvas: oklch(99.5% 0.002 255); - --color-surface: oklch(99.5% 0.002 255); - --color-surface-subtle: oklch(97.5% 0.004 255); - --color-selected: oklch(96.4% 0.016 238); - --color-text: oklch(21% 0.018 255); - --color-text-soft: oklch(39% 0.016 255); - --color-text-muted: oklch(54% 0.014 255); - --color-text-faint: oklch(70% 0.009 255); - --color-border: oklch(92% 0.006 255); - --color-border-strong: oklch(82% 0.008 255); - --color-accent: oklch(45% 0.105 238); - --color-accent-strong: oklch(35% 0.09 238); - --color-success: oklch(43% 0.09 153); - --color-warning: oklch(60% 0.09 75); - --color-danger: oklch(50% 0.11 28); - --color-scrim: oklch(20% 0.006 250 / 0.22); + --color-canvas: #ffffff; + --color-surface: #ffffff; + --color-surface-subtle: #ffffff; + --color-selected: #ffffff; + --color-text: #171717; + --color-text-soft: rgb(23 23 23 / 74%); + --color-text-muted: rgb(23 23 23 / 54%); + --color-text-faint: rgb(23 23 23 / 30%); + --color-border: rgb(23 23 23 / 18%); + --color-border-strong: rgb(23 23 23 / 42%); + --color-accent: #171717; + --color-accent-strong: #171717; + --color-success: #171717; + --color-warning: #171717; + --color-danger: #171717; + --color-scrim: rgb(23 23 23 / 22%); --paper: var(--color-surface); --hover: var(--color-surface-subtle); --selected: var(--color-selected); @@ -39,44 +39,48 @@ --ease: cubic-bezier(0.16, 1, 0.3, 1); } +html { + font-size: 17px; +} + :root[data-theme="dark"] { color-scheme: dark; - --color-canvas: oklch(17.5% 0.012 255); - --color-surface: oklch(19.5% 0.012 255); - --color-surface-subtle: oklch(23.5% 0.014 255); - --color-selected: oklch(27% 0.035 238); - --color-text: oklch(92% 0.008 255); - --color-text-soft: oklch(80% 0.01 255); - --color-text-muted: oklch(68% 0.012 255); - --color-text-faint: oklch(56% 0.011 255); - --color-border: oklch(29% 0.012 255); - --color-border-strong: oklch(40% 0.014 255); - --color-accent: oklch(73% 0.105 238); - --color-accent-strong: oklch(79% 0.085 238); - --color-success: oklch(72% 0.09 153); - --color-warning: oklch(78% 0.09 75); - --color-danger: oklch(72% 0.115 28); - --color-scrim: oklch(5% 0.006 250 / 0.62); + --color-canvas: #121212; + --color-surface: #121212; + --color-surface-subtle: #181818; + --color-selected: #1b1b1b; + --color-text: #f0f0ed; + --color-text-soft: rgb(240 240 237 / 78%); + --color-text-muted: rgb(240 240 237 / 56%); + --color-text-faint: rgb(240 240 237 / 30%); + --color-border: rgb(240 240 237 / 22%); + --color-border-strong: rgb(240 240 237 / 48%); + --color-accent: #f0f0ed; + --color-accent-strong: #f0f0ed; + --color-success: #f0f0ed; + --color-warning: #f0f0ed; + --color-danger: #f0f0ed; + --color-scrim: rgb(0 0 0 / 62%); } @media (prefers-color-scheme: dark) { :root:not([data-theme]) { color-scheme: dark; - --color-canvas: oklch(17.5% 0.012 255); - --color-surface: oklch(19.5% 0.012 255); - --color-surface-subtle: oklch(23.5% 0.014 255); - --color-selected: oklch(27% 0.035 238); - --color-text: oklch(92% 0.008 255); - --color-text-soft: oklch(80% 0.01 255); - --color-text-muted: oklch(68% 0.012 255); - --color-text-faint: oklch(56% 0.011 255); - --color-border: oklch(29% 0.012 255); - --color-border-strong: oklch(40% 0.014 255); - --color-accent: oklch(73% 0.105 238); - --color-accent-strong: oklch(79% 0.085 238); - --color-success: oklch(72% 0.09 153); - --color-warning: oklch(78% 0.09 75); - --color-danger: oklch(72% 0.115 28); - --color-scrim: oklch(5% 0.006 250 / 0.62); + --color-canvas: #121212; + --color-surface: #121212; + --color-surface-subtle: #181818; + --color-selected: #1b1b1b; + --color-text: #f0f0ed; + --color-text-soft: rgb(240 240 237 / 78%); + --color-text-muted: rgb(240 240 237 / 56%); + --color-text-faint: rgb(240 240 237 / 30%); + --color-border: rgb(240 240 237 / 22%); + --color-border-strong: rgb(240 240 237 / 48%); + --color-accent: #f0f0ed; + --color-accent-strong: #f0f0ed; + --color-success: #f0f0ed; + --color-warning: #f0f0ed; + --color-danger: #f0f0ed; + --color-scrim: rgb(0 0 0 / 62%); } } diff --git a/public/theme-bootstrap.js b/public/theme-bootstrap.js index 777c4cd..0b3b958 100644 --- a/public/theme-bootstrap.js +++ b/public/theme-bootstrap.js @@ -1,10 +1,15 @@ try { const theme = /^\/authorize\/[0-9a-f-]+$/i.test(location.pathname) - ? "system" + ? null : localStorage.getItem("mdbase:theme"); - if (theme === "light" || theme === "dark") document.documentElement.dataset.theme = theme; - const dark = theme === "dark" || (theme !== "light" && matchMedia("(prefers-color-scheme: dark)").matches); - document.querySelector('meta[name="theme-color"]')?.setAttribute("content", dark ? "#1c1e24" : "#fcfcfd"); + if (theme === "light" || theme === "dark") { + document.documentElement.dataset.theme = theme; + } + const dark = theme === "dark" + || (theme !== "light" && matchMedia("(prefers-color-scheme: dark)").matches); + document + .querySelector('meta[name="theme-color"]') + ?.setAttribute("content", dark ? "#121212" : "#ffffff"); } catch { // The system preference remains available when local storage is unavailable. } diff --git a/scripts/check-connect-release-order.mjs b/scripts/check-connect-release-order.mjs new file mode 100644 index 0000000..9135df5 --- /dev/null +++ b/scripts/check-connect-release-order.mjs @@ -0,0 +1,30 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { readFile } from "node:fs/promises"; +import { compareSemanticVersions } from "./connect-release-record.mjs"; + +const baseRevision = process.argv[2]; +assert.match(baseRevision, /^[0-9a-f]{40}$/, "a full base revision is required"); +const current = JSON.parse(await readFile(new URL("../src/data/connect-release.json", import.meta.url))); +const base = JSON.parse(execFileSync("git", [ + "show", + `${baseRevision}:src/data/connect-release.json` +], { encoding: "utf8" })); +const comparison = compareSemanticVersions(current.version, base.version); +assert.ok(comparison >= 0, `Connect release ${current.version} would downgrade base release ${base.version}`); +if (comparison === 0) { + assert.deepEqual(releaseIdentity(current), releaseIdentity(base), "an existing Connect release identity cannot be rewritten"); +} +console.log(`Connect release order verified: ${base.version} -> ${current.version}.`); + +function releaseIdentity(record) { + return { + version: record.version, + sdkVersion: record.sdkVersion, + tag: record.tag, + sourceRevision: record.sourceRevision, + releaseUrl: record.releaseUrl, + channelManifestUrl: record.channelManifestUrl, + artifacts: [...record.desktop, ...record.cli].map(({ file, size }) => ({ file, size })) + }; +} diff --git a/scripts/check-connect-release.mjs b/scripts/check-connect-release.mjs index 511a872..2fee8d7 100644 --- a/scripts/check-connect-release.mjs +++ b/scripts/check-connect-release.mjs @@ -1,6 +1,10 @@ import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; -import { readFile } from "node:fs/promises"; +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { buildConnectReleaseRecord, validateNpmProvenance } from "./connect-release-record.mjs"; +import { verifyNpmPackageSignatures } from "./verify-npm-release.mjs"; const release = JSON.parse(await readFile(new URL("../src/data/connect-release.json", import.meta.url))); const sources = JSON.parse(await readFile(new URL("../site-sources.json", import.meta.url))); @@ -37,16 +41,22 @@ const github = JSON.parse(execFileSync("gh", [ ], { encoding: "utf8" })); assert.ok(github, "selected GitHub release must exist"); assert.equal(github.draft, false, "selected GitHub release must be published"); -const channelAsset = github.assets.find((asset) => asset.name === "mdbase-connect-channel-v1.json"); -assert.ok(channelAsset, "selected signed channel manifest must exist"); -const channel = JSON.parse(execFileSync("gh", [ +const tagRef = JSON.parse(execFileSync("gh", [ "api", - "-H", - "Accept: application/octet-stream", - `repos/mdbase-dev/mdbase-connect/releases/assets/${channelAsset.id}` + `repos/mdbase-dev/mdbase-connect/git/ref/tags/${release.tag}` ], { encoding: "utf8" })); +const tagTarget = tagRef.object.type === "tag" + ? JSON.parse(execFileSync("gh", [ + "api", + `repos/mdbase-dev/mdbase-connect/git/tags/${tagRef.object.sha}` + ], { encoding: "utf8" })).object + : tagRef.object; +assert.equal(tagTarget.type, "commit", "release tag must resolve to a commit"); +assert.equal(tagTarget.sha, release.sourceRevision, "released documentation source differs from the tag"); +const channel = await verifiedChannel(github, release.tag, release.sourceRevision); const sdkResponse = await fetch(`https://registry.npmjs.org/@mdbase-dev%2fconnect/${release.sdkVersion}`, { - headers: { accept: "application/json" } + headers: { accept: "application/json" }, + signal: AbortSignal.timeout(30000) }); assert.equal(sdkResponse.status, 200, "selected SDK package must exist"); assert.equal(channel.version, release.version, "channel manifest version differs from website"); @@ -60,16 +70,63 @@ for (const artifact of artifacts) { const sdk = await sdkResponse.json(); assert.equal(sdk.version, release.sdkVersion, "registry returned a different SDK version"); -const tagRef = JSON.parse(execFileSync("gh", [ - "api", - `repos/mdbase-dev/mdbase-connect/git/ref/tags/${release.tag}` -], { encoding: "utf8" })); -const tagTarget = tagRef.object.type === "tag" - ? JSON.parse(execFileSync("gh", [ - "api", - `repos/mdbase-dev/mdbase-connect/git/tags/${tagRef.object.sha}` - ], { encoding: "utf8" })).object - : tagRef.object; -assert.equal(tagTarget.type, "commit", "release tag must resolve to a commit"); -assert.equal(tagTarget.sha, release.sourceRevision, "released documentation source differs from the tag"); +const npmWork = await mkdtemp(join(tmpdir(), "mdbase-connect-npm-")); +try { + verifyNpmPackageSignatures(release.sdkVersion, npmWork); +} finally { + await rm(npmWork, { recursive: true, force: true }); +} +const npmAttestationsResponse = await fetch(`https://registry.npmjs.org/-/npm/v1/attestations/@mdbase-dev%2fconnect@${release.sdkVersion}`, { + headers: { accept: "application/json" }, + signal: AbortSignal.timeout(30000) +}); +assert.equal(npmAttestationsResponse.status, 200, "npm provenance request failed"); +validateNpmProvenance({ + version: release.sdkVersion, + releaseTag: release.tag, + sourceRevision: release.sourceRevision, + metadata: sdk, + attestations: await npmAttestationsResponse.json() +}); +const canonical = buildConnectReleaseRecord({ + tag: release.tag, + sourceRevision: release.sourceRevision, + release: github, + channel, + npmVersion: sdk.version +}); +assert.deepEqual(release, canonical, "website release record differs from canonical public evidence"); console.log(`Connect release record verified: ${release.version}, ${artifacts.length} artifacts, SDK ${release.sdkVersion}.`); + +async function verifiedChannel(githubRelease, tag, sourceRevision) { + const names = ["mdbase-connect-channel-v1.json", "mdbase-connect-channel-v1.json.sigstore.json"]; + const selected = names.map((name) => { + const matches = githubRelease.assets.filter((asset) => asset.name === name); + assert.equal(matches.length, 1, `selected release must contain exactly one ${name}`); + return matches[0]; + }); + const work = await mkdtemp(join(tmpdir(), "mdbase-connect-channel-")); + const manifestPath = join(work, names[0]); + const bundlePath = join(work, names[1]); + try { + for (const [asset, path] of [[selected[0], manifestPath], [selected[1], bundlePath]]) { + await writeFile(path, execFileSync("gh", [ + "api", + "-H", + "Accept: application/octet-stream", + `repos/mdbase-dev/mdbase-connect/releases/assets/${asset.id}` + ], { encoding: "buffer", maxBuffer: 20 * 1024 * 1024 })); + } + execFileSync("cosign", [ + "verify-blob", + "--bundle", bundlePath, + "--certificate-identity", `https://github.com/mdbase-dev/mdbase-connect/.github/workflows/desktop-release.yml@refs/tags/${tag}`, + "--certificate-oidc-issuer", "https://token.actions.githubusercontent.com", + "--certificate-github-workflow-sha", sourceRevision, + manifestPath + ], { stdio: ["ignore", "ignore", "inherit"] }); + return JSON.parse(await readFile(manifestPath, "utf8")); + } finally { + await rm(work, { recursive: true, force: true }); + } +} diff --git a/scripts/connect-release-record.mjs b/scripts/connect-release-record.mjs new file mode 100644 index 0000000..298d11e --- /dev/null +++ b/scripts/connect-release-record.mjs @@ -0,0 +1,167 @@ +import assert from "node:assert/strict"; + +const CONNECT_REPOSITORY = "mdbase-dev/mdbase-connect"; +const CHANNEL_NAME = "mdbase-connect-channel-v1.json"; + +export function buildConnectReleaseRecord({ tag, sourceRevision, release, channel, npmVersion }) { + const version = versionFromTag(tag); + assert.equal(release.tag_name, tag, "GitHub release tag differs from requested tag"); + assert.equal(release.draft, false, "GitHub release is still a draft"); + assert.equal(release.prerelease, version.includes("-"), "GitHub release type differs from semantic version"); + assert.equal(channel.schema_version, 1, "unsupported channel manifest schema"); + assert.equal(channel.version, version, "channel manifest version differs from tag"); + assert.equal(channel.tag, tag, "channel manifest tag differs from requested tag"); + assert.equal(channel.channel, version.includes("-") ? "beta" : "stable", "channel differs from semantic version"); + assert.equal(channel.release_url, `https://github.com/${CONNECT_REPOSITORY}/releases/tag/${tag}`, "channel release URL differs from tag"); + assert.equal(npmVersion, version, "published SDK version differs from client release"); + assert.match(sourceRevision, /^[0-9a-f]{40}$/, "release source must be a full commit SHA"); + assert.ok(Number.isFinite(Date.parse(release.published_at)), "GitHub release has no publication time"); + + const assets = release.assets ?? []; + const desktop = [ + websiteArtifact(assets, version, "macOS", "Apple Silicon", /^mdbase-connect-.+-macos-arm64(?:-UNSIGNED)?\.dmg$/, macTrust(channel.channel), "Download for Apple Silicon"), + websiteArtifact(assets, version, "macOS", "Intel", /^mdbase-connect-.+-macos-x64(?:-UNSIGNED)?\.dmg$/, macTrust(channel.channel), "Download for Intel"), + websiteArtifact(assets, version, "Windows", "64-bit", /^mdbase-connect-.+-windows-x64(?:-UNSIGNED)?-Setup\.exe$/, "Unsigned beta preview", "Download for Windows"), + websiteArtifact(assets, version, "Linux", "64-bit Debian or Ubuntu", /^mdbase-connect-.+-linux-x64\.deb$/, "DEB package", "Download DEB"), + websiteArtifact(assets, version, "Linux", "64-bit Fedora, RHEL, or compatible", /^mdbase-connect-.+-linux-x64\.rpm$/, "RPM package", "Download RPM") + ]; + const cli = [ + websiteArtifact(assets, version, "macOS", "Apple Silicon", /^mdbase-cli-.+-macos-arm64\.tar\.gz$/, "Beta preview", "Download CLI for Apple Silicon"), + websiteArtifact(assets, version, "macOS", "Intel", /^mdbase-cli-.+-macos-x64\.tar\.gz$/, "Beta preview", "Download CLI for Intel"), + websiteArtifact(assets, version, "Windows", "64-bit", /^mdbase-cli-.+-windows-x64(?:-UNSIGNED)?\.tar\.gz$/, "Unsigned beta preview", "Download CLI for Windows"), + websiteArtifact(assets, version, "Linux", "64-bit", /^mdbase-cli-.+-linux-x64\.tar\.gz$/, "tar.gz", "Download CLI for Linux") + ]; + + const publishedAssets = new Map(assets.map((asset) => [asset.name, asset])); + assert.equal(publishedAssets.size, assets.length, "GitHub release contains duplicate asset names"); + const signedArtifacts = Object.values(channel.targets ?? {}).flatMap((target) => + Array.isArray(target?.artifacts) ? target.artifacts : [] + ); + const channelArtifacts = new Set(signedArtifacts.map((artifact) => artifact?.name)); + assert.ok(channelArtifacts.size > 0, "channel manifest has no client targets"); + assert.equal(channelArtifacts.size, signedArtifacts.length, "channel manifest contains duplicate artifacts"); + for (const artifact of signedArtifacts) { + const published = publishedAssets.get(artifact.name); + assert.ok(published, `${artifact.name} from the signed channel is absent from the GitHub release`); + assert.equal(artifact.size, published.size, `${artifact.name} size differs from the signed channel`); + assert.equal(`sha256:${artifact.sha256}`, published.digest, `${artifact.name} digest differs from the signed channel`); + assert.equal( + artifact.url, + `https://github.com/${CONNECT_REPOSITORY}/releases/download/${tag}/${encodeURIComponent(artifact.name)}`, + `${artifact.name} has a non-canonical channel URL` + ); + } + for (const artifact of desktop.filter(({ platform }) => platform === "Linux" || platform === "Windows")) { + assert.ok(channelArtifacts.has(artifact.file), `${artifact.file} is absent from signed channel targets`); + } + + return { + schemaVersion: 1, + channel: channel.channel, + version, + sdkVersion: version, + tag, + sourceRevision, + publishedAt: release.published_at, + releaseUrl: channel.release_url, + channelManifestUrl: `https://github.com/${CONNECT_REPOSITORY}/releases/download/${tag}/${CHANNEL_NAME}`, + desktop, + cli + }; +} + +export function compareSemanticVersions(left, right) { + const a = parseSemanticVersion(left); + const b = parseSemanticVersion(right); + for (const key of ["major", "minor", "patch"]) { + if (a[key] !== b[key]) return a[key] < b[key] ? -1 : 1; + } + if (a.pre.length === 0 || b.pre.length === 0) { + return a.pre.length === b.pre.length ? 0 : a.pre.length === 0 ? 1 : -1; + } + const length = Math.max(a.pre.length, b.pre.length); + for (let index = 0; index < length; index += 1) { + const x = a.pre[index]; + const y = b.pre[index]; + if (x === undefined || y === undefined) return x === y ? 0 : x === undefined ? -1 : 1; + if (x === y) continue; + const xNumber = /^\d+$/.test(x); + const yNumber = /^\d+$/.test(y); + if (xNumber && yNumber) return Number(x) < Number(y) ? -1 : 1; + if (xNumber !== yNumber) return xNumber ? -1 : 1; + return x < y ? -1 : 1; + } + return 0; +} + +export function validateNpmProvenance({ version, releaseTag, sourceRevision, metadata, attestations }) { + assert.equal(metadata.version, version, "npm registry returned a different SDK version"); + assert.equal(metadata.repository?.url, "git+https://github.com/mdbase-dev/mdbase-connect.git", "npm package has an unexpected source repository"); + assert.ok(metadata.dist?.attestations?.provenance, "npm package has no provenance attestation"); + const statements = (attestations.attestations ?? []) + .filter((entry) => entry.predicateType === "https://slsa.dev/provenance/v1") + .map((entry) => JSON.parse(Buffer.from(entry.bundle.dsseEnvelope.payload, "base64url").toString("utf8"))); + assert.equal(statements.length, 1, "npm package must have exactly one SLSA provenance statement"); + const definition = statements[0].predicate?.buildDefinition; + assert.deepEqual(definition?.externalParameters?.workflow, { + ref: `refs/tags/${releaseTag}`, + repository: "https://github.com/mdbase-dev/mdbase-connect", + path: ".github/workflows/publish-npm.yml" + }, "npm provenance has an unexpected publishing workflow"); + assert.ok( + definition?.resolvedDependencies?.some((dependency) => + dependency.uri === `git+https://github.com/mdbase-dev/mdbase-connect@refs/tags/${releaseTag}` && + dependency.digest?.gitCommit === sourceRevision + ), + "npm provenance is not bound to the released source commit" + ); +} + +export function releaseUpdateDisposition(current, next) { + const comparison = compareSemanticVersions(next.version, current.version); + if (comparison < 0) return "stale"; + if (comparison > 0) return "update"; + return JSON.stringify(current) === JSON.stringify(next) ? "current" : "conflict"; +} + +export function versionFromTag(tag) { + const match = typeof tag === "string" && /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.exec(tag); + assert.ok(match, "invalid release tag"); + assert.ok( + !match[4]?.split(".").some((part) => /^\d+$/.test(part) && !/^(0|[1-9]\d*)$/.test(part)), + "invalid release tag" + ); + return tag.slice(1); +} + +function parseSemanticVersion(version) { + versionFromTag(`v${version}`); + const match = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/.exec(version); + return { + major: Number(match[1]), + minor: Number(match[2]), + patch: Number(match[3]), + pre: match[4] ? match[4].split(".") : [] + }; +} + +function websiteArtifact(assets, version, platform, detail, pattern, trust, label) { + const matches = assets.filter((asset) => pattern.test(asset.name) && asset.name.includes(version)); + assert.equal(matches.length, 1, `expected exactly one ${platform} ${detail} release artifact`); + const [{ name: file, size, digest }] = matches; + assert.ok(Number.isSafeInteger(size) && size > 0, `${file} has an invalid size`); + assert.match(digest, /^sha256:[0-9a-f]{64}$/, `${file} has no bounded GitHub digest`); + return { + platform, + detail, + trust: typeof trust === "function" ? trust(file) : trust, + file, + size, + sha256: digest.slice("sha256:".length), + label + }; +} + +function macTrust(channel) { + return channel === "stable" ? "Signed and notarized" : "Beta preview · not notarized"; +} diff --git a/scripts/connect-release-record.test.mjs b/scripts/connect-release-record.test.mjs new file mode 100644 index 0000000..c88cf92 --- /dev/null +++ b/scripts/connect-release-record.test.mjs @@ -0,0 +1,132 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { buildConnectReleaseRecord, compareSemanticVersions, releaseUpdateDisposition, validateNpmProvenance, versionFromTag } from "./connect-release-record.mjs"; + +const tag = "v0.1.0-beta.84"; +const version = tag.slice(1); +const names = [ + `mdbase-connect-${version}-macos-arm64.dmg`, + `mdbase-connect-${version}-macos-x64.dmg`, + `mdbase-connect-${version}-windows-x64-UNSIGNED-Setup.exe`, + `mdbase-connect-${version}-linux-x64.deb`, + `mdbase-connect-${version}-linux-x64.rpm`, + `mdbase-cli-${version}-macos-arm64.tar.gz`, + `mdbase-cli-${version}-macos-x64.tar.gz`, + `mdbase-cli-${version}-windows-x64-UNSIGNED.tar.gz`, + `mdbase-cli-${version}-linux-x64.tar.gz` +]; +const release = { + tag_name: tag, + draft: false, + prerelease: true, + published_at: "2026-08-23T00:00:00Z", + assets: names.map((name, index) => ({ name, size: 1000 + index, digest: `sha256:${String(index + 1).padStart(64, "0")}` })) +}; +const signedArtifact = (name) => ({ + name, + size: release.assets.find((asset) => asset.name === name).size, + sha256: release.assets.find((asset) => asset.name === name).digest.slice("sha256:".length), + url: `https://github.com/mdbase-dev/mdbase-connect/releases/download/${tag}/${encodeURIComponent(name)}` +}); +const channel = { + schema_version: 1, + version, + tag, + channel: "beta", + release_url: `https://github.com/mdbase-dev/mdbase-connect/releases/tag/${tag}`, + targets: { + "linux-x64": { artifacts: [signedArtifact(names[3]), signedArtifact(names[4])] }, + "win32-x64": { artifacts: [signedArtifact(names[2])] } + } +}; + +function build(overrides = {}) { + return buildConnectReleaseRecord({ + tag, + sourceRevision: "a".repeat(40), + release, + channel, + npmVersion: version, + ...overrides + }); +} + +test("derives the website record from verified release evidence", () => { + const record = build(); + assert.equal(record.version, version); + assert.equal(record.channel, "beta"); + assert.equal(record.desktop.length, 5); + assert.equal(record.cli.length, 4); + assert.equal(record.desktop[0].file, names[0]); + assert.equal(record.cli[3].size, 1008); + assert.equal(record.cli[3].sha256, String(9).padStart(64, "0")); + assert.equal(record.channelManifestUrl, `https://github.com/mdbase-dev/mdbase-connect/releases/download/${tag}/mdbase-connect-channel-v1.json`); +}); + +test("rejects inconsistent release evidence and duplicate artifacts", () => { + assert.throws(() => build({ npmVersion: "0.1.0-beta.83" }), /SDK version/); + assert.throws(() => build({ channel: { ...channel, tag: "v0.1.0-beta.83" } }), /manifest tag/); + const wrongDigest = structuredClone(channel); + wrongDigest.targets["linux-x64"].artifacts[0].sha256 = "f".repeat(64); + assert.throws(() => build({ channel: wrongDigest }), /digest differs from the signed channel/); + assert.throws(() => build({ release: { ...release, assets: [...release.assets, release.assets[0]] } }), /exactly one macOS Apple Silicon/); +}); + +test("orders semantic versions including prereleases", () => { + assert.equal(compareSemanticVersions("0.1.0-beta.9", "0.1.0-beta.10"), -1); + assert.equal(compareSemanticVersions("0.1.0", "0.1.0-beta.99"), 1); + assert.equal(compareSemanticVersions("1.0.0", "1.0.0"), 0); + assert.equal(compareSemanticVersions("1.0.0-beta-2", "1.0.0-beta-1"), 1); + assert.throws(() => versionFromTag("latest"), /invalid release tag/); + assert.throws(() => versionFromTag("v1.0.0-beta.01"), /invalid release tag/); +}); + +test("binds npm provenance to the release tag and source commit", () => { + const sourceRevision = "a".repeat(40); + const statement = { + predicate: { + buildDefinition: { + externalParameters: { + workflow: { + ref: `refs/tags/${tag}`, + repository: "https://github.com/mdbase-dev/mdbase-connect", + path: ".github/workflows/publish-npm.yml" + } + }, + resolvedDependencies: [{ + uri: `git+https://github.com/mdbase-dev/mdbase-connect@refs/tags/${tag}`, + digest: { gitCommit: sourceRevision } + }] + } + } + }; + const evidence = { + version, + releaseTag: tag, + sourceRevision, + metadata: { + version, + repository: { url: "git+https://github.com/mdbase-dev/mdbase-connect.git" }, + dist: { attestations: { provenance: {} } } + }, + attestations: { + attestations: [{ + predicateType: "https://slsa.dev/provenance/v1", + bundle: { dsseEnvelope: { payload: Buffer.from(JSON.stringify(statement)).toString("base64url") } } + }] + } + }; + validateNpmProvenance(evidence); + assert.throws( + () => validateNpmProvenance({ ...evidence, sourceRevision: "b".repeat(40) }), + /not bound to the released source commit/ + ); +}); + +test("classifies idempotent, stale, newer, and conflicting updates", () => { + const current = build(); + assert.equal(releaseUpdateDisposition(current, structuredClone(current)), "current"); + assert.equal(releaseUpdateDisposition(current, { ...current, version: "0.1.0-beta.83" }), "stale"); + assert.equal(releaseUpdateDisposition(current, { ...current, version: "0.1.0-beta.85" }), "update"); + assert.equal(releaseUpdateDisposition(current, { ...current, publishedAt: "different" }), "conflict"); +}); diff --git a/scripts/import-spec.mjs b/scripts/import-spec.mjs index f0b7139..a833a34 100644 --- a/scripts/import-spec.mjs +++ b/scripts/import-spec.mjs @@ -55,6 +55,24 @@ function rewrite(html, archive) { .replaceAll('href="mdbase-favicon.svg"', 'href="/spec/mdbase-favicon.svg"') .replaceAll('href="runtime.html"', 'href="/runtime/"') .replaceAll('Implementations', '') + .replace( + /