From ce5458e1a87b1afe3dec2bb787051672151fc624 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 11 Aug 2026 18:02:54 +0800 Subject: [PATCH 1/2] Add CI workflow and layout unit tests Run typecheck, unit tests, and production build on every PR so main can require a green gate. Co-authored-by: Cursor --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++ package.json | 3 +++ src/services/layout.test.ts | 38 ++++++++++++++++++++++++++++++++++++ src/services/layout.ts | 12 +++++++++--- 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 src/services/layout.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..44cc5ba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: typecheck · test · build + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Typecheck + run: npm run typecheck + + - name: Unit tests + run: npm test + + - name: Production build + run: npm run build diff --git a/package.json b/package.json index b73f6e8..544349f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.4.0", "description": "A local-first personal workstation for Chrome.", "private": true, + "engines": { + "node": ">=20" + }, "scripts": { "dev": "vite", "build": "tsc -b && vite build", diff --git a/src/services/layout.test.ts b/src/services/layout.test.ts new file mode 100644 index 0000000..4c5e474 --- /dev/null +++ b/src/services/layout.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest'; +import type { WorkstationLayout } from '../types'; +import { DEFAULT_LAYOUT, normalizeLayout } from './layout'; + +describe('workstation layout', () => { + it('returns the default layout when nothing is stored', () => { + expect(normalizeLayout()).toEqual(DEFAULT_LAYOUT); + expect(normalizeLayout(null)).toEqual(DEFAULT_LAYOUT); + }); + + it('keeps known card preferences and fills missing cards', () => { + const layout = normalizeLayout({ + version: 1, + cards: { + openTabs: { collapsed: true }, + savedForLater: { visible: false, collapsed: true }, + } as Partial['cards'], + }); + + expect(layout.cards.openTabs).toEqual({ collapsed: true }); + expect(layout.cards.savedForLater).toEqual({ + visible: false, + collapsed: true, + }); + expect(layout.cards.dailyHoroscope).toEqual( + DEFAULT_LAYOUT.cards.dailyHoroscope, + ); + }); + + it('forces layout version 1 even if storage has another value', () => { + expect( + normalizeLayout({ + version: 9 as WorkstationLayout['version'], + cards: DEFAULT_LAYOUT.cards, + }).version, + ).toBe(1); + }); +}); diff --git a/src/services/layout.ts b/src/services/layout.ts index 6284b2b..33e4596 100644 --- a/src/services/layout.ts +++ b/src/services/layout.ts @@ -11,9 +11,9 @@ export const DEFAULT_LAYOUT: WorkstationLayout = { }, }; -export async function getLayout(): Promise { - const result = await chrome.storage.local.get(STORAGE_KEY); - const stored = result[STORAGE_KEY] as Partial | undefined; +export function normalizeLayout( + stored?: Partial | null, +): WorkstationLayout { return { ...DEFAULT_LAYOUT, ...stored, @@ -35,6 +35,12 @@ export async function getLayout(): Promise { }; } +export async function getLayout(): Promise { + const result = await chrome.storage.local.get(STORAGE_KEY); + const stored = result[STORAGE_KEY] as Partial | undefined; + return normalizeLayout(stored); +} + export async function saveLayout(layout: WorkstationLayout): Promise { await chrome.storage.local.set({ [STORAGE_KEY]: layout }); } From f1a0bff1507372b75905cb3cf70245605f2752f7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 11 Aug 2026 18:03:59 +0800 Subject: [PATCH 2/2] Make digest day-boundary tests timezone-stable Pin unit tests to UTC so local-day cache checks do not depend on the runner timezone. Co-authored-by: Cursor --- .github/workflows/ci.yml | 2 ++ package.json | 2 +- tests/builder-digest.test.js | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44cc5ba..ab1a168 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: name: typecheck · test · build runs-on: ubuntu-latest timeout-minutes: 10 + env: + TZ: UTC steps: - name: Checkout diff --git a/package.json b/package.json index 544349f..ec1d152 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", - "test": "node --test tests/*.test.js && vitest run", + "test": "TZ=UTC node --test tests/*.test.js && TZ=UTC vitest run", "typecheck": "tsc -b" }, "repository": { diff --git a/tests/builder-digest.test.js b/tests/builder-digest.test.js index 555b46f..4265c08 100644 --- a/tests/builder-digest.test.js +++ b/tests/builder-digest.test.js @@ -105,10 +105,15 @@ test('merges duplicate items and drops entries older than 48 hours', () => { }); test('detects local-day cache hits and stale feeds', () => { + // Use explicit UTC instants so the local-day check is stable across CI timezones. assert.equal( - digest.isSameLocalDay('2026-07-25T01:00:00+08:00', new Date('2026-07-25T20:00:00+08:00')), + digest.isSameLocalDay('2026-07-25T01:00:00.000Z', new Date('2026-07-25T20:00:00.000Z')), true, ); + assert.equal( + digest.isSameLocalDay('2026-07-24T23:00:00.000Z', new Date('2026-07-25T01:00:00.000Z')), + false, + ); assert.equal( digest.isStale({ feedGeneratedAt: '2026-07-22T00:00:00.000Z' }, NOW), true,