From 58953aeaa9d2501e9c89dc4fd2fe28241d835ec5 Mon Sep 17 00:00:00 2001 From: AlanRosston <3025108366@qq.com> Date: Wed, 11 Nov 2026 15:38:04 +0000 Subject: [PATCH 1/5] style(knowledge): expand single-line blocks flagged by lint Co-Authored-By: Claude Opus 5.5 --- main/knowledge/changes.ts | 10 ++++++++-- main/knowledge/ipc.ts | 5 ++++- main/knowledge/records.ts | 17 +++++++++++++---- main/knowledge/service.ts | 4 +++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/main/knowledge/changes.ts b/main/knowledge/changes.ts index 871a13a..ff390e9 100644 --- a/main/knowledge/changes.ts +++ b/main/knowledge/changes.ts @@ -272,7 +272,10 @@ export class EditChanges { const queue = [...seeds]; while (queue.length) { const t = queue.pop()!; - if (t.kind === "page") { candidates.add(t.id); continue; } + if (t.kind === "page") { + candidates.add(t.id); + continue; + } if (inspectedBlocks.has(t.id)) continue; inspectedBlocks.add(t.id); for (const id of this.children(t)) queue.push({ kind: "block", id }); @@ -289,7 +292,10 @@ export class EditChanges { while (true) { const lost = [...candidates].filter(id => !recycled.has(id) && !this.flags(id).deleted && !this.reachable({ kind: "page", id }, recycled)); if (!lost.length) return [...recycled].sort(); - for (const id of lost) { recycled.add(id); expandPage(id); } + for (const id of lost) { + recycled.add(id); + expandPage(id); + } } } diff --git a/main/knowledge/ipc.ts b/main/knowledge/ipc.ts index c598603..cccf8a5 100644 --- a/main/knowledge/ipc.ts +++ b/main/knowledge/ipc.ts @@ -37,7 +37,10 @@ export function registerKnowledgeIPCs(window: BrowserWindow, startup: Startup, s }; const ipc = (channel: string, fn: (...args: unknown[]) => unknown): void => handle(window.webContents, channel, fn); const optional = (value: unknown): string | undefined => value === undefined ? undefined : string(value); - const tab = (id: unknown): string => { checkTab(id); return id; }; + const tab = (id: unknown): string => { + checkTab(id); + return id; + }; function publish(change: KnowledgeChange): void { const db = get().knowledge; if (change.blocks.length) { diff --git a/main/knowledge/records.ts b/main/knowledge/records.ts index 0bf6cc2..334ce8d 100644 --- a/main/knowledge/records.ts +++ b/main/knowledge/records.ts @@ -24,7 +24,9 @@ export function decodeBlock(row: BlockRow): ContentBlock { if (type === "blocked_reference") body.target = null; let value: unknown; if (row.content?.trimStart().startsWith("{")) { - try { value = JSON.parse(row.content); } + try { + value = JSON.parse(row.content); + } catch { /* Early workspaces stored plain text verbatim. */ } } if (record(value) && value.type === type && "schemaVersion" in value) { @@ -48,8 +50,12 @@ export class KnowledgeRecords { if (!content) return ""; if (!content.trimStart().startsWith("{")) return content; let body: ContentBlock["payload"]; - try { body = JSON.parse(content); } - catch { return content; } + try { + body = JSON.parse(content); + } + catch { + return content; + } return body?.schemaVersion === 1 && body.type === type && Array.isArray(body.inline) ? blockText({ id: "", type: body.type, payload: body, children: [] }) : content; }); const definitions = new Map(); @@ -207,7 +213,10 @@ export class KnowledgeRecords { where.push("p.id IN (SELECT value FROM json_each(?))"); params.push(JSON.stringify(query.ids)); } - if (query.kind) { where.push("p.kind = ?"); params.push(query.kind); } + if (query.kind) { + where.push("p.kind = ?"); + params.push(query.kind); + } if (query.pinned !== undefined) { where.push("(SELECT value FROM page_attrs WHERE page_id=p.id AND attr_id='pinned') = ?"); params.push(Number(query.pinned)); diff --git a/main/knowledge/service.ts b/main/knowledge/service.ts index f40cd87..b7d0ec4 100644 --- a/main/knowledge/service.ts +++ b/main/knowledge/service.ts @@ -9,7 +9,9 @@ import { EditChanges, type ReminderChange, type RowChanges } from "./changes"; import { KnowledgeRecords } from "./records"; class DefinitionRollback extends Error { - constructor(readonly impact: AttributeImpact) { super("definition preview"); } + constructor(readonly impact: AttributeImpact) { + super("definition preview"); + } } export function checkTab(id: unknown): asserts id is string { if (typeof id !== "string" || !id || id.length > 100) throw new Error("编辑会话无效。"); From 0db96b5d7360ccd69be8b6e21d1218e73e490edc Mon Sep 17 00:00:00 2001 From: AlanRosston <3025108366@qq.com> Date: Wed, 11 Nov 2026 15:38:04 +0000 Subject: [PATCH 2/5] ci: run typecheck, lint and all tests on pull requests - Add a GitHub Actions workflow for pull requests and pushes to main. - Add `pnpm test` to run the feed and workspace suites together. - Run the appearance tests, which no script executed before. - Remove `lint:test`, whose configs/config.test.js was deleted in 712be2c. - Pin pnpm through packageManager so local installs and CI match. - Document the checks in both READMEs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ README.chs.md | 4 ++++ README.md | 4 ++++ package.json | 3 ++- tests/run-workspace.mjs | 2 +- 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b6c1ccd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + # Reads the pnpm version from packageManager in package.json. + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v5 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm typecheck + - run: pnpm lint --max-warnings 0 + - run: pnpm test \ No newline at end of file diff --git a/README.chs.md b/README.chs.md index 138fefd..5784b07 100644 --- a/README.chs.md +++ b/README.chs.md @@ -32,6 +32,10 @@ pnpm install pnpm dev ``` +### 检查 + +推送前运行 `pnpm typecheck`、`pnpm lint` 和 `pnpm test`。CI 会在拉取请求和 `main` 分支上运行同样的检查。 + ### 数据库开发 使用 `pnpm db:generate --name <名称>` 生成迁移,`pnpm db:check` 检查仓库定义与迁移是否一致,`pnpm db:diagram` 查看表结构图,`pnpm test:db` 运行数据库测试。 diff --git a/README.md b/README.md index f06f91e..6a8becc 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ pnpm install pnpm dev ``` +### Checks + +Run `pnpm typecheck`, `pnpm lint` and `pnpm test` before pushing. CI runs the same checks on pull requests and on `main`. + ### Database development Use `pnpm db:generate --name ` to generate migrations, `pnpm db:check` to check repository consistency, and `pnpm db:diagram` to view the schema. Run `pnpm test:db` for database tests. diff --git a/package.json b/package.json index d44ffb7..6d48b27 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,11 @@ "license": "MIT", "author": "Labloom Contributors", "homepage": "https://labloom.dev", + "packageManager": "pnpm@11.28.11", "scripts": { "lint": "eslint --config configs/eslint.config.js --cache --cache-location dist/.eslintcache .", "lint:fix": "eslint --config configs/eslint.config.js --fix .", - "lint:test": "node configs/config.test.js", + "test": "npm run test:feed && npm run test:db", "test:feed": "node --test configs/feed.test.js", "test:db": "node --import tsx --test tests/database-tools.test.ts && node tests/run-workspace.mjs", "perf": "node tests/run-workspace.mjs --perf", diff --git a/tests/run-workspace.mjs b/tests/run-workspace.mjs index 086f356..053653e 100644 --- a/tests/run-workspace.mjs +++ b/tests/run-workspace.mjs @@ -7,7 +7,7 @@ import { build } from "esbuild"; const require = createRequire(import.meta.url); const benchmark = process.argv.includes("--perf"); -const suites = ["workspace", "builtin-attrs", "drizzle", "attributes", "content", "papers", "schedule", "retention", "timestamps", "editor", "tabs", "session-views", "pdf-text"]; +const suites = ["workspace", "builtin-attrs", "drizzle", "attributes", "content", "papers", "schedule", "retention", "timestamps", "editor", "tabs", "session-views", "pdf-text", "appearance"]; const projectRoot = dirname(dirname(fileURLToPath(import.meta.url))); const localRoot = join(projectRoot, ".local"); mkdirSync(localRoot, { recursive: true }); From 6de383920fa0567e115fd3bbdd480fdf4c15eec0 Mon Sep 17 00:00:00 2001 From: LJM12914 Date: Wed, 18 Nov 2026 17:03:26 +0800 Subject: [PATCH 3/5] ci: pin pnpm 12.5.1 and allow existing lint warnings The lockfile is written by pnpm 12. The old renderer still has 47 lint warnings and is rebuilt later, so CI fails only on lint errors for now. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6c1ccd..61d6437 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,5 +19,5 @@ jobs: cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm typecheck - - run: pnpm lint --max-warnings 0 + - run: pnpm lint - run: pnpm test \ No newline at end of file diff --git a/package.json b/package.json index 5c81990..723d490 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "author": "Labloom Contributors", "homepage": "https://labloom.dev", - "packageManager": "pnpm@11.28.11", + "packageManager": "pnpm@12.5.1", "scripts": { "lint": "eslint --config configs/eslint.config.js --cache --cache-location dist/.eslintcache .", "lint:fix": "eslint --config configs/eslint.config.js --fix .", From a0cd97fa2d863279657458be80920e3071c32033 Mon Sep 17 00:00:00 2001 From: LJM12914 Date: Wed, 18 Nov 2026 17:04:13 +0800 Subject: [PATCH 4/5] chore: record the pinned pnpm in the lockfile Co-Authored-By: Claude Opus 5.5 --- pnpm-lock.yaml | 160 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6d65cfc..da8edb1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,3 +1,161 @@ +--- +lockfileVersion: '9.0' + +importers: + + .: + configDependencies: {} + packageManagerDependencies: + pnpm: + specifier: 12.5.1 + version: 12.5.1 + +packages: + + '@pnpm/exe.android-arm64@12.5.1': + resolution: {integrity: sha512-6LGBmQuDzUmgpHSuy+haG0jrmkwFNa4EuShDZqK3cIBv4Wfb75CzjJmowkzr+iJg40vnBKMQ62t4Ko6mwsId7A==} + cpu: [arm64] + os: [android] + + '@pnpm/exe.android-x64@12.5.1': + resolution: {integrity: sha512-091oCltP3Rx89yxL1Wh5rXkUXEyFzyxIzSHKRFDyDFlQkb8Ox8FaDcm+M8PNkMyqnLA+qeGOLzY7Rjj9izl1Ww==} + cpu: [x64] + os: [android] + + '@pnpm/exe.darwin-arm64@12.5.1': + resolution: {integrity: sha512-r1vEMQPVjRexZMyL2HonxJoo3+nuB/+G+tg+f2PK6faRdXX1TDwevKXOxJAfqlPInTy6W/pm912+s+m0NcR4BQ==} + cpu: [arm64] + os: [darwin] + + '@pnpm/exe.darwin-x64@12.5.1': + resolution: {integrity: sha512-YHwI1g2B+Y2cAEylOR31r781GWijdJL7Gy7TEn/ZpZ5v/Cuwp5/Pz0EFCgo0M2MKLafAbL/laUMGvOpAdnerAw==} + cpu: [x64] + os: [darwin] + + '@pnpm/exe.freebsd-x64@12.5.1': + resolution: {integrity: sha512-sFUMHiYFs6q5syFwgaVppzhQSmqnXoJIz/YwTXIOXTDE76ndIpTRpDGAnBCBKjsaEBnqjJA/2l6hpJcNDNoMiA==} + cpu: [x64] + os: [freebsd] + + '@pnpm/exe.linux-arm64-musl@12.5.1': + resolution: {integrity: sha512-zupuxYZBuBEGjUz805/4/Asq01UNziFADANt8yp+LdUjU9bbMa3xY78Bx1PsGDqBy7aiad4sdUMK8ZxH4n4gmQ==} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@pnpm/exe.linux-arm64@12.5.1': + resolution: {integrity: sha512-6hbMWW2/eQo1b5wvQPe/ndLHVTH88Rav6N+ffD4/h6IuFMjWCgasFYYsFv0GrvpqREAx3SwmZSvli+0NFXqbxA==} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-ppc64@12.5.1': + resolution: {integrity: sha512-Gg3maDzaE/ZFMV9HIx/BwMN0Y6QbEs13URfxmiYHtKjjLAs5wEQZRMUP87YNLYO7cNaEfbM8GRbS9vPosyD9Gw==} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-riscv64@12.5.1': + resolution: {integrity: sha512-6fgWxXYMBMsWQ8DAiRevscX4QZQjwh+FsyCj8ZOk8pMXvqeq84MqBLCmS6KckvnbdqJ+HlSVQ7fs/kd0ldwfhA==} + cpu: [riscv64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-s390x@12.5.1': + resolution: {integrity: sha512-nzMZruRvxDhEfYUhzu+7EmM39+82Dgagc/6hPFPqGqzXNGcIG0anuxbUxfeNtI64SHt91KuuYUmCB/inlM+Pag==} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-x64-musl@12.5.1': + resolution: {integrity: sha512-kHCbegdTNHpzmPtUD4S5fqkVkqgdQR47spF9p2VPP3dIIkZl6Ytk8w0vhlAsAGgge8FmucfwX+vvPKgm0NtOCQ==} + cpu: [x64] + os: [linux] + libc: [musl] + + '@pnpm/exe.linux-x64@12.5.1': + resolution: {integrity: sha512-3PkUBYo5z4dgtlnTNIFj7QGpcDUAuqXz9WGVigPDCeccEnhGiRkWmA5102TmYJHtwJP3LfmE+ZF9PGeWhn8p9Q==} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.win32-arm64@12.5.1': + resolution: {integrity: sha512-49NvjZIXHly56/PLoEDD7VphbO4N8dwMXoApElDFCpVGDNGeKlwlib1tXtnpTF6i2/XIsAj7GgatHB5KHXgBnA==} + cpu: [arm64] + os: [win32] + + '@pnpm/exe.win32-x64@12.5.1': + resolution: {integrity: sha512-ePUmQFPAPJFNMwg1lelDx2PdjHqYRiF0yfg5e6qeDbPNOu97QNo557Ru/SxmCrmt8ydQWNuZXWpdEp019md5vw==} + cpu: [x64] + os: [win32] + + pnpm@12.5.1: + resolution: {integrity: sha512-4/MFvHhKK8ifWtO2E4iJRw+ujSr182thIW7JHCw9ZAiXdfneOKrDMQROpA8kXLDVZmOS399lgk4ZB+9qLGLeXw==} + engines: {node: '>=18.*'} + hasBin: true + +snapshots: + + '@pnpm/exe.android-arm64@12.5.1': + optional: true + + '@pnpm/exe.android-x64@12.5.1': + optional: true + + '@pnpm/exe.darwin-arm64@12.5.1': + optional: true + + '@pnpm/exe.darwin-x64@12.5.1': + optional: true + + '@pnpm/exe.freebsd-x64@12.5.1': + optional: true + + '@pnpm/exe.linux-arm64-musl@12.5.1': + optional: true + + '@pnpm/exe.linux-arm64@12.5.1': + optional: true + + '@pnpm/exe.linux-ppc64@12.5.1': + optional: true + + '@pnpm/exe.linux-riscv64@12.5.1': + optional: true + + '@pnpm/exe.linux-s390x@12.5.1': + optional: true + + '@pnpm/exe.linux-x64-musl@12.5.1': + optional: true + + '@pnpm/exe.linux-x64@12.5.1': + optional: true + + '@pnpm/exe.win32-arm64@12.5.1': + optional: true + + '@pnpm/exe.win32-x64@12.5.1': + optional: true + + pnpm@12.5.1: + optionalDependencies: + '@pnpm/exe.android-arm64': 12.5.1 + '@pnpm/exe.android-x64': 12.5.1 + '@pnpm/exe.darwin-arm64': 12.5.1 + '@pnpm/exe.darwin-x64': 12.5.1 + '@pnpm/exe.freebsd-x64': 12.5.1 + '@pnpm/exe.linux-arm64': 12.5.1 + '@pnpm/exe.linux-arm64-musl': 12.5.1 + '@pnpm/exe.linux-ppc64': 12.5.1 + '@pnpm/exe.linux-riscv64': 12.5.1 + '@pnpm/exe.linux-s390x': 12.5.1 + '@pnpm/exe.linux-x64': 12.5.1 + '@pnpm/exe.linux-x64-musl': 12.5.1 + '@pnpm/exe.win32-arm64': 12.5.1 + '@pnpm/exe.win32-x64': 12.5.1 + +--- lockfileVersion: '9.0' settings: @@ -6611,4 +6769,4 @@ snapshots: yocto-queue@1.2.2: {} - zimmerframe@1.1.5: {} \ No newline at end of file + zimmerframe@1.1.5: {} From d9e76d1eea45ebb0b528f83656866e9e7b25b556 Mon Sep 17 00:00:00 2001 From: LJM12914 Date: Wed, 18 Nov 2026 17:05:43 +0800 Subject: [PATCH 5/5] test: create the test root before making session folders A fresh checkout has no .local folder, so the feed tests failed in CI. Co-Authored-By: Claude Opus 5.5 --- tests/support/session.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/support/session.ts b/tests/support/session.ts index 8f8162c..32d33b3 100644 --- a/tests/support/session.ts +++ b/tests/support/session.ts @@ -1,4 +1,4 @@ -import { mkdtempSync } from "node:fs"; +import { mkdirSync, mkdtempSync } from "node:fs"; import { join } from "node:path"; import * as session from "../../main/session"; import * as state from "../../main/workspace-state"; @@ -32,6 +32,7 @@ export function openWorkspace(path: string, expectedId?: string, input?: Session export function openTest(t: TestContext, input: SessionOptions = {}): ReturnType { const root = process.env.LABLOOM_TEST_ROOT ?? join(process.cwd(), ".local"); options = input; + mkdirSync(root, { recursive: true }); const workspace = session.open(mkdtempSync(join(root, "session-test-")), "create", options); t.after(() => session.close()); return workspace;