mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
src/next is src (the main export), src/next-node is src/node with short subpaths (/http, /workers, /plugins, /plugins/runtime, /app, /surfaces, /web, /react, /tui, /tui/launcher); the foundations get /json and /watch; Chord v1 moves to src/old (/old, /old/node) until p2 runs on v2; tests and docs move likewise (test/, docs/, test/old, docs/old). Durable and env import the foundations from their subpaths.
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
// Tests of the data directory's layout (slice 13 §4): the directories made (the data directory 0700), the default
|
|
// data directory, and worker directories: one directory name per address key, distinct even on a case-insensitive
|
|
// file system, never leaving `workers/<kind>/`.
|
|
|
|
import { readdir, stat } from "node:fs/promises";
|
|
import { homedir } from "node:os";
|
|
import { basename, dirname, join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { hostKind, str } from "../../../src/contracts/index.ts";
|
|
import { createLayout, defaultDataDir, workerDirectory } from "../../../src/node/app/layout.ts";
|
|
import { tempDir } from "./support.ts";
|
|
|
|
const Doc = hostKind("doc", { id: str() });
|
|
|
|
describe("the data directory", () => {
|
|
it("makes the layout's directories, the data directory with mode 0700", async () => {
|
|
const dataDir = join(await tempDir(), "data");
|
|
const layout = await createLayout(dataDir);
|
|
expect((await readdir(dataDir)).sort()).toEqual(["logs", "plugins", "server", "workers"]);
|
|
expect((await stat(dataDir)).mode & 0o777).toBe(0o700);
|
|
expect([layout.serverStore, layout.ownerToken, layout.cookieSecret]).toEqual([
|
|
join(dataDir, "server", "store.sqlite"),
|
|
join(dataDir, "owner-token"),
|
|
join(dataDir, "server", "cookie-secret"),
|
|
]);
|
|
expect(defaultDataDir("acme")).toBe(join(homedir(), ".acme"));
|
|
});
|
|
});
|
|
|
|
describe("worker directories", () => {
|
|
it("encodes an address key as one directory name under its kind", () => {
|
|
const dir = workerDirectory("/data", Doc({ id: "../../etc/x" }));
|
|
expect(dirname(dir)).toBe("/data/workers/doc");
|
|
expect(basename(dir)).toBe("doc%7C%2E%2E%2F%2E%2E%2Fetc%2Fx");
|
|
expect(basename(workerDirectory("/data", Doc({ id: "." })))).toBe("doc%7C%2E");
|
|
});
|
|
|
|
it("keeps keys differing only in case apart, lowercased as a case-insensitive file system sees them", () => {
|
|
const names = ["a", "A", "%41", "%2541"].map((id) => basename(workerDirectory("/data", Doc({ id }))));
|
|
expect(new Set(names.map((name) => name.toLowerCase())).size).toBe(4);
|
|
});
|
|
|
|
it("names a long key by its hash", () => {
|
|
const name = basename(workerDirectory("/data", Doc({ id: "x".repeat(200) })));
|
|
expect(name).toMatch(/^sha256-[0-9a-f]{64}$/);
|
|
});
|
|
});
|