Repository navigation
ci(test): packed layer in a fresh app and against comark.dev #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: setup | ||
| description: Node.js and the pnpm version `packageManager` pins, then the workspace dependencies. | ||
|
|
||
| inputs: | ||
| install: | ||
| description: Install the workspace dependencies, not needed by jobs that only pack the layer. | ||
| default: 'true' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| package-manager-cache: false | ||
| node-version: '24' | ||
| - run: npm i -g --force corepack && corepack enable | ||
| shell: bash | ||
| - if: inputs.install == 'true' | ||
| run: pnpm install --frozen-lockfile | ||
| shell: bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: smoke | ||
|
|
||
| # Vercel's GitHub integration reports every deployment, preview and production, through this event. | ||
| # Content-only pushes skip the build (Ignored Build Step), so they deploy nothing and run nothing here. | ||
| on: deployment_status | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.deployment.id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| smoke: | ||
| name: smoke (${{ github.event.deployment.environment }}) | ||
| if: github.event.deployment_status.state == 'success' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
|
|
||
| steps: | ||
| # The tests of the deployed commit, not the default branch's. | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.deployment.sha }} | ||
| persist-credentials: false | ||
| - uses: ./.github/actions/setup | ||
| - run: pnpm test:smoke | ||
| env: | ||
| SMOKE_URL: ${{ github.event.deployment_status.environment_url || github.event.deployment_status.target_url }} | ||
| SMOKE_ENVIRONMENT: ${{ github.event.deployment.environment }} | ||
| # Vercel project → Deployment Protection → Protection Bypass for Automation. | ||
| VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }} | ||
| # Set the repository variable to `true` to also call the assistant, which costs AI Gateway calls. | ||
| SMOKE_ASSISTANT: ${{ vars.SMOKE_ASSISTANT }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # Builds a site extending the layer against the packed layer, instead of the version it pins. | ||
| # Usage: scripts/test-consumer.sh <site-checkout> [app-dir] | ||
| # - `app-dir` is the Nuxt app inside the site's repository, `docs` by default. | ||
| set -euo pipefail | ||
|
|
||
| site="$(cd "${1:?Usage: scripts/test-consumer.sh <site-checkout> [app-dir]}" && pwd)" | ||
| app="${2:-docs}" | ||
| root="$(cd "$(dirname "$0")/.." && pwd)" | ||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "$work"' EXIT | ||
|
|
||
| echo "› Packing the layer" | ||
| pnpm --dir "$root" pack --pack-destination "$work" > /dev/null | ||
| tarball="$(ls "$work"/comark-docs-*.tgz)" | ||
|
|
||
| # A copy, so the checkout keeps its own layer version and lockfile. | ||
| # `.git` stays: the layer reads the content commit from it. | ||
| echo "› Copying the site to $work/site" | ||
| rsync -a --exclude node_modules --exclude .nuxt --exclude .output --exclude .vercel --exclude .data "$site/" "$work/site/" | ||
| cd "$work/site" | ||
|
|
||
| echo "› Pointing $app at the packed layer" | ||
| (cd "$app" && npm pkg set "dependencies.comark-docs=file:$tarball") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # The site's lockfile pins the layer it ships, so it has to move. | ||
| pnpm install --no-frozen-lockfile | ||
|
|
||
| echo "› Building $app" | ||
| pnpm --dir "$app" run build | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| # Packs the layer as a consumer installs it, then builds a fresh copy of test/fixtures/consumer with it. | ||
| # - Catches what the workspace hides: a file missing from `files`, a dependency only the workspace provides. | ||
| # - `WORKDIR` keeps the app there instead of in a temporary folder. | ||
| set -euo pipefail | ||
|
|
||
| root="$(cd "$(dirname "$0")/.." && pwd)" | ||
|
|
||
| if [ -n "${WORKDIR:-}" ]; then | ||
| work="$WORKDIR" | ||
| if [ -e "$work/app" ]; then | ||
| echo "$work/app already exists, remove it or pick another WORKDIR" >&2 | ||
| exit 1 | ||
| fi | ||
| mkdir -p "$work" | ||
| else | ||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "$work"' EXIT | ||
| fi | ||
|
|
||
| echo "› Packing the layer" | ||
| pnpm --dir "$root" pack --pack-destination "$work" > /dev/null | ||
| tarball="$(ls "$work"/comark-docs-*.tgz)" | ||
|
|
||
| # Outside the repo: pnpm would otherwise pick up its workspace and overrides. | ||
| echo "› Copying the consumer fixture to $work/app" | ||
| cp -R "$root/test/fixtures/consumer" "$work/app" | ||
| cd "$work/app" | ||
|
|
||
| # A git checkout like a real site, so the build-time content snapshot runs too. | ||
| # The empty root commit gives the content commit a parent, as in any non-shallow clone. | ||
| git init -q | ||
| git -c user.name=ci -c user.email=ci@localhost commit -q --allow-empty -m root | ||
| git add -A | ||
| git -c user.name=ci -c user.email=ci@localhost commit -qm fixture | ||
|
|
||
| echo "› Installing the packed layer" | ||
| npm pkg set "dependencies.comark-docs=file:$tarball" "packageManager=$(npm pkg get packageManager --prefix "$root" | tr -d '"')" | ||
| pnpm install | ||
|
|
||
| echo "› Building" | ||
| pnpm exec nuxt build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/fixtures/consumer/content/1.getting-started/.navigation.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| title: Getting Started |
6 changes: 6 additions & 0 deletions
6
test/fixtures/consumer/content/1.getting-started/1.introduction.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: Introduction | ||
| description: What this project does and why it exists. | ||
| --- | ||
|
|
||
| Welcome to the docs! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| title: Consumer Fixture | ||
| description: A site extending the packed comark-docs layer. | ||
| navigation: false | ||
| --- | ||
|
|
||
| # Consumer Fixture | ||
|
|
||
| Read the [introduction](/getting-started/introduction). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // The setup the installation guide documents, nothing more. | ||
| export default defineNuxtConfig({ | ||
| extends: ['comark-docs'], | ||
| site: { | ||
| url: 'https://docs.example.com', | ||
| name: 'Consumer Fixture', | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "comark-docs-consumer", | ||
| "private": true, | ||
| "type": "module", | ||
| "dependencies": { | ||
| "comark-docs": "set by scripts/test-pack.sh", | ||
| "nuxt": "^4.6.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # The layer depends on a pkg.pr.new build of nuxt-llms, which pnpm blocks in subdependencies by default. | ||
| # Remove once nuxt-llms ships a registry release the layer can depend on instead. | ||
| blockExoticSubdeps: false | ||
|
larbish marked this conversation as resolved.
|
||
|
|
||
| # pnpm fails a non-interactive install on unreviewed build scripts, same decisions as the repo root. | ||
| allowBuilds: | ||
| esbuild: false | ||
| vue-demi: false | ||
|
|
||
| minimumReleaseAgeExclude: | ||
| - '@comark/nuxt' | ||
| - '@comark/vue' | ||
| - comark | ||
| - comark-content | ||
| - nuxt-agent-discovery | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { TestProject } from 'vitest/node' | ||
|
|
||
| /** Points the e2e suite at a deployment instead of booting the local build. */ | ||
| export default function setup(project: TestProject) { | ||
| const url = process.env.SMOKE_URL | ||
| if (!url) { | ||
| throw new Error('No deployment to test: set `SMOKE_URL`, e.g. `SMOKE_URL=https://docs-template.comark.dev pnpm test:smoke`.') | ||
| } | ||
| project.provide('baseURL', new URL(url).origin) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { setTimeout as sleep } from 'node:timers/promises' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { INTRO_PAGE, request } from '../e2e/utils' | ||
|
|
||
| const FROM_CACHE = /^(?:HIT|STALE|PRERENDER)$/ | ||
|
|
||
| describe('ISR', () => { | ||
| it('serves a repeat request from the cache', async () => { | ||
| let cache: string | null = null | ||
| // Vercel stores a fresh response about a second after serving it, so an immediate repeat still misses. | ||
| for (let attempt = 0; attempt < 10 && !FROM_CACHE.test(cache ?? ''); attempt++) { | ||
| if (attempt) await sleep(1000) | ||
| const response = await request(INTRO_PAGE.path) | ||
| expect(response.status).toBe(200) | ||
| await response.text() | ||
| cache = response.headers.get('x-vercel-cache') | ||
| } | ||
| expect(cache).toMatch(FROM_CACHE) | ||
| }) | ||
| }) | ||
|
|
||
| // The push webhook only targets production. | ||
| describe.runIf(process.env.SMOKE_ENVIRONMENT === 'Production')('revalidation webhook', () => { | ||
| it('refuses an unsigned call', async () => { | ||
| const response = await request('/api/revalidate', { method: 'POST' }) | ||
| // A 501 means `WEBHOOK_SECRET` or `VERCEL_BYPASS_TOKEN` is missing from the deployment. | ||
| expect(response.status).toBe(401) | ||
| }) | ||
| }) | ||
|
|
||
| // Every run costs AI Gateway calls, so it is opt-in. | ||
| describe.runIf(process.env.SMOKE_ASSISTANT === 'true')('assistant', () => { | ||
| it('streams an answer', async () => { | ||
| const response = await request('/api/assistant', { | ||
| method: 'POST', | ||
| headers: { 'content-type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| messages: [{ id: 'smoke', role: 'user', parts: [{ type: 'text', text: 'In one sentence, what is this documentation about?' }] }], | ||
| }), | ||
| signal: AbortSignal.timeout(55_000), | ||
| }) | ||
| expect(response.status).toBe(200) | ||
| expect(response.headers.get('content-type')).toContain('text/event-stream') | ||
|
|
||
| const stream = await response.text() | ||
| expect(stream).not.toContain('"type":"error"') | ||
| expect(stream).toContain('"type":"text-delta"') | ||
| expect(stream).toContain('"type":"finish"') | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.