/
raiden
/
obsidian-git-encrypt
Обзор
Документация
Войти
/
raiden
/
obsidian-git-encrypt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/sourceControl/changeStatus.test.ts
61 строка
2 KB
Robert Kuzhin
fix: clear staging after manual revert
10 авг 2026, 07:35
10 авг 2026, 07:35
1de1382
Код
Авторство
О чём код?
import { describe, expect, it } from "vitest"; import type { Manifest, ManifestEntry } from "../../src/mirror/index.js"; import { planSourceChanges } from "../../src/sourceControl/index.js"; const vaultId = "11111111-1111-4111-8111-111111111111"; const fileId = "22222222-2222-4222-8222-222222222222"; describe("source control change status", () => { it("reports additions, modifications, renames, and deletions by stable identity", () => { const baseEntry = entry({ path: "Old.md", plaintextHash: hash("a"), objectVersion: 1 }); const base = manifest({ [fileId]: baseEntry }); expect(planSourceChanges(manifest({}), { [fileId]: baseEntry })).toEqual([ expect.objectContaining({ fileId, kind: "added", path: "Old.md" }), ]); expect(planSourceChanges(base, { [fileId]: entry({ path: "Old.md", plaintextHash: hash("b"), objectVersion: 2 }), })).toEqual([expect.objectContaining({ kind: "modified" })]); expect(planSourceChanges(base, { [fileId]: entry({ path: "New.md", plaintextHash: hash("a"), objectVersion: 1 }), })).toEqual([expect.objectContaining({ kind: "renamed", oldPath: "Old.md", path: "New.md" })]); expect(planSourceChanges(base, { [fileId]: { ...baseEntry, deleted: true } })).toEqual([ expect.objectContaining({ kind: "deleted", path: "Old.md" }), ]); }); it("does not report tombstones that were never committed", () => { expect(planSourceChanges(manifest({}), { [fileId]: { ...entry({}), deleted: true }, })).toEqual([]); }); it("ignores encryption version and filesystem time when content matches", () => { const committed = entry({ objectVersion: 1, modifiedAt: 100 }); const reencrypted = entry({ objectVersion: 3, modifiedAt: 900 }); expect(planSourceChanges(manifest({ [fileId]: committed }), { [fileId]: reencrypted, })).toEqual([]); }); }); function manifest(files: Record<string, ManifestEntry>): Manifest { return { formatVersion: 1, vaultId, revision: 0, files }; } function entry(overrides: Partial<ManifestEntry> = {}): ManifestEntry { return { fileId, path: "Note.md", plaintextHash: hash("0"), objectVersion: 1, size: 1, modifiedAt: 1, ...overrides, }; } function hash(character: string): `sha256:${string}` { return `sha256:${character.repeat(64)}`; }