Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  state-migrations.fs.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { withTempDir } from "../test-helpers/temp-dir.js";
import {
  ensureDir,
  existsDir,
  fileExists,
  isLegacyWhatsAppAuthFile,
  readSessionStoreJson5,
  safeReadDir,
} from "./state-migrations.fs.js";

describe("state migration fs helpers", () => {
  it("reads directories safely and creates missing directories", async () => {
    await withTempDir({ prefix: "openclaw-state-migrations-fs-" }, async (base) => {
      const nested = path.join(base, "nested");

      expect(safeReadDir(nested)).toEqual([]);
      ensureDir(nested);
      fs.writeFileSync(path.join(nested, "file.txt"), "ok", "utf8");

      expect(safeReadDir(nested).map((entry) => entry.name)).toEqual(["file.txt"]);
      expect(existsDir(nested)).toBe(true);
      expect(existsDir(path.join(nested, "file.txt"))).toBe(false);
    });
  });

  it("distinguishes files from directories", async () => {
    await withTempDir({ prefix: "openclaw-state-migrations-fs-" }, async (base) => {
      const filePath = path.join(base, "store.json");
      const dirPath = path.join(base, "dir");
      fs.writeFileSync(filePath, "{}", "utf8");
      fs.mkdirSync(dirPath);

      expect(fileExists(filePath)).toBe(true);
      expect(fileExists(dirPath)).toBe(false);
      expect(fileExists(path.join(base, "missing.json"))).toBe(false);
    });
  });

  it("recognizes legacy whatsapp auth file names", () => {
    expect(isLegacyWhatsAppAuthFile("creds.json")).toBe(true);
    expect(isLegacyWhatsAppAuthFile("creds.json.bak")).toBe(true);
    expect(isLegacyWhatsAppAuthFile("session-123.json")).toBe(true);
    expect(isLegacyWhatsAppAuthFile("pre-key-1.json")).toBe(true);
    expect(isLegacyWhatsAppAuthFile("sender-key-1.txt")).toBe(false);
    expect(isLegacyWhatsAppAuthFile("other.json")).toBe(false);
  });

  it("parses json5 session stores and rejects invalid shapes", async () => {
    await withTempDir({ prefix: "openclaw-state-migrations-fs-" }, async (base) => {
      const okPath = path.join(base, "store.json");
      const badPath = path.join(base, "bad.json");
      const listPath = path.join(base, "list.json");

      fs.writeFileSync(okPath, "{session: {sessionId: 'abc', updatedAt: 1}}", "utf8");
      fs.writeFileSync(badPath, "{not valid", "utf8");
      fs.writeFileSync(listPath, "[]", "utf8");

      expect(readSessionStoreJson5(okPath)).toEqual({
        ok: true,
        store: {
          session: {
            sessionId: "abc",
            updatedAt: 1,
          },
        },
      });
      expect(readSessionStoreJson5(badPath)).toEqual({ ok: false, store: {} });
      expect(readSessionStoreJson5(listPath)).toEqual({ ok: false, store: {} });
    });
  });
});

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge