Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.
TypeScript canva-alternativecanvasdesigndesign-tooldrag-and-dropeditorgraphic-designkonvanextjsopen-sourcereactself-hostedtemplatestypescript
chore(v0.12): CI gate — PRs run tsc+eslint+vitest, main merges run the Playwright suite (H2) (#10)
Ashiq Hussain Mir481ceeca4ed1
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlnew file mode 100644index 0000000..5a3ac6e--- /dev/null+++ b/.github/workflows/ci.yml@@ -0,0 +1,121 @@+name: CI++# H2 (roadmap: research/V0118-ROADMAP-RESEARCH.md §4.2) — the test gate+# the deploy pipelines never had. Three deploy targets publish `main`+# directly, and until now every test in this repo ran only on a+# contributor's laptop.+#+# pull_request → fast feedback, no DB required:+# npm ci → tsc --noEmit → eslint → vitest run+# push to main → the same gate + the full Playwright browser suite+# against a real Postgres service container, so+# nothing lands on `main` untested by e2e either.+# workflow_dispatch → run the whole pipeline (incl. e2e) on demand,+# e.g. before cutting a release or on a risky PR.+#+# Binding the gate: CONTRIBUTING.md → "CI & required checks" documents+# the one-time branch-protection setup (require the `lint-unit` check).++on:+ pull_request:+ push:+ branches: [main]+ workflow_dispatch:++concurrency:+ group: ci-${{ github.ref }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}++permissions:+ contents: read++jobs:+ # ── Fast gate: every pull request ─────────────────────────────────+ lint-unit:+ name: lint-unit+ runs-on: ubuntu-latest+ timeout-minutes: 10+ steps:+ - name: Checkout+ uses: actions/checkout@v4++ - name: Set up Node.js+ uses: actions/setup-node@v4+ with:+ node-version: 22+ cache: npm++ # postinstall runs `prisma generate` + the wasm portability patch,+ # so tsc has the generated client types it type-checks against.+ - name: Install dependencies+ run: npm ci --no-audit --no-fund++ - name: Typecheck+ run: npm run typecheck++ - name: Lint+ run: npm run lint++ # 316 unit tests — pure functions + mocked-route tests, no DB.+ - name: Unit tests+ run: npm test++ # ── Browser suite: merges to main + manual dispatch ───────────────+ e2e:+ name: e2e+ needs: lint-unit+ if: github.event_name != 'pull_request'+ runs-on: ubuntu-latest+ timeout-minutes: 20++ services:+ postgres:+ image: postgres:17+ env:+ POSTGRES_USER: canvix+ POSTGRES_PASSWORD: canvix+ POSTGRES_DB: canvix+ ports:+ - 5432:5432+ options: >-+ --health-cmd "pg_isready -U canvix"+ --health-interval 5s+ --health-timeout 5s+ --health-retries 12++ env:+ # Plain local URL — db-url.ts leaves localhost alone (no SSL).+ # db:setup applies migrations + seeds the 110-template library;+ # playwright.config.ts boots `npm run dev` itself.+ DATABASE_URL: postgresql://canvix:canvix@localhost:5432/canvix++ steps:+ - name: Checkout+ uses: actions/checkout@v4++ - name: Set up Node.js+ uses: actions/setup-node@v4+ with:+ node-version: 22+ cache: npm++ - name: Install dependencies+ run: npm ci --no-audit --no-fund++ - name: Install Playwright browser (chromium)+ run: npx playwright install --with-deps chromium++ - name: Set up database (migrations + template seed)+ run: npm run db:setup++ - name: Run Playwright e2e suite+ run: npx playwright test++ - name: Upload Playwright traces (on failure)+ if: failure()+ uses: actions/upload-artifact@v4+ with:+ name: playwright-failures+ path: test-results/+ if-no-files-found: ignore+ retention-days: 7diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 287c8ee..0908e51 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,6 +3,55 @@All notable changes to Canvix will be documented in this file.The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).+## [0.12.0] — 2026-11-02++### Added++- **CI gate — tests finally gate what ships (H2).** A new **CI** workflow+ (`.github/workflows/ci.yml`) closes the gap the v1.0 roadmap research+ flagged as the highest-leverage fix: the repo had 316 unit tests and 28+ browser tests, but both GitHub workflows were manual-only and all three+ deploy pipelines (Vercel, Cloudflare Workers Builds, Netlify) publish+ `main` directly — so every test ran only on a contributor's laptop.+ Now: every **pull request** runs `npm ci` (with the npm cache) →+ `tsc --noEmit` → `eslint .` → `vitest run` — no database required, the+ check lands in minutes; every **merge to `main`** additionally runs the+ full Playwright browser suite against a real Postgres 17 service+ container (migrations + the 110-template seed + `next dev`, all inside+ the job), with traces uploaded on failure. The pipeline is also+ manually dispatchable on any branch for pre-merge e2e on risky PRs.+ Runtime targets: PR gate < 10 min, e2e job verified at ~4 min locally.+ The whole command sequence was verified end-to-end before this+ release: 316/316 unit, 28/28 Playwright against a fresh database.+- **README CI badge** — live build status for `main` next to the license+ badge.+- **CONTRIBUTING: "CI & required checks"** — documents what each check+ runs and the one-time branch-protection setup that makes `lint-unit`+ a required status check on `main` (branch protection cannot be enabled+ from a PR, so the exact click-path is written down), plus the+ contributor-facing local equivalents (`npm run lint`, `npm run+ typecheck`, `npm run db:setup && npx playwright test`).++### Fixed++- **`image-guard` happy-path test is now hermetic** — the first catch of+ the new CI gate. The test mocked the AI SDK but not the provider-config+ resolution (`ZAI_BASE_URL`/`ZAI_API_KEY` env → `.z-ai-config` file chain+ cwd → ~ → /etc), so the "same-origin POSTs pass the guard" assertion+ only held on machines that carry a real provider config (dev sandbox:+ 200) while clean CI runners answered 503. The test now stubs the env+ pair in `beforeEach` (restored after each test), so every machine+ exercises the same code path.++### Changed++- **CONTRIBUTING setup flow modernized** — the quick-start now matches+ what CI itself runs (`npm install` → `npm run db:setup`, the one+ command that applies migrations and seeds the template library)+ instead of the pre-v0.8 `db:push` + `db:seed` two-step, and the+ stale `src/lib/templates.ts` pointer now names the real+ `src/lib/templates/collection-v08-*.ts` files.+## [0.11.8] — 2026-11-01### Securitydiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 85ba712..6e1d7ed 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -7,20 +7,20 @@ Thanks for helping build the open-source Canva alternative! 🎨```bashgit clone https://github.com/mir-ashiq/canvix.gitcd canvix-bun install-cp .env.example .env-bun run db:push-bun run db:seed-bun run dev+npm install+cp .env.example .env # then set DATABASE_URL (Supabase / Neon / local Postgres)+npm run db:setup # migrations + the 110-template seed, one command+npm run dev```-> `bun run lint` must pass before every commit.+> `npm run lint` and `npm run typecheck` must pass before every commit.+> (bun works too — `bun install`, `bun run dev` — the lockfile is npm's.)## Where to help| Area | Files ||---|---|-| New templates | `src/lib/templates.ts` (compose elements with the builder helpers) |+| New templates | `src/lib/templates/collection-v08-*.ts` (compose elements with the builder helpers in `src/lib/templates/helpers.ts`) || New fonts | `src/lib/editor-utils.ts` → `FONTS` + the Google Fonts link in `src/app/layout.tsx` || Stickers / graphics | `src/lib/editor-utils.ts` → `STICKER_GROUPS`, `GRAPHICS` || Canvas behavior | `src/components/editor/canvas/` |@@ -30,7 +30,7 @@ bun run dev## Adding a template-1. Open `src/lib/templates.ts`.+1. Open one of the `src/lib/templates/collection-v08-*.ts` files.2. Compose pages using `tx` (text), `sh` (shape), `ln` (line), `st` (sticker), `gr` (graphic).3. Pick a unique `slug`, `category` (`social | presentation | print | logo | thumbnail`) and an `accent` color.4. Run `bun run db:seed` and restart the dev server.@@ -42,9 +42,41 @@ bun run dev- Test your change in the browser on **desktop and mobile** widths.- Keep design documents small: templates are plain JSON, no binary assets in the repo.+## CI & required checks++Every pull request runs the **CI** workflow (`.github/workflows/ci.yml`):++| Check | What runs | When |+|---|---|---|+| `lint-unit` | `npm ci` → `tsc --noEmit` → `eslint .` → `vitest run` (316 unit tests, no database needed) | every pull request |+| `e2e` | the full Playwright browser suite (28 tests) against a real Postgres service container — migrations + template seed + `next dev`, all inside the job | merges to `main`, and on demand via *Actions → CI → Run workflow* |++Merges to `main` run both jobs, so nothing lands on `main` without the+browser suite either. The deploy pipelines (Vercel, Cloudflare Workers+Builds, Netlify) publish `main` directly — CI is the only test gate they+get, which is why it exists.++**One-time setup for maintainers — make the gate binding.** Branch+protection cannot be enabled from a PR, so after merging the CI workflow:++1. Repo **Settings → Branches → Add branch ruleset** (or classic branch+ protection rule) for `main`.+2. Enable **Require status checks to pass** and select **`lint-unit`**+ (the picker lists it after the workflow's first run on a PR).+3. Optionally enable *Require branches to be up to date*.++`e2e` runs after the merge on `main` pushes by design (keeps PR feedback+fast); for risky PRs — UI, collab, export changes — run it pre-merge via+*Actions → CI → Run workflow*, or locally:++```bash+npm run db:setup && npx playwright test+```+## Pull requests1. Fork & branch (`feat/my-feature`).2. One logical change per PR.3. Describe what changed + screenshots for UI changes.-4. `bun run lint` passes.+4. `npm run lint` and `npm run typecheck` pass, and the `lint-unit` CI+ check is green.diff --git a/README.md b/README.mdindex 9ba35c8..9a8a87c 100644--- a/README.md+++ b/README.md@@ -9,6 +9,7 @@Free & open-source graphic design tool — a community-built [Canva](https://canva.com) alternative.[](LICENSE)+[](https://github.com/mir-ashiq/canvix/actions/workflows/ci.yml)[](https://nextjs.org)[](https://react.dev)[](https://typescriptlang.org)@@ -766,6 +767,10 @@ tool descriptions so agents pick the right format.apply the same design-guard rule as the document rail (owned designs403 non-owners; ownerless designs stay link-editable), plussame-origin enforcement and design-gated presence writes *(v0.11.8)*+- [x] CI gate — every pull request now runs `tsc --noEmit` + eslint + the+ full vitest suite on GitHub Actions, and merges to `main` also run the+ Playwright browser suite against a real Postgres service container —+ the deploy pipelines finally get tested code *(v0.12)*- [ ] Plugin system (external, installable apps) — sandboxed-iframe MVPper `research/PLUGIN-SYSTEM.md`: manifest + permission model, iframesandbox with postMessage bridge, an “Apps” panel store, and 2–3@@ -790,7 +795,7 @@ and verified.Contributions are very welcome! Areas that especially need help:-- New templates (add them in `src/lib/templates.ts`)+- New templates (add them in `src/lib/templates/collection-v08-*.ts`)- New fonts, sticker packs, shape graphics- Mobile UX polish- Testsdiff --git a/package-lock.json b/package-lock.jsonindex ca01595..c0f3cdc 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "canvix",- "version": "0.11.6",+ "version": "0.12.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "canvix",- "version": "0.11.6",+ "version": "0.12.0","hasInstallScript": true,"dependencies": {"@imgly/background-removal": "^1.7.0",diff --git a/package.json b/package.jsonindex 2726f82..ff65a7c 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "canvix",- "version": "0.11.8",+ "version": "0.12.0","private": false,"description": "Canvix — free & open-source graphic design tool. A community-built Canva alternative.","scripts": {diff --git a/src/app/api/ai/image/image-guard.test.ts b/src/app/api/ai/image/image-guard.test.tsindex bbaeea6..a827d1d 100644--- a/src/app/api/ai/image/image-guard.test.ts+++ b/src/app/api/ai/image/image-guard.test.ts@@ -5,9 +5,18 @@// 1. POSTs without Origin/Referer (direct API bots) → 403, zero provider work// 2. POSTs with a foreign Origin → 403// 3. Same-origin POSTs (browser fetch from the app) → pass the guard-// (then reach the provider path; unconfigured providers answer 503)+// and complete the (mocked) provider path → 200+//+// Hermeticity: the SDK is mocked below, but withProvider() checks+// resolveProviderConfig() BEFORE touching the SDK — env vars+// (ZAI_BASE_URL/ZAI_API_KEY) → .z-ai-config file chain (cwd → ~ → /etc).+// Machines that carry a real config (e.g. a dev sandbox with+// /etc/.z-ai-config) used to answer 200 while clean CI runners+// answered 503 — caught by the first run of the v0.12 CI gate. The+// env pair is stubbed in beforeEach so every machine takes the same+// path; the mocked SDK supplies the response.-import { describe, it, expect, vi, beforeEach } from 'vitest'+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'// This sandbox (and dev machines) can carry a real /etc/.z-ai-config, which// would make getZAI() hit the live gateway from unit tests. Mock the SDK@@ -48,11 +57,19 @@ function post(opts: { origin?: string; referer?: string } = {}) {}beforeEach(() => {+ // configured-server simulation — short-circuits the config-file chain+ // deterministically (see the hermeticity note above)+ vi.stubEnv('ZAI_BASE_URL', 'http://provider.test')+ vi.stubEnv('ZAI_API_KEY', 'test-key')vi.clearAllMocks()dbMock.aIUsage.create.mockResolvedValue({})generationsCreate.mockResolvedValue({ data: [{ base64: 'aGVsbG8=' }] })})+afterEach(() => {+ vi.unstubAllEnvs()+})+describe('POST /api/ai/image — v0.9.2 abuse guard', () => {it('rejects Origin-less POSTs (direct API bots) before any provider work', async () => {const res = await post()