Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
env:
TZ: UTC

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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"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",
"test": "node --test tests/*.test.js && vitest run",
"test": "TZ=UTC node --test tests/*.test.js && TZ=UTC vitest run",
"typecheck": "tsc -b"
},
"repository": {
Expand Down
38 changes: 38 additions & 0 deletions src/services/layout.test.ts
Original file line number Diff line number Diff line change
@@ -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<WorkstationLayout>['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);
});
});
12 changes: 9 additions & 3 deletions src/services/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const DEFAULT_LAYOUT: WorkstationLayout = {
},
};

export async function getLayout(): Promise<WorkstationLayout> {
const result = await chrome.storage.local.get(STORAGE_KEY);
const stored = result[STORAGE_KEY] as Partial<WorkstationLayout> | undefined;
export function normalizeLayout(
stored?: Partial<WorkstationLayout> | null,
): WorkstationLayout {
return {
...DEFAULT_LAYOUT,
...stored,
Expand All @@ -35,6 +35,12 @@ export async function getLayout(): Promise<WorkstationLayout> {
};
}

export async function getLayout(): Promise<WorkstationLayout> {
const result = await chrome.storage.local.get(STORAGE_KEY);
const stored = result[STORAGE_KEY] as Partial<WorkstationLayout> | undefined;
return normalizeLayout(stored);
}

export async function saveLayout(layout: WorkstationLayout): Promise<void> {
await chrome.storage.local.set({ [STORAGE_KEY]: layout });
}
7 changes: 6 additions & 1 deletion tests/builder-digest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading